use of org.apache.kafka.common.serialization.Serdes.String in project kafka by apache.
the class KTableSuppressProcessorTest method zeroTimeLimitShouldImmediatelyEmit.
@Test
public void zeroTimeLimitShouldImmediatelyEmit() {
final Harness<String, Long> harness = new Harness<>(untilTimeLimit(ZERO, unbounded()), String(), Long());
final MockInternalNewProcessorContext<String, Change<Long>> context = harness.context;
final long timestamp = ARBITRARY_LONG;
context.setRecordMetadata("", 0, 0L);
context.setTimestamp(timestamp);
final String key = "hey";
final Change<Long> value = ARBITRARY_CHANGE;
harness.processor.process(new Record<>(key, value, timestamp));
assertThat(context.forwarded(), hasSize(1));
final MockProcessorContext.CapturedForward capturedForward = context.forwarded().get(0);
assertThat(capturedForward.record(), is(new Record<>(key, value, timestamp)));
}
use of org.apache.kafka.common.serialization.Serdes.String in project kafka by apache.
the class KTableSuppressProcessorTest method intermediateSuppressionShouldBufferAndEmitLater.
@Test
public void intermediateSuppressionShouldBufferAndEmitLater() {
final Harness<String, Long> harness = new Harness<>(untilTimeLimit(ofMillis(1), unbounded()), String(), Long());
final MockInternalNewProcessorContext<String, Change<Long>> context = harness.context;
final long timestamp = 0L;
context.setRecordMetadata("topic", 0, 0);
context.setTimestamp(timestamp);
final String key = "hey";
final Change<Long> value = new Change<>(null, 1L);
harness.processor.process(new Record<>(key, value, timestamp));
assertThat(context.forwarded(), hasSize(0));
context.setRecordMetadata("topic", 0, 1);
context.setTimestamp(1L);
harness.processor.process(new Record<>("tick", new Change<>(null, null), 1L));
assertThat(context.forwarded(), hasSize(1));
final MockProcessorContext.CapturedForward capturedForward = context.forwarded().get(0);
assertThat(capturedForward.record(), is(new Record<>(key, value, timestamp)));
}
use of org.apache.kafka.common.serialization.Serdes.String in project kafka by apache.
the class KTableSuppressProcessorTest method suppressShouldNotDropTombstonesForKTable.
/**
* It's SUPER NOT OK to drop tombstones for non-windowed streams, since we may have emitted some results for
* the key before getting the tombstone (see the {@link SuppressedInternal} javadoc).
*/
@Test
public void suppressShouldNotDropTombstonesForKTable() {
final Harness<String, Long> harness = new Harness<>(untilTimeLimit(ofMillis(0), maxRecords(0)), String(), Long());
final MockInternalNewProcessorContext<String, Change<Long>> context = harness.context;
final long timestamp = 100L;
context.setRecordMetadata("", 0, 0L);
context.setTimestamp(timestamp);
final String key = "hey";
final Change<Long> value = new Change<>(null, ARBITRARY_LONG);
harness.processor.process(new Record<>(key, value, timestamp));
assertThat(context.forwarded(), hasSize(1));
final MockProcessorContext.CapturedForward capturedForward = context.forwarded().get(0);
assertThat(capturedForward.record(), is(new Record<>(key, value, timestamp)));
}
use of org.apache.kafka.common.serialization.Serdes.String in project kafka by apache.
the class KTableSuppressProcessorTest method suppressShouldShutDownWhenOverByteCapacity.
@Test
public void suppressShouldShutDownWhenOverByteCapacity() {
final Harness<String, Long> harness = new Harness<>(untilTimeLimit(Duration.ofDays(100), maxBytes(60L).shutDownWhenFull()), String(), Long());
final MockInternalNewProcessorContext<String, Change<Long>> context = harness.context;
final long timestamp = 100L;
context.setRecordMetadata("", 0, 0L);
context.setTimestamp(timestamp);
context.setCurrentNode(new ProcessorNode("testNode"));
final String key = "hey";
final Change<Long> value = new Change<>(null, ARBITRARY_LONG);
harness.processor.process(new Record<>(key, value, timestamp));
context.setRecordMetadata("", 0, 1L);
context.setTimestamp(1L);
try {
harness.processor.process(new Record<>("dummyKey", value, timestamp));
fail("expected an exception");
} catch (final StreamsException e) {
assertThat(e.getMessage(), containsString("buffer exceeded its max capacity"));
}
}
use of org.apache.kafka.common.serialization.Serdes.String in project kafka by apache.
the class KTableSuppressProcessorTest method finalResultsShouldDropTombstonesForSessionWindows.
/**
* It's desirable to drop tombstones for final-results windowed streams, since (as described in the
* {@link SuppressedInternal} javadoc), they are unnecessary to emit.
*/
@Test
public void finalResultsShouldDropTombstonesForSessionWindows() {
final Harness<Windowed<String>, Long> harness = new Harness<>(finalResults(ofMillis(0L)), sessionWindowedSerdeFrom(String.class), Long());
final MockInternalNewProcessorContext<Windowed<String>, Change<Long>> context = harness.context;
final long timestamp = 100L;
context.setRecordMetadata("", 0, 0L);
context.setTimestamp(timestamp);
final Windowed<String> key = new Windowed<>("hey", new SessionWindow(0L, 0L));
final Change<Long> value = new Change<>(null, ARBITRARY_LONG);
harness.processor.process(new Record<>(key, value, timestamp));
assertThat(context.forwarded(), hasSize(0));
}
Aggregations