Search in sources :

Example 31 with ProcessorStateException

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

the class ProcessorStateManagerTest method shouldThrowProcessorStateExceptionOnFlushIfStoreThrowsAnException.

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

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

Example 32 with ProcessorStateException

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

the class ProcessorStateManagerTest method shouldThrowProcessorStateExceptionOnCloseIfStoreThrowsAnException.

@Test
public void shouldThrowProcessorStateExceptionOnCloseIfStoreThrowsAnException() {
    final RuntimeException exception = new RuntimeException("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 ProcessorStateException thrown = assertThrows(ProcessorStateException.class, stateManager::close);
    assertEquals(exception, thrown.getCause());
}
Also used : MockKeyValueStore(org.apache.kafka.test.MockKeyValueStore) ProcessorStateException(org.apache.kafka.streams.errors.ProcessorStateException) Test(org.junit.Test)

Example 33 with ProcessorStateException

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

the class ProcessorStateManagerTest method shouldThrowIfRestoreCallbackThrows.

@Test
public void shouldThrowIfRestoreCallbackThrows() {
    final ProcessorStateManager stateMgr = getStateManager(Task.TaskType.ACTIVE);
    stateMgr.registerStore(persistentStore, (key, value) -> {
        throw new RuntimeException("KABOOM!");
    }, null);
    final StateStoreMetadata storeMetadata = stateMgr.storeMetadata(persistentStorePartition);
    try {
        stateMgr.restore(storeMetadata, singletonList(consumerRecord));
        fail("should have thrown processor state exception when IO exception happens");
    } catch (final ProcessorStateException e) {
    // pass
    }
}
Also used : StateStoreMetadata(org.apache.kafka.streams.processor.internals.ProcessorStateManager.StateStoreMetadata) ProcessorStateException(org.apache.kafka.streams.errors.ProcessorStateException) Test(org.junit.Test)

Example 34 with ProcessorStateException

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

the class ProcessorStateManagerTest method shouldFlushGoodStoresEvenSomeThrowsException.

@Test
public void shouldFlushGoodStoresEvenSomeThrowsException() {
    final AtomicBoolean flushedStore = new AtomicBoolean(false);
    final MockKeyValueStore stateStore1 = new MockKeyValueStore(persistentStoreName, true) {

        @Override
        public void flush() {
            throw new RuntimeException("KABOOM!");
        }
    };
    final MockKeyValueStore stateStore2 = new MockKeyValueStore(persistentStoreTwoName, true) {

        @Override
        public void flush() {
            flushedStore.set(true);
        }
    };
    final ProcessorStateManager stateManager = getStateManager(Task.TaskType.ACTIVE);
    stateManager.registerStore(stateStore1, stateStore1.stateRestoreCallback, null);
    stateManager.registerStore(stateStore2, stateStore2.stateRestoreCallback, null);
    try {
        stateManager.flush();
    } catch (final ProcessorStateException expected) {
    /* ignore */
    }
    Assert.assertTrue(flushedStore.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MockKeyValueStore(org.apache.kafka.test.MockKeyValueStore) ProcessorStateException(org.apache.kafka.streams.errors.ProcessorStateException) Test(org.junit.Test)

Example 35 with ProcessorStateException

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

the class RocksDBStore method putAll.

@Override
public void putAll(final List<KeyValue<Bytes, byte[]>> entries) {
    try (final WriteBatch batch = new WriteBatch()) {
        dbAccessor.prepareBatch(entries, batch);
        StoreQueryUtils.updatePosition(position, context);
        write(batch);
    } catch (final RocksDBException e) {
        throw new ProcessorStateException("Error while batch writing to store " + name, e);
    }
}
Also used : RocksDBException(org.rocksdb.RocksDBException) WriteBatch(org.rocksdb.WriteBatch) ProcessorStateException(org.apache.kafka.streams.errors.ProcessorStateException)

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