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:56 UTC

[geode] 02/07: GEODE-1279: Rename Bug36457DUnitTest to ClientDestroyRegionUnregisterInterestRegressionTest

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 3968b947adca6e88b5edc3478d32b54432577941
Author: Kirk Lund <kl...@apache.org>
AuthorDate: Thu Apr 26 16:36:55 2018 -0700

    GEODE-1279: Rename Bug36457DUnitTest to ClientDestroyRegionUnregisterInterestRegressionTest
    
    Rename test method in ClientDestroyRegionUnregisterInterestRegressionTest:
    * destroyRegionShouldNotUnregisterInterest -> destroyRegionFromClientDoesNotUnregisterInterest
---
 .../internal/cache/ClientServerObserverHolder.java |   5 +
 .../cache/tier/sockets/Bug36457DUnitTest.java      | 204 ---------------------
 ...troyRegionUnregisterInterestRegressionTest.java | 164 +++++++++++++++++
 3 files changed, 169 insertions(+), 204 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/ClientServerObserverHolder.java b/geode-core/src/main/java/org/apache/geode/internal/cache/ClientServerObserverHolder.java
index c89f235..0c0a490 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/ClientServerObserverHolder.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/ClientServerObserverHolder.java
@@ -50,4 +50,9 @@ public class ClientServerObserverHolder {
     return _instance;
   }
 
