You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ji...@apache.org on 2018/01/19 16:30:36 UTC

[geode] branch develop updated: GEODE-4275: Improved StartMemberUtils.addMaxHeap (#1270)

This is an automated email from the ASF dual-hosted git repository.

jinmeiliao pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 33d7f4f  GEODE-4275: Improved StartMemberUtils.addMaxHeap (#1270)
33d7f4f is described below

commit 33d7f4fcd925e4f32b3232aedde34ea2c0cdfe16
Author: Juan José Ramos <ju...@users.noreply.github.com>
AuthorDate: Fri Jan 19 13:30:34 2018 -0300

    GEODE-4275: Improved StartMemberUtils.addMaxHeap (#1270)
    
    - Added test methods.
    - Modified the method to avoid adding `"-XX:+UseConcMarkSweepGC"` if
      the user already specified parameter as a jvm argument.
    - Modified the logic to avoid setting the default value for
      `"-XX:CMSInitiatingOccupancyFraction="` if the user already specified
      one as a jvm argument.
---
 .../internal/cli/commands/StartMemberUtils.java    | 12 +++++++--
 .../cli/commands/StartMemberUtilsTest.java         | 30 ++++++++++++++++++++++
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java
index 3b0dbc7..c2defa5 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/StartMemberUtils.java
@@ -126,8 +126,16 @@ public class StartMemberUtils {
   static void addMaxHeap(final List<String> commandLine, final String maxHeap) {
     if (StringUtils.isNotBlank(maxHeap)) {
       commandLine.add("-Xmx" + maxHeap);
-      commandLine.add("-XX:+UseConcMarkSweepGC");
-      commandLine.add("-XX:CMSInitiatingOccupancyFraction=" + CMS_INITIAL_OCCUPANCY_FRACTION);
+
+      String collectorKey = "-XX:+UseConcMarkSweepGC";
+      if (!commandLine.contains(collectorKey)) {
+        commandLine.add(collectorKey);
+      }
+
+      String occupancyFractionKey = "-XX:CMSInitiatingOccupancyFraction=";
+      if (commandLine.stream().noneMatch(s -> s.contains(occupancyFractionKey))) {
+        commandLine.add(occupancyFractionKey + CMS_INITIAL_OCCUPANCY_FRACTION);
+      }
     }
   }
 
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartMemberUtilsTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartMemberUtilsTest.java
index 1fea694..e0b327d 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartMemberUtilsTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/StartMemberUtilsTest.java
@@ -24,6 +24,10 @@ import java.io.FileWriter;
 import java.io.IOException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
 
 import org.apache.commons.io.FileUtils;
 import org.junit.Rule;
@@ -101,6 +105,32 @@ public class StartMemberUtilsTest {
     assertThat(gemfireClasspath).startsWith(customGeodeCore);
   }
 
+  @Test
+  public void testAddMaxHeap() {
+    List<String> baseCommandLine = new ArrayList<>();
+
+    // Empty Max Heap Option
+    StartMemberUtils.addMaxHeap(baseCommandLine, null);
+    assertThat(baseCommandLine.size()).isEqualTo(0);
+
+    StartMemberUtils.addMaxHeap(baseCommandLine, "");
+    assertThat(baseCommandLine.size()).isEqualTo(0);
+
+    // Only Max Heap Option Set
+    StartMemberUtils.addMaxHeap(baseCommandLine, "32g");
+    assertThat(baseCommandLine.size()).isEqualTo(3);
+    assertThat(baseCommandLine).containsExactly("-Xmx32g", "-XX:+UseConcMarkSweepGC",
+        "-XX:CMSInitiatingOccupancyFraction=" + StartMemberUtils.CMS_INITIAL_OCCUPANCY_FRACTION);
+
+    // All Options Set
+    List<String> customCommandLine = new ArrayList<>(
+        Arrays.asList("-XX:+UseConcMarkSweepGC", "-XX:CMSInitiatingOccupancyFraction=30"));
+    StartMemberUtils.addMaxHeap(customCommandLine, "16g");
+    assertThat(customCommandLine.size()).isEqualTo(3);
+    assertThat(customCommandLine).containsExactly("-XX:+UseConcMarkSweepGC",
+        "-XX:CMSInitiatingOccupancyFraction=30", "-Xmx16g");
+  }
+
   private void writePid(final File pidFile, final int pid) throws IOException {
     final FileWriter fileWriter = new FileWriter(pidFile, false);
     fileWriter.write(String.valueOf(pid));

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].