@Test public void testDeleteForwardConfigured() { try (final UnwrapFromEnvelope<SourceRecord> transform = new UnwrapFromEnvelope<>()) { final Map<String, String> props = new HashMap<>(); props.put(DROP_DELETES, "false"); props.put(OPERATION_HEADER, "true"); transform.configure(props); final SourceRecord deleteRecord = createDeleteRecord(); final SourceRecord tombstone = transform.apply(deleteRecord); assertThat(tombstone.value()).isNull(); assertThat(tombstone.headers()).hasSize(1); String headerValue = getSourceRecordHeaderByKey(tombstone, transform.DEBEZIUM_OPERATION_HEADER_KEY); assertThat(headerValue).isEqualTo(Envelope.Operation.DELETE.code()); } }
@Test public void testHandleCreateRewrite() { try (final UnwrapFromEnvelope<SourceRecord> transform = new UnwrapFromEnvelope<>()) { final Map<String, String> props = new HashMap<>(); props.put(HANDLE_DELETES, "rewrite"); props.put(OPERATION_HEADER, "true"); transform.configure(props); final SourceRecord createRecord = createCreateRecord(); final SourceRecord unwrapped = transform.apply(createRecord); assertThat(((Struct)unwrapped.value()).getString("__deleted")).isEqualTo("false"); assertThat(unwrapped.headers()).hasSize(1); String headerValue = getSourceRecordHeaderByKey(unwrapped, transform.DEBEZIUM_OPERATION_HEADER_KEY); assertThat(headerValue).isEqualTo(Envelope.Operation.CREATE.code()); } }
@Test @FixFor("DBZ-971") public void shouldPropagatePreviousRecordHeaders() 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")); // given 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); record.headers().addString("application/debezium-test-header", "shouldPropagatePreviousRecordHeaders"); // when SourceRecord transformedRecord = transformation.apply(record); assertThat(transformedRecord.headers()).hasSize(1); Iterator<Header> headers = transformedRecord.headers().allWithName("application/debezium-test-header"); assertThat(headers.hasNext()).isTrue(); assertThat(headers.next().value().toString()).isEqualTo("shouldPropagatePreviousRecordHeaders"); }
@Test @FixFor("DBZ-971") public void testUnwrapPropagatesRecordHeaders() { try (final UnwrapFromEnvelope<SourceRecord> transform = new UnwrapFromEnvelope<>()) { final Map<String, String> props = new HashMap<>(); transform.configure(props); final SourceRecord createRecord = createCreateRecord(); createRecord.headers().addString("application/debezium-test-header", "shouldPropagatePreviousRecordHeaders"); final SourceRecord unwrapped = transform.apply(createRecord); assertThat(((Struct)unwrapped.value()).getInt8("id")).isEqualTo((byte) 1); assertThat(unwrapped.headers()).hasSize(1); Iterator<Header> headers = unwrapped.headers().allWithName("application/debezium-test-header"); assertThat(headers.hasNext()).isTrue(); assertThat(headers.next().value().toString()).isEqualTo("shouldPropagatePreviousRecordHeaders"); } } }
@Test public void shouldRegisterPayback() { PaybackConfirmation confirmation = bookKeeper.registerPaybackFor(purchase()); assertThat(confirmation.getNumber()).isNotNull(); assertThat(confirmation.getIncome().getAmount()).isEqualTo(Money.of(EUR, 6L)); assertThat(confirmation.getIncome().getDistributions()).hasSize(2); assertThat(confirmation.getIncome().getDistribution("Glock").getAmount()).isEqualTo(Money.of(EUR, 3L)); assertThat(confirmation.getIncome().getDistribution("M60").getAmount()).isEqualTo(Money.of(EUR, 3L)); } }
@Test public void shouldRegisterPayback() { PaybackConfirmation confirmation = bookKeeper.registerPaybackFor(purchase()); assertThat(confirmation.getNumber()).isNotNull(); assertThat(confirmation.getIncome().getAmount()).isEqualTo(Money.of(EUR, 6L)); assertThat(confirmation.getIncome().getDistributions()).hasSize(2); assertThat(confirmation.getIncome().getDistribution("Glock").getAmount()).isEqualTo(Money.of(EUR, 3L)); assertThat(confirmation.getIncome().getDistribution("M60").getAmount()).isEqualTo(Money.of(EUR, 3L)); } }
@Test public void shouldRegisterPayback() { PaybackConfirmation confirmation = bookKeeper.registerPaybackFor(purchase()); assertThat(confirmation.getNumber()).isNotNull(); assertThat(confirmation.getIncome().getAmount()).isEqualTo(Money.of(EUR, 6L)); assertThat(confirmation.getIncome().getDistributions()).hasSize(2); assertThat(confirmation.getIncome().getDistribution("Glock").getAmount()).isEqualTo(Money.of(EUR, 3L)); assertThat(confirmation.getIncome().getDistribution("M60").getAmount()).isEqualTo(Money.of(EUR, 3L)); } }
@Test public void shouldRegisterPayback() { PaybackConfirmation confirmation = bookKeeper.registerPaybackFor(purchase()); assertThat(confirmation.getNumber()).isNotNull(); assertThat(confirmation.getIncome().getAmount()).isEqualTo(Money.of(EUR, 6L)); assertThat(confirmation.getIncome().getDistributions()).hasSize(2); assertThat(confirmation.getIncome().getDistribution("Glock").getAmount()).isEqualTo(Money.of(EUR, 3L)); assertThat(confirmation.getIncome().getDistribution("M60").getAmount()).isEqualTo(Money.of(EUR, 3L)); } }
@Test public void shouldRegisterPayback() { PaybackConfirmation confirmation = bookKeeper.registerPaybackFor(purchase()); assertThat(confirmation.getNumber()).isNotNull(); assertThat(confirmation.getIncome().getAmount()).isEqualTo(Money.of(EUR, 6L)); assertThat(confirmation.getIncome().getDistributions()).hasSize(2); assertThat(confirmation.getIncome().getDistribution("Glock").getAmount()).isEqualTo(Money.of(EUR, 3L)); assertThat(confirmation.getIncome().getDistribution("M60").getAmount()).isEqualTo(Money.of(EUR, 3L)); } }