Search in sources :

Example 6 with ThreadMetadata

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

the class StreamThreadTest method shouldAlwaysUpdateTasksMetadataAfterChangingState.

@Test
public void shouldAlwaysUpdateTasksMetadataAfterChangingState() {
    final StreamThread thread = createStreamThread(clientId, config, false);
    ThreadMetadata metadata = thread.threadMetadata();
    assertEquals(StreamThread.State.CREATED.name(), metadata.threadState());
    thread.setState(StreamThread.State.RUNNING);
    metadata = thread.threadMetadata();
    assertEquals(StreamThread.State.RUNNING.name(), metadata.threadState());
}
Also used : ThreadMetadata(org.apache.kafka.streams.processor.ThreadMetadata) InternalStreamsBuilderTest(org.apache.kafka.streams.kstream.internals.InternalStreamsBuilderTest) Test(org.junit.Test)

Example 7 with ThreadMetadata

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

the class StreamThreadTest method shouldReturnActiveTaskMetadataWhileRunningState.

@Test
public void shouldReturnActiveTaskMetadataWhileRunningState() {
    internalTopologyBuilder.addSource(null, "source", null, null, null, topic1);
    final StreamThread thread = createStreamThread(clientId, config, false);
    thread.setState(StreamThread.State.RUNNING);
    thread.rebalanceListener.onPartitionsRevoked(null);
    final Map<TaskId, Set<TopicPartition>> activeTasks = new HashMap<>();
    final List<TopicPartition> assignedPartitions = new ArrayList<>();
    // assign single partition
    assignedPartitions.add(t1p1);
    activeTasks.put(task1, Collections.singleton(t1p1));
    thread.taskManager().setAssignmentMetadata(activeTasks, Collections.<TaskId, Set<TopicPartition>>emptyMap());
    final MockConsumer<byte[], byte[]> mockConsumer = (MockConsumer<byte[], byte[]>) thread.consumer;
    mockConsumer.assign(assignedPartitions);
    mockConsumer.updateBeginningOffsets(Collections.singletonMap(t1p1, 0L));
    thread.rebalanceListener.onPartitionsAssigned(assignedPartitions);
    thread.runOnce(-1);
    ThreadMetadata threadMetadata = thread.threadMetadata();
    assertEquals(StreamThread.State.RUNNING.name(), threadMetadata.threadState());
    assertTrue(threadMetadata.activeTasks().contains(new TaskMetadata(task1.toString(), Utils.mkSet(t1p1))));
    assertTrue(threadMetadata.standbyTasks().isEmpty());
}
Also used : TaskId(org.apache.kafka.streams.processor.TaskId) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition) TaskMetadata(org.apache.kafka.streams.processor.TaskMetadata) ThreadMetadata(org.apache.kafka.streams.processor.ThreadMetadata) ArrayList(java.util.ArrayList) MockConsumer(org.apache.kafka.clients.consumer.MockConsumer) InternalStreamsBuilderTest(org.apache.kafka.streams.kstream.internals.InternalStreamsBuilderTest) Test(org.junit.Test)

Aggregations

ThreadMetadata (org.apache.kafka.streams.processor.ThreadMetadata)7 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 Set (java.util.Set)3 InternalStreamsBuilderTest (org.apache.kafka.streams.kstream.internals.InternalStreamsBuilderTest)3 TaskId (org.apache.kafka.streams.processor.TaskId)3 TaskMetadata (org.apache.kafka.streams.processor.TaskMetadata)3 TopicPartition (org.apache.kafka.common.TopicPartition)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Properties (java.util.Properties)1 MockConsumer (org.apache.kafka.clients.consumer.MockConsumer)1 PartitionInfo (org.apache.kafka.common.PartitionInfo)1 Bytes (org.apache.kafka.common.utils.Bytes)1 KafkaStreams (org.apache.kafka.streams.KafkaStreams)1 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)1 ValueMapper (org.apache.kafka.streams.kstream.ValueMapper)1 GlobalStreamThread (org.apache.kafka.streams.processor.internals.GlobalStreamThread)1 StreamThread (org.apache.kafka.streams.processor.internals.StreamThread)1