Improve test coverage of CompositeReadOnlyKeyValueStore
Author: Jeyhun Karimov
Reviewers: Matthias J. Sax Eno Thereska Damian Guy
Closes from jeyhunkarimov/KAFKA-4656
@@ -18,6 +18,7 @@ package org.apache.kafka.streams.state.internals;
import org.apache.kafka.streams.KeyValue;
import org.apache.kafka.streams.errors.InvalidStateStoreException;
+import org.apache.kafka.streams.state.KeyValueIterator;
import org.apache.kafka.streams.state.KeyValueStore;
import org.apache.kafka.streams.state.QueryableStoreTypes;
import org.apache.kafka.test.NoOpReadOnlyStore;
@@ -28,11 +29,13 @@ import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.NoSuchElementException;
import static org.apache.kafka.test.StreamsTestUtils.toList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
public class CompositeReadOnlyKeyValueStoreTest {
@@ -96,6 +99,49 @@ public class CompositeReadOnlyKeyValueStoreTest {
assertNull(theStore.get("otherKey"));
}
+ @Test
+ public void shouldThrowNoSuchElementExceptionWhileNext() {
+ stubOneUnderlying.put("a", "1");
+ KeyValueIterator<String, String> keyValueIterator = theStore.range("a", "b");
+ keyValueIterator.next();
+ try {
+ keyValueIterator.next();
+ fail("Should have thrown NoSuchElementException with next()");
+ } catch (NoSuchElementException e) { }
+ }
+
+ @Test
+ public void shouldThrowNoSuchElementExceptionWhilePeekNext() {
+ stubOneUnderlying.put("a", "1");
+ KeyValueIterator<String, String> keyValueIterator = theStore.range("a", "b");
+ keyValueIterator.next();
+ try {
+ keyValueIterator.peekNextKey();
+ fail("Should have thrown NoSuchElementException with peekNextKey()");
+ } catch (NoSuchElementException e) { }
+ }
+
+ @Test
+ public void shouldThrowUnsupportedOperationExceptionWhileRemove() {
+ KeyValueIterator<String, String> keyValueIterator = theStore.all();
+ try {
+ keyValueIterator.remove();
+ fail("Should have thrown UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) { }
+ }
+
+ @Test
+ public void shouldThrowUnsupportedOperationExceptionWhileRange() {
+ stubOneUnderlying.put("a", "1");
+ stubOneUnderlying.put("b", "1");
+ KeyValueIterator<String, String> keyValueIterator = theStore.range("a", "b");
+ try {
+ keyValueIterator.remove();
+ fail("Should have thrown UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) { }
+ }
+
+
@SuppressWarnings("unchecked")
@Test
public void shouldFindValueForKeyWhenMultiStores() throws Exception {
@@ -171,6 +217,10 @@ public class CompositeReadOnlyKeyValueStoreTest {
rebalancing().get("anything");
}
+ @Test(expected = InvalidStateStoreException.class)
+ public void shouldThrowInvalidStoreExceptionOnApproximateNumEntriesDuringRebalance() throws Exception {
+ rebalancing().approximateNumEntries();
+ }
@Test(expected = InvalidStateStoreException.class)
public void shouldThrowInvalidStoreExceptionOnRangeDuringRebalance() throws Exception {
