use of org.apache.kafka.streams.errors.TaskMigratedException in project apache-kafka-on-k8s by banzaicloud.
the class StreamThreadTest method shouldCloseTaskAsZombieAndRemoveFromActiveTasksIfProducerGotFencedAtBeginTransactionWhenTaskIsResumed.
@Test
public void shouldCloseTaskAsZombieAndRemoveFromActiveTasksIfProducerGotFencedAtBeginTransactionWhenTaskIsResumed() {
internalTopologyBuilder.addSource(null, "name", null, null, null, topic1);
internalTopologyBuilder.addSink("out", "output", null, null, null);
final StreamThread thread = createStreamThread(clientId, new StreamsConfig(configProps(true)), true);
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);
assertThat(thread.tasks().size(), equalTo(1));
thread.rebalanceListener.onPartitionsRevoked(null);
clientSupplier.producers.get(0).fenceProducer();
thread.rebalanceListener.onPartitionsAssigned(assignedPartitions);
try {
thread.runOnce(-1);
fail("Should have thrown TaskMigratedException");
} catch (final TaskMigratedException expected) {
/* ignore */
}
assertTrue(thread.tasks().isEmpty());
}
use of org.apache.kafka.streams.errors.TaskMigratedException in project apache-kafka-on-k8s by banzaicloud.
the class AssignedStreamsTasksTest method shouldCloseTaskOnProcessesIfTaskMigratedException.
@Test
public void shouldCloseTaskOnProcessesIfTaskMigratedException() {
mockTaskInitialization();
t1.process();
EasyMock.expectLastCall().andThrow(new TaskMigratedException(t1));
t1.close(false, true);
EasyMock.expectLastCall();
EasyMock.replay(t1);
addAndInitTask();
try {
assignedTasks.process();
fail("Should have thrown TaskMigratedException.");
} catch (final TaskMigratedException expected) {
/* ignore */
}
assertThat(assignedTasks.runningTaskIds(), equalTo(Collections.EMPTY_SET));
EasyMock.verify(t1);
}
use of org.apache.kafka.streams.errors.TaskMigratedException in project apache-kafka-on-k8s by banzaicloud.
the class AssignedStreamsTasksTest method shouldCloseTaskOnMaybePunctuateSystemTimeIfTaskMigratedException.
@Test
public void shouldCloseTaskOnMaybePunctuateSystemTimeIfTaskMigratedException() {
mockTaskInitialization();
EasyMock.expect(t1.maybePunctuateStreamTime()).andReturn(true);
t1.maybePunctuateSystemTime();
EasyMock.expectLastCall().andThrow(new TaskMigratedException(t1));
t1.close(false, true);
EasyMock.expectLastCall();
EasyMock.replay(t1);
addAndInitTask();
try {
assignedTasks.punctuate();
fail("Should have thrown TaskMigratedException.");
} catch (final TaskMigratedException expected) {
/* ignore */
}
EasyMock.verify(t1);
}
use of org.apache.kafka.streams.errors.TaskMigratedException in project apache-kafka-on-k8s by banzaicloud.
the class AssignedStreamsTasksTest method shouldCloseTaskOnMaybeCommitIfTaskMigratedException.
@Test
public void shouldCloseTaskOnMaybeCommitIfTaskMigratedException() {
mockTaskInitialization();
EasyMock.expect(t1.commitNeeded()).andReturn(true);
t1.commit();
EasyMock.expectLastCall().andThrow(new TaskMigratedException(t1));
t1.close(false, true);
EasyMock.expectLastCall();
EasyMock.replay(t1);
addAndInitTask();
try {
assignedTasks.maybeCommit();
fail("Should have thrown TaskMigratedException.");
} catch (final TaskMigratedException expected) {
/* ignore */
}
assertThat(assignedTasks.runningTaskIds(), equalTo(Collections.EMPTY_SET));
EasyMock.verify(t1);
}
use of org.apache.kafka.streams.errors.TaskMigratedException in project apache-kafka-on-k8s by banzaicloud.
the class AssignedStreamsTasksTest method shouldCloseTaskOnResumeSuspendedIfTaskMigratedException.
@Test
public void shouldCloseTaskOnResumeSuspendedIfTaskMigratedException() {
mockRunningTaskSuspension();
t1.resume();
t1.initializeTopology();
EasyMock.expectLastCall().andThrow(new TaskMigratedException(t1));
t1.close(false, true);
EasyMock.expectLastCall();
EasyMock.replay(t1);
assertThat(suspendTask(), nullValue());
try {
assignedTasks.maybeResumeSuspendedTask(taskId1, Collections.singleton(tp1));
fail("Should have thrown TaskMigratedException.");
} catch (final TaskMigratedException expected) {
/* ignore */
}
assertThat(assignedTasks.runningTaskIds(), equalTo(Collections.EMPTY_SET));
EasyMock.verify(t1);
}
Aggregations