Search in sources :

Example 1 with NoOpReadOnlyStore

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

the class GlobalStateManagerImplTest method shouldNotCloseStoresIfCloseAlreadyCalled.

@Test
public void shouldNotCloseStoresIfCloseAlreadyCalled() throws Exception {
    stateManager.initialize(context);
    initializeConsumer(1, 1, t1);
    stateManager.register(new NoOpReadOnlyStore("t1-store") {

        @Override
        public void close() {
            if (!isOpen()) {
                throw new RuntimeException("store already closed");
            }
            super.close();
        }
    }, false, stateRestoreCallback);
    stateManager.close(Collections.<TopicPartition, Long>emptyMap());
    stateManager.close(Collections.<TopicPartition, Long>emptyMap());
}
Also used : NoOpReadOnlyStore(org.apache.kafka.test.NoOpReadOnlyStore) Test(org.junit.Test)

Example 2 with NoOpReadOnlyStore

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

the class GlobalStateManagerImplTest method shouldAttemptToCloseAllStoresEvenWhenSomeException.

@Test
public void shouldAttemptToCloseAllStoresEvenWhenSomeException() throws Exception {
    stateManager.initialize(context);
    initializeConsumer(1, 1, t1);
    initializeConsumer(1, 1, t2);
    final NoOpReadOnlyStore store = new NoOpReadOnlyStore("t1-store") {

        @Override
        public void close() {
            super.close();
            throw new RuntimeException("KABOOM!");
        }
    };
    stateManager.register(store, false, stateRestoreCallback);
    stateManager.register(store2, false, stateRestoreCallback);
    try {
        stateManager.close(Collections.<TopicPartition, Long>emptyMap());
    } catch (ProcessorStateException e) {
    // expected
    }
    assertFalse(store.isOpen());
    assertFalse(store2.isOpen());
}
Also used : NoOpReadOnlyStore(org.apache.kafka.test.NoOpReadOnlyStore) ProcessorStateException(org.apache.kafka.streams.errors.ProcessorStateException) Test(org.junit.Test)

Example 3 with NoOpReadOnlyStore

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

the class GlobalStateManagerImplTest method shouldThrowProcessorStateStoreExceptionIfStoreCloseFailed.

@Test(expected = ProcessorStateException.class)
public void shouldThrowProcessorStateStoreExceptionIfStoreCloseFailed() throws Exception {
    stateManager.initialize(context);
    initializeConsumer(1, 1, t1);
    stateManager.register(new NoOpReadOnlyStore(store1.name()) {

        @Override
        public void close() {
            throw new RuntimeException("KABOOM!");
        }
    }, false, stateRestoreCallback);
    stateManager.close(Collections.<TopicPartition, Long>emptyMap());
}
Also used : NoOpReadOnlyStore(org.apache.kafka.test.NoOpReadOnlyStore) Test(org.junit.Test)

Example 4 with NoOpReadOnlyStore

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

the class GlobalStateManagerImplTest method shouldThrowProcessorStateStoreExceptionIfStoreFlushFailed.

@Test(expected = ProcessorStateException.class)
public void shouldThrowProcessorStateStoreExceptionIfStoreFlushFailed() throws Exception {
    stateManager.initialize(context);
    final TheStateRestoreCallback stateRestoreCallback = new TheStateRestoreCallback();
    // register the stores
    initializeConsumer(1, 1, t1);
    stateManager.register(new NoOpReadOnlyStore(store1.name()) {

        @Override
        public void flush() {
            throw new RuntimeException("KABOOM!");
        }
    }, false, stateRestoreCallback);
    stateManager.flush(context);
}
Also used : NoOpReadOnlyStore(org.apache.kafka.test.NoOpReadOnlyStore) Test(org.junit.Test)

Example 5 with NoOpReadOnlyStore

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

the class GlobalStateManagerImplTest method before.

@Before
public void before() throws IOException {
    final Map<String, String> storeToTopic = new HashMap<>();
    storeToTopic.put("t1-store", "t1");
    storeToTopic.put("t2-store", "t2");
    final Map<StateStore, ProcessorNode> storeToProcessorNode = new HashMap<>();
    store1 = new NoOpReadOnlyStore<>("t1-store");
    storeToProcessorNode.put(store1, new MockProcessorNode(-1));
    store2 = new NoOpReadOnlyStore("t2-store");
    storeToProcessorNode.put(store2, new MockProcessorNode(-1));
    topology = new ProcessorTopology(Collections.<ProcessorNode>emptyList(), Collections.<String, SourceNode>emptyMap(), Collections.<String, SinkNode>emptyMap(), Collections.<StateStore>emptyList(), storeToTopic, Arrays.<StateStore>asList(store1, store2));
    context = new NoOpProcessorContext();
    stateDirPath = TestUtils.tempDirectory().getPath();
    stateDirectory = new StateDirectory("appId", stateDirPath, time);
    consumer = new MockConsumer<>(OffsetResetStrategy.EARLIEST);
    stateManager = new GlobalStateManagerImpl(topology, consumer, stateDirectory);
    checkpointFile = new File(stateManager.baseDir(), ProcessorStateManager.CHECKPOINT_FILE_NAME);
}
Also used : MockProcessorNode(org.apache.kafka.test.MockProcessorNode) HashMap(java.util.HashMap) NoOpProcessorContext(org.apache.kafka.test.NoOpProcessorContext) StateStore(org.apache.kafka.streams.processor.StateStore) MockProcessorNode(org.apache.kafka.test.MockProcessorNode) NoOpReadOnlyStore(org.apache.kafka.test.NoOpReadOnlyStore) File(java.io.File) Before(org.junit.Before)

Aggregations

NoOpReadOnlyStore (org.apache.kafka.test.NoOpReadOnlyStore)5 Test (org.junit.Test)4 File (java.io.File)1 HashMap (java.util.HashMap)1 ProcessorStateException (org.apache.kafka.streams.errors.ProcessorStateException)1 StateStore (org.apache.kafka.streams.processor.StateStore)1 MockProcessorNode (org.apache.kafka.test.MockProcessorNode)1 NoOpProcessorContext (org.apache.kafka.test.NoOpProcessorContext)1 Before (org.junit.Before)1