use of org.apache.kafka.streams.errors.StreamsException in project kafka by apache.
the class TaskManagerTest method shouldWrapRuntimeExceptionsInProcessActiveTasksAndSetTaskId.
@Test
public void shouldWrapRuntimeExceptionsInProcessActiveTasksAndSetTaskId() {
final StateMachineTask task00 = new StateMachineTask(taskId00, taskId00Partitions, true) {
@Override
public boolean process(final long wallClockTime) {
throw new RuntimeException("oops");
}
};
expectRestoreToBeCompleted(consumer, changeLogReader);
expect(activeTaskCreator.createTasks(anyObject(), eq(taskId00Assignment))).andStubReturn(singletonList(task00));
replay(activeTaskCreator, consumer, changeLogReader);
taskManager.handleAssignment(taskId00Assignment, emptyMap());
assertThat(taskManager.tryToCompleteRestoration(time.milliseconds(), null), is(true));
assertThat(task00.state(), is(Task.State.RUNNING));
final TopicPartition partition = taskId00Partitions.iterator().next();
task00.addRecords(partition, singletonList(getConsumerRecord(partition, 0L)));
final StreamsException exception = assertThrows(StreamsException.class, () -> taskManager.process(1, time));
assertThat(exception.taskId().isPresent(), is(true));
assertThat(exception.taskId().get(), is(taskId00));
assertThat(exception.getCause().getMessage(), is("oops"));
}
use of org.apache.kafka.streams.errors.StreamsException in project kafka by apache.
the class TaskManagerTest method shouldThrowSameKafkaExceptionWhenEncounteredDuringTaskClose.
@Test
public void shouldThrowSameKafkaExceptionWhenEncounteredDuringTaskClose() {
final StateMachineTask migratedTask01 = new StateMachineTask(taskId01, taskId01Partitions, false) {
@Override
public void suspend() {
super.suspend();
throw new TaskMigratedException("t1 close exception", new RuntimeException());
}
};
final StateMachineTask migratedTask02 = new StateMachineTask(taskId02, taskId02Partitions, false) {
@Override
public void suspend() {
super.suspend();
throw new KafkaException("Kaboom for t2!", new RuntimeException());
}
};
taskManager.addTask(migratedTask01);
taskManager.addTask(migratedTask02);
final StreamsException thrown = assertThrows(StreamsException.class, () -> taskManager.handleAssignment(emptyMap(), emptyMap()));
assertThat(thrown.taskId().isPresent(), is(true));
assertThat(thrown.taskId().get(), is(taskId02));
// Expecting the original Kafka exception wrapped in the StreamsException.
assertThat(thrown.getCause().getMessage(), equalTo("Kaboom for t2!"));
}
use of org.apache.kafka.streams.errors.StreamsException in project kafka by apache.
the class StreamTaskTest method shouldInitTaskTimeoutAndEventuallyThrow.
@Test
public void shouldInitTaskTimeoutAndEventuallyThrow() {
task = createStatelessTask(createConfig());
task.maybeInitTaskTimeoutOrThrow(0L, null);
task.maybeInitTaskTimeoutOrThrow(Duration.ofMinutes(5).toMillis(), null);
final StreamsException thrown = assertThrows(StreamsException.class, () -> task.maybeInitTaskTimeoutOrThrow(Duration.ofMinutes(5).plus(Duration.ofMillis(1L)).toMillis(), null));
assertThat(thrown.getCause(), isA(TimeoutException.class));
}
use of org.apache.kafka.streams.errors.StreamsException in project kafka by apache.
the class StreamsProducerTest method shouldThrowStreamsExceptionOnEosSendOffsetError.
@Test
public void shouldThrowStreamsExceptionOnEosSendOffsetError() {
eosAlphaMockProducer.sendOffsetsToTransactionException = new KafkaException("KABOOM!");
final StreamsException thrown = assertThrows(StreamsException.class, // `sendOffsetsToTransaction()` would throw an NPE on `null` offsets
() -> eosAlphaStreamsProducer.commitTransaction(null, new ConsumerGroupMetadata("appId")));
assertThat(thrown.getCause(), is(eosAlphaMockProducer.sendOffsetsToTransactionException));
assertThat(thrown.getMessage(), is("Error encountered trying to commit a transaction [test]"));
}
use of org.apache.kafka.streams.errors.StreamsException in project kafka by apache.
the class StreamsProducerTest method shouldThrowTaskMigrateExceptionOnEosBeginTxnError.
@Test
public void shouldThrowTaskMigrateExceptionOnEosBeginTxnError() {
eosAlphaMockProducer.beginTransactionException = new KafkaException("KABOOM!");
// calling `send()` implicitly starts a new transaction
final StreamsException thrown = assertThrows(StreamsException.class, () -> eosAlphaStreamsProducer.send(null, null));
assertThat(thrown.getCause(), is(eosAlphaMockProducer.beginTransactionException));
assertThat(thrown.getMessage(), is("Error encountered trying to begin a new transaction [test]"));
}
Aggregations