Search in sources :

Example 51 with StreamsException

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"));
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) StreamsException(org.apache.kafka.streams.errors.StreamsException) Test(org.junit.Test)

Example 52 with StreamsException

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!"));
}
Also used : StreamsException(org.apache.kafka.streams.errors.StreamsException) KafkaException(org.apache.kafka.common.KafkaException) TaskMigratedException(org.apache.kafka.streams.errors.TaskMigratedException) Test(org.junit.Test)

Example 53 with StreamsException

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));
}
Also used : StreamsException(org.apache.kafka.streams.errors.StreamsException) TimeoutException(org.apache.kafka.common.errors.TimeoutException) Test(org.junit.Test)

Example 54 with StreamsException

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]"));
}
Also used : ConsumerGroupMetadata(org.apache.kafka.clients.consumer.ConsumerGroupMetadata) StreamsException(org.apache.kafka.streams.errors.StreamsException) KafkaException(org.apache.kafka.common.KafkaException) Test(org.junit.Test)

Example 55 with StreamsException

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]"));
}
Also used : StreamsException(org.apache.kafka.streams.errors.StreamsException) KafkaException(org.apache.kafka.common.KafkaException) Test(org.junit.Test)

Aggregations

StreamsException (org.apache.kafka.streams.errors.StreamsException)186 Test (org.junit.Test)90 KafkaException (org.apache.kafka.common.KafkaException)41 TopicPartition (org.apache.kafka.common.TopicPartition)38 TimeoutException (org.apache.kafka.common.errors.TimeoutException)36 HashMap (java.util.HashMap)27 Map (java.util.Map)25 HashSet (java.util.HashSet)18 Properties (java.util.Properties)17 TaskId (org.apache.kafka.streams.processor.TaskId)14 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)13 StreamsConfig (org.apache.kafka.streams.StreamsConfig)12 ArrayList (java.util.ArrayList)11 ExecutionException (java.util.concurrent.ExecutionException)11 TaskMigratedException (org.apache.kafka.streams.errors.TaskMigratedException)11 IOException (java.io.IOException)10 Set (java.util.Set)10 LogContext (org.apache.kafka.common.utils.LogContext)10 MockTime (org.apache.kafka.common.utils.MockTime)10 StateStore (org.apache.kafka.streams.processor.StateStore)10