use of org.xbib.elasticsearch.common.util.StringKeyValueStreamListener in project elasticsearch-jdbc by jprante.
the class MockTests method testMockHighBills.
@Test
@Parameters({ "sql3" })
public void testMockHighBills(String sql) throws Exception {
List<Object> params = new LinkedList<Object>();
params.add(2.00);
Sink output = new MockSink() {
@Override
public void index(IndexableObject object, boolean create) throws IOException {
logger.debug("sql3={}", object);
}
};
PreparedStatement statement = source.prepareQuery(sql);
source.bind(statement, params);
ResultSet results = source.executeQuery(statement);
KeyValueStreamListener listener = new StringKeyValueStreamListener().output(output);
source.beforeRows(results, listener);
long rows = 0L;
while (source.nextRow(results, listener)) {
rows++;
}
source.afterRows(results, listener);
assertEquals(rows, 2);
source.close(results);
source.close(statement);
}
use of org.xbib.elasticsearch.common.util.StringKeyValueStreamListener in project elasticsearch-jdbc by jprante.
the class MockTests method testMockDepartments.
@Test
@Parameters({ "sql2" })
public void testMockDepartments(String sql) throws Exception {
List<Object> params = new LinkedList<Object>();
Sink output = new MockSink() {
@Override
public void index(IndexableObject object, boolean create) throws IOException {
logger.debug("sql2 object={}", object);
}
};
PreparedStatement statement = source.prepareQuery(sql);
source.bind(statement, params);
ResultSet results = source.executeQuery(statement);
StringKeyValueStreamListener listener = new StringKeyValueStreamListener().output(output);
source.beforeRows(results, listener);
long rows = 0L;
while (source.nextRow(results, listener)) {
rows++;
}
source.afterRows(results, listener);
assertEquals(rows, 11);
source.close(results);
source.close(statement);
}
use of org.xbib.elasticsearch.common.util.StringKeyValueStreamListener in project elasticsearch-jdbc by jprante.
the class StandardSourceTests method testSimpleArray.
/**
* Test JDBC Array to structured object array
*
* @param sql the array select statement
* @throws Exception if test fails
*/
@Test
@Parameters({ "sql4", "res1", "res2" })
public void testSimpleArray(@Optional String sql, @Optional String res1, @Optional String res2) throws Exception {
if (sql == null) {
return;
}
List<Object> params = new LinkedList<Object>();
final List<IndexableObject> result = new LinkedList<IndexableObject>();
Sink sink = new MockSink() {
@Override
public void index(IndexableObject object, boolean create) throws IOException {
if (object == null || object.source() == null) {
throw new IllegalArgumentException("object missing");
}
result.add(object);
}
};
PreparedStatement statement = source.prepareQuery(sql);
source.bind(statement, params);
ResultSet results = source.executeQuery(statement);
StringKeyValueStreamListener listener = new StringKeyValueStreamListener().output(sink);
long rows = 0L;
source.beforeRows(results, listener);
while (source.nextRow(results, listener)) {
rows++;
}
source.afterRows(results, listener);
assertEquals(rows, 2);
source.close(results);
source.close(statement);
Iterator<IndexableObject> it = result.iterator();
assertEquals(it.next().source().toString(), res1);
assertEquals(it.next().source().toString(), res2);
}
Aggregations