@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()); } }
protected void appendCommand(Path results, Document command) throws IOException { assertThat(command).isNotNull(); assertThat(Files.exists(results)).isTrue(); Array arrayOfDocuments = readResults(results.toFile()); arrayOfDocuments.add(command); try (OutputStream stream = new FileOutputStream(results.toFile())) { ArrayWriter.prettyWriter().write(arrayOfDocuments, stream); } if (Testing.Debug.isEnabled()) { String content = IoUtil.read(results.toFile()); Testing.debug("expected results file '" + results + "' after appending command:"); Testing.debug(content); } }
@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()); } }
HistoryRecord deserialized = new HistoryRecord(reader.read(serialized)); assertThat(deserialized.source()).isNotNull(); assertThat(deserialized.source().get("server")).isEqualTo("abc"); assertThat(deserialized.position()).isNotNull(); assertThat(deserialized.position().get("file")).isEqualTo("x.log"); assertThat(deserialized.position().get("positionInt")).isEqualTo(100);
@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"); }
protected void appendCommand(Path results, Document command) throws IOException { assertThat(command).isNotNull(); assertThat(Files.exists(results)).isTrue(); Array arrayOfDocuments = readResults(results.toFile()); arrayOfDocuments.add(command); try (OutputStream stream = new FileOutputStream(results.toFile())) { ArrayWriter.prettyWriter().write(arrayOfDocuments, stream); } if (Testing.Debug.isEnabled()) { String content = IoUtil.read(results.toFile()); Testing.debug("expected results file '" + results + "' after appending command:"); Testing.debug(content); } }
@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)); } }