Search in sources :

Example 6 with MockSink

use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.

the class ValueListenerTests method testSequenceObjects.

@Test
public void testSequenceObjects() throws Exception {
    List<String> columns = Arrays.asList("_id", "person.name", "person.coursename[name]", "person.coursename[count]");
    List<String> row1 = Arrays.asList("1", "Andrew Ng", "Machine Learning", "5");
    List<String> row2 = Arrays.asList("1", "Andrew Ng", "Recommender Systems", "5");
    List<String> row3 = Arrays.asList("2", "Doug Cutting", "Hadoop Internals", "12");
    List<String> row4 = Arrays.asList("2", "Doug Cutting", "Basic of Lucene", "25");
    List<String> row5 = Arrays.asList("2", "Doug Cutting", "Advanced Lucene", "5");
    List<String> row6 = Arrays.asList("2", "Doug Cutting", "Introduction to Apache Avro", "5");
    MockSink output = new MockSink();
    new StringKeyValueStreamListener().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=[{name=\"Machine Learning\", count=\"5\"}, {name=\"Recommender Systems\", count=\"5\"}]}}={\"person\":{\"name\":\"Andrew Ng\",\"coursename\":[{\"name\":\"Machine Learning\",\"count\":\"5\"},{\"name\":\"Recommender Systems\",\"count\":\"5\"}]}}, [null/null/null/2]->{person={name=\"Doug Cutting\", coursename=[{name=\"Hadoop Internals\", count=\"12\"}, {name=\"Basic of Lucene\", count=\"25\"}, {name=\"Advanced Lucene\", count=\"5\"}, {name=\"Introduction to Apache Avro\", count=\"5\"}]}}={\"person\":{\"name\":\"Doug Cutting\",\"coursename\":[{\"name\":\"Hadoop Internals\",\"count\":\"12\"},{\"name\":\"Basic of Lucene\",\"count\":\"25\"},{\"name\":\"Advanced Lucene\",\"count\":\"5\"},{\"name\":\"Introduction to Apache Avro\",\"count\":\"5\"}]}}}");
}
Also used : MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) Test(org.testng.annotations.Test)

Example 7 with MockSink

use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.

the class ValueListenerTests method testNestedObjects.

@Test
public void testNestedObjects() 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", "2012-06-12");
    List<String> row2 = Arrays.asList("2", "$2000", "Bill Smith", "Boss", "2012-06-13");
    MockSink output = new MockSink();
    new StringKeyValueStreamListener().output(output).begin().keys(columns).values(row1).values(row2).end();
    assertEquals(output.data().size(), 2, "Number of inserted objects");
    assertEquals(output.data().toString(), "{[null/null/null/1]->{person={salary=\"$1000\", name=\"Joe Doe\", position={name=\"Worker\", since=\"2012-06-12\"}}}={\"person\":{\"salary\":\"$1000\",\"name\":\"Joe Doe\",\"position\":{\"name\":\"Worker\",\"since\":\"2012-06-12\"}}}, [null/null/null/2]->{person={salary=\"$2000\", name=\"Bill Smith\", position={name=\"Boss\", since=\"2012-06-13\"}}}={\"person\":{\"salary\":\"$2000\",\"name\":\"Bill Smith\",\"position\":{\"name\":\"Boss\",\"since\":\"2012-06-13\"}}}}");
}
Also used : MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) Test(org.testng.annotations.Test)

Example 8 with MockSink

use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.

the class ValueListenerTests method testJSON.

@Test
public void testJSON() throws Exception {
    List<String> columns = Arrays.asList("_optype", "_id", "message", "person", "person.attributes");
    List<String> row1 = Arrays.asList("index", "1", "{\"Hello\":\"World\"}", "{\"name\":[\"Joe\",\"John\"]}", "{\"haircolor\":\"blue\"}");
    MockSink output = new MockSink();
    new StringKeyValueStreamListener().output(output).begin().keys(columns).values(row1).end();
    assertEquals(output.data().toString(), "{[index/null/null/1]->{message=\"{Hello=World}\", person=\"{name=[Joe, John], attributes=\"{haircolor=blue}\"}\"}={\"message\":{\"Hello\":\"World\"},\"person\":{\"name\":[\"Joe\",\"John\"],\"attributes\":{\"haircolor\":\"blue\"}}}}");
}
Also used : MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) Test(org.testng.annotations.Test)

Example 9 with MockSink

use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.

the class ValueListenerTests method testOverlappingOps.

@Test
public void testOverlappingOps() throws Exception {
    List<String> columns = Arrays.asList("_optype", "_id", "label");
    List<String> row1 = Arrays.asList("index", "1", "label1");
    List<String> row2 = Arrays.asList("create", "1", "label2");
    List<String> row3 = Arrays.asList("delete", "2", "label3");
    List<String> row4 = Arrays.asList("index", "2", "label4");
    MockSink output = new MockSink();
    new StringKeyValueStreamListener().output(output).begin().keys(columns).values(row1).values(row2).values(row3).values(row4).end();
    assertEquals(output.data().size(), 3, "Number of objects");
}
Also used : MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) Test(org.testng.annotations.Test)

Example 10 with MockSink

use of org.xbib.elasticsearch.jdbc.strategy.mock.MockSink in project elasticsearch-jdbc by jprante.

the class ValueListenerTests method testJSONSource.

@Test
public void testJSONSource() throws Exception {
    List<String> columns = Arrays.asList("_optype", "_id", "_source");
    List<String> row1 = Arrays.asList("index", "1", "{\"Hello\":\"World\"}");
    MockSink output = new MockSink();
    new StringKeyValueStreamListener().output(output).begin().keys(columns).values(row1).end();
    assertEquals(output.data().toString(), "{[index/null/null/1]->{Hello=World}={\"Hello\":\"World\"}}");
}
Also used : MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) Test(org.testng.annotations.Test)

Aggregations

MockSink (org.xbib.elasticsearch.jdbc.strategy.mock.MockSink)25 Test (org.testng.annotations.Test)23 LinkedList (java.util.LinkedList)7 Parameters (org.testng.annotations.Parameters)6 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 IndexableObject (org.xbib.elasticsearch.common.util.IndexableObject)3 StringKeyValueStreamListener (org.xbib.elasticsearch.common.util.StringKeyValueStreamListener)3 Sink (org.xbib.elasticsearch.jdbc.strategy.Sink)3 Settings (org.elasticsearch.common.settings.Settings)2 MockJDBCSource (org.xbib.elasticsearch.jdbc.strategy.mock.MockJDBCSource)2 DateTime (org.joda.time.DateTime)1 Values (org.xbib.elasticsearch.common.util.Values)1