geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [02/12] geode git commit: GEODE-2732 after auto-reconnect a server is restarted on the default port
Date Fri, 07 Apr 2017 19:49:53 GMT
GEODE-2732 after auto-reconnect a server is restarted on the default port

Gfsh command line parameters were put into ThreadLocals to make them
available to the XML parser.  These are now held in non-thread-local
variables so that all threads, including the auto-reconnect thread,
can see them when building the cache.


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/391502a2
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/391502a2
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/391502a2

Branch: refs/heads/feature/GEODE-2632
Commit: 391502a2615dbc80cde0b9a111fa967f4d76c39a
Parents: 39c72b2
Author: Bruce Schuchardt <bschuchardt@pivotal.io>
Authored: Wed Apr 5 15:11:04 2017 -0700
Committer: Bruce Schuchardt <bschuchardt@pivotal.io>
Committed: Wed Apr 5 15:31:33 2017 -0700

----------------------------------------------------------------------
 .../geode/distributed/ServerLauncher.java       |  10 +-
 .../internal/cache/CacheServerLauncher.java     |  43 +++++---
 .../internal/cache/xmlcache/CacheCreation.java  |   2 +-
 .../cache30/ReconnectWithCacheXMLDUnitTest.java | 107 +++++++++++++++++++
 .../ReconnectWithUDPSecurityDUnitTest.java      |   6 ++
 .../ReconnectedCacheServerDUnitTest.java        |   4 +-
 .../cache30/ReconnectWithCacheXMLDUnitTest.xml  |  25 +++++
 7 files changed, 176 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/391502a2/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java b/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java
