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));
}
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);
}
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);
}
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
}
}
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();
}
}
Aggregations