Search in sources :

Example 96 with StreamsException

use of org.apache.kafka.streams.errors.StreamsException in project kafka by apache.

the class ActiveTaskCreatorTest method shouldThrowStreamsExceptionOnErrorCloseTaskProducerIfEosAlphaEnabled.

@SuppressWarnings("deprecation")
@Test
public void shouldThrowStreamsExceptionOnErrorCloseTaskProducerIfEosAlphaEnabled() {
    properties.put(StreamsConfig.PROCESSING_GUARANTEE_CONFIG, StreamsConfig.EXACTLY_ONCE);
    mockClientSupplier.setApplicationIdForProducer("appId");
    createTasks();
    mockClientSupplier.producers.get(0).closeException = new RuntimeException("KABOOM!");
    final StreamsException thrown = assertThrows(StreamsException.class, () -> activeTaskCreator.closeAndRemoveTaskProducerIfNeeded(new TaskId(0, 0)));
    assertThat(thrown.getMessage(), is("[0_0] task producer encounter error trying to close."));
    assertThat(thrown.getCause().getMessage(), is("KABOOM!"));
    // should not throw again because producer should be removed
    activeTaskCreator.closeAndRemoveTaskProducerIfNeeded(new TaskId(0, 0));
}
Also used : TaskId(org.apache.kafka.streams.processor.TaskId) StreamsException(org.apache.kafka.streams.errors.StreamsException) Test(org.junit.Test)

Example 97 with StreamsException

use of org.apache.kafka.streams.errors.StreamsException in project kafka by apache.

the class ProcessorStateManagerTest method shouldPreserveStreamsExceptionOnCloseIfStoreThrows.

@Test
public void shouldPreserveStreamsExceptionOnCloseIfStoreThrows() {
    final StreamsException exception = new StreamsException("KABOOM!");
    final ProcessorStateManager stateManager = getStateManager(Task.TaskType.ACTIVE);
    final MockKeyValueStore stateStore = new MockKeyValueStore(persistentStoreName, true) {

        @Override
        public void close() {
            throw exception;
        }
    };
    stateManager.registerStore(stateStore, stateStore.stateRestoreCallback, null);
    final StreamsException thrown = assertThrows(StreamsException.class, stateManager::close);
    assertEquals(exception, thrown);
}
Also used : StreamsException(org.apache.kafka.streams.errors.StreamsException) MockKeyValueStore(org.apache.kafka.test.MockKeyValueStore) Test(org.junit.Test)

Example 98 with StreamsException

use of org.apache.kafka.streams.errors.StreamsException in project kafka by apache.

the class GlobalStateManagerImplTest method shouldNotRetryWhenPartitionsForThrowsTimeoutExceptionAndTaskTimeoutIsZero.

@Test
public void shouldNotRetryWhenPartitionsForThrowsTimeoutExceptionAndTaskTimeoutIsZero() {
    final AtomicInteger numberOfCalls = new AtomicInteger(0);
    consumer = new MockConsumer<byte[], byte[]>(OffsetResetStrategy.EARLIEST) {

        @Override
        public List<PartitionInfo> partitionsFor(final String topic) {
            numberOfCalls.incrementAndGet();
            throw new TimeoutException("KABOOM!");
        }
    };
    initializeConsumer(0, 0, t1, t2, t3, t4);
    streamsConfig = new StreamsConfig(mkMap(mkEntry(StreamsConfig.APPLICATION_ID_CONFIG, "appId"), mkEntry(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "dummy:1234"), mkEntry(StreamsConfig.STATE_DIR_CONFIG, TestUtils.tempDirectory().getPath()), mkEntry(StreamsConfig.TASK_TIMEOUT_MS_CONFIG, 0L)));
    stateManager = new GlobalStateManagerImpl(new LogContext("mock"), time, topology, consumer, stateDirectory, stateRestoreListener, streamsConfig);
    processorContext.setStateManger(stateManager);
    stateManager.setGlobalProcessorContext(processorContext);
    final StreamsException expected = assertThrows(StreamsException.class, () -> stateManager.initialize());
    final Throwable cause = expected.getCause();
    assertThat(cause, instanceOf(TimeoutException.class));
    assertThat(cause.getMessage(), equalTo("KABOOM!"));
    assertEquals(numberOfCalls.get(), 1);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StreamsException(org.apache.kafka.streams.errors.StreamsException) LogContext(org.apache.kafka.common.utils.LogContext) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) TimeoutException(org.apache.kafka.common.errors.TimeoutException) StreamsConfig(org.apache.kafka.streams.StreamsConfig) Test(org.junit.Test)

Example 99 with StreamsException

use of org.apache.kafka.streams.errors.StreamsException in project kafka by apache.

the class KStreamTransformValuesTest method shouldNotAllowValueTransformerToCallInternalProcessorContextMethods.

@Test
public void shouldNotAllowValueTransformerToCallInternalProcessorContextMethods() {
    final KStreamTransformValues<Integer, Integer, Integer> transformValue = new KStreamTransformValues<>(new ValueTransformerSupplier<Integer, Integer>() {

        @Override
        public ValueTransformer<Integer, Integer> get() {
            return new BadValueTransformer();
        }
    });
    final Processor transformValueProcessor = transformValue.get();
    transformValueProcessor.init(null);
    try {
        transformValueProcessor.process(null, 0);
        fail("should not allow call to context.forward() within ValueTransformer");
    } catch (final StreamsException e) {
    // expected
    }
    try {
        transformValueProcessor.process(null, 1);
        fail("should not allow call to context.forward() within ValueTransformer");
    } catch (final StreamsException e) {
    // expected
    }
    try {
        transformValueProcessor.process(null, 2);
        fail("should not allow call to context.forward() within ValueTransformer");
    } catch (final StreamsException e) {
    // expected
    }
    try {
        transformValueProcessor.punctuate(0);
        fail("should not allow ValueTransformer#puntuate() to return not-null value");
    } catch (final StreamsException e) {
    // expected
    }
}
Also used : ValueTransformer(org.apache.kafka.streams.kstream.ValueTransformer) Processor(org.apache.kafka.streams.processor.Processor) StreamsException(org.apache.kafka.streams.errors.StreamsException) Test(org.junit.Test)

Example 100 with StreamsException

use of org.apache.kafka.streams.errors.StreamsException in project kafka by apache.

the class GlobalStateManagerImplTest method shouldReleaseLockIfExceptionWhenLoadingCheckpoints.

@Test
public void shouldReleaseLockIfExceptionWhenLoadingCheckpoints() throws Exception {
    writeCorruptCheckpoint();
    try {
        stateManager.initialize(context);
    } catch (StreamsException e) {
    // expected
    }
    final StateDirectory stateDir = new StateDirectory("appId", stateDirPath, new MockTime());
    try {
        // should be able to get the lock now as it should've been released
        assertTrue(stateDir.lockGlobalState(1));
    } finally {
        stateDir.unlockGlobalState();
    }
}
Also used : StreamsException(org.apache.kafka.streams.errors.StreamsException) MockTime(org.apache.kafka.common.utils.MockTime) 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