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 2015/12/11 23:31:35 UTC

[6/7] incubator-geode git commit: GEODE-528: Locator not stopping correctly if jmx-manager-port=0

GEODE-528: Locator not stopping correctly if jmx-manager-port=0


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

Branch: refs/heads/feature/GEODE-291
Commit: eb685b45c26260abb844dc8f92dbc2f50f728bb5
Parents: 80c61f4
Author: Jens Deppe <jd...@pivotal.io>
Authored: Thu Dec 10 13:15:45 2015 -0800
Committer: Jens Deppe <jd...@pivotal.io>
Committed: Fri Dec 11 13:59:15 2015 -0800

----------------------------------------------------------------------
 .../LocatorLauncherAssemblyJUnitTest.java       | 157 +++++++++++++++++++
 .../internal/SystemManagementService.java       |   3 +-
 2 files changed, 158 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/eb685b45/gemfire-assembly/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherAssemblyJUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-assembly/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherAssemblyJUnitTest.java b/gemfire-assembly/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherAssemblyJUnitTest.java
new file mode 100644
index 0000000..1deff22
--- /dev/null
+++ b/gemfire-assembly/src/test/java/com/gemstone/gemfire/distributed/LocatorLauncherAssemblyJUnitTest.java
@@ -0,0 +1,157 @@
+/*
+ * 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 com.gemstone.gemfire.distributed;
+
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.CacheFactory;
+import com.gemstone.gemfire.distributed.AbstractLauncher.Status;
+import com.gemstone.gemfire.distributed.LocatorLauncher.Builder;
+import com.gemstone.gemfire.distributed.internal.DistributionConfig;
+import com.gemstone.gemfire.internal.AvailablePortHelper;
+import com.gemstone.gemfire.internal.process.ProcessType;
+import com.gemstone.gemfire.internal.process.ProcessUtils;
+import com.gemstone.gemfire.management.ManagementService;
+import com.gemstone.gemfire.management.ManagerMXBean;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.File;
+
+import static org.junit.Assert.*;
+
+/**
+ * These tests are part of assembly as they require the REST war file to be present.
+ *
+ * @author Jens Deppe
+ */
+@Category(IntegrationTest.class)
+public class LocatorLauncherAssemblyJUnitTest extends AbstractLocatorLauncherJUnitTestCase {
+
+  @Before
+  public final void setUpLocatorLauncherLocalTest() throws Exception {
+    disconnectFromDS();
+    System.setProperty(ProcessType.TEST_PREFIX_PROPERTY, getUniqueName() + "-");
+  }
+
+  @After
+  public final void tearDownLocatorLauncherLocalTest() throws Exception {
+    disconnectFromDS();
+  }
+
+  /*
+   * This test addresses GEODE-528
+   */
+  @Test
+  public void testLocatorStopsWhenJmxPortIsZero() throws Throwable {
+    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+
+    final Builder builder = new Builder()
+        .setMemberName(getUniqueName())
+        .setPort(this.locatorPort)
+        .setRedirectOutput(false)
+        .setWorkingDirectory(rootFolder)
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "false")
+        .set(DistributionConfig.JMX_MANAGER_NAME, "true")
+        .set(DistributionConfig.JMX_MANAGER_START_NAME, "true")
+        .set(DistributionConfig.JMX_MANAGER_PORT_NAME, "0");
+
+    performTest(builder);
+  }
+
+  /*
+   * This test addresses GEODE-528
+   */
+  @Test
+  public void testLocatorStopsWhenJmxPortIsNonZero() throws Throwable {
+    String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
+    final int jmxPort = AvailablePortHelper.getRandomAvailableTCPPorts(1)[0];
+
+    final Builder builder = new Builder().setMemberName(getUniqueName())
+        .setPort(this.locatorPort)
+        .setRedirectOutput(false)
+        .setWorkingDirectory(rootFolder)
+        .set(DistributionConfig.LOG_LEVEL_NAME, "config")
+        .set(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "false")
+        .set(DistributionConfig.JMX_MANAGER_NAME, "true")
+        .set(DistributionConfig.JMX_MANAGER_START_NAME, "true")
+        .set(DistributionConfig.JMX_MANAGER_PORT_NAME, Integer.toString(jmxPort));
+
+    performTest(builder);
+  }
+
+  private void performTest(Builder builder) {
+    assertFalse(builder.getForce());
+    this.launcher = builder.build();
+    assertFalse(this.launcher.isForcing());
+
+    LocatorLauncher dirLauncher = null;
+    int initialThreadCount = Thread.activeCount();
+
+    try {
+      this.launcher.start();
+      waitForLocatorToStart(this.launcher);
+
+      // validate the pid file and its contents
+      this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.getPidFileName());
+      assertTrue("Pid file " + this.pidFile.getCanonicalPath().toString() + " should exist", this.pidFile.exists());
+      final int pid = readPid(this.pidFile);
+      assertTrue(pid > 0);
+      assertEquals(ProcessUtils.identifyPid(), pid);
+
+      dirLauncher = new Builder().setWorkingDirectory(builder.getWorkingDirectory()).build();
+      assertNotNull(dirLauncher);
+      assertFalse(dirLauncher.isRunning());
+
+      // Stop the manager
+      Cache cache = CacheFactory.getAnyInstance();
+      ManagerMXBean managerBean = ManagementService.getManagementService(cache).getManagerMXBean();
+      managerBean.stop();
+
+      // stop the locator
+      final LocatorLauncher.LocatorState locatorState = dirLauncher.stop();
+      assertNotNull(locatorState);
+      assertEquals(Status.STOPPED, locatorState.getStatus());
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+
+    try {
+      // verify the PID file was deleted
+      waitForFileToDelete(this.pidFile);
+    } catch (Throwable e) {
+      this.errorCollector.addError(e);
+    }
+
+    int finalThreadCount = Integer.MAX_VALUE;
+
+    // Spin for up to 5 seconds waiting for threads to finish
+    for (int i = 0; i < 50 && finalThreadCount > initialThreadCount; i++) {
+      try {
+        Thread.sleep(100);
+      } catch (InterruptedException ex) {
+        // ignored
+      }
+      finalThreadCount = Thread.activeCount();
+    }
+
+    assertEquals(initialThreadCount, finalThreadCount);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/eb685b45/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/SystemManagementService.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/SystemManagementService.java b/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/SystemManagementService.java
index 68209f2..1ca10cc 100755
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/SystemManagementService.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/management/internal/SystemManagementService.java
@@ -527,12 +527,11 @@ public final class SystemManagementService extends BaseManagementService {
         federatingManager.stopManager();
         system.handleResourceEvent(ResourceEvent.MANAGER_STOP, null);
         getGemFireCacheImpl().getJmxManagerAdvisor().broadcastChange();
-        if (this.agent != null && this.agent.isRunning()) {
+        if (this.agent != null && (this.agent.isRunning() || this.agent.isHttpServiceRunning())) {
           this.agent.stopAgent();
         }
       }
     }
-
   }
 
   @Override