Search in sources :

Example 1 with IndexableObject

use of org.xbib.elasticsearch.common.util.IndexableObject in project elasticsearch-jdbc by jprante.

the class MockTests method testMockIndexId.

@Test
@Parameters({ "sql5" })
public void testMockIndexId(String sql) throws Exception {
    MockSink mock = new MockSink() {

        @Override
        public void index(IndexableObject object, boolean create) throws IOException {
            super.index(object, create);
            logger.debug("products={}", object);
        }
    };
    PreparedStatement statement = source.prepareQuery(sql);
    ResultSet results = source.executeQuery(statement);
    StringKeyValueStreamListener listener = new StringKeyValueStreamListener().output(mock);
    source.beforeRows(results, listener);
    while (source.nextRow(results, listener)) {
    // ignore
    }
    source.afterRows(results, listener);
    assertEquals(mock.getCounter(), 3);
    source.close(results);
    source.close(statement);
}
Also used : StringKeyValueStreamListener(org.xbib.elasticsearch.common.util.StringKeyValueStreamListener) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) IndexableObject(org.xbib.elasticsearch.common.util.IndexableObject) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) AbstractSinkTest(org.xbib.elasticsearch.jdbc.strategy.standard.AbstractSinkTest)

Example 2 with IndexableObject

use of org.xbib.elasticsearch.common.util.IndexableObject in project elasticsearch-jdbc by jprante.

the class MockTests method testMockTimePeriod.

@Test
@Parameters({ "sql4" })
public void testMockTimePeriod(String sql) throws Exception {
    List<Object> params = new LinkedList<Object>();
    params.add("2012-06-10 00:00:00");
    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);
    source.beforeRows(results, listener);
    long rows = 0L;
    while (source.nextRow(results, listener)) {
        rows++;
    }
    source.afterRows(results, listener);
    assertEquals(rows, 3);
    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 3 with IndexableObject

use of org.xbib.elasticsearch.common.util.IndexableObject in project elasticsearch-jdbc by jprante.

the class MockTests method testMockBill.

@Test
@Parameters({ "sql1" })
public void testMockBill(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("sql1 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, 5);
    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 4 with IndexableObject

use of org.xbib.elasticsearch.common.util.IndexableObject in project elasticsearch-jdbc by jprante.

the class ColumnStrategySourceTests method createFixturesAndPopulateSink.

private ProductFixtures createFixturesAndPopulateSink(boolean[] shouldProductsBeDeleted, MockSink sink) throws IOException {
    ProductFixture[] fixtures = new ProductFixture[shouldProductsBeDeleted.length];
    int expectedExistsCountAfterRun = 0;
    for (int i = 0; i < shouldProductsBeDeleted.length; i++) {
        IndexableObject p = new PlainIndexableObject().id(Integer.toString(i)).source(createSource(i)).optype("delete");
        sink.index(p, false);
        Timestamp deletedAt;
        if (shouldProductsBeDeleted[i]) {
            deletedAt = okTimestamp();
        } else {
            deletedAt = oldTimestamp();
            expectedExistsCountAfterRun++;
        }
        fixtures[i] = ProductFixture.one().setId(i).createdAt(oldTimestamp()).updatedAt(oldTimestamp()).deletedAt(deletedAt);
    }
    return new ProductFixtures(fixtures, expectedExistsCountAfterRun);
}
Also used : PlainIndexableObject(org.xbib.elasticsearch.common.util.PlainIndexableObject) IndexableObject(org.xbib.elasticsearch.common.util.IndexableObject) PlainIndexableObject(org.xbib.elasticsearch.common.util.PlainIndexableObject) Timestamp(java.sql.Timestamp)

Example 5 with IndexableObject

use of org.xbib.elasticsearch.common.util.IndexableObject 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);
}
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) Values(org.xbib.elasticsearch.common.util.Values) 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)

Aggregations

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