kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From guozh...@apache.org
Subject kafka git commit: KAFKA-4654: Improve test coverage for MemoryLRUCacheStore
Date Fri, 10 Feb 2017 01:20:33 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk b865a8b1d -> d24616777


KAFKA-4654: Improve test coverage for MemoryLRUCacheStore

Author: bbejeck <bbejeck@gmail.com>

Reviewers: Damian Guy, Guozhang Wang

Closes #2500 from bbejeck/KAFKA-4654_improve_MemroryLRUCache_test_coverage


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/d2461677
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/d2461677
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/d2461677

Branch: refs/heads/trunk
Commit: d24616777ade24a37c5e7e517bcd1d8912eaf19d
Parents: b865a8b
Author: Bill Bejeck <bbejeck@gmail.com>
Authored: Thu Feb 9 17:20:30 2017 -0800
Committer: Guozhang Wang <wangguoz@gmail.com>
Committed: Thu Feb 9 17:20:30 2017 -0800

----------------------------------------------------------------------
 .../internals/InMemoryLRUCacheStoreTest.java    | 45 ++++++++++++++++++++
 1 file changed, 45 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/d2461677/streams/src/test/java/org/apache/kafka/streams/state/internals/InMemoryLRUCacheStoreTest.java
----------------------------------------------------------------------
diff --git a/streams/src/test/java/org/apache/kafka/streams/state/internals/InMemoryLRUCacheStoreTest.java
b/streams/src/test/java/org/apache/kafka/streams/state/internals/InMemoryLRUCacheStoreTest.java
index fd9ea96..ed176f2 100644
--- a/streams/src/test/java/org/apache/kafka/streams/state/internals/InMemoryLRUCacheStoreTest.java
+++ b/streams/src/test/java/org/apache/kafka/streams/state/internals/InMemoryLRUCacheStoreTest.java
@@ -16,13 +16,20 @@
  */
 package org.apache.kafka.streams.state.internals;
 
+import org.apache.kafka.streams.KeyValue;
 import org.apache.kafka.streams.processor.ProcessorContext;
 import org.apache.kafka.streams.processor.StateStoreSupplier;
 import org.apache.kafka.streams.state.KeyValueStore;
 import org.apache.kafka.streams.state.Stores;
 import org.junit.Test;
 
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.equalTo;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 public class InMemoryLRUCacheStoreTest extends AbstractKeyValueStoreTest {
@@ -48,6 +55,43 @@ public class InMemoryLRUCacheStoreTest extends AbstractKeyValueStoreTest
{
     }
 
     @Test
+    public void shouldPutAllKeyValuePairs() {
+        final List<KeyValue<Integer, String>> kvPairs = Arrays.asList(KeyValue.pair(1,
"1"),
+                KeyValue.pair(2, "2"),
+                KeyValue.pair(3, "3"));
+
+        store.putAll(kvPairs);
+
+        assertThat(store.approximateNumEntries(), equalTo(3L));
+
+        for (KeyValue<Integer, String> kvPair : kvPairs) {
+            assertThat(store.get(kvPair.key), equalTo(kvPair.value));
+        }
+    }
+
+    @Test
+    public void shouldUpdateValuesForExistingKeysOnPutAll() {
+        final List<KeyValue<Integer, String>> kvPairs = Arrays.asList(KeyValue.pair(1,
"1"),
+                KeyValue.pair(2, "2"),
+                KeyValue.pair(3, "3"));
+
+        store.putAll(kvPairs);
+        
+
+        final List<KeyValue<Integer, String>> updatedKvPairs = Arrays.asList(KeyValue.pair(1,
"ONE"),
+                KeyValue.pair(2, "TWO"),
+                KeyValue.pair(3, "THREE"));
+
+        store.putAll(updatedKvPairs);
+
+        assertThat(store.approximateNumEntries(), equalTo(3L));
+        
+        for (KeyValue<Integer, String> kvPair : updatedKvPairs) {
+            assertThat(store.get(kvPair.key), equalTo(kvPair.value));
+        }
+    }
+
+    @Test
     public void testEvict() {
         // Create the test driver ...
         store.put(0, "zero");
@@ -93,4 +137,5 @@ public class InMemoryLRUCacheStoreTest extends AbstractKeyValueStoreTest
{
         assertTrue(driver.flushedEntryRemoved(3));
         assertEquals(3, driver.numFlushedEntryRemoved());
     }
+    
 }


Mime
View raw message