lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject lucene-solr:branch_6x: SOLR-9209, SOLR-9256: extracting JdbcDataSource.createResultSetIterator(), adding a test for ResultSetIterator.hasNext()
Date Tue, 02 Aug 2016 12:15:23 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x 5ace3b430 -> 77409fd43


SOLR-9209,SOLR-9256: extracting
JdbcDataSource.createResultSetIterator(), adding a test for
ResultSetIterator.hasNext() 

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

Branch: refs/heads/branch_6x
Commit: 77409fd43264e57d1b65f5fee3b9c7277d2f740a
Parents: 5ace3b4
Author: Mikhail Khludnev <mkhl@apache.org>
Authored: Tue Aug 2 14:45:37 2016 +0300
Committer: Mikhail Khludnev <Mikhail_Khludnev@epam.com>
Committed: Tue Aug 2 15:12:17 2016 +0300

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  4 ++
 .../solr/handler/dataimport/JdbcDataSource.java |  6 ++-
 .../handler/dataimport/TestJdbcDataSource.java  | 39 ++++++++++++++++++++
 3 files changed, 48 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/77409fd4/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 8f0b0b5..c8ec8c7 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -187,6 +187,10 @@ Other Changes
 
 * SOLR-9358: [AngularUI] In Cloud->Tree file view area, collapse metadata by default (janhoy)
 
+* SOLR-9256: asserting hasNext() contract in JdbcDataSource in DataImportHandler (Kristine
Jetzke via Mikhai Khludnev)
+
+* SOLR-9209: extracting JdbcDataSource.createResultSetIterator() for extension (Kristine
Jetzke via Mikhai Khludnev)
+
 ==================  6.1.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/77409fd4/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/JdbcDataSource.java
----------------------------------------------------------------------
diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/JdbcDataSource.java
b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/JdbcDataSource.java
index 09ad775..ce8671a 100644
--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/JdbcDataSource.java
+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/JdbcDataSource.java
@@ -280,10 +280,14 @@ public class JdbcDataSource extends
       resultSetIterator.close();
       resultSetIterator = null;
     }
-    resultSetIterator = new ResultSetIterator(query);
+    resultSetIterator = createResultSetIterator(query);
     return resultSetIterator.getIterator();
   }
 
+  protected ResultSetIterator createResultSetIterator(String query) {
+    return new ResultSetIterator(query);
+  }
+
   private void logError(String msg, Exception e) {
     LOG.warn(msg, e);
   }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/77409fd4/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java
----------------------------------------------------------------------
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java
b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java
index b6d05c4..7853ad1 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestJdbcDataSource.java
@@ -510,6 +510,45 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase
{
       DriverManager.deregisterDriver(driver);
     }
   }
+  
+  
+  @Test
+  public void testEmptyResultSet() throws Exception {
+      MockInitialContextFactory.bind("java:comp/env/jdbc/JndiDB", dataSource);
+
+      props.put(JdbcDataSource.JNDI_NAME, "java:comp/env/jdbc/JndiDB");
+      EasyMock.expect(dataSource.getConnection()).andReturn(connection);
+
+      jdbcDataSource.init(context, props);
+
+      connection.setAutoCommit(false);
+
+      Statement statement = mockControl.createMock(Statement.class);
+      EasyMock.expect(connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY))
+          .andReturn(statement);
+      statement.setFetchSize(500);
+      statement.setMaxRows(0);
+      EasyMock.expect(statement.execute("query")).andReturn(true);
+      ResultSet resultSet = mockControl.createMock(ResultSet.class);
+      EasyMock.expect(statement.getResultSet()).andReturn(resultSet);
+      ResultSetMetaData metaData = mockControl.createMock(ResultSetMetaData.class);
+      EasyMock.expect(resultSet.getMetaData()).andReturn(metaData);
+      EasyMock.expect(metaData.getColumnCount()).andReturn(0);
+      EasyMock.expect(resultSet.next()).andReturn(false);
+      resultSet.close();
+      EasyMock.expect(statement.getMoreResults()).andReturn(false);
+      EasyMock.expect(statement.getUpdateCount()).andReturn(-1);
+      statement.close();
+
+      mockControl.replay();
+
+      Iterator<Map<String,Object>> resultSetIterator = jdbcDataSource.getData("query");
+      resultSetIterator.hasNext();
+      resultSetIterator.hasNext();
+
+      mockControl.verify();
+  }
+  
   @Test
   @Ignore("Needs a Mock database server to work")
   public void testBasic() throws Exception {


Mime
View raw message