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:57:55 UTC

[geode] 01/07: GEODE-1279: Rename Bug36269DUnitTest to ClientDestroyRegionNotificationRegressionTest

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 324717a277f14b1733e7ac7f5e90cea87f1d84e2
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Thu Apr 26 15:40:24 2018 -0700

    GEODE-1279: Rename Bug36269DUnitTest to ClientDestroyRegionNotificationRegressionTest
    
    Rename test method in ClientDestroyRegionNotificationRegressionTest:
    * testRegionDestroyNotReceivedBySender -> senderDoesNotReceiveRegionDestroy
---
 .../cache/tier/sockets/Bug36269DUnitTest.java      | 195 ---------------------
 ...entDestroyRegionNotificationRegressionTest.java | 152 ++++++++++++++++
 2 files changed, 152 insertions(+), 195 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/Bug36269DUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/Bug36269DUnitTest.java
deleted file mode 100644
index bf79492..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/Bug36269DUnitTest.java
+++ /dev/null
@@ -1,195 +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.LOCATORS;
-import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.junit.Assert.assertNotNull;
-
-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.MirrorType;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.cache.client.PoolManager;
-import org.apache.geode.cache.client.internal.Connection;
-import org.apache.geode.cache.client.internal.PoolImpl;
-import org.apache.geode.cache.client.internal.ServerRegionProxy;
-import org.apache.geode.cache.server.CacheServer;
-import org.apache.geode.distributed.DistributedSystem;
-import org.apache.geode.distributed.internal.ServerLocation;
-import org.apache.geode.internal.AvailablePort;
-import org.apache.geode.internal.cache.EventID;
-import org.apache.geode.test.dunit.Assert;
-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.Wait;
-import org.apache.geode.test.dunit.WaitCriterion;
-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 Region Destroy Operation from Cache Client does not pass the Client side Context object nor
- * does the p2p messaging has provision of sending Context object in the DestroyRegionMessage. This
- * can cause sender to receive it own region destruction message.
- */
-@Category({DistributedTest.class, ClientServerTest.class})
-public class Bug36269DUnitTest extends JUnit4DistributedTestCase {
-
-  VM server1 = null;
-
-  VM server2 = null;
-
-  private static int PORT1;
-
-  private static int PORT2;
-
-  private static final String REGION_NAME = "Bug36269DUnitTest_region";
-
-  protected static Cache cache = null;
-
-  private static PoolImpl pool = null;
-
-  @Override
-  public final void postSetUp() throws Exception {
-    disconnectAllFromDS();
-
-    final Host host = Host.getHost(0);
-    server1 = host.getVM(0);
-    server2 = host.getVM(1);
-
-    PORT1 = server1.invoke(() -> Bug36269DUnitTest.createServerCache());
-    PORT2 = server2.invoke(() -> Bug36269DUnitTest.createServerCache());
-  }
-
-  private void createCache(Properties props) throws Exception {
-    DistributedSystem ds = getSystem(props);
-    cache = CacheFactory.create(ds);
-    assertNotNull(cache);
-  }
-
-  /**
-   * This tests whether the region destroy are not received by the sender
-   */
-  @Test
-  public void testRegionDestroyNotReceivedBySender() throws Exception {
-    createClientCache();
-    acquireConnectionsAndDestroyRegion(NetworkUtils.getServerHostName(Host.getHost(0)));
-    server1.invoke(() -> Bug36269DUnitTest.verifyRegionDestroy());
-    server2.invoke(() -> Bug36269DUnitTest.verifyRegionDestroy());
-    Wait.pause(5000);
-    verifyNoRegionDestroyOnOriginator();
-  }
-
-  public static void acquireConnectionsAndDestroyRegion(String host) {
-    try {
-      Connection desCon = pool.acquireConnection(new ServerLocation(host, PORT2));
-      ServerRegionProxy srp = new ServerRegionProxy(Region.SEPARATOR + REGION_NAME, pool);
-      srp.destroyRegionOnForTestsOnly(desCon, new EventID(new byte[] {1}, 1, 1), null);
-    } catch (Exception ex) {
-      Assert.fail("while setting acquireConnections", ex);
-    }
-  }
-
-  public static void createClientCache() throws Exception {
-    Properties props = new Properties();
-    props.setProperty(MCAST_PORT, "0");
-    props.setProperty(LOCATORS, "");
-    new Bug36269DUnitTest().createCache(props);
-    CacheServerTestUtil.disableShufflingOfEndpoints();
-    PoolImpl p;
-    String host = NetworkUtils.getServerHostName(Host.getHost(0));
-    try {
-      p = (PoolImpl) PoolManager.createFactory().addServer(host, PORT1).addServer(host, PORT2)
-          .setSubscriptionEnabled(true).setReadTimeout(2000).setSocketBufferSize(1000)
-          .setMinConnections(4)
-          // .setRetryAttempts(2)
-          // .setRetryInterval(250)
-          .create("Bug36269DUnitTestPool");
-    } finally {
-      CacheServerTestUtil.enableShufflingOfEndpoints();
-    }
-    AttributesFactory factory = new AttributesFactory();
-    factory.setScope(Scope.DISTRIBUTED_ACK);
-    factory.setPoolName(p.getName());
-    pool = p;
-    assertNotNull(pool);
-    cache.createRegion(REGION_NAME, factory.create());
-  }
-
-  public static Integer createServerCache() throws Exception {
-    new Bug36269DUnitTest().createCache(new Properties());
-    AttributesFactory factory = new AttributesFactory();
-    factory.setScope(Scope.DISTRIBUTED_ACK);
-    factory.setMirrorType(MirrorType.KEYS_VALUES);
-    cache.createRegion(REGION_NAME, factory.create());
-    CacheServer server = cache.addCacheServer();
-    assertNotNull(server);
-    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-    server.setPort(port);
-    server.setNotifyBySubscription(true);
-    server.start();
-    return new Integer(server.getPort());
-  }
-
-  public static void verifyNoRegionDestroyOnOriginator() {
-    try {
-      Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME);
-      assertNotNull(r);
-    } catch (Exception ex) {
-      Assert.fail("failed while verifyNoRegionDestroyOnOriginator()", ex);
-    }
-  }
-
-  public static void verifyRegionDestroy() {
-    try {
-      WaitCriterion ev = new WaitCriterion() {
-        public boolean done() {
-          return cache.getRegion(Region.SEPARATOR + REGION_NAME) == null;
-        }
-
-        public String description() {
-          return null;
-        }
-      };
-      Wait.waitForCriterion(ev, 40 * 1000, 200, true);
-    } catch (Exception ex) {
-      Assert.fail("failed while verifyRegionDestroy", ex);
-    }
-  }
-
-  public static void closeCache() {
-    if (cache != null && !cache.isClosed()) {
-      cache.close();
-      cache.getDistributedSystem().disconnect();
-    }
-  }
-
-  @Override
-  public final void preTearDown() throws Exception {
-    closeCache();
-    // close server
-    server1.invoke(() -> Bug36269DUnitTest.closeCache());
-    server2.invoke(() -> Bug36269DUnitTest.closeCache());
-  }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientDestroyRegionNotificationRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientDestroyRegionNotificationRegressionTest.java
new file mode 100644
index 0000000..96ca523
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientDestroyRegionNotificationRegressionTest.java
@@ -0,0 +1,152 @@
+/*
+ * 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 java.util.concurrent.TimeUnit.MINUTES;
+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 static org.awaitility.Awaitility.await;
+
+import java.io.IOException;
+import java.io.Serializable;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.client.ClientRegionFactory;
+import org.apache.geode.cache.client.ClientRegionShortcut;
+import org.apache.geode.cache.client.PoolManager;
+import org.apache.geode.cache.client.internal.Connection;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.client.internal.ServerRegionProxy;
+import org.apache.geode.cache.server.CacheServer;
+import org.apache.geode.distributed.internal.ServerLocation;
+import org.apache.geode.internal.cache.EventID;
+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;
+
+/**
+ * The Region Destroy Operation from Cache Client does not pass the Client side Context object nor
+ * does the p2p messaging has provision of sending Context object in the DestroyRegionMessage. This
+ * can cause sender to receive it own region destruction message.
+ *
+ * <p>
+ * TRAC #36269: RegionDestroy operation may get sent to the originator
+ */
+@Category({DistributedTest.class, ClientServerTest.class})
+public class ClientDestroyRegionNotificationRegressionTest implements Serializable {
+
+  private String hostName;
+  private String uniqueName;
+  private String regionName;
+
+  private int port1;
+  private int port2;
+
+  private VM server1;
+  private VM server2;
+
+  @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 {
+    server1 = getVM(0);
+    server2 = getVM(1);
+
+    hostName = getHostName();
+    uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+    regionName = uniqueName + "_region";
+
+    port1 = server1.invoke(() -> createServerCache());
+    port2 = server2.invoke(() -> createServerCache());
+
+    createClientCacheAndDestroyRegion();
+  }
+
+  /**
+   * This tests whether the region destroy are not received by the sender
+   */
+  @Test
+  public void senderDoesNotReceiveRegionDestroy() throws Exception {
+    server1.invoke(() -> {
+      await().atMost(1, MINUTES).until(() -> cacheRule.getCache().getRegion(regionName) == null);
+    });
+    server2.invoke(() -> {
+      await().atMost(1, MINUTES).until(() -> cacheRule.getCache().getRegion(regionName) == null);
+    });
+
+    Thread.sleep(5 * 1000);
+
+    assertThat(clientCacheRule.getClientCache().getRegion(regionName).isDestroyed()).isFalse();
+  }
+
+  private void createClientCacheAndDestroyRegion() {
+    clientCacheRule.createClientCache();
+
+    CacheServerTestUtil.disableShufflingOfEndpoints();
+    PoolImpl pool;
+    try {
+      pool = (PoolImpl) PoolManager.createFactory().addServer(hostName, port1)
+          .addServer(hostName, port2).setSubscriptionEnabled(true).setReadTimeout(2000)
+          .setSocketBufferSize(1000).setMinConnections(4).create(uniqueName);
+    } finally {
+      CacheServerTestUtil.enableShufflingOfEndpoints();
+    }
+
+    ClientRegionFactory crf =
+        clientCacheRule.getClientCache().createClientRegionFactory(ClientRegionShortcut.LOCAL);
+    crf.setPoolName(pool.getName());
+    crf.create(regionName);
+
+    Connection connection = pool.acquireConnection(new ServerLocation(hostName, port2));
+    EventID eventId = new EventID(new byte[] {1}, 1, 1);
+    ServerRegionProxy serverRegionProxy = new ServerRegionProxy(regionName, pool);
+
+    serverRegionProxy.destroyRegionOnForTestsOnly(connection, eventId, null);
+  }
+
+  private int createServerCache() throws IOException {
+    cacheRule.createCache();
+
+    RegionFactory rf = cacheRule.getCache().createRegionFactory(RegionShortcut.REPLICATE);
+    rf.create(regionName);
+
+    CacheServer server = cacheRule.getCache().addCacheServer();
+    server.setPort(0);
+    server.setNotifyBySubscription(true);
+    server.start();
+    return server.getPort();
+  }
+}

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