Search in sources :

Example 1 with NoOpProcessorContext

use of org.apache.kafka.test.NoOpProcessorContext in project kafka by apache.

the class StreamTaskTest method shouldWrapKafkaExceptionsWithStreamsExceptionAndAddContextWhenPunctuating.

@SuppressWarnings("unchecked")
@Test
public void shouldWrapKafkaExceptionsWithStreamsExceptionAndAddContextWhenPunctuating() throws Exception {
    final ProcessorNode punctuator = new ProcessorNode("test", new AbstractProcessor() {

        @Override
        public void init(final ProcessorContext context) {
            context.schedule(1);
        }

        @Override
        public void process(final Object key, final Object value) {
        //
        }

        @Override
        public void punctuate(final long timestamp) {
            throw new KafkaException("KABOOM!");
        }
    }, Collections.<String>emptySet());
    punctuator.init(new NoOpProcessorContext());
    try {
        task.punctuate(punctuator, 1);
        fail("Should've thrown StreamsException");
    } catch (StreamsException e) {
        final String message = e.getMessage();
        assertTrue("message=" + message + " should contain processor", message.contains("processor=test"));
        assertThat(((ProcessorContextImpl) task.processorContext()).currentNode(), nullValue());
    }
}
Also used : MockProcessorNode(org.apache.kafka.test.MockProcessorNode) NoOpProcessorContext(org.apache.kafka.test.NoOpProcessorContext) StreamsException(org.apache.kafka.streams.errors.StreamsException) AbstractProcessor(org.apache.kafka.streams.processor.AbstractProcessor) KafkaException(org.apache.kafka.common.KafkaException) ProcessorContext(org.apache.kafka.streams.processor.ProcessorContext) NoOpProcessorContext(org.apache.kafka.test.NoOpProcessorContext) Test(org.junit.Test)

Example 2 with NoOpProcessorContext

use of org.apache.kafka.test.NoOpProcessorContext in project kafka by apache.

the class GlobalStateManagerImplTest method before.

@Before
public void before() throws IOException {
    final Map<String, String> storeToTopic = new HashMap<>();
    storeToTopic.put("t1-store", "t1");
    storeToTopic.put("t2-store", "t2");
    final Map<StateStore, ProcessorNode> storeToProcessorNode = new HashMap<>();
    store1 = new NoOpReadOnlyStore<>("t1-store");
    storeToProcessorNode.put(store1, new MockProcessorNode(-1));
    store2 = new NoOpReadOnlyStore("t2-store");
    storeToProcessorNode.put(store2, new MockProcessorNode(-1));
    topology = new ProcessorTopology(Collections.<ProcessorNode>emptyList(), Collections.<String, SourceNode>emptyMap(), Collections.<String, SinkNode>emptyMap(), Collections.<StateStore>emptyList(), storeToTopic, Arrays.<StateStore>asList(store1, store2));
    context = new NoOpProcessorContext();
    stateDirPath = TestUtils.tempDirectory().getPath();
    stateDirectory = new StateDirectory("appId", stateDirPath, time);
    consumer = new MockConsumer<>(OffsetResetStrategy.EARLIEST);
    stateManager = new GlobalStateManagerImpl(topology, consumer, stateDirectory);
    checkpointFile = new File(stateManager.baseDir(), ProcessorStateManager.CHECKPOINT_FILE_NAME);
}
Also used : MockProcessorNode(org.apache.kafka.test.MockProcessorNode) HashMap(java.util.HashMap) NoOpProcessorContext(org.apache.kafka.test.NoOpProcessorContext) StateStore(org.apache.kafka.streams.processor.StateStore) MockProcessorNode(org.apache.kafka.test.MockProcessorNode) NoOpReadOnlyStore(org.apache.kafka.test.NoOpReadOnlyStore) File(java.io.File) Before(org.junit.Before)

Example 3 with NoOpProcessorContext

use of org.apache.kafka.test.NoOpProcessorContext in project kafka by apache.

the class GlobalStateTaskTest method before.

@Before
public void before() {
    sourceOne = new MockSourceNode<>(new String[] { "t1" }, new StringDeserializer(), new StringDeserializer());
    sourceTwo = new MockSourceNode<>(new String[] { "t2" }, new IntegerDeserializer(), new IntegerDeserializer());
    processorNodes = Arrays.asList(sourceOne, sourceTwo, new MockProcessorNode<>(-1), new MockProcessorNode<>(-1));
    final Set<String> storeNames = Utils.mkSet("t1-store", "t2-store");
    final Map<String, SourceNode> sourceByTopics = new HashMap<>();
    sourceByTopics.put("t1", sourceOne);
    sourceByTopics.put("t2", sourceTwo);
    final Map<String, String> storeToTopic = new HashMap<>();
    storeToTopic.put("t1-store", "t1");
    storeToTopic.put("t2-store", "t2");
    final ProcessorTopology topology = new ProcessorTopology(processorNodes, sourceByTopics, Collections.<String, SinkNode>emptyMap(), Collections.<StateStore>emptyList(), storeToTopic, Collections.<StateStore>emptyList());
    context = new NoOpProcessorContext();
    t1 = new TopicPartition("t1", 1);
    t2 = new TopicPartition("t2", 1);
    offsets = new HashMap<>();
    offsets.put(t1, 50L);
    offsets.put(t2, 100L);
    stateMgr = new GlobalStateManagerStub(storeNames, offsets);
    globalStateTask = new GlobalStateUpdateTask(topology, context, stateMgr);
}
Also used : IntegerDeserializer(org.apache.kafka.common.serialization.IntegerDeserializer) MockProcessorNode(org.apache.kafka.test.MockProcessorNode) HashMap(java.util.HashMap) StringDeserializer(org.apache.kafka.common.serialization.StringDeserializer) NoOpProcessorContext(org.apache.kafka.test.NoOpProcessorContext) GlobalStateManagerStub(org.apache.kafka.test.GlobalStateManagerStub) MockSourceNode(org.apache.kafka.test.MockSourceNode) TopicPartition(org.apache.kafka.common.TopicPartition) Before(org.junit.Before)

Aggregations

MockProcessorNode (org.apache.kafka.test.MockProcessorNode)3 NoOpProcessorContext (org.apache.kafka.test.NoOpProcessorContext)3 HashMap (java.util.HashMap)2 Before (org.junit.Before)2 File (java.io.File)1 KafkaException (org.apache.kafka.common.KafkaException)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 IntegerDeserializer (org.apache.kafka.common.serialization.IntegerDeserializer)1 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)1 StreamsException (org.apache.kafka.streams.errors.StreamsException)1 AbstractProcessor (org.apache.kafka.streams.processor.AbstractProcessor)1 ProcessorContext (org.apache.kafka.streams.processor.ProcessorContext)1 StateStore (org.apache.kafka.streams.processor.StateStore)1 GlobalStateManagerStub (org.apache.kafka.test.GlobalStateManagerStub)1 MockSourceNode (org.apache.kafka.test.MockSourceNode)1 NoOpReadOnlyStore (org.apache.kafka.test.NoOpReadOnlyStore)1 Test (org.junit.Test)1