You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jb...@apache.org on 2016/02/11 19:10:39 UTC

lucene-solr git commit: SOLR-8527: Improve JdbcTest to cleanup properly on failures

Repository: lucene-solr
Updated Branches:
  refs/heads/master b2e47984f -> 56b79ece8


SOLR-8527: Improve JdbcTest to cleanup properly on failures


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/56b79ece
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/56b79ece
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/56b79ece

Branch: refs/heads/master
Commit: 56b79ece8b3c670b936792759aed9d0bb5e3eb7f
Parents: b2e4798
Author: jbernste <jb...@apache.org>
Authored: Thu Feb 11 13:14:48 2016 -0500
Committer: jbernste <jb...@apache.org>
Committed: Thu Feb 11 13:15:29 2016 -0500

----------------------------------------------------------------------
 solr/CHANGES.txt                                |   3 +
 .../solr/client/solrj/io/sql/JdbcTest.java      | 443 ++++++++++---------
 2 files changed, 227 insertions(+), 219 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/56b79ece/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 639c08c..bc7b39a 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)
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/56b79ece/solr/solrj/src/test/org/apache/solr/client/solrj/io/sql/JdbcTest.java
----------------------------------------------------------------------
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.java
index 6d9c51a..e8c0c50 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 aggregation
     props = 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 properties
     Properties 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();
   }