use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.
the class ValueListenerTests method testSequenceValues.
@Test
public void testSequenceValues() throws Exception {
List<String> columns = Arrays.asList("_id", "person.salary", "person.name[]", "person.position.name", "person.position.since");
List<String> row1 = Arrays.asList("1", "$1000", "Joe,John", "Worker", null);
List<String> row2 = Arrays.asList("1", "$1000", "Mark", "Worker", "2012-06-13");
List<String> row3 = Arrays.asList("2", "$1000", "Mark", "Worker", "2012-06-13");
MockSink output = new MockSink();
new StringKeyValueStreamListener().output(output).begin().keys(columns).values(row1).values(row2).values(row3).end();
assertEquals(output.data().size(), 2, "Number of inserted objects");
assertEquals(output.data().toString(), "{[null/null/null/1]->{person={salary=\"$1000\", name=[\"Joe\",\"John\",\"Mark\"], position={name=\"Worker\", since=\"2012-06-13\"}}}={\"person\":{\"salary\":\"$1000\",\"name\":[\"Joe\",\"John\",\"Mark\"],\"position\":{\"name\":\"Worker\",\"since\":\"2012-06-13\"}}}, [null/null/null/2]->{person={salary=\"$1000\", name=\"Mark\", position={name=\"Worker\", since=\"2012-06-13\"}}}={\"person\":{\"salary\":\"$1000\",\"name\":\"Mark\",\"position\":{\"name\":\"Worker\",\"since\":\"2012-06-13\"}}}}");
}
use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.
the class ValueListenerTests method testMultipleValuesWithNull.
@Test
public void testMultipleValuesWithNull() throws Exception {
List<String> columns = Arrays.asList("_id", "person.salary", "person.name", "person.position.name", "person.position.since");
List<String> row1 = Arrays.asList("1", "$1000", "Joe Doe", "Worker", null);
List<String> row2 = Arrays.asList("1", "$1000", "Joe Doe", "Worker", "2012-06-13");
MockSink output = new MockSink();
new StringKeyValueStreamListener().output(output).begin().keys(columns).values(row1).values(row2).end();
assertEquals(output.data().size(), 1, "Number of inserted objects");
assertEquals(output.data().toString(), "{[null/null/null/1]->{person={salary=\"$1000\", name=\"Joe Doe\", position={name=\"Worker\", since=\"2012-06-13\"}}}={\"person\":{\"salary\":\"$1000\",\"name\":\"Joe Doe\",\"position\":{\"name\":\"Worker\",\"since\":\"2012-06-13\"}}}}");
}
use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.
the class ColumnStrategyContextTests method testReadLastRunTime.
@Test
@Parameters({ "existedWhereClause" })
@SuppressWarnings("unchecked")
public void testReadLastRunTime(String resource) throws Exception {
Settings settings = createSettings(resource);
final DateTime lastRunAt = new DateTime(new DateTime().getMillis() - 600);
context = newContext();
MockJDBCSource source = new MockJDBCSource() {
@Override
public void fetch() {
DateTime readlastRunAt = context.getLastRunTimestamp();
assertNotNull(readlastRunAt);
assertEquals(readlastRunAt, lastRunAt);
}
};
MockSink mockSink = new MockSink();
context.setSettings(settings).setSink(mockSink).setSource(source);
//mockSink.setIngestFactory(createIngestFactory(settings));
context.setLastRunTimeStamp(lastRunAt);
context.execute();
}
use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.
the class StandardSourceTests method testSimpleNullInteger.
@Test
@Parameters({ "sql3" })
public void testSimpleNullInteger(String sql) throws Exception {
List<Object> params = new LinkedList<Object>();
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");
}
Values o = (Values) object.source().get("amount");
if (o == null) {
// hsqldb is uppercase
o = (Values) object.source().get("AMOUNT");
}
if (!o.isNull()) {
throw new IllegalArgumentException("amount not null??? " + o.getClass().getName());
}
}
};
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);
if (source.nextRow(results, listener)) {
// only one row
rows++;
}
source.afterRows(results, listener);
assertEquals(rows, 1);
source.close(results);
source.close(statement);
}
use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.
the class ValueListenerTests method testNestedDots.
@Test
public void testNestedDots() throws Exception {
List<String> columns = Arrays.asList("_id", "person.name", "person.coursename[teacher.id]", "person.coursename[teacher.name]");
List<String> row1 = Arrays.asList("1", "Andrew Ng", "1", "Brian Smith");
List<String> row2 = Arrays.asList("1", "Andrew Ng", "2", "Marc Levengood");
List<String> row3 = Arrays.asList("2", "Doug Cutting", "1", "Brian Smith");
List<String> row4 = Arrays.asList("2", "Doug Cutting", "2", "Marc Levengood");
List<String> row5 = Arrays.asList("2", "Doug Cutting", "3", "Samantha Carter");
List<String> row6 = Arrays.asList("2", "Doug Cutting", "4", "Jack O'Neill");
MockSink output = new MockSink();
new SinkKeyValueStreamListener<String, String>().output(output).begin().keys(columns).values(row1).values(row2).values(row3).values(row4).values(row5).values(row6).end();
assertEquals(output.data().toString(), "{[null/null/null/1]->{person={name=\"Andrew Ng\", coursename=[{teacher={id=\"1\", name=\"Brian Smith\"}}, {teacher={id=\"2\", name=\"Marc Levengood\"}}]}}={\"person\":{\"name\":\"Andrew Ng\",\"coursename\":[{\"teacher\":{\"id\":\"1\",\"name\":\"Brian Smith\"}},{\"teacher\":{\"id\":\"2\",\"name\":\"Marc Levengood\"}}]}}, [null/null/null/2]->{person={name=\"Doug Cutting\", coursename=[{teacher={id=\"1\", name=\"Brian Smith\"}}, {teacher={id=\"2\", name=\"Marc Levengood\"}}, {teacher={id=\"3\", name=\"Samantha Carter\"}}, {teacher={id=\"4\", name=\"Jack O'Neill\"}}]}}={\"person\":{\"name\":\"Doug Cutting\",\"coursename\":[{\"teacher\":{\"id\":\"1\",\"name\":\"Brian Smith\"}},{\"teacher\":{\"id\":\"2\",\"name\":\"Marc Levengood\"}},{\"teacher\":{\"id\":\"3\",\"name\":\"Samantha Carter\"}},{\"teacher\":{\"id\":\"4\",\"name\":\"Jack O'Neill\"}}]}}}");
}
Aggregations