Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,15 @@ public void flush() {

@Override
public void close() {
flush();
underlying.close();
cache.close(cacheName);
try {
flush();
} finally {
try {
underlying.close();
} finally {
cache.close(cacheName);
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.kafka.streams.state.StoreBuilder;
import org.apache.kafka.streams.state.Stores;
import org.apache.kafka.test.InternalMockProcessorContext;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -103,6 +104,22 @@ protected <K, V> KeyValueStore<K, V> createKeyValueStore(final ProcessorContext
return store;
}

@Test
public void shouldCloseAfterErrorWithFlush() {
try {
cache = EasyMock.niceMock(ThreadCache.class);
context = new InternalMockProcessorContext(null, null, null, (RecordCollector) null, cache);
context.setRecordContext(new ProcessorRecordContext(10, 0, 0, topic, null));
store.init(context, null);
cache.flush("0_0-store");
EasyMock.expectLastCall().andThrow(new NullPointerException("Simulating an error on flush"));
EasyMock.replay(cache);
store.close();
} catch (final NullPointerException npe) {
assertFalse(underlyingStore.isOpen());
}
}

@Test
public void shouldPutGetToFromCache() {
store.put(bytesKey("key"), bytesValue("value"));
Expand Down Expand Up @@ -274,7 +291,8 @@ public void shouldThrowNullPointerExceptionOnPutAllWithNullKey() {
try {
store.putAll(entries);
fail("Should have thrown NullPointerException while putAll null key");
} catch (final NullPointerException e) { }
} catch (final NullPointerException e) {
}
}

@Test
Expand Down