Apache Solr open-source search software
SOLR-8527: Improve JdbcTest to cleanup properly on failures
jbernste56b79ece8b3c
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 639c08c9fb9..bc7b39affca 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -167,6 +167,8 @@ Bug Fixes* SOLR-8461: CloudSolrStream and ParallelStream can choose replicas that are not active(Cao Manh Dat, Varun Thacker, Joel Bernstein)+* SOLR-8527: Improve JdbcTest to cleanup properly on failures (Kevin Risden, Joel Bernstein)+Optimizations----------------------* SOLR-7876: Speed up queries and operations that use many terms when timeAllowed has not been@@ -244,6 +246,7 @@ Other Changes* SOLR-8190: Implement Closeable on TupleStream (Kevin Risden, Joel Bernstein)+======================= 5.6.0 =======================(No Changes)diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.javaindex 6d9c51acfc4..e8c0c50e8fd 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java@@ -111,208 +111,213 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {String zkHost = zkServer.getZkAddress();Properties props = new Properties();- Connection con = DriverManager.getConnection("jdbc:solr://" + zkHost + "?collection=collection1", props);- Statement stmt = con.createStatement();- ResultSet rs = stmt.executeQuery("select id, a_i, a_s, a_f from collection1 order by a_i desc limit 2");- assertTrue(rs.getMetaData() != null);-- assert(rs.next());- assert(rs.getLong("a_i") == 14);- assert(rs.getLong(2) == 14);- assert(rs.getString("a_s").equals("hello0"));- assert(rs.getString(3).equals("hello0"));- assert(rs.getDouble("a_f") == 10);- assert(rs.getDouble(4) == 10);-- assert(rs.next());- assert(rs.getLong("a_i") == 13);- assert(rs.getLong(2) == 13);- assert(rs.getString("a_s").equals("hello3"));- assert(rs.getString(3).equals("hello3"));- assert(rs.getDouble("a_f") == 9);- assert(rs.getDouble(4) == 9);- assert(!rs.next());- stmt.close();-- //Test statement reuse- rs = stmt.executeQuery("select id, a_i, a_s, a_f from collection1 order by a_i asc limit 2");- assert(rs.next());- assert(rs.getLong("a_i") == 0);- assert(rs.getLong(2) == 0);- assert(rs.getString("a_s").equals("hello0"));- assert(rs.getString(3).equals("hello0"));- assert(rs.getDouble("a_f") == 1);- assert(rs.getDouble(4) == 1);-- assert(rs.next());- assert(rs.getLong("a_i") == 1);- assert(rs.getLong(2) == 1);- assert(rs.getString("a_s").equals("hello0"));- assert(rs.getString(3).equals("hello0"));- assert(rs.getDouble("a_f") == 5);- assert(rs.getDouble(4) == 5);- assert(!rs.next());- stmt.close();-- //Test connection reuse- stmt = con.createStatement();- rs = stmt.executeQuery("select id, a_i, a_s, a_f from collection1 order by a_i desc limit 2");- assert(rs.next());- assert(rs.getLong("a_i") == 14);- assert(rs.getLong(2) == 14);- assert(rs.next());- assert(rs.getLong("a_i") == 13);- assert(rs.getLong(2) == 13);- stmt.close();-- //Test statement reuse- stmt.setMaxRows(2);- rs = stmt.executeQuery("select id, a_i, a_s, a_f from collection1 order by a_i asc");- assert(rs.next());- assert(rs.getLong("a_i") == 0);- assert(rs.getLong(2) == 0);- assert(rs.next());- assert(rs.getLong("a_i") == 1);- assert(rs.getLong(2) == 1);- assert(!rs.next());- stmt.close();-- //Test simple loop. Since limit is set it will override the statement maxRows.- rs = stmt.executeQuery("select id, a_i, a_s, a_f from collection1 order by a_i asc LIMIT 100");- int count = 0;- while(rs.next()) {- ++count;- }-- assert(count == 10);-- stmt.close();- con.close();- //Test facet aggregation- props = new Properties();- props.put("aggregationMode", "facet");- con = DriverManager.getConnection("jdbc:solr://" + zkHost + "?collection=collection1", props);- stmt = con.createStatement();- rs = stmt.executeQuery("select a_s, sum(a_f) from collection1 group by a_s order by sum(a_f) desc");-- assert(rs.next());- assert(rs.getString("a_s").equals("hello3"));- assert(rs.getString(1).equals("hello3"));- assert(rs.getDouble("sum(a_f)") == 26);- assert(rs.getDouble(2) == 26);+ try (Connection con = DriverManager.getConnection("jdbc:solr://" + zkHost + "?collection=collection1", props)) {+ try (Statement stmt = con.createStatement()) {+ try (ResultSet rs = stmt.executeQuery("select id, a_i, a_s, a_f from collection1 order by a_i desc limit 2")) {+ assertTrue(rs.getMetaData() != null);++ assert(rs.next());+ assert(rs.getLong("a_i") == 14);+ assert(rs.getLong(2) == 14);+ assert(rs.getString("a_s").equals("hello0"));+ assert(rs.getString(3).equals("hello0"));+ assert(rs.getDouble("a_f") == 10);+ assert(rs.getDouble(4) == 10);++ assert(rs.next());+ assert(rs.getLong("a_i") == 13);+ assert(rs.getLong(2) == 13);+ assert(rs.getString("a_s").equals("hello3"));+ assert(rs.getString(3).equals("hello3"));+ assert(rs.getDouble("a_f") == 9);+ assert(rs.getDouble(4) == 9);+ assert(!rs.next());+ }+ //Test statement reuse+ try (ResultSet rs = stmt.executeQuery("select id, a_i, a_s, a_f from collection1 order by a_i asc limit 2")) {+ assert(rs.next());+ assert(rs.getLong("a_i") == 0);+ assert(rs.getLong(2) == 0);+ assert(rs.getString("a_s").equals("hello0"));+ assert(rs.getString(3).equals("hello0"));+ assert(rs.getDouble("a_f") == 1);+ assert(rs.getDouble(4) == 1);++ assert(rs.next());+ assert(rs.getLong("a_i") == 1);+ assert(rs.getLong(2) == 1);+ assert(rs.getString("a_s").equals("hello0"));+ assert(rs.getString(3).equals("hello0"));+ assert(rs.getDouble("a_f") == 5);+ assert(rs.getDouble(4) == 5);+ assert(!rs.next());+ }+ }- assert(rs.next());- assert(rs.getString("a_s").equals("hello0"));- assert(rs.getString(1).equals("hello0"));- assert(rs.getDouble("sum(a_f)") == 18);- assert(rs.getDouble(2) == 18);+ //Test connection reuse+ try (Statement stmt = con.createStatement()) {+ try (ResultSet rs = stmt.executeQuery("select id, a_i, a_s, a_f from collection1 order by a_i desc limit 2")) {+ assert(rs.next());+ assert(rs.getLong("a_i") == 14);+ assert(rs.getLong(2) == 14);+ assert(rs.next());+ assert(rs.getLong("a_i") == 13);+ assert(rs.getLong(2) == 13);+ }+ //Test statement reuse+ stmt.setMaxRows(2);+ try (ResultSet rs = stmt.executeQuery("select id, a_i, a_s, a_f from collection1 order by a_i asc")) {+ assert(rs.next());+ assert(rs.getLong("a_i") == 0);+ assert(rs.getLong(2) == 0);+ assert(rs.next());+ assert(rs.getLong("a_i") == 1);+ assert(rs.getLong(2) == 1);+ assert(!rs.next());+ }- assert(rs.next());- assert(rs.getString("a_s").equals("hello4"));- assert(rs.getString(1).equals("hello4"));- assert(rs.getDouble("sum(a_f)") == 11);- assert(rs.getDouble(2) == 11);+ //Test simple loop. Since limit is set it will override the statement maxRows.+ try (ResultSet rs = stmt.executeQuery("select id, a_i, a_s, a_f from collection1 order by a_i asc LIMIT 100")) {+ int count = 0;+ while (rs.next()) {+ ++count;+ }+ assert(count == 10);+ }+ }+ }- stmt.close();- con.close();+ //Test facet aggregation+ props = new Properties();+ props.put("aggregationMode", "facet");+ try (Connection con = DriverManager.getConnection("jdbc:solr://" + zkHost + "?collection=collection1", props)) {+ try (Statement stmt = con.createStatement()) {+ try (ResultSet rs = stmt.executeQuery("select a_s, sum(a_f) from collection1 group by a_s " ++ "order by sum(a_f) desc")) {++ assert(rs.next());+ assert(rs.getString("a_s").equals("hello3"));+ assert(rs.getString(1).equals("hello3"));+ assert(rs.getDouble("sum(a_f)") == 26);+ assert(rs.getDouble(2) == 26);+++ assert(rs.next());+ assert(rs.getString("a_s").equals("hello0"));+ assert(rs.getString(1).equals("hello0"));+ assert(rs.getDouble("sum(a_f)") == 18);+ assert(rs.getDouble(2) == 18);++ assert(rs.next());+ assert(rs.getString("a_s").equals("hello4"));+ assert(rs.getString(1).equals("hello4"));+ assert(rs.getDouble("sum(a_f)") == 11);+ assert(rs.getDouble(2) == 11);+ }+ }+ }//Test map / reduce aggregationprops = new Properties();props.put("aggregationMode", "map_reduce");props.put("numWorkers", "2");- con = DriverManager.getConnection("jdbc:solr://" + zkHost + "?collection=collection1", props);- stmt = con.createStatement();- rs = stmt.executeQuery("select a_s, sum(a_f) from collection1 group by a_s order by sum(a_f) desc");-- assert(rs.next());- assert(rs.getString("a_s").equals("hello3"));- assert(rs.getString(1).equals("hello3"));- assert(rs.getDouble("sum(a_f)") == 26);- assert(rs.getDouble(2) == 26);-- assert(rs.next());- assert(rs.getString("a_s").equals("hello0"));- assert(rs.getString(1).equals("hello0"));- assert(rs.getDouble("sum(a_f)") == 18);- assert(rs.getDouble(2) == 18);-- assert(rs.next());- assert(rs.getString("a_s").equals("hello4"));- assert(rs.getString(1).equals("hello4"));- assert(rs.getDouble("sum(a_f)") == 11);- assert(rs.getDouble(2) == 11);-- stmt.close();- con.close();-+ try (Connection con = DriverManager.getConnection("jdbc:solr://" + zkHost + "?collection=collection1", props)) {+ try (Statement stmt = con.createStatement()) {+ try (ResultSet rs = stmt.executeQuery("select a_s, sum(a_f) from collection1 group by a_s " ++ "order by sum(a_f) desc")) {++ assert(rs.next());+ assert(rs.getString("a_s").equals("hello3"));+ assert(rs.getString(1).equals("hello3"));+ assert(rs.getDouble("sum(a_f)") == 26);+ assert(rs.getDouble(2) == 26);++ assert(rs.next());+ assert(rs.getString("a_s").equals("hello0"));+ assert(rs.getString(1).equals("hello0"));+ assert(rs.getDouble("sum(a_f)") == 18);+ assert(rs.getDouble(2) == 18);++ assert(rs.next());+ assert(rs.getString("a_s").equals("hello4"));+ assert(rs.getString(1).equals("hello4"));+ assert(rs.getDouble("sum(a_f)") == 11);+ assert(rs.getDouble(2) == 11);+ }+ }+ }+//Test params on the url- con = DriverManager.getConnection("jdbc:solr://" + zkHost + "?collection=collection1&aggregationMode=map_reduce&numWorkers=2");-- Properties p = ((ConnectionImpl) con).getProperties();-- assert(p.getProperty("aggregationMode").equals("map_reduce"));- assert(p.getProperty("numWorkers").equals("2"));-- stmt = con.createStatement();- rs = stmt.executeQuery("select a_s, sum(a_f) from collection1 group by a_s order by sum(a_f) desc");-- assert(rs.next());- assert(rs.getString("a_s").equals("hello3"));- assert(rs.getString(1).equals("hello3"));- assert(rs.getDouble("sum(a_f)") == 26);- assert(rs.getDouble(2) == 26);-- assert(rs.next());- assert(rs.getString("a_s").equals("hello0"));- assert(rs.getString(1).equals("hello0"));- assert(rs.getDouble("sum(a_f)") == 18);- assert(rs.getDouble(2) == 18);-- assert(rs.next());- assert(rs.getString("a_s").equals("hello4"));- assert(rs.getString(1).equals("hello4"));- assert(rs.getDouble("sum(a_f)") == 11);- assert(rs.getDouble(2) == 11);-- stmt.close();- con.close();+ try (Connection con = DriverManager.getConnection("jdbc:solr://" + zkHost ++ "?collection=collection1&aggregationMode=map_reduce&numWorkers=2")) {++ Properties p = ((ConnectionImpl) con).getProperties();++ assert(p.getProperty("aggregationMode").equals("map_reduce"));+ assert(p.getProperty("numWorkers").equals("2"));++ try (Statement stmt = con.createStatement()) {+ try (ResultSet rs = stmt.executeQuery("select a_s, sum(a_f) from collection1 group by a_s " ++ "order by sum(a_f) desc")) {++ assert(rs.next());+ assert(rs.getString("a_s").equals("hello3"));+ assert(rs.getString(1).equals("hello3"));+ assert(rs.getDouble("sum(a_f)") == 26);+ assert(rs.getDouble(2) == 26);++ assert(rs.next());+ assert(rs.getString("a_s").equals("hello0"));+ assert(rs.getString(1).equals("hello0"));+ assert(rs.getDouble("sum(a_f)") == 18);+ assert(rs.getDouble(2) == 18);++ assert(rs.next());+ assert(rs.getString("a_s").equals("hello4"));+ assert(rs.getString(1).equals("hello4"));+ assert(rs.getDouble("sum(a_f)") == 11);+ assert(rs.getDouble(2) == 11);+ }+ }+ }// Test JDBC paramters in URL- con = DriverManager.getConnection(- "jdbc:solr://" + zkHost + "?collection=collection1&username=&password=&testKey1=testValue&testKey2");-- p = ((ConnectionImpl) con).getProperties();- assert(p.getProperty("username").equals(""));- assert(p.getProperty("password").equals(""));- assert(p.getProperty("testKey1").equals("testValue"));- assert(p.getProperty("testKey2").equals(""));-- stmt = con.createStatement();- rs = stmt.executeQuery("select a_s, sum(a_f) from collection1 group by a_s order by sum(a_f) desc");-- assert(rs.next());- assert(rs.getString("a_s").equals("hello3"));- assert(rs.getString(1).equals("hello3"));- assert(rs.getDouble("sum(a_f)") == 26);- assert(rs.getDouble(2) == 26);-- assert(rs.next());- assert(rs.getString("a_s").equals("hello0"));- assert(rs.getString(1).equals("hello0"));- assert(rs.getDouble("sum(a_f)") == 18);- assert(rs.getDouble(2) == 18);-- assert(rs.next());- assert(rs.getString("a_s").equals("hello4"));- assert(rs.getString(1).equals("hello4"));- assert(rs.getDouble("sum(a_f)") == 11);- assert(rs.getDouble(2) == 11);-- stmt.close();- con.close();+ try (Connection con = DriverManager.getConnection(+ "jdbc:solr://" + zkHost + "?collection=collection1&username=&password=&testKey1=testValue&testKey2")) {++ Properties p = ((ConnectionImpl) con).getProperties();+ assert(p.getProperty("username").equals(""));+ assert(p.getProperty("password").equals(""));+ assert(p.getProperty("testKey1").equals("testValue"));+ assert(p.getProperty("testKey2").equals(""));++ try (Statement stmt = con.createStatement()) {+ try (ResultSet rs = stmt.executeQuery("select a_s, sum(a_f) from collection1 group by a_s " ++ "order by sum(a_f) desc")) {++ assert(rs.next());+ assert(rs.getString("a_s").equals("hello3"));+ assert(rs.getString(1).equals("hello3"));+ assert(rs.getDouble("sum(a_f)") == 26);+ assert(rs.getDouble(2) == 26);++ assert(rs.next());+ assert(rs.getString("a_s").equals("hello0"));+ assert(rs.getString(1).equals("hello0"));+ assert(rs.getDouble("sum(a_f)") == 18);+ assert(rs.getDouble(2) == 18);++ assert(rs.next());+ assert(rs.getString("a_s").equals("hello4"));+ assert(rs.getString(1).equals("hello4"));+ assert(rs.getDouble("sum(a_f)") == 11);+ assert(rs.getDouble(2) == 11);+ }+ }+ }// Test JDBC paramters in propertiesProperties providedProperties = new Properties();@@ -322,37 +327,37 @@ public class JdbcTest extends AbstractFullDistribZkTestBase {providedProperties.put("testKey1", "testValue");providedProperties.put("testKey2", "");- con = DriverManager.getConnection("jdbc:solr://" + zkHost, providedProperties);-- p = ((ConnectionImpl) con).getProperties();- assert(p.getProperty("username").equals(""));- assert(p.getProperty("password").equals(""));- assert(p.getProperty("testKey1").equals("testValue"));- assert(p.getProperty("testKey2").equals(""));-- stmt = con.createStatement();- rs = stmt.executeQuery("select a_s, sum(a_f) from collection1 group by a_s order by sum(a_f) desc");-- assert(rs.next());- assert(rs.getString("a_s").equals("hello3"));- assert(rs.getString(1).equals("hello3"));- assert(rs.getDouble("sum(a_f)") == 26);- assert(rs.getDouble(2) == 26);-- assert(rs.next());- assert(rs.getString("a_s").equals("hello0"));- assert(rs.getString(1).equals("hello0"));- assert(rs.getDouble("sum(a_f)") == 18);- assert(rs.getDouble(2) == 18);-- assert(rs.next());- assert(rs.getString("a_s").equals("hello4"));- assert(rs.getString(1).equals("hello4"));- assert(rs.getDouble("sum(a_f)") == 11);- assert(rs.getDouble(2) == 11);-- stmt.close();- con.close();+ try (Connection con = DriverManager.getConnection("jdbc:solr://" + zkHost, providedProperties)) {+ Properties p = ((ConnectionImpl) con).getProperties();+ assert(p.getProperty("username").equals(""));+ assert(p.getProperty("password").equals(""));+ assert(p.getProperty("testKey1").equals("testValue"));+ assert(p.getProperty("testKey2").equals(""));++ try (Statement stmt = con.createStatement()) {+ try (ResultSet rs = stmt.executeQuery("select a_s, sum(a_f) from collection1 group by a_s " ++ "order by sum(a_f) desc")) {++ assert(rs.next());+ assert(rs.getString("a_s").equals("hello3"));+ assert(rs.getString(1).equals("hello3"));+ assert(rs.getDouble("sum(a_f)") == 26);+ assert(rs.getDouble(2) == 26);++ assert(rs.next());+ assert(rs.getString("a_s").equals("hello0"));+ assert(rs.getString(1).equals("hello0"));+ assert(rs.getDouble("sum(a_f)") == 18);+ assert(rs.getDouble(2) == 18);++ assert(rs.next());+ assert(rs.getString("a_s").equals("hello4"));+ assert(rs.getString(1).equals("hello4"));+ assert(rs.getDouble("sum(a_f)") == 11);+ assert(rs.getDouble(2) == 11);+ }+ }+ }testDriverMetadata();}