Search in sources :

Example 66 with ProcessorStateException

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

the class StateManagerUtilTest method shouldStillWipeStateStoresIfCloseThrowsException.

@Test
public void shouldStillWipeStateStoresIfCloseThrowsException() throws IOException {
    final File randomFile = new File("/random/path");
    mockStatic(Utils.class);
    expect(stateManager.taskId()).andReturn(taskId);
    expect(stateDirectory.lock(taskId)).andReturn(true);
    stateManager.close();
    expectLastCall().andThrow(new ProcessorStateException("Close failed"));
    expect(stateManager.baseDir()).andReturn(randomFile);
    Utils.delete(randomFile);
    stateDirectory.unlock(taskId);
    expectLastCall();
    ctrl.checkOrder(true);
    ctrl.replay();
    replayAll();
    assertThrows(ProcessorStateException.class, () -> StateManagerUtil.closeStateManager(logger, "logPrefix:", false, true, stateManager, stateDirectory, TaskType.ACTIVE));
    ctrl.verify();
}
Also used : File(java.io.File) ProcessorStateException(org.apache.kafka.streams.errors.ProcessorStateException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 67 with ProcessorStateException

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

the class StateManagerUtilTest method testCloseStateManagerWithStateStoreWipeOutRethrowWrappedIOException.

@Test
public void testCloseStateManagerWithStateStoreWipeOutRethrowWrappedIOException() throws IOException {
    final File unknownFile = new File("/unknown/path");
    mockStatic(Utils.class);
    expect(stateManager.taskId()).andReturn(taskId);
    expect(stateDirectory.lock(taskId)).andReturn(true);
    stateManager.close();
    expectLastCall();
    expect(stateManager.baseDir()).andReturn(unknownFile);
    Utils.delete(unknownFile);
    expectLastCall().andThrow(new IOException("Deletion failed"));
    stateDirectory.unlock(taskId);
    expectLastCall();
    ctrl.checkOrder(true);
    ctrl.replay();
    replayAll();
    final ProcessorStateException thrown = assertThrows(ProcessorStateException.class, () -> StateManagerUtil.closeStateManager(logger, "logPrefix:", false, true, stateManager, stateDirectory, TaskType.ACTIVE));
    assertEquals(IOException.class, thrown.getCause().getClass());
    ctrl.verify();
}
Also used : IOException(java.io.IOException) File(java.io.File) ProcessorStateException(org.apache.kafka.streams.errors.ProcessorStateException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 68 with ProcessorStateException

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

the class StandbyTaskTest method shouldNotFlushAndThrowOnCloseDirty.

@Test
public void shouldNotFlushAndThrowOnCloseDirty() {
    EasyMock.expect(stateManager.changelogOffsets()).andStubReturn(Collections.emptyMap());
    stateManager.close();
    EasyMock.expectLastCall().andThrow(new ProcessorStateException("KABOOM!")).anyTimes();
    stateManager.flush();
    EasyMock.expectLastCall().andThrow(new AssertionError("Flush should not be called")).anyTimes();
    stateManager.checkpoint();
    EasyMock.expectLastCall().andThrow(new AssertionError("Checkpoint should not be called")).anyTimes();
    EasyMock.expect(stateManager.changelogPartitions()).andReturn(Collections.emptySet()).anyTimes();
    EasyMock.replay(stateManager);
    final MetricName metricName = setupCloseTaskMetric();
    task = createStandbyTask();
    task.initializeIfNeeded();
    task.suspend();
    task.closeDirty();
    assertEquals(Task.State.CLOSED, task.state());
    final double expectedCloseTaskMetric = 1.0;
    verifyCloseTaskMetric(expectedCloseTaskMetric, streamsMetrics, metricName);
    EasyMock.verify(stateManager);
}
Also used : MetricName(org.apache.kafka.common.MetricName) ProcessorStateException(org.apache.kafka.streams.errors.ProcessorStateException) Test(org.junit.Test)

Aggregations

ProcessorStateException (org.apache.kafka.streams.errors.ProcessorStateException)68 Test (org.junit.Test)23 IOException (java.io.IOException)19 File (java.io.File)15 RocksDBException (org.rocksdb.RocksDBException)11 StreamsException (org.apache.kafka.streams.errors.StreamsException)7 StateStore (org.apache.kafka.streams.processor.StateStore)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 WriteBatch (org.rocksdb.WriteBatch)5 ParseException (java.text.ParseException)4 Map (java.util.Map)4 MetricName (org.apache.kafka.common.MetricName)4 TopicPartition (org.apache.kafka.common.TopicPartition)4 LockException (org.apache.kafka.streams.errors.LockException)4 MockKeyValueStore (org.apache.kafka.test.MockKeyValueStore)4 MockStateStore (org.apache.kafka.test.MockStateStore)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)3