Search in sources :

Example 6 with Sink

use of org.xbib.elasticsearch.jdbc.strategy.Sink 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);
}
Also used : Sink(org.xbib.elasticsearch.jdbc.strategy.Sink) MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) StringKeyValueStreamListener(org.xbib.elasticsearch.common.util.StringKeyValueStreamListener) ResultSet(java.sql.ResultSet) IndexableObject(org.xbib.elasticsearch.common.util.IndexableObject) PreparedStatement(java.sql.PreparedStatement) IndexableObject(org.xbib.elasticsearch.common.util.IndexableObject) LinkedList(java.util.LinkedList) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 7 with Sink

use of org.xbib.elasticsearch.jdbc.strategy.Sink 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);
}
Also used : Sink(org.xbib.elasticsearch.jdbc.strategy.Sink) StringKeyValueStreamListener(org.xbib.elasticsearch.common.util.StringKeyValueStreamListener) ResultSet(java.sql.ResultSet) IndexableObject(org.xbib.elasticsearch.common.util.IndexableObject) PreparedStatement(java.sql.PreparedStatement) IndexableObject(org.xbib.elasticsearch.common.util.IndexableObject) LinkedList(java.util.LinkedList) KeyValueStreamListener(org.xbib.elasticsearch.common.keyvalue.KeyValueStreamListener) StringKeyValueStreamListener(org.xbib.elasticsearch.common.util.StringKeyValueStreamListener) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) AbstractSinkTest(org.xbib.elasticsearch.jdbc.strategy.standard.AbstractSinkTest)

Example 8 with Sink

use of org.xbib.elasticsearch.jdbc.strategy.Sink 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);
}
Also used : Sink(org.xbib.elasticsearch.jdbc.strategy.Sink) StringKeyValueStreamListener(org.xbib.elasticsearch.common.util.StringKeyValueStreamListener) ResultSet(java.sql.ResultSet) IndexableObject(org.xbib.elasticsearch.common.util.IndexableObject) PreparedStatement(java.sql.PreparedStatement) IndexableObject(org.xbib.elasticsearch.common.util.IndexableObject) LinkedList(java.util.LinkedList) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) AbstractSinkTest(org.xbib.elasticsearch.jdbc.strategy.standard.AbstractSinkTest)

Example 9 with Sink

use of org.xbib.elasticsearch.jdbc.strategy.Sink 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);
}
Also used : StringKeyValueStreamListener(org.xbib.elasticsearch.common.util.StringKeyValueStreamListener) PreparedStatement(java.sql.PreparedStatement) LinkedList(java.util.LinkedList) Sink(org.xbib.elasticsearch.jdbc.strategy.Sink) MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) ResultSet(java.sql.ResultSet) IndexableObject(org.xbib.elasticsearch.common.util.IndexableObject) IndexableObject(org.xbib.elasticsearch.common.util.IndexableObject) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Aggregations

Sink (org.xbib.elasticsearch.jdbc.strategy.Sink)9 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 LinkedList (java.util.LinkedList)7 Parameters (org.testng.annotations.Parameters)7 Test (org.testng.annotations.Test)7 IndexableObject (org.xbib.elasticsearch.common.util.IndexableObject)7 StringKeyValueStreamListener (org.xbib.elasticsearch.common.util.StringKeyValueStreamListener)7 AbstractSinkTest (org.xbib.elasticsearch.jdbc.strategy.standard.AbstractSinkTest)4 MockSink (org.xbib.elasticsearch.jdbc.strategy.mock.MockSink)3 KeyValueStreamListener (org.xbib.elasticsearch.common.keyvalue.KeyValueStreamListener)1 Values (org.xbib.elasticsearch.common.util.Values)1