Search in sources :

Example 21 with MockSink

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());
}
Also used : MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) MockJDBCSource(org.xbib.elasticsearch.jdbc.strategy.mock.MockJDBCSource) Settings(org.elasticsearch.common.settings.Settings) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 22 with MockSink

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);
}
Also used : MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 23 with MockSink

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);
}
Also used : MockSink(org.xbib.elasticsearch.jdbc.strategy.mock.MockSink)

Example 24 with MockSink

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);
}
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 25 with MockSink

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);
}
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

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