SOLR-9209,SOLR-9256: extracting

JdbcDataSource.createResultSetIterator(), adding a test for
ResultSetIterator.hasNext()
This commit is contained in:
Mikhail Khludnev 2016-08-02 14:45:37 +03:00
parent d9df295bb7
commit 209bfcf021
3 changed files with 48 additions and 1 deletions

View File

@ -221,6 +221,10 @@ Other Changes
* SOLR-9358: [AngularUI] In Cloud->Tree file view area, collapse metadata by default (janhoy) * 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 ================== ================== 6.1.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release. Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

View File

@ -280,10 +280,14 @@ public class JdbcDataSource extends
resultSetIterator.close(); resultSetIterator.close();
resultSetIterator = null; resultSetIterator = null;
} }
resultSetIterator = new ResultSetIterator(query); resultSetIterator = createResultSetIterator(query);
return resultSetIterator.getIterator(); return resultSetIterator.getIterator();
} }
protected ResultSetIterator createResultSetIterator(String query) {
return new ResultSetIterator(query);
}
private void logError(String msg, Exception e) { private void logError(String msg, Exception e) {
LOG.warn(msg, e); LOG.warn(msg, e);
} }

View File

@ -510,6 +510,45 @@ public class TestJdbcDataSource extends AbstractDataImportHandlerTestCase {
DriverManager.deregisterDriver(driver); 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 @Test
@Ignore("Needs a Mock database server to work") @Ignore("Needs a Mock database server to work")
public void testBasic() throws Exception { public void testBasic() throws Exception {