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/04/30 23:58:01 UTC

[geode] 07/07: GEODE-1279: Rename Bug37805DUnitTest to RootRegionsExcludesHARegionsRegressionTest

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 204f127d37ea595b750fae9f96e9dde031204372
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Mon Apr 30 12:46:20 2018 -0700

    GEODE-1279: Rename Bug37805DUnitTest to RootRegionsExcludesHARegionsRegressionTest
---
 .../cache/tier/sockets/Bug37805DUnitTest.java      | 140 --------------------
 ...RootRegionsExcludesHARegionsRegressionTest.java | 142 +++++++++++++++++++++
 2 files changed, 142 insertions(+), 140 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/Bug37805DUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/Bug37805DUnitTest.java
deleted file mode 100644
index f20ecd5..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/Bug37805DUnitTest.java
+++ /dev/null
@@ -1,140 +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.tier.sockets;
-
-import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID;
-import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_TIMEOUT;
-import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
-import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.junit.Assert.fail;
-
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.Set;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.cache.CacheException;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.client.Pool;
-import org.apache.geode.cache.client.PoolFactory;
-import org.apache.geode.cache.client.PoolManager;
-import org.apache.geode.cache30.CacheSerializableRunnable;
-import org.apache.geode.internal.cache.HARegion;
-import org.apache.geode.internal.cache.PoolFactoryImpl;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.NetworkUtils;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
-import org.apache.geode.test.junit.categories.ClientServerTest;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-/**
- * The test is written to verify that the rootRegion() in GemfireCache.java doesn't return any
- * metaRegions or HA Regions.
- */
-@Category({DistributedTest.class, ClientServerTest.class})
-public class Bug37805DUnitTest extends JUnit4DistributedTestCase {
-
-  private VM server1VM;
-
-  private VM durableClientVM;
-
-  private String regionName;
-
-  private int PORT1;
-
-  @Override
-  public final void postSetUp() throws Exception {
-    Host host = Host.getHost(0);
-    this.server1VM = host.getVM(0);
-    this.durableClientVM = host.getVM(1);
-    regionName = "Bug37805_region";
-    CacheServerTestUtil.disableShufflingOfEndpoints();
-  }
-
-  @Override
-  public final void preTearDown() throws Exception {
-    // Stop server 1
-    this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
-    CacheServerTestUtil.resetDisableShufflingOfEndpointsFlag();
-  }
-
-  @Test
-  public void testFunctionality() {
-    // Step 1: Starting the servers
-
-    PORT1 = ((Integer) this.server1VM
-        .invoke(() -> CacheServerTestUtil.createCacheServer(regionName, new Boolean(true))))
-            .intValue();
-    final int durableClientTimeout = 600;
-
-
-    // Step 2: Starting Client and creating durableRegion
-    final String durableClientId = getName() + "_client";
-
-    this.durableClientVM
-        .invoke(() -> CacheServerTestUtil.createCacheClient(
-            getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), PORT1, true,
-                0),
-            regionName,
-            getDurableClientDistributedSystemProperties(durableClientId, durableClientTimeout),
-            Boolean.TRUE));
-
-    // Send clientReady message
-    this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
-      public void run2() throws CacheException {
-        CacheServerTestUtil.getCache().readyForEvents();
-      }
-    });
-
-    this.server1VM.invoke(() -> Bug37805DUnitTest.checkRootRegions());
-
-
-    this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
-  }
-
-  public static void checkRootRegions() {
-    Set rootRegions = CacheServerTestUtil.getCache().rootRegions();
-    if (rootRegions != null) {
-      for (Iterator itr = rootRegions.iterator(); itr.hasNext();) {
-        Region region = (Region) itr.next();
-        if (region instanceof HARegion)
-          fail("region of HARegion present");
-      }
-    }
-    // assertNull(rootRegions);
-    // assertIndexDetailsEquals(0,((Collection)CacheServerTestUtil.getCache().rootRegions()).size());
-  }
-
-  private Pool getClientPool(String host, int server1Port, boolean establishCallbackConnection,
-      int redundancyLevel) {
-    PoolFactory pf = PoolManager.createFactory();
-    pf.addServer(host, server1Port).setSubscriptionEnabled(establishCallbackConnection)
-        .setSubscriptionRedundancy(redundancyLevel);
-    return ((PoolFactoryImpl) pf).getPoolAttributes();
-  }
-
-  private Properties getDurableClientDistributedSystemProperties(String durableClientId,
-      int durableClientTimeout) {
-    Properties properties = new Properties();
-    properties.setProperty(MCAST_PORT, "0");
-    properties.setProperty(LOCATORS, "");
-    properties.setProperty(DURABLE_CLIENT_ID, durableClientId);
-    properties.setProperty(DURABLE_CLIENT_TIMEOUT, String.valueOf(durableClientTimeout));
-    return properties;
-  }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/RootRegionsExcludesHARegionsRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/RootRegionsExcludesHARegionsRegressionTest.java
new file mode 100644
index 0000000..a4badf6
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/RootRegionsExcludesHARegionsRegressionTest.java
@@ -0,0 +1,142 @@
+/*
+ * 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.tier.sockets;
+
+import static org.apache.geode.cache.RegionShortcut.REPLICATE;
+import static org.apache.geode.cache.client.ClientRegionShortcut.LOCAL;
+import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_ID;
+import static org.apache.geode.distributed.ConfigurationProperties.DURABLE_CLIENT_TIMEOUT;
+import static org.apache.geode.test.dunit.VM.getHostName;
+import static org.apache.geode.test.dunit.VM.getVM;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Properties;
+import java.util.Set;
+
+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.RegionFactory;
+import org.apache.geode.cache.RegionService;
+import org.apache.geode.cache.client.ClientRegionFactory;
+import org.apache.geode.cache.client.PoolManager;
+import org.apache.geode.cache.server.CacheServer;
+import org.apache.geode.internal.cache.HARegion;
+import org.apache.geode.internal.cache.PoolFactoryImpl;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.dunit.rules.CacheRule;
+import org.apache.geode.test.dunit.rules.ClientCacheRule;
+import org.apache.geode.test.dunit.rules.DistributedTestRule;
+import org.apache.geode.test.junit.categories.ClientServerTest;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
+
+/**
+ * Verifies that {@link RegionService#rootRegions()} does not return any {@link HARegion}s.
+ *
+ * <p>
+ * TRAC #37805: Cache level API is required, which will return rootRegions() excluding all Meta
+ * Regions and HA Regions
+ */
+@Category({DistributedTest.class, ClientServerTest.class})
+public class RootRegionsExcludesHARegionsRegressionTest implements Serializable {
+
+  private static final String DURABLE_CLIENT_TIMEOUT_VALUE = String.valueOf(600);
+
+  private String uniqueName;
+  private String regionName;
+  private String hostName;
+
+  private int port;
+
+  private VM server;
+  private VM client;
+
+  @Rule
+  public DistributedTestRule distributedTestRule = new DistributedTestRule();
+
+  @Rule
+  public CacheRule cacheRule = new CacheRule();
+
+  @Rule
+  public ClientCacheRule clientCacheRule = new ClientCacheRule();
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Before
+  public void setUp() throws Exception {
+    server = getVM(0);
+    client = getVM(1);
+
+    uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+    regionName = uniqueName + "_region";
+    hostName = getHostName();
+
+    port = server.invoke(() -> createServer());
+    client.invoke(() -> createCacheClient());
+  }
+
+  @Test
+  public void rootRegionsExcludesHARegions() {
+    server.invoke(() -> validateRootRegions());
+  }
+
+  private int createServer() throws IOException {
+    cacheRule.createCache();
+
+    RegionFactory rf = cacheRule.getCache().createRegionFactory(REPLICATE);
+    rf.setEnableSubscriptionConflation(true);
+    rf.create(regionName);
+
+    CacheServer cacheServer = cacheRule.getCache().addCacheServer();
+    cacheServer.setPort(port);
+    cacheServer.setNotifyBySubscription(true);
+    cacheServer.start();
+    return cacheServer.getPort();
+  }
+
+  private void createCacheClient() {
+    Properties config = new Properties();
+    config.setProperty(DURABLE_CLIENT_ID, uniqueName);
+    config.setProperty(DURABLE_CLIENT_TIMEOUT, DURABLE_CLIENT_TIMEOUT_VALUE);
+
+    clientCacheRule.createClientCache(config);
+
+    PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory();
+    pf.addServer(hostName, port).setSubscriptionEnabled(true).setSubscriptionRedundancy(0);
+
+    ClientRegionFactory crf = clientCacheRule.getClientCache().createClientRegionFactory(LOCAL);
+    crf.setPoolName(pf.create(uniqueName).getName());
+
+    crf.create(regionName);
+
+    clientCacheRule.getClientCache().readyForEvents();
+  }
+
+  private void validateRootRegions() {
+    Set<Region<?, ?>> regions = cacheRule.getCache().rootRegions();
+    if (regions != null) {
+      for (Region region : regions) {
+        assertThat(region).isNotInstanceOf(HARegion.class);
+      }
+    }
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
klund@apache.org.