Search in sources :

Example 11 with MockProcessorContext

use of org.apache.kafka.streams.processor.MockProcessorContext in project apache-kafka-on-k8s by banzaicloud.

the class MockProcessorContextTest method shouldCaptureOutputRecordsUsingTo.

@Test
public void shouldCaptureOutputRecordsUsingTo() {
    final AbstractProcessor<String, Long> processor = new AbstractProcessor<String, Long>() {

        @Override
        public void process(final String key, final Long value) {
            context().forward(key + value, key.length() + value, To.all());
        }
    };
    final MockProcessorContext context = new MockProcessorContext();
    processor.init(context);
    processor.process("foo", 5L);
    processor.process("barbaz", 50L);
    final Iterator<CapturedForward> forwarded = context.forwarded().iterator();
    assertEquals(new KeyValue<>("foo5", 8L), forwarded.next().keyValue());
    assertEquals(new KeyValue<>("barbaz50", 56L), forwarded.next().keyValue());
    assertFalse(forwarded.hasNext());
    context.resetForwards();
    assertEquals(0, context.forwarded().size());
}
Also used : CapturedForward(org.apache.kafka.streams.processor.MockProcessorContext.CapturedForward) AbstractProcessor(org.apache.kafka.streams.processor.AbstractProcessor) MockProcessorContext(org.apache.kafka.streams.processor.MockProcessorContext) Test(org.junit.Test)

Aggregations

MockProcessorContext (org.apache.kafka.streams.processor.MockProcessorContext)11 Test (org.junit.Test)11 AbstractProcessor (org.apache.kafka.streams.processor.AbstractProcessor)9 CapturedForward (org.apache.kafka.streams.processor.MockProcessorContext.CapturedForward)3 Iterator (java.util.Iterator)2 Properties (java.util.Properties)2 TaskId (org.apache.kafka.streams.processor.TaskId)2 File (java.io.File)1 Processor (org.apache.kafka.streams.processor.Processor)1 ProcessorContext (org.apache.kafka.streams.processor.ProcessorContext)1 Punctuator (org.apache.kafka.streams.processor.Punctuator)1 To (org.apache.kafka.streams.processor.To)1 KeyValueStore (org.apache.kafka.streams.state.KeyValueStore)1 InMemoryKeyValueStore (org.apache.kafka.streams.state.internals.InMemoryKeyValueStore)1