+  public static ClientServerObserver clearInstance() {
+    ClientServerObserver oldObserver = _instance;
+    _instance = NO_OBSERVER;
+    return oldObserver;
+  }
 }
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/Bug36457DUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/Bug36457DUnitTest.java
deleted file mode 100755
index d13fd4d..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/Bug36457DUnitTest.java
+++ /dev/null
@@ -1,204 +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 static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-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.DataPolicy;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionAttributes;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.cache.client.Pool;
-import org.apache.geode.cache.client.PoolManager;
-import org.apache.geode.cache.client.internal.PoolImpl;
-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.ClientServerObserverAdapter;
-import org.apache.geode.internal.cache.ClientServerObserverHolder;
-import org.apache.geode.test.dunit.Assert;
-import org.apache.geode.test.dunit.Host;
-import org.apache.geode.test.dunit.LogWriterUtils;
-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;
-
-/**
- * Bug Test for bug#36457
- *
- * Region destroy message from server to client results in client calling unregister to server (an
- * unnecessary callback). The unregister encounters an error because the region has been destroyed
- * on the server and hence falsely marks the server dead.
- */
-@Category({DistributedTest.class, ClientServerTest.class})
-public class Bug36457DUnitTest extends JUnit4DistributedTestCase {
-
-  private static Cache cache = null;
-
-  private VM server1 = null;
-
-  private static VM server2 = null;
-
-  private static VM client1 = null;
-
-  private static VM client2 = null;
-
-  static boolean isFaileoverHappened = false;
-
-  private static final String regionName = "Bug36457DUnitTest_Region";
-
-  /** constructor */
-  public Bug36457DUnitTest() {
-    super();
-  }
-
-  @Override
-  public final void postSetUp() throws Exception {
-    final Host host = Host.getHost(0);
-    server1 = host.getVM(0);
-    server2 = host.getVM(1);
-    client1 = host.getVM(2);
-    client2 = host.getVM(3);
-  }
-
-  private void createCache(Properties props) throws Exception {
-    DistributedSystem ds = getSystem(props);
-    ds.disconnect();
-    ds = getSystem(props);
-    assertNotNull(ds);
-    cache = CacheFactory.create(ds);
-    assertNotNull(cache);
-  }
-
-  public static void createClientCache(String host, Integer port1, Integer port2) throws Exception {
-    Properties props = new Properties();
-    props.setProperty(MCAST_PORT, "0");
-    props.setProperty(LOCATORS, "");
-    new Bug36457DUnitTest().createCache(props);
-    Pool p = PoolManager.createFactory().addServer(host, port1.intValue())
-        .addServer(host, port2.intValue()).setSubscriptionEnabled(true).setMinConnections(4)
-        // .setRetryInterval(2345671)
-        .create("Bug36457DUnitTestPool");
-    AttributesFactory factory = new AttributesFactory();
-    factory.setScope(Scope.DISTRIBUTED_ACK);
-    factory.setPoolName(p.getName());
-    RegionAttributes attrs = factory.create();
-    Region r = cache.createRegion(regionName, attrs);
-    List listOfKeys = new ArrayList();
-    listOfKeys.add("key-1");
-    listOfKeys.add("key-2");
-    listOfKeys.add("key-3");
-    listOfKeys.add("key-4");
-    listOfKeys.add("key-5");
-    r.registerInterest(listOfKeys);
-
-  }
-
-  public static Integer createServerCache() throws Exception {
-    new Bug36457DUnitTest().createCache(new Properties());
-    AttributesFactory factory = new AttributesFactory();
-    factory.setScope(Scope.DISTRIBUTED_ACK);
-    factory.setDataPolicy(DataPolicy.REPLICATE);
-    RegionAttributes attrs = factory.create();
-    cache.createRegion(regionName, attrs);
-    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-    CacheServer server1 = cache.addCacheServer();
-    server1.setPort(port);
-    server1.setNotifyBySubscription(true);
-    server1.start();
-    return new Integer(server1.getPort());
-  }
-
-  @Override
-  public final void preTearDown() throws Exception {
-    // close the clients first
-    client1.invoke(() -> Bug36457DUnitTest.closeCache());
-    client2.invoke(() -> Bug36457DUnitTest.closeCache());
-    // then close the servers
-    server1.invoke(() -> Bug36457DUnitTest.closeCache());
-    server2.invoke(() -> Bug36457DUnitTest.closeCache());
-  }
-
-  public static void closeCache() {
-    if (cache != null && !cache.isClosed()) {
-      cache.close();
-      cache.getDistributedSystem().disconnect();
-    }
-  }
-
-  @Test
-  public void testBug36457() {
-    Integer port1 = ((Integer) server1.invoke(() -> Bug36457DUnitTest.createServerCache()));
-    Integer port2 = ((Integer) server2.invoke(() -> Bug36457DUnitTest.createServerCache()));
-    client1.invoke(() -> Bug36457DUnitTest
-        .createClientCache(NetworkUtils.getServerHostName(server1.getHost()), port1, port2));
-    client2.invoke(() -> Bug36457DUnitTest
-        .createClientCache(NetworkUtils.getServerHostName(server1.getHost()), port1, port2));
-    // set a cllabck so that we come to know that whether a failover is called or not
-    // if failover is called means this bug is present.
-    client2.invoke(() -> Bug36457DUnitTest.setClientServerObserver());
-    client1.invoke(() -> Bug36457DUnitTest.destroyRegion());
-    isFaileoverHappened =
-        ((Boolean) client2.invoke(() -> Bug36457DUnitTest.isFaileoverHappened())).booleanValue();
-    if (isFaileoverHappened) { // if failover is called means this bug is present, else fixed
-      fail("Test failed because of unregistration failed due to region  is destroyed on server");
-    }
-  }
-
-  public static Boolean isFaileoverHappened() {
-    return new Boolean(isFaileoverHappened);
-  }
-
-  public static void setClientServerObserver() {
-    PoolImpl.AFTER_PRIMARY_IDENTIFICATION_FROM_BACKUP_CALLBACK_FLAG = true;
-    ClientServerObserverHolder.setInstance(new ClientServerObserverAdapter() {
-      public void afterPrimaryIdentificationFromBackup(ServerLocation primaryEndpoint) {
-        LogWriterUtils.getLogWriter().fine("TEST FAILED HERE YOGI ");
-        isFaileoverHappened = true;
-      }
-    });
-  }
-
-  public static void unSetClientServerObserver() {
-    PoolImpl.AFTER_PRIMARY_IDENTIFICATION_FROM_BACKUP_CALLBACK_FLAG = false;
-  }
-
-  public static void destroyRegion() {
-    try {
-      Region r = cache.getRegion("/" + regionName);
-      assertNotNull(r);
-      r.destroyRegion();
-    } catch (Exception ex) {
-      Assert.fail("failed while destroy region ", ex);
-    }
-  }
-
-}
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientDestroyRegionUnregisterInterestRegressionTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientDestroyRegionUnregisterInterestRegressionTest.java
new file mode 100755
index 0000000..bab675c
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/tier/sockets/ClientDestroyRegionUnregisterInterestRegressionTest.java
@@ -0,0 +1,164 @@
+/*
+ * 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.test.dunit.Invoke.invokeInEveryVM;
+import static org.apache.geode.test.dunit.VM.getHostName;
+import static org.apache.geode.test.dunit.VM.getVM;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.After;
+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.RegionShortcut;
+import org.apache.geode.cache.client.ClientRegionFactory;
+import org.apache.geode.cache.client.ClientRegionShortcut;
+import org.apache.geode.cache.client.Pool;
+import org.apache.geode.cache.client.PoolManager;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.cache.server.CacheServer;
+import org.apache.geode.internal.cache.ClientServerObserver;
+import org.apache.geode.internal.cache.ClientServerObserverHolder;
+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;
+
+/**
+ * Region destroy message from server to client results in client calling unregister to server (an
+ * unnecessary callback). The unregister encounters an error because the region has been destroyed
+ * on the server and hence falsely marks the server dead.
+ *
+ * <p>
+ * TRAC #36457: Region Destroy results in unregister interest propagation to server resulting in
+ * server being falsely marked dead
+ */
+@Category({DistributedTest.class, ClientServerTest.class})
+public class ClientDestroyRegionUnregisterInterestRegressionTest implements Serializable {
+
+  private String uniqueName;
+  private String regionName;
+  private String hostName;
+
+  private VM server1;
+  private VM server2;
+  private VM client1;
+  private VM client2;
+
+  @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);
+    client1 = getVM(2);
+    client2 = getVM(3);
+
+    uniqueName = getClass().getSimpleName() + "_" + testName.getMethodName();
+    regionName = uniqueName + "_region";
+    hostName = getHostName();
+
+    int port1 = server1.invoke(() -> createServerCache());
+    int port2 = server2.invoke(() -> createServerCache());
+
+    client1.invoke(() -> createClientCache(port1, port2));
+    client2.invoke(() -> createClientCache(port1, port2));
+  }
+
+  @After
+  public void tearDown() {
+    invokeInEveryVM(() -> {
+      PoolImpl.AFTER_PRIMARY_IDENTIFICATION_FROM_BACKUP_CALLBACK_FLAG = false;
+      ClientServerObserverHolder.clearInstance();
+    });
+  }
+
+  @Test
+  public void destroyRegionFromClientDoesNotUnregisterInterest() {
+    client2.invoke(() -> {
+      PoolImpl.AFTER_PRIMARY_IDENTIFICATION_FROM_BACKUP_CALLBACK_FLAG = true;
+      ClientServerObserverHolder.setInstance(spy(ClientServerObserver.class));
+    });
+
+    client1.invoke(() -> clientCacheRule.getClientCache().getRegion(regionName).destroyRegion());
+
+    client2.invoke(() -> {
+      verify(ClientServerObserverHolder.getInstance(), times(0))
+          .afterPrimaryIdentificationFromBackup(any());
+    });
+  }
+
+  private void createClientCache(int port1, int port2) {
+    clientCacheRule.createClientCache();
+
+    Pool pool = PoolManager.createFactory().addServer(hostName, port1).addServer(hostName, port2)
+        .setSubscriptionEnabled(true).setMinConnections(4).create(uniqueName);
+
+    ClientRegionFactory crf =
+        clientCacheRule.getClientCache().createClientRegionFactory(ClientRegionShortcut.LOCAL);
+    crf.setPoolName(pool.getName());
+
+    Region region = crf.create(regionName);
+
+    List listOfKeys = new ArrayList();
+    listOfKeys.add("key-1");
+    listOfKeys.add("key-2");
+    listOfKeys.add("key-3");
+    listOfKeys.add("key-4");
+    listOfKeys.add("key-5");
+
+    region.registerInterest(listOfKeys);
+  }
+
+  private int createServerCache() throws IOException {
+    cacheRule.createCache();
+
+    RegionFactory rf = cacheRule.getCache().createRegionFactory(RegionShortcut.REPLICATE);
+
+    rf.create(regionName);
+
+    CacheServer cacheServer = cacheRule.getCache().addCacheServer();
+    cacheServer.setPort(0);
+    cacheServer.setNotifyBySubscription(true);
+    cacheServer.start();
+    return cacheServer.getPort();
+  }
+}

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