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

commit 55610788f5852d2a3574c3b7f0d6d7bc8f569c82
Author: Kirk Lund <[email protected]>
AuthorDate: Fri Mar 23 14:05:58 2018 -0700

    GEODE-1279: Rename Bug45164DUnitTest as PREntrySetIteratorRegressionTest
---
 .../geode/internal/cache/Bug45164DUnitTest.java    | 113 ---------------------
 .../cache/PREntrySetIteratorRegressionTest.java    |  98 ++++++++++++++++++
 2 files changed, 98 insertions(+), 113 deletions(-)

diff --git 
a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug45164DUnitTest.java
 
b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug45164DUnitTest.java
deleted file mode 100644
index a295bfe..0000000
--- 
a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug45164DUnitTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
- * agreements. See the NOTICE file distributed with this work for additional 
information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the 
License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software 
distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
- * or implied. See the License for the specific language governing permissions 
and limitations under
- * the License.
- */
-package org.apache.geode.internal.cache;
-
-import static org.junit.Assert.*;
-
-import java.util.Map.Entry;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionShortcut;
-import org.apache.geode.cache30.CacheTestCase;
-import org.apache.geode.test.dunit.AsyncInvocation;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.LogWriterUtils;
-import org.apache.geode.test.dunit.SerializableRunnable;
-import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-@Category(DistributedTest.class)
-public class Bug45164DUnitTest extends JUnit4CacheTestCase {
-  private static final int count = 10000;
-  private static final int stride = 3;
-
-  public Bug45164DUnitTest() {
-    super();
-  }
-
-  @Test
-  public void testIterateWhileDestroy() throws Throwable {
-    SerializableRunnable destroy = new SerializableRunnable() {
-      @Override
-      public void run() {
-        Region<Integer, Object> region = getCache().getRegion("test");
-        for (int j = 0; j < count / stride; j += stride) {
-          region.destroy(j);
-        }
-      }
-    };
-
-    SerializableRunnable iterate = new SerializableRunnable() {
-      @Override
-      public void run() {
-        Region<Integer, Object> region = getCache().getRegion("test");
-
-        int i = 0;
-        for (Entry<Integer, Object> entry : region.entrySet()) {
-          i++;
-          if (entry == null) {
-            fail("Element " + i + " is null");
-
-          }
-        }
-      }
-    };
-
-    Host h = Host.getHost(0);
-    AsyncInvocation async1 = h.getVM(1).invokeAsync(destroy);
-    AsyncInvocation async2 = h.getVM(2).invokeAsync(iterate);
-
-    async1.getResult();
-    async2.getResult();
-  }
-
-  @Override
-  public final void postSetUp() throws Exception {
-    SerializableRunnable create = new SerializableRunnable() {
-      @Override
-      public void run() {
-        Cache cache = getCache(new CacheFactory());
-        Region<Integer, Object> region =
-            cache.<Integer, 
Object>createRegionFactory(RegionShortcut.PARTITION).create("test");
-        if (region == null) {
-          LogWriterUtils.getLogWriter().error("oops!");
-        }
-      }
-    };
-
-    SerializableRunnable load = new SerializableRunnable() {
-      @Override
-      public void run() {
-        Region<Integer, Object> region = getCache().getRegion("test");
-        for (int i = 0; i < count; i++) {
-          region.put(i, i);
-        }
-      }
-    };
-
-    Host h = Host.getHost(0);
-    h.getVM(1).invoke(create);
-    h.getVM(2).invoke(create);
-    h.getVM(3).invoke(create);
-
-    h.getVM(1).invoke(load);
-  }
-}
diff --git 
a/geode-core/src/test/java/org/apache/geode/internal/cache/PREntrySetIteratorRegressionTest.java
 
b/geode-core/src/test/java/org/apache/geode/internal/cache/PREntrySetIteratorRegressionTest.java
new file mode 100644
index 0000000..e67cab7
--- /dev/null
+++ 
b/geode-core/src/test/java/org/apache/geode/internal/cache/PREntrySetIteratorRegressionTest.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+package org.apache.geode.internal.cache;
+
+import static org.apache.geode.test.dunit.Host.getHost;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Map.Entry;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.test.dunit.AsyncInvocation;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.cache.CacheTestCase;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
+
+/**
+ * Iterating over Region.entrySet() should not return null for 
PartitionedRegion.
+ *
+ * <p>
+ * TRAC #45164: Iterating on Region.entrySet() can return null on partitioned 
region
+ */
+@Category(DistributedTest.class)
+public class PREntrySetIteratorRegressionTest extends CacheTestCase {
+
+  private static final int ENTRY_COUNT = 10_000;
+  private static final int ENTRY_DESTROY_SEQUENCE = 3;
+
+  private String uniqueName;
+
+  private VM vm1;
+  private VM vm2;
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Before
+  public void setUp() throws Exception {
+    vm1 = getHost(0).getVM(1);
+    vm2 = getHost(0).getVM(2);
+
+    uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+
+    vm1.invoke(() -> createPartitionedRegion());
+    vm2.invoke(() -> createPartitionedRegion());
+
+    vm1.invoke(() -> doPuts());
+  }
+
+  @Test
+  public void regionEntrySetIteratorNextShouldNeverReturnNull() throws 
Exception {
+    AsyncInvocation destroySomeEntries = vm1.invokeAsync(() -> {
+      Region<Integer, Object> region = getCache().getRegion(uniqueName);
+      for (int j = 0; j < ENTRY_COUNT / ENTRY_DESTROY_SEQUENCE; j += 
ENTRY_DESTROY_SEQUENCE) {
+        region.destroy(j);
+      }
+    });
+
+    AsyncInvocation validateEntrySetIteratorContainsNoNulls = 
vm2.invokeAsync(() -> {
+      Region<Integer, Object> region = getCache().getRegion(uniqueName);
+      for (Entry<Integer, Object> entry : region.entrySet()) {
+        assertThat(entry).isNotNull();
+      }
+    });
+
+    destroySomeEntries.await();
+    validateEntrySetIteratorContainsNoNulls.await();
+  }
+
+  private void createPartitionedRegion() {
+    getCache().<Integer, 
Object>createRegionFactory(RegionShortcut.PARTITION).create(uniqueName);
+  }
+
+  private void doPuts() {
+    Region<Integer, Object> region = getCache().getRegion(uniqueName);
+    for (int i = 0; i < ENTRY_COUNT; i++) {
+      region.put(i, i);
+    }
+  }
+}

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

Reply via email to