use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.
the class ColumnStrategyContextTests method testWriteLastRunTime.
@Test
@Parameters({ "existedWhereClause" })
@SuppressWarnings("unchecked")
public void testWriteLastRunTime(String resource) throws Exception {
Settings settings = createSettings(resource);
context = newContext();
MockJDBCSource source = new MockJDBCSource() {
@Override
public void fetch() {
}
};
MockSink mockSink = new MockSink();
context.setSettings(settings).setSink(mockSink).setSource(source);
//mockSink.setIngestFactory(createIngestFactory(settings));
context.execute();
assertNotNull(context.getLastRunTimestamp());
}
use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.
the class ColumnStrategySourceTests method testCreateObjects_withLastRunTimeStampOverlap.
@Test
@Parameters({ "existedWhereClauseWithOverlap", "sqlInsert" })
public void testCreateObjects_withLastRunTimeStampOverlap(String resource, String sql) throws Exception {
final int newRecordsOutOfTimeRange = 3;
final int newRecordsInTimeRange = 2;
final int updatedRecordsInTimeRange = 4;
final int updatedRecordsInTimeRangeWithOverlap = 1;
testColumnStrategy(new MockSink(), resource, sql, new ProductFixture[] { ProductFixture.size(newRecordsOutOfTimeRange).createdAt(oldTimestamp()), ProductFixture.size(newRecordsInTimeRange).createdAt(okTimestamp()), ProductFixture.size(updatedRecordsInTimeRange).createdAt(oldTimestamp()).updatedAt(okTimestamp()), ProductFixture.size(updatedRecordsInTimeRangeWithOverlap).createdAt(oldTimestamp()).updatedAt(overlapTimestamp()) }, newRecordsInTimeRange + updatedRecordsInTimeRange + updatedRecordsInTimeRangeWithOverlap);
}
use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.
the class ColumnStrategySourceTests method verifyCreateObjects.
private void verifyCreateObjects(String resource, String sql) throws Exception {
final int newRecordsOutOfTimeRange = 3;
final int newRecordsInTimeRange = 2;
final int updatedRecordsInTimeRange = 4;
testColumnStrategy(new MockSink(), resource, sql, new ProductFixture[] { new ProductFixture(newRecordsOutOfTimeRange).createdAt(oldTimestamp()), new ProductFixture(newRecordsInTimeRange).createdAt(okTimestamp()), new ProductFixture(updatedRecordsInTimeRange).createdAt(oldTimestamp()).updatedAt(okTimestamp()) }, newRecordsInTimeRange + updatedRecordsInTimeRange);
}
use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.
the class StandardSourceTests method testSimpleStarQuery.
@Test
@Parameters({ "sql2", "n" })
public void testSimpleStarQuery(String sql, @Optional Integer n) throws Exception {
List<Object> params = new LinkedList<Object>();
Sink output = new MockSink() {
@Override
public void index(IndexableObject object, boolean create) throws IOException {
logger.debug("object={}", object);
}
};
PreparedStatement statement = source.prepareQuery(sql);
source.bind(statement, params);
ResultSet results = source.executeQuery(statement);
StringKeyValueStreamListener listener = new StringKeyValueStreamListener().output(output);
long rows = 0L;
source.beforeRows(results, listener);
while (source.nextRow(results, listener)) {
rows++;
}
source.afterRows(results, listener);
assertEquals(rows, n == null ? 5 : n);
source.close(results);
source.close(statement);
}
use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink 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