This is an automated email from the ASF dual-hosted git repository.

klund pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 8f36acf  GEODE-4832: Cleanup CacheWriterGetOldValueIntegrationTest
8f36acf is described below

commit 8f36acf34b91708f37a46f95e61561dd8b741823
Author: Kirk Lund <[email protected]>
AuthorDate: Mon Mar 19 16:42:11 2018 -0700

    GEODE-4832: Cleanup CacheWriterGetOldValueIntegrationTest
---
 .../CacheWriterGetOldValueIntegrationTest.java     | 179 ++++++++++-----------
 1 file changed, 88 insertions(+), 91 deletions(-)

diff --git 
a/geode-core/src/test/java/org/apache/geode/internal/cache/CacheWriterGetOldValueIntegrationTest.java
 
b/geode-core/src/test/java/org/apache/geode/internal/cache/CacheWriterGetOldValueIntegrationTest.java
index 392af3e..448c4f1 100644
--- 
a/geode-core/src/test/java/org/apache/geode/internal/cache/CacheWriterGetOldValueIntegrationTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/internal/cache/CacheWriterGetOldValueIntegrationTest.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.junit.After;
 import org.junit.Before;
@@ -46,16 +47,13 @@ import 
org.apache.geode.test.junit.categories.IntegrationTest;
 @Category({IntegrationTest.class, FlakyTest.class})
 public class CacheWriterGetOldValueIntegrationTest {
 
-  private GemFireCacheImpl cache = null;
+  private final Map<String, String> expectedValues = new HashMap<>();
+
+  private InternalCache cache;
 
   @Before
   public void setUp() throws Exception {
-    createCache();
-  }
-
-  private void createCache() {
-    cache =
-        (GemFireCacheImpl) new CacheFactory().set("locators", 
"").set("mcast-port", "0").create();
+    cache = (InternalCache) new CacheFactory().set("locators", 
"").set("mcast-port", "0").create();
   }
 
   @After
@@ -65,153 +63,152 @@ public class CacheWriterGetOldValueIntegrationTest {
   }
 
   @Test
-  public void getOldValueInCacheWriterReturnsValueOfEvictedEntry() {
-    doTest(false);
-  }
+  public void doPutAll() {
+    Region<String, String> region = createOverflowRegion();
+    put(region, "k1", "v1");
+    put(region, "k2", "v2");
 
-  @Test
-  public void 
getOldValueWithTransactionInCacheWriterReturnsValueOfEvictedEntry() {
-    doTest(true);
-  }
+    PutAllCacheWriter<String, String> cacheWriter = new PutAllCacheWriter<>();
+    region.getAttributesMutator().setCacheWriter(cacheWriter);
 
-  @Test
-  public void doPutAll() {
-    PutAllCacheWriter<String, String> cw;
-    Region<String, String> r = createOverflowRegion();
-    put(r, "k1", "v1");
-    put(r, "k2", "v2");
-    cw = new PutAllCacheWriter<>();
-    r.getAttributesMutator().setCacheWriter(cw);
-    HashMap<String, String> putAllMap = new HashMap<>();
+    Map<String, String> putAllMap = new HashMap<>();
     putAllMap.put("k1", "update1");
     putAllMap.put("k2", "update2");
-    r.putAll(putAllMap);
+    region.putAll(putAllMap);
 
-    assertThat(cw.getSeenEntries()).isEqualTo(this.expectedValues);
+    assertThat(cacheWriter.getSeenEntries()).isEqualTo(expectedValues);
   }
 
   @Test
   public void doRemoveAll() {
-    RemoveAllCacheWriter<String, String> cw;
-    Region<String, String> r = createOverflowRegion();
-    put(r, "k1", "v1");
-    put(r, "k2", "v2");
-    cw = new RemoveAllCacheWriter<>();
-    r.getAttributesMutator().setCacheWriter(cw);
-    r.removeAll(Arrays.asList("k1", "k2"));
-
-    assertThat(cw.getSeenEntries()).isEqualTo(this.expectedValues);
+    Region<String, String> region = createOverflowRegion();
+    put(region, "k1", "v1");
+    put(region, "k2", "v2");
+
+    RemoveAllCacheWriter<String, String> cacheWriter = new 
RemoveAllCacheWriter<>();
+    region.getAttributesMutator().setCacheWriter(cacheWriter);
+
+    region.removeAll(Arrays.asList("k1", "k2"));
+
+    assertThat(cacheWriter.getSeenEntries()).isEqualTo(expectedValues);
   }
 
-  private void doTest(boolean useTx) {
-    String evictedKey;
-    String unevictedKey;
-    String evictedValue;
-    String unevictedValue;
-    CacheWriterWithExpectedOldValue<String, String> cw;
+  @Test
+  public void getOldValueInCacheWriterReturnsValueOfEvictedEntry() {
+    doOldValueTest(false);
+  }
+
+  @Test
+  public void 
getOldValueWithTransactionInCacheWriterReturnsValueOfEvictedEntry() {
+    doOldValueTest(true);
+  }
 
-    Region<String, String> r = createOverflowRegion();
-    put(r, "k1", "v1");
-    put(r, "k2", "v2");
+  private void doOldValueTest(boolean useTx) {
+    Region<String, String> region = createOverflowRegion();
+    put(region, "k1", "v1");
+    put(region, "k2", "v2");
 
     beginTx(useTx);
-    unevictedKey = getUnevictedKey(r);
-    unevictedValue = expectedValues.get(unevictedKey);
-    cw = new CacheWriterWithExpectedOldValue<>(unevictedValue);
-    r.getAttributesMutator().setCacheWriter(cw);
-    assertThat(put(r, unevictedKey, "update1")).isEqualTo(unevictedValue);
-    assertThat(cw.getUnexpectedEvents()).isEmpty();
+    String unevictedKey = getUnevictedKey(region);
+    String unevictedValue = expectedValues.get(unevictedKey);
+    CacheWriterWithExpectedOldValue<String, String> cacheWriter =
+        new CacheWriterWithExpectedOldValue<>(unevictedValue);
+    region.getAttributesMutator().setCacheWriter(cacheWriter);
+    assertThat(put(region, unevictedKey, "update1")).isEqualTo(unevictedValue);
+    assertThat(cacheWriter.getUnexpectedEvents()).isEmpty();
     endTx(useTx);
 
     beginTx(useTx);
-    evictedKey = getEvictedKey(r);
-    evictedValue = expectedValues.get(evictedKey);
-    cw = new CacheWriterWithExpectedOldValue<>(evictedValue);
-    r.getAttributesMutator().setCacheWriter(cw);
-    assertThat(put(r, evictedKey, "update2")).isEqualTo(useTx ? evictedValue : 
null);
-    assertThat(cw.getUnexpectedEvents()).isEmpty();
+    String evictedKey = getEvictedKey(region);
+    String evictedValue = expectedValues.get(evictedKey);
+    cacheWriter = new CacheWriterWithExpectedOldValue<>(evictedValue);
+    region.getAttributesMutator().setCacheWriter(cacheWriter);
+    assertThat(put(region, evictedKey, "update2")).isEqualTo(useTx ? 
evictedValue : null);
+    assertThat(cacheWriter.getUnexpectedEvents()).isEmpty();
     endTx(useTx);
 
     beginTx(useTx);
-    evictedKey = getEvictedKey(r);
+    evictedKey = getEvictedKey(region);
     evictedValue = expectedValues.get(evictedKey);
-    cw = new CacheWriterWithExpectedOldValue<>(evictedValue);
-    r.getAttributesMutator().setCacheWriter(cw);
-    assertThat(r.destroy(evictedKey)).isEqualTo(useTx ? evictedValue : null);
-    assertThat(cw.getUnexpectedEvents()).isEmpty();
+    cacheWriter = new CacheWriterWithExpectedOldValue<>(evictedValue);
+    region.getAttributesMutator().setCacheWriter(cacheWriter);
+    assertThat(region.destroy(evictedKey)).isEqualTo(useTx ? evictedValue : 
null);
+    assertThat(cacheWriter.getUnexpectedEvents()).isEmpty();
     endTx(useTx);
   }
 
   private void beginTx(boolean useTx) {
     if (useTx) {
-      this.cache.getCacheTransactionManager().begin();
+      cache.getCacheTransactionManager().begin();
     }
   }
 
   private void endTx(boolean useTx) {
     if (useTx) {
-      this.cache.getCacheTransactionManager().commit();
+      cache.getCacheTransactionManager().commit();
     }
   }
 
-  private final HashMap<String, String> expectedValues = new HashMap<>();
-
-  private String put(Region<String, String> r, String k, String v) {
-    String result = r.put(k, v);
-    expectedValues.put(k, v);
+  private String put(Map<String, String> region, String key, String value) {
+    String result = region.put(key, value);
+    expectedValues.put(key, value);
     return result;
   }
 
-  private String getEvictedKey(Region<String, String> r) {
-    InternalRegion ir = (InternalRegion) r;
+  private String getEvictedKey(Region<String, String> region) {
+    InternalRegion internalRegion = (InternalRegion) region;
+    RegionEntry regionEntry = internalRegion.getRegionEntry("k1");
+
     String evictedKey = null;
-    RegionEntry re = ir.getRegionEntry("k1");
-    if (re.getValueAsToken() == null) {
+    if (regionEntry.getValueAsToken() == null) {
       evictedKey = "k1";
     }
-    re = ir.getRegionEntry("k2");
-    if (re.getValueAsToken() == null) {
+    regionEntry = internalRegion.getRegionEntry("k2");
+    if (regionEntry.getValueAsToken() == null) {
       evictedKey = "k2";
     }
+
     assertThat(evictedKey).isNotNull();
     return evictedKey;
   }
 
-  private String getUnevictedKey(Region<String, String> r) {
-    InternalRegion ir = (InternalRegion) r;
+  private String getUnevictedKey(Region<String, String> region) {
+    InternalRegion internalRegion = (InternalRegion) region;
+    RegionEntry regionEntry = internalRegion.getRegionEntry("k1");
+
     String unevictedKey = null;
-    RegionEntry re = ir.getRegionEntry("k1");
-    if (re.getValueAsToken() != null) {
+    if (regionEntry.getValueAsToken() != null) {
       unevictedKey = "k1";
     }
-    re = ir.getRegionEntry("k2");
-    if (re.getValueAsToken() != null) {
+    regionEntry = internalRegion.getRegionEntry("k2");
+    if (regionEntry.getValueAsToken() != null) {
       unevictedKey = "k2";
     }
+
     assertThat(unevictedKey).isNotNull();
     return unevictedKey;
   }
 
   private static class CacheWriterWithExpectedOldValue<K, V> extends 
CacheWriterAdapter<K, V> {
     private final V expectedOldValue;
-    private final ArrayList<EntryEvent<K, V>> unexpectedEvents = new 
ArrayList<>();
+    private final List<EntryEvent<K, V>> unexpectedEvents = new ArrayList<>();
 
     CacheWriterWithExpectedOldValue(V expectedOldValue) {
       this.expectedOldValue = expectedOldValue;
     }
 
     public List<EntryEvent<K, V>> getUnexpectedEvents() {
-      return this.unexpectedEvents;
+      return unexpectedEvents;
     }
 
     private void checkEvent(EntryEvent<K, V> event) {
-      if (this.expectedOldValue == null) {
+      if (expectedOldValue == null) {
         if (event.getOldValue() != null) {
-          this.unexpectedEvents.add(event);
+          unexpectedEvents.add(event);
         }
       } else {
-        if (!this.expectedOldValue.equals(event.getOldValue())) {
-          this.unexpectedEvents.add(event);
+        if (!expectedOldValue.equals(event.getOldValue())) {
+          unexpectedEvents.add(event);
         }
       }
     }
@@ -233,10 +230,10 @@ public class CacheWriterGetOldValueIntegrationTest {
   }
 
   private static class PutAllCacheWriter<K, V> extends CacheWriterAdapter<K, 
V> {
-    private final HashMap<K, V> seenEntries = new HashMap<>();
+    private final Map<K, V> seenEntries = new HashMap<>();
 
-    public HashMap<K, V> getSeenEntries() {
-      return this.seenEntries;
+    public Map<K, V> getSeenEntries() {
+      return seenEntries;
     }
 
     @Override
@@ -256,10 +253,10 @@ public class CacheWriterGetOldValueIntegrationTest {
   }
 
   private static class RemoveAllCacheWriter<K, V> extends 
CacheWriterAdapter<K, V> {
-    private final HashMap<K, V> seenEntries = new HashMap<>();
+    private final Map<K, V> seenEntries = new HashMap<>();
 
-    public HashMap<K, V> getSeenEntries() {
-      return this.seenEntries;
+    public Map<K, V> getSeenEntries() {
+      return seenEntries;
     }
 
     @Override

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to