Search in sources :

Example 16 with ChangeRecord

use of com.hazelcast.jet.cdc.ChangeRecord in project hazelcast by hazelcast.

the class MySqlCdcListenBeforeExistIntegrationTest method listenBeforeDatabaseExists.

@Test
public void listenBeforeDatabaseExists() throws Exception {
    List<String> expectedRecords = Collections.singletonList("1001/0:INSERT:TableRow {id=1001, value1=someValue1, value2=someValue2, value3=null}");
    StreamSource<ChangeRecord> source = sourceBuilder("cdcMysql").setDatabaseWhitelist(DATABASE).build();
    Pipeline pipeline = pipeline(source);
    // when
    HazelcastInstance hz = createHazelcastInstances(2)[0];
    Job job = hz.getJet().newJob(pipeline);
    assertJobStatusEventually(job, RUNNING);
    try {
        // then
        createDb(DATABASE);
        createTableWithData(DATABASE, "someTable");
        insertToTable(DATABASE, "someTable", 1001, "someValue1", "someValue2");
        assertEqualsEventually(() -> mapResultsToSortedList(hz.getMap(SINK_MAP_NAME)), expectedRecords);
    } finally {
        job.cancel();
        assertJobStatusEventually(job, JobStatus.FAILED);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Job(com.hazelcast.jet.Job) ChangeRecord(com.hazelcast.jet.cdc.ChangeRecord) Pipeline(com.hazelcast.jet.pipeline.Pipeline) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 17 with ChangeRecord

use of com.hazelcast.jet.cdc.ChangeRecord in project hazelcast by hazelcast.

the class MySqlCdcWhiteBlackListIntegrationTest method pipeline.

private Pipeline pipeline(StreamSource<ChangeRecord> source) {
    Pipeline pipeline = Pipeline.create();
    pipeline.readFrom(source).withNativeTimestamps(0).filter(t -> t.database().startsWith(DB_PREFIX)).setLocalParallelism(1).<ChangeRecord>customTransform("filter_timestamps", filterTimestampsProcessorSupplier()).setLocalParallelism(1).groupingKey(record -> (Integer) record.key().toMap().get("id")).mapStateful(LongAccumulator::new, (accumulator, rowId, record) -> {
        long count = accumulator.get();
        accumulator.add(1);
        Operation operation = record.operation();
        RecordPart value = record.value();
        TableRow row = value.toObject(TableRow.class);
        return entry(rowId + "/" + count, operation + ":" + row);
    }).setLocalParallelism(1).writeTo(Sinks.map(SINK_MAP_NAME));
    return pipeline;
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Arrays(java.util.Arrays) Connection(java.sql.Connection) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Sinks(com.hazelcast.jet.pipeline.Sinks) RecordPart(com.hazelcast.jet.cdc.RecordPart) Test(org.junit.Test) StreamSource(com.hazelcast.jet.pipeline.StreamSource) Category(org.junit.experimental.categories.Category) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) List(java.util.List) Operation(com.hazelcast.jet.cdc.Operation) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Util.entry(com.hazelcast.jet.Util.entry) Statement(java.sql.Statement) ChangeRecord(com.hazelcast.jet.cdc.ChangeRecord) JobStatus(com.hazelcast.jet.core.JobStatus) Job(com.hazelcast.jet.Job) Before(org.junit.Before) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) RecordPart(com.hazelcast.jet.cdc.RecordPart) Operation(com.hazelcast.jet.cdc.Operation) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)17 Job (com.hazelcast.jet.Job)17 ChangeRecord (com.hazelcast.jet.cdc.ChangeRecord)17 Pipeline (com.hazelcast.jet.pipeline.Pipeline)17 NightlyTest (com.hazelcast.test.annotation.NightlyTest)17 Test (org.junit.Test)17 Operation (com.hazelcast.jet.cdc.Operation)8 RecordPart (com.hazelcast.jet.cdc.RecordPart)8 Sinks (com.hazelcast.jet.pipeline.Sinks)8 StreamSource (com.hazelcast.jet.pipeline.StreamSource)8 Arrays (java.util.Arrays)8 List (java.util.List)8 Category (org.junit.experimental.categories.Category)8 Util.entry (com.hazelcast.jet.Util.entry)7 LongAccumulator (com.hazelcast.jet.accumulator.LongAccumulator)7 JobStatus (com.hazelcast.jet.core.JobStatus)7 Connection (java.sql.Connection)7 Statement (java.sql.Statement)6 SQLException (java.sql.SQLException)5 ParsingException (com.hazelcast.jet.cdc.ParsingException)4