Search in sources :

Example 6 with MockKeyValueStore

use of org.apache.kafka.test.MockKeyValueStore 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 7 with MockKeyValueStore

use of org.apache.kafka.test.MockKeyValueStore 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 8 with MockKeyValueStore

use of org.apache.kafka.test.MockKeyValueStore 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 9 with MockKeyValueStore

use of org.apache.kafka.test.MockKeyValueStore in project kafka by apache.

the class ProcessorStateManagerTest method shouldRestoreTimestampedStoreWithConverter.

@Test
public void shouldRestoreTimestampedStoreWithConverter() {
    final ProcessorStateManager stateMgr = getStateManager(Task.TaskType.ACTIVE);
    final MockKeyValueStore store = getConverterStore();
    try {
        stateMgr.registerStore(store, store.stateRestoreCallback, null);
        final StateStoreMetadata storeMetadata = stateMgr.storeMetadata(persistentStorePartition);
        assertThat(storeMetadata, notNullValue());
        stateMgr.restore(storeMetadata, singletonList(consumerRecord));
        assertThat(store.keys.size(), is(1));
        assertTrue(store.keys.contains(key));
        // we just check timestamped value length
        assertEquals(17, store.values.get(0).length);
    } finally {
        stateMgr.close();
    }
}
Also used : StateStoreMetadata(org.apache.kafka.streams.processor.internals.ProcessorStateManager.StateStoreMetadata) MockKeyValueStore(org.apache.kafka.test.MockKeyValueStore) Test(org.junit.Test)

Example 10 with MockKeyValueStore

use of org.apache.kafka.test.MockKeyValueStore 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)

Aggregations

MockKeyValueStore (org.apache.kafka.test.MockKeyValueStore)15 Test (org.junit.Test)11 Properties (java.util.Properties)5 ProcessorStateException (org.apache.kafka.streams.errors.ProcessorStateException)4 Utils.mkProperties (org.apache.kafka.common.utils.Utils.mkProperties)3 StreamsException (org.apache.kafka.streams.errors.StreamsException)3 TopologyConfig (org.apache.kafka.streams.processor.internals.namedtopology.TopologyConfig)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 TopicPartition (org.apache.kafka.common.TopicPartition)2 StateStore (org.apache.kafka.streams.processor.StateStore)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 File (java.io.File)1 BigInteger (java.math.BigInteger)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 MockConsumer (org.apache.kafka.clients.consumer.MockConsumer)1 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)1 TimeoutException (org.apache.kafka.common.errors.TimeoutException)1 Serdes (org.apache.kafka.common.serialization.Serdes)1 Utils.mkSet (org.apache.kafka.common.utils.Utils.mkSet)1