index 9435bd8..c96732c 100755
--- a/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java
+++ b/geode-core/src/main/java/org/apache/geode/distributed/ServerLauncher.java
@@ -274,7 +274,7 @@ public class ServerLauncher extends AbstractLauncher<String> {
     this.assignBuckets = Boolean.TRUE.equals(builder.getAssignBuckets());
     setDebug(Boolean.TRUE.equals(builder.getDebug()));
     this.disableDefaultServer = Boolean.TRUE.equals(builder.getDisableDefaultServer());
-    CacheServerLauncher.disableDefaultServer.set(this.disableDefaultServer);
+    CacheServerLauncher.setDisableDefaultServer(this.disableDefaultServer);
     this.distributedSystemProperties = builder.getDistributedSystemProperties();
     this.force = Boolean.TRUE.equals(builder.getForce());
     this.help = Boolean.TRUE.equals(builder.getHelp());
@@ -286,11 +286,11 @@ public class ServerLauncher extends AbstractLauncher<String> {
     this.redirectOutput = Boolean.TRUE.equals(builder.getRedirectOutput());
     this.serverBindAddress = builder.getServerBindAddress();
     if (builder.isServerBindAddressSetByUser() && this.serverBindAddress != null)
{
-      CacheServerLauncher.serverBindAddress.set(this.serverBindAddress.getHostAddress());
+      CacheServerLauncher.setServerBindAddress(this.serverBindAddress.getHostAddress());
     }
     this.serverPort = builder.getServerPort();
     if (builder.isServerPortSetByUser() && this.serverPort != null) {
-      CacheServerLauncher.serverPort.set(this.serverPort);
+      CacheServerLauncher.setServerPort(this.serverPort);
     }
     this.springXmlLocation = builder.getSpringXmlLocation();
     this.workingDirectory = builder.getWorkingDirectory();
@@ -954,8 +954,8 @@ public class ServerLauncher extends AbstractLauncher<String> {
       final String serverBindAddress =
           (getServerBindAddress() == null ? null : getServerBindAddress().getHostAddress());
       final Integer serverPort = getServerPort();
-      CacheServerLauncher.serverBindAddress.set(serverBindAddress);
-      CacheServerLauncher.serverPort.set(serverPort);
+      CacheServerLauncher.setServerBindAddress(serverBindAddress);
+      CacheServerLauncher.setServerPort(serverPort);
       final CacheServer cacheServer = cache.addCacheServer();
       cacheServer.setBindAddress(serverBindAddress);
       cacheServer.setPort(serverPort);

http://git-wip-us.apache.org/repos/asf/geode/blob/391502a2/geode-core/src/main/java/org/apache/geode/internal/cache/CacheServerLauncher.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/CacheServerLauncher.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/CacheServerLauncher.java
index 760abd3..9a544d2 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/CacheServerLauncher.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/CacheServerLauncher.java
@@ -565,28 +565,43 @@ public class CacheServerLauncher {
     }
   }
 
-  public static ThreadLocal<Integer> serverPort = new ThreadLocal<Integer>();
+  private static Integer serverPort;
+
+  private static String serverBindAddress;
+
+  public static void setServerPort(Integer serverPort) {
+    CacheServerLauncher.serverPort = serverPort;
+  }
+
+  public static void setServerBindAddress(String serverBindAddress) {
+    CacheServerLauncher.serverBindAddress = serverBindAddress;
+  }
+
+  public static void setDisableDefaultServer(Boolean disableDefaultServer) {
+    CacheServerLauncher.disableDefaultServer = disableDefaultServer;
+  }
+
+  public static Boolean disableDefaultServer;
+
 
-  public static ThreadLocal<String> serverBindAddress = new ThreadLocal<String>();
 
   public static Integer getServerPort() {
-    return serverPort.get();
+    return serverPort;
   }
 
   public static String getServerBindAddress() {
-    return serverBindAddress.get();
+    return serverBindAddress;
   }
 
-  public static ThreadLocal<Boolean> disableDefaultServer = new ThreadLocal<Boolean>();
-
   public static Boolean getDisableDefaultServer() {
-    return disableDefaultServer.get();
+    return disableDefaultServer;
   }
 
+
   public static void clearStatics() {
-    disableDefaultServer.set(null);
-    serverPort.set(null);
-    serverBindAddress.set(null);
+    disableDefaultServer = null;
+    serverPort = null;
+    serverBindAddress = null;
   }
 
 
@@ -616,11 +631,11 @@ public class CacheServerLauncher {
     final String serverPortString = (String) options.get(SERVER_PORT);
 
     if (serverPortString != null) {
-      serverPort.set(Integer.parseInt(serverPortString));
+      serverPort = Integer.parseInt(serverPortString);
     }
 
-    serverBindAddress.set((String) options.get(SERVER_BIND_ADDRESS_NAME));
-    disableDefaultServer.set((Boolean) options.get(DISABLE_DEFAULT_SERVER));
+    serverBindAddress = (String) options.get(SERVER_BIND_ADDRESS_NAME);
+    disableDefaultServer = (Boolean) options.get(DISABLE_DEFAULT_SERVER);
     workingDir = new File(System.getProperty("user.dir"));
 
     // Say that we're starting...
@@ -835,7 +850,7 @@ public class CacheServerLauncher {
     // Create and start a default cache server
     // If (disableDefaultServer is not set or it is set but false) AND (the number of cacheservers
     // is 0)
-    Boolean disable = disableDefaultServer.get();
+    Boolean disable = disableDefaultServer;
     if ((disable == null || !disable) && cache.getCacheServers().size() == 0) {
       // Create and add a cache server
       CacheServer server = cache.addCacheServer();

http://git-wip-us.apache.org/repos/asf/geode/blob/391502a2/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheCreation.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheCreation.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheCreation.java
index 1c3c933..a0810d9 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheCreation.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheCreation.java
@@ -503,7 +503,7 @@ public class CacheCreation implements InternalCache {
 
     Integer serverPort = CacheServerLauncher.getServerPort();
     String serverBindAdd = CacheServerLauncher.getServerBindAddress();
-    Boolean disableDefaultServer = CacheServerLauncher.disableDefaultServer.get();
+    Boolean disableDefaultServer = CacheServerLauncher.getDisableDefaultServer();
     startCacheServers(this.getCacheServers(), cache, serverPort, serverBindAdd,
         disableDefaultServer);
 

http://git-wip-us.apache.org/repos/asf/geode/blob/391502a2/geode-core/src/test/java/org/apache/geode/cache30/ReconnectWithCacheXMLDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache30/ReconnectWithCacheXMLDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/cache30/ReconnectWithCacheXMLDUnitTest.java
new file mode 100755
index 0000000..4f2fac1
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/cache30/ReconnectWithCacheXMLDUnitTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.cache30;
+
+import static org.apache.geode.internal.Assert.assertTrue;
+import static org.awaitility.Awaitility.await;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.server.CacheServer;
+import org.apache.geode.distributed.ConfigurationProperties;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.membership.MembershipTestHook;
+import org.apache.geode.distributed.internal.membership.gms.MembershipManagerHelper;
+import org.apache.geode.internal.AvailablePortHelper;
+import org.apache.geode.internal.cache.CacheServerLauncher;
+import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
+import org.apache.geode.test.junit.categories.ClientServerTest;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.categories.MembershipTest;
+import org.apache.geode.util.test.TestUtil;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+@Category({DistributedTest.class, MembershipTest.class, ClientServerTest.class})
+public class ReconnectWithCacheXMLDUnitTest extends JUnit4CacheTestCase {
+
+
+  public ReconnectWithCacheXMLDUnitTest() {
+    super();
+  }
+
+  private static final long serialVersionUID = 1L;
+
+
+  private String xmlProperty = DistributionConfig.GEMFIRE_PREFIX + "autoReconnect-useCacheXMLFile";
+  private String oldPropertySetting;
+
+  @Override
+  public final void postSetUp() {
+    oldPropertySetting = System.setProperty(xmlProperty, "true");
+  }
+
+  @Override
+  public final void preTearDownCacheTestCase() throws Exception {
+    if (oldPropertySetting == null) {
+      System.getProperties().remove(xmlProperty);
+    } else {
+      System.setProperty(xmlProperty, oldPropertySetting);
+    }
+  }
+
+  @Override
+  public Properties getDistributedSystemProperties() {
+    Properties result = super.getDistributedSystemProperties();
+    String fileName = TestUtil.getResourcePath(getClass(), "ReconnectWithCacheXMLDUnitTest.xml");
+    result.put(ConfigurationProperties.CACHE_XML_FILE, fileName);
+    result.put(ConfigurationProperties.ENABLE_NETWORK_PARTITION_DETECTION, "true");
+    result.put(ConfigurationProperties.DISABLE_AUTO_RECONNECT, "false");
+    result.put(ConfigurationProperties.MAX_WAIT_TIME_RECONNECT, "2000");
+    return result;
+  }
+
+  @Test
+  public void testCacheServerLauncherPortRetained() throws Exception {
+    CacheServerLauncher.setDisableDefaultServer(true);
+    CacheServerLauncher.setServerPort(AvailablePortHelper.getRandomAvailableTCPPort());
+    Cache cache = getCache();
+
+    final AtomicBoolean membershipFailed = new AtomicBoolean();
+    MembershipManagerHelper.addTestHook(cache.getDistributedSystem(), new MembershipTestHook()
{
+      @Override
+      public void beforeMembershipFailure(String reason, Throwable cause) {
+        membershipFailed.set(true);
+      }
+
+      @Override
+      public void afterMembershipFailure(String reason, Throwable cause) {}
+    });
+    MembershipManagerHelper.crashDistributedSystem(cache.getDistributedSystem());
+    assertTrue(membershipFailed.get());
+
+    await().atMost(60, TimeUnit.SECONDS).until(() -> cache.getReconnectedCache() != null);
+
+    Cache newCache = cache.getReconnectedCache();
+    CacheServer server = newCache.getCacheServers().iterator().next();
+    assertEquals(CacheServerLauncher.getServerPort().intValue(), server.getPort());
+    assertEquals(20, server.getMaxConnections()); // this setting is in the XML file
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/391502a2/geode-core/src/test/java/org/apache/geode/cache30/ReconnectWithUDPSecurityDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache30/ReconnectWithUDPSecurityDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/cache30/ReconnectWithUDPSecurityDUnitTest.java
index a52d8bf..55d0a3c 100755
--- a/geode-core/src/test/java/org/apache/geode/cache30/ReconnectWithUDPSecurityDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache30/ReconnectWithUDPSecurityDUnitTest.java
@@ -17,8 +17,14 @@ package org.apache.geode.cache30;
 import java.util.Properties;
 
 import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.test.junit.categories.ClientServerTest;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.categories.MembershipTest;
+import org.junit.experimental.categories.Category;
+
 import static org.apache.geode.distributed.ConfigurationProperties.*;
 
+@Category({DistributedTest.class, MembershipTest.class, ClientServerTest.class})
 public class ReconnectWithUDPSecurityDUnitTest extends ReconnectDUnitTest {
 
   public ReconnectWithUDPSecurityDUnitTest() {

http://git-wip-us.apache.org/repos/asf/geode/blob/391502a2/geode-core/src/test/java/org/apache/geode/cache30/ReconnectedCacheServerDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache30/ReconnectedCacheServerDUnitTest.java
b/geode-core/src/test/java/org/apache/geode/cache30/ReconnectedCacheServerDUnitTest.java
index 3224257..2a2fe73 100755
--- a/geode-core/src/test/java/org/apache/geode/cache30/ReconnectedCacheServerDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache30/ReconnectedCacheServerDUnitTest.java
@@ -14,6 +14,8 @@
  */
 package org.apache.geode.cache30;
 
+import org.apache.geode.test.junit.categories.ClientServerTest;
+import org.apache.geode.test.junit.categories.MembershipTest;
 import org.junit.experimental.categories.Category;
 import org.junit.Test;
 
@@ -32,7 +34,7 @@ import org.apache.geode.distributed.internal.membership.gms.mgr.GMSMembershipMan
 import org.apache.geode.internal.cache.GemFireCacheImpl;
 
 
-@Category(DistributedTest.class)
+@Category({DistributedTest.class, MembershipTest.class, ClientServerTest.class})
 public class ReconnectedCacheServerDUnitTest extends JUnit4CacheTestCase {
 
   public ReconnectedCacheServerDUnitTest() {

http://git-wip-us.apache.org/repos/asf/geode/blob/391502a2/geode-core/src/test/resources/org/apache/geode/cache30/ReconnectWithCacheXMLDUnitTest.xml
----------------------------------------------------------------------
diff --git a/geode-core/src/test/resources/org/apache/geode/cache30/ReconnectWithCacheXMLDUnitTest.xml
b/geode-core/src/test/resources/org/apache/geode/cache30/ReconnectWithCacheXMLDUnitTest.xml
new file mode 100644
index 0000000..f7e338b
--- /dev/null
+++ b/geode-core/src/test/resources/org/apache/geode/cache30/ReconnectWithCacheXMLDUnitTest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<cache
+    xmlns="http://geode.apache.org/schema/cache"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd"
+    version="1.0">
+  <cache-server max-connections="20"/>
+</cache>
+


Mime
View raw message