use of io.debezium.connector.mongodb.RecordMakers.RecordsForCollection in project debezium by debezium.
the class RecordMakersTest method shouldGenerateRecordForUpdateEvent.
@Test
public void shouldGenerateRecordForUpdateEvent() throws InterruptedException {
BsonTimestamp ts = new BsonTimestamp(1000, 1);
CollectionId collectionId = new CollectionId("rs0", "dbA", "c1");
ObjectId objId = new ObjectId();
Document obj = new Document().append("$set", new Document("name", "Sally"));
Document event = new Document().append("o", obj).append("o2", objId).append("ns", "dbA.c1").append("ts", ts).append("h", Long.valueOf(12345678)).append("op", "u");
RecordsForCollection records = recordMakers.forCollection(collectionId);
records.recordEvent(event, 1002);
assertThat(produced.size()).isEqualTo(1);
SourceRecord record = produced.get(0);
Struct key = (Struct) record.key();
Struct value = (Struct) record.value();
assertThat(key.schema()).isSameAs(record.keySchema());
assertThat(key.get("id")).isEqualTo(JSONSerializers.getStrict().serialize(objId));
assertThat(value.schema()).isSameAs(record.valueSchema());
// assertThat(value.getString(FieldName.BEFORE)).isNull();
assertThat(value.getString(FieldName.AFTER)).isNull();
assertThat(value.getString("patch")).isEqualTo(obj.toJson(WRITER_SETTINGS));
assertThat(value.getString(FieldName.OPERATION)).isEqualTo(Operation.UPDATE.code());
assertThat(value.getInt64(FieldName.TIMESTAMP)).isEqualTo(1002L);
Struct actualSource = value.getStruct(FieldName.SOURCE);
Struct expectedSource = source.lastOffsetStruct("rs0", collectionId);
assertThat(actualSource).isEqualTo(expectedSource);
}
use of io.debezium.connector.mongodb.RecordMakers.RecordsForCollection in project debezium by debezium.
the class RecordMakersTest method shouldSupportDbRef.
@Test
public void shouldSupportDbRef() throws InterruptedException {
CollectionId collectionId = new CollectionId("rs0", "dbA", "c1");
BsonTimestamp ts = new BsonTimestamp(1000, 1);
ObjectId objId = new ObjectId();
Document obj = new Document().append("_id", objId).append("name", "Sally").append("ref", new DBRef("othercollection", 15));
Document event = new Document().append("o", obj).append("ns", "dbA.c1").append("ts", ts).append("h", Long.valueOf(12345678)).append("op", "i");
RecordsForCollection records = recordMakers.forCollection(collectionId);
records.recordEvent(event, 1002);
assertThat(produced.size()).isEqualTo(1);
SourceRecord record = produced.get(0);
Struct key = (Struct) record.key();
Struct value = (Struct) record.value();
assertThat(key.schema()).isSameAs(record.keySchema());
assertThat(key.get("id")).isEqualTo("{ \"$oid\" : \"" + objId + "\"}");
assertThat(value.schema()).isSameAs(record.valueSchema());
assertThat(value.getString(FieldName.AFTER)).isEqualTo("{" + "\"_id\" : {\"$oid\" : \"" + objId + "\"}," + "\"name\" : \"Sally\"," + "\"ref\" : {\"$ref\" : \"othercollection\",\"$id\" : 15}" + "}");
assertThat(value.getString(FieldName.OPERATION)).isEqualTo(Operation.CREATE.code());
assertThat(value.getInt64(FieldName.TIMESTAMP)).isEqualTo(1002L);
Struct actualSource = value.getStruct(FieldName.SOURCE);
Struct expectedSource = source.lastOffsetStruct("rs0", collectionId);
assertThat(actualSource).isEqualTo(expectedSource);
}
use of io.debezium.connector.mongodb.RecordMakers.RecordsForCollection in project debezium by debezium.
the class RecordMakersTest method shouldAlwaysFindRecordMakerForCollection.
@Test
public void shouldAlwaysFindRecordMakerForCollection() {
for (int i = 0; i != 100; ++i) {
CollectionId id = new CollectionId("rs0", "dbA", "c" + i);
RecordsForCollection records = recordMakers.forCollection(id);
assertThat(records).isNotNull();
assertThat(records.collectionId()).isSameAs(id);
}
}
use of io.debezium.connector.mongodb.RecordMakers.RecordsForCollection in project debezium by debezium.
the class RecordMakersTest method shouldGenerateRecordForDeleteEvent.
@Test
public void shouldGenerateRecordForDeleteEvent() throws InterruptedException {
BsonTimestamp ts = new BsonTimestamp(1000, 1);
CollectionId collectionId = new CollectionId("rs0", "dbA", "c1");
ObjectId objId = new ObjectId();
Document obj = new Document("_id", objId);
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(2);
SourceRecord record = produced.get(0);
Struct key = (Struct) record.key();
Struct value = (Struct) record.value();
assertThat(key.schema()).isSameAs(record.keySchema());
assertThat(key.get("id")).isEqualTo(JSONSerializers.getStrict().serialize(objId));
assertThat(value.schema()).isSameAs(record.valueSchema());
assertThat(value.getString(FieldName.AFTER)).isNull();
assertThat(value.getString("patch")).isNull();
assertThat(value.getString(FieldName.OPERATION)).isEqualTo(Operation.DELETE.code());
assertThat(value.getInt64(FieldName.TIMESTAMP)).isEqualTo(1002L);
Struct actualSource = value.getStruct(FieldName.SOURCE);
Struct expectedSource = source.lastOffsetStruct("rs0", collectionId);
assertThat(actualSource).isEqualTo(expectedSource);
SourceRecord tombstone = produced.get(1);
Struct key2 = (Struct) tombstone.key();
assertThat(key2.schema()).isSameAs(tombstone.keySchema());
assertThat(key2.get("id")).isEqualTo(JSONSerializers.getStrict().serialize(objId));
assertThat(tombstone.value()).isNull();
assertThat(tombstone.valueSchema()).isNull();
}
Aggregations