Search in sources :

Example 6 with Punctuator

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

the class StreamTaskTest method shouldWrapKafkaExceptionsWithStreamsExceptionAndAddContextWhenPunctuatingWallClockTimeTime.

@Test
public void shouldWrapKafkaExceptionsWithStreamsExceptionAndAddContextWhenPunctuatingWallClockTimeTime() {
    task = createStatelessTask(false);
    task.initializeStateStores();
    task.initializeTopology();
    try {
        task.punctuate(processorSystemTime, 1, PunctuationType.WALL_CLOCK_TIME, new Punctuator() {

            @Override
            public void punctuate(long timestamp) {
                throw new KafkaException("KABOOM!");
            }
        });
        fail("Should've thrown StreamsException");
    } catch (final StreamsException e) {
        final String message = e.getMessage();
        assertTrue("message=" + message + " should contain processor", message.contains("processor '" + processorSystemTime.name() + "'"));
        assertThat(task.processorContext.currentNode(), nullValue());
    }
}
Also used : Punctuator(org.apache.kafka.streams.processor.Punctuator) StreamsException(org.apache.kafka.streams.errors.StreamsException) KafkaException(org.apache.kafka.common.KafkaException) Test(org.junit.Test)

Example 7 with Punctuator

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

the class StreamTaskTest method shouldNotThrowExceptionOnScheduleIfCurrentNodeIsNotNull.

@Test
public void shouldNotThrowExceptionOnScheduleIfCurrentNodeIsNotNull() {
    task = createStatelessTask(false);
    task.processorContext.setCurrentNode(processorStreamTime);
    task.schedule(1, PunctuationType.STREAM_TIME, new Punctuator() {

        @Override
        public void punctuate(long timestamp) {
        // no-op
        }
    });
}
Also used : Punctuator(org.apache.kafka.streams.processor.Punctuator) Test(org.junit.Test)

Example 8 with Punctuator

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

the class PunctuationQueueTest method testPunctuationInterval.

@Test
public void testPunctuationInterval() {
    final TestProcessor processor = new TestProcessor();
    final ProcessorNode<String, String> node = new ProcessorNode<>("test", processor, null);
    final PunctuationQueue queue = new PunctuationQueue();
    final Punctuator punctuator = new Punctuator() {

        @Override
        public void punctuate(long timestamp) {
            node.processor().punctuate(timestamp);
        }
    };
    final PunctuationSchedule sched = new PunctuationSchedule(node, 0L, 100L, punctuator);
    final long now = sched.timestamp - 100L;
    queue.schedule(sched);
    ProcessorNodePunctuator processorNodePunctuator = new ProcessorNodePunctuator() {

        @Override
        public void punctuate(ProcessorNode node, long time, PunctuationType type, Punctuator punctuator) {
            punctuator.punctuate(time);
        }
    };
    queue.mayPunctuate(now, PunctuationType.STREAM_TIME, processorNodePunctuator);
    assertEquals(0, processor.punctuatedAt.size());
    queue.mayPunctuate(now + 99L, PunctuationType.STREAM_TIME, processorNodePunctuator);
    assertEquals(0, processor.punctuatedAt.size());
    queue.mayPunctuate(now + 100L, PunctuationType.STREAM_TIME, processorNodePunctuator);
    assertEquals(1, processor.punctuatedAt.size());
    queue.mayPunctuate(now + 199L, PunctuationType.STREAM_TIME, processorNodePunctuator);
    assertEquals(1, processor.punctuatedAt.size());
    queue.mayPunctuate(now + 200L, PunctuationType.STREAM_TIME, processorNodePunctuator);
    assertEquals(2, processor.punctuatedAt.size());
    queue.mayPunctuate(now + 1001L, PunctuationType.STREAM_TIME, processorNodePunctuator);
    assertEquals(3, processor.punctuatedAt.size());
    queue.mayPunctuate(now + 1002L, PunctuationType.STREAM_TIME, processorNodePunctuator);
    assertEquals(3, processor.punctuatedAt.size());
    queue.mayPunctuate(now + 1100L, PunctuationType.STREAM_TIME, processorNodePunctuator);
    assertEquals(4, processor.punctuatedAt.size());
}
Also used : PunctuationType(org.apache.kafka.streams.processor.PunctuationType) Punctuator(org.apache.kafka.streams.processor.Punctuator) Test(org.junit.Test)

Aggregations

Punctuator (org.apache.kafka.streams.processor.Punctuator)8 Test (org.junit.Test)8 KafkaException (org.apache.kafka.common.KafkaException)2 StreamsException (org.apache.kafka.streams.errors.StreamsException)2 Processor (org.apache.kafka.streams.processor.Processor)2 ProcessorContext (org.apache.kafka.streams.processor.ProcessorContext)2 PunctuationType (org.apache.kafka.streams.processor.PunctuationType)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 InternalStreamsBuilderTest (org.apache.kafka.streams.kstream.internals.InternalStreamsBuilderTest)1 AbstractProcessor (org.apache.kafka.streams.processor.AbstractProcessor)1 MockProcessorContext (org.apache.kafka.streams.processor.MockProcessorContext)1 ProcessorSupplier (org.apache.kafka.streams.processor.ProcessorSupplier)1 TaskId (org.apache.kafka.streams.processor.TaskId)1