You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2018/03/26 17:37:27 UTC
[geode] 02/19: GEODE-1279: Rename Bug33726JUnitTest as
AfterRegionCreateNotBeforeRegionInitRegressionTest
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 0618d54dc1ea5ea2a75406918f404bc76b016eab
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Tue Mar 20 13:43:59 2018 -0700
GEODE-1279: Rename Bug33726JUnitTest as AfterRegionCreateNotBeforeRegionInitRegressionTest
General fixup of test to use Awaitility and ErrorCollector.
---
...ionCreateNotBeforeRegionInitRegressionTest.java | 94 ++++++++++++++++++
.../geode/internal/cache/Bug33726JUnitTest.java | 110 ---------------------
2 files changed, 94 insertions(+), 110 deletions(-)
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/AfterRegionCreateNotBeforeRegionInitRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/AfterRegionCreateNotBeforeRegionInitRegressionTest.java
new file mode 100755
index 0000000..985f42f
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/AfterRegionCreateNotBeforeRegionInitRegressionTest.java
@@ -0,0 +1,94 @@
+/*
+ * 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 java.util.concurrent.TimeUnit.MINUTES;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+import static org.hamcrest.CoreMatchers.is;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ErrorCollector;
+
+import org.apache.geode.cache.AttributesFactory;
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionEvent;
+import org.apache.geode.cache.util.CacheListenerAdapter;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+
+/**
+ * AFTER_REGION_CREATE was being sent before region initialization (bug 33726). Test to verify that
+ * that is no longer the case.
+ *
+ * <p>
+ * TRAC #33726: afterRegionCreate event delivered before region initialization occurs
+ */
+@Category(IntegrationTest.class)
+public class AfterRegionCreateNotBeforeRegionInitRegressionTest {
+
+ private Cache cache;
+ private TestCacheListener cacheListener;
+
+ @Rule
+ public ErrorCollector errorCollector = new ErrorCollector();
+
+ @Before
+ public void setUp() {
+ cache = new CacheFactory().set(LOCATORS, "").set(MCAST_PORT, "0").create();
+ cacheListener = new TestCacheListener();
+ }
+
+ @After
+ public void tearDown() {
+ cache.close();
+ }
+
+ @Test
+ public void testAfterRegionCreate() throws Exception {
+ AttributesFactory factory = new AttributesFactory();
+ factory.setCacheListener(cacheListener);
+
+ Region region = cache.createRegion("testRegion", factory.create());
+ region.createSubregion("testSubRegion", factory.create());
+
+ await().atMost(1, MINUTES)
+ .until(() -> assertThat(cacheListener.afterRegionCreateCount.get()).isEqualTo(2));
+ }
+
+ private class TestCacheListener extends CacheListenerAdapter {
+
+ final AtomicInteger afterRegionCreateCount = new AtomicInteger();
+
+ @Override
+ public void afterRegionCreate(RegionEvent event) {
+ InternalRegion region = (InternalRegion) event.getRegion();
+ String regionPath = event.getRegion().getFullPath();
+ if (regionPath.contains("/testRegion/testSubRegion") || regionPath.contains("/testRegion")) {
+ afterRegionCreateCount.incrementAndGet();
+ errorCollector.checkThat(region.isInitialized(), is(true));
+ }
+ }
+ }
+}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug33726JUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/Bug33726JUnitTest.java
deleted file mode 100755
index 09e0b9a..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/Bug33726JUnitTest.java
+++ /dev/null
@@ -1,110 +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.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.junit.Assert.fail;
-
-import java.util.Properties;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.cache.AttributesFactory;
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionEvent;
-import org.apache.geode.cache.util.CacheListenerAdapter;
-import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.test.junit.categories.IntegrationTest;
-
-/**
- * AFTER_REGION_CREATE was being sent before region initialization (bug 33726). Test to verify that
- * that is no longer the case.
- *
- */
-@Category(IntegrationTest.class)
-public class Bug33726JUnitTest {
-
- private boolean[] flags = new boolean[2];
-
- private static boolean isOK = false;
-
- @Test
- public void testAfterRegionCreate() {
- Properties props = new Properties();
- props.put(MCAST_PORT, "0");
- DistributedSystem ds = DistributedSystem.connect(props);
- AttributesFactory factory = new AttributesFactory();
- factory.setCacheListener(new TestCacheListener());
- Cache cache = null;
- try {
- cache = CacheFactory.create(ds);
-
- Region region = cache.createRegion("testRegion", factory.create());
- region.createSubregion("testSubRegion", factory.create());
- } catch (Exception e) {
- fail("Failed to create cache due to " + e);
- e.printStackTrace();
- }
-
-
- if (!testFlag()) {
- fail("After create sent although region was not initialized");
- }
- }
-
- public boolean testFlag() {
- if (isOK) {
- return isOK;
- } else {
- synchronized (Bug33726JUnitTest.class) {
- if (isOK) {
- return isOK;
- } else {
- try {
- Bug33726JUnitTest.class.wait(120000);
- } catch (InterruptedException ie) {
- fail("interrupted");
- }
- }
- }
- return isOK;
- }
- }
-
- protected class TestCacheListener extends CacheListenerAdapter {
-
- public void afterRegionCreate(RegionEvent event) {
- Region region = event.getRegion();
- if (((LocalRegion) region).isInitialized()) {
- String regionPath = event.getRegion().getFullPath();
- if (regionPath.indexOf("/testRegion/testSubRegion") >= 0) {
- flags[1] = true;
- } else if (regionPath.indexOf("/testRegion") >= 0) {
- flags[0] = true;
- }
-
- }
- if (flags[0] && flags[1]) {
- isOK = true;
- synchronized (Bug33726JUnitTest.class) {
- Bug33726JUnitTest.class.notify();
- }
- }
- }
- }
-}
--
To stop receiving notification emails like this one, please contact
klund@apache.org.