Search in sources :

Example 6 with ProcessorContext

use of org.apache.kafka.streams.processor.api.ProcessorContext in project kafka by apache.

the class MockProcessorContextAPITest method shouldCapturePunctuator.

@Test
public void shouldCapturePunctuator() {
    final Processor<String, Long, Void, Void> processor = new Processor<String, Long, Void, Void>() {

        @Override
        public void init(final ProcessorContext<Void, Void> context) {
            context.schedule(Duration.ofSeconds(1L), PunctuationType.WALL_CLOCK_TIME, timestamp -> context.commit());
        }

        @Override
        public void process(final Record<String, Long> record) {
        }
    };
    final MockProcessorContext<Void, Void> context = new MockProcessorContext<>();
    processor.init(context);
    final MockProcessorContext.CapturedPunctuator capturedPunctuator = context.scheduledPunctuators().get(0);
    assertThat(capturedPunctuator.getInterval(), is(Duration.ofMillis(1000L)));
    assertThat(capturedPunctuator.getType(), is(PunctuationType.WALL_CLOCK_TIME));
    assertThat(capturedPunctuator.cancelled(), is(false));
    final Punctuator punctuator = capturedPunctuator.getPunctuator();
    assertThat(context.committed(), is(false));
    punctuator.punctuate(1234L);
    assertThat(context.committed(), is(true));
}
Also used : Processor(org.apache.kafka.streams.processor.api.Processor) Punctuator(org.apache.kafka.streams.processor.Punctuator) Record(org.apache.kafka.streams.processor.api.Record) MockProcessorContext(org.apache.kafka.streams.processor.api.MockProcessorContext) MockProcessorContext(org.apache.kafka.streams.processor.api.MockProcessorContext) ProcessorContext(org.apache.kafka.streams.processor.api.ProcessorContext) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessorContext (org.apache.kafka.streams.processor.api.ProcessorContext)6 Record (org.apache.kafka.streams.processor.api.Record)6 Processor (org.apache.kafka.streams.processor.api.Processor)5 Test (org.junit.Test)3 List (java.util.List)2 MockProcessorContext (org.apache.kafka.streams.processor.api.MockProcessorContext)2 RecordMetadata (org.apache.kafka.streams.processor.api.RecordMetadata)2 Test (org.junit.jupiter.api.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collections.singletonList (java.util.Collections.singletonList)1 Properties (java.util.Properties)1 UnsupportedVersionException (org.apache.kafka.common.errors.UnsupportedVersionException)1 Sensor (org.apache.kafka.common.metrics.Sensor)1 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)1 Bytes (org.apache.kafka.common.utils.Bytes)1 Utils.mkProperties (org.apache.kafka.common.utils.Utils.mkProperties)1 KeyValue (org.apache.kafka.streams.KeyValue)1