Search in sources :

Example 1 with RecordMakers

use of io.debezium.connector.mongodb.RecordMakers in project debezium by debezium.

the class UnwrapFromMongoDbEnvelopeTest method setup.

@Before
public void setup() {
    source = new SourceInfo(SERVER_NAME);
    topicSelector = TopicSelector.defaultSelector(PREFIX);
    produced = new ArrayList<>();
    recordMakers = new RecordMakers(source, topicSelector, produced::add, true);
    transformation = new UnwrapFromMongoDbEnvelope<SourceRecord>();
    transformation.configure(Collections.emptyMap());
}
Also used : SourceInfo(io.debezium.connector.mongodb.SourceInfo) RecordMakers(io.debezium.connector.mongodb.RecordMakers) SourceRecord(org.apache.kafka.connect.source.SourceRecord) Before(org.junit.Before)

Example 2 with RecordMakers

use of io.debezium.connector.mongodb.RecordMakers in project debezium by debezium.

the class UnwrapFromMongoDbEnvelopeTest method shouldGenerateRecordForDeleteEventWithoutTombstone.

@Test
@FixFor("DBZ-582")
public void shouldGenerateRecordForDeleteEventWithoutTombstone() throws InterruptedException {
    RecordMakers recordMakers = new RecordMakers(source, topicSelector, produced::add, false);
    BsonTimestamp ts = new BsonTimestamp(1000, 1);
    CollectionId collectionId = new CollectionId("rs0", "dbA", "c1");
    ObjectId objId = new ObjectId();
    Document obj = new Document("_id", objId);
    // given
    Document event = new Document().append("o", obj).append("ns", "dbA.c1").append("ts", ts).append("h", Long.valueOf(12345678)).append("op", "d");
    RecordsForCollection records = recordMakers.forCollection(collectionId);
    records.recordEvent(event, 1002);
    assertThat(produced.size()).isEqualTo(1);
    SourceRecord record = produced.get(0);
    // when
    SourceRecord transformed = transformation.apply(record);
    Struct key = (Struct) transformed.key();
    Struct value = (Struct) transformed.value();
    // then assert key and its schema
    assertThat(key.schema()).isSameAs(transformed.keySchema());
    assertThat(key.schema().field("id").schema()).isEqualTo(SchemaBuilder.OPTIONAL_STRING_SCHEMA);
    assertThat(key.get("id")).isEqualTo(objId.toString());
    assertThat(value).isNull();
}
Also used : RecordsForCollection(io.debezium.connector.mongodb.RecordMakers.RecordsForCollection) ObjectId(org.bson.types.ObjectId) CollectionId(io.debezium.connector.mongodb.CollectionId) RecordMakers(io.debezium.connector.mongodb.RecordMakers) Document(org.bson.Document) SourceRecord(org.apache.kafka.connect.source.SourceRecord) BsonTimestamp(org.bson.BsonTimestamp) Struct(org.apache.kafka.connect.data.Struct) Test(org.junit.Test) FixFor(io.debezium.doc.FixFor)

Aggregations

RecordMakers (io.debezium.connector.mongodb.RecordMakers)2 SourceRecord (org.apache.kafka.connect.source.SourceRecord)2 CollectionId (io.debezium.connector.mongodb.CollectionId)1 RecordsForCollection (io.debezium.connector.mongodb.RecordMakers.RecordsForCollection)1 SourceInfo (io.debezium.connector.mongodb.SourceInfo)1 FixFor (io.debezium.doc.FixFor)1 Struct (org.apache.kafka.connect.data.Struct)1 BsonTimestamp (org.bson.BsonTimestamp)1 Document (org.bson.Document)1 ObjectId (org.bson.types.ObjectId)1 Before (org.junit.Before)1 Test (org.junit.Test)1