geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [13/16] incubator-geode git commit: GEODE-1369: change ConfigCommandsDUnitTest to use TemporaryFolder
Date Tue, 10 May 2016 21:10:00 GMT
GEODE-1369: change ConfigCommandsDUnitTest to use TemporaryFolder

* use TemporaryFolder for all disk files
* re-enable testAlterUpdatesSharedConfig (might be a FlakyTest) -- was disabled for TRAC #52204
but it passes
* use static imports


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

Branch: refs/heads/feature/GEODE-1371
Commit: f93c87f13b4bf1bda67d994587d1299163694772
Parents: c8ca8a0
Author: Kirk Lund <klund@apache.org>
Authored: Tue May 10 11:03:09 2016 -0700
Committer: Kirk Lund <klund@apache.org>
Committed: Tue May 10 11:03:09 2016 -0700

----------------------------------------------------------------------
 .../cli/commands/ConfigCommandsDUnitTest.java   | 319 ++++++++++---------
 1 file changed, 171 insertions(+), 148 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f93c87f1/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConfigCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConfigCommandsDUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConfigCommandsDUnitTest.java
index c342142..1d861c6 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConfigCommandsDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/ConfigCommandsDUnitTest.java
@@ -16,10 +16,13 @@
  */
 package com.gemstone.gemfire.management.internal.cli.commands;
 
+import static com.gemstone.gemfire.distributed.internal.DistributionConfig.*;
+import static com.gemstone.gemfire.internal.AvailablePort.*;
+import static com.gemstone.gemfire.internal.AvailablePortHelper.*;
 import static com.gemstone.gemfire.test.dunit.Assert.*;
-import static com.gemstone.gemfire.test.dunit.Invoke.*;
 import static com.gemstone.gemfire.test.dunit.LogWriterUtils.*;
 import static com.gemstone.gemfire.test.dunit.Wait.*;
+import static org.apache.commons.io.FileUtils.*;
 
 import java.io.File;
 import java.io.FileReader;
@@ -32,6 +35,9 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
 
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
 import com.gemstone.gemfire.cache.Cache;
 import com.gemstone.gemfire.cache.server.CacheServer;
 import com.gemstone.gemfire.distributed.Locator;
@@ -39,9 +45,6 @@ import com.gemstone.gemfire.distributed.internal.DistributionConfig;
 import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
 import com.gemstone.gemfire.distributed.internal.InternalLocator;
 import com.gemstone.gemfire.distributed.internal.SharedConfiguration;
-import com.gemstone.gemfire.internal.AvailablePort;
-import com.gemstone.gemfire.internal.AvailablePortHelper;
-import com.gemstone.gemfire.internal.FileUtil;
 import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
 import com.gemstone.gemfire.internal.cache.xmlcache.CacheXmlGenerator;
 import com.gemstone.gemfire.internal.logging.LogWriterImpl;
@@ -58,10 +61,6 @@ import com.gemstone.gemfire.test.dunit.VM;
 import com.gemstone.gemfire.test.dunit.WaitCriterion;
 import com.gemstone.gemfire.test.junit.categories.DistributedTest;
 
-import org.apache.commons.io.FileUtils;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
 /**
  * Dunit class for testing GemFire config commands : export config
  *
@@ -71,110 +70,113 @@ import org.junit.experimental.categories.Category;
 @SuppressWarnings("serial")
 public class ConfigCommandsDUnitTest extends CliCommandTestBase {
 
-  File managerConfigFile = new File("Manager-cache.xml");
-  File managerPropsFile = new File("Manager-gf.properties");
-  File vm1ConfigFile = new File("VM1-cache.xml");
-  File vm1PropsFile = new File("VM1-gf.properties");
-  File vm2ConfigFile = new File("VM2-cache.xml");
-  File vm2PropsFile = new File("VM2-gf.properties");
-  File shellConfigFile = new File("Shell-cache.xml");
-  File shellPropsFile = new File("Shell-gf.properties");
-  File subDir = new File("ConfigCommandsDUnitTestSubDir");
-  File subManagerConfigFile = new File(subDir, managerConfigFile.getName());
+  private File managerConfigFile;
+  private File managerPropsFile;
+  private File vm1ConfigFile;
+  private File vm1PropsFile;
+  private File vm2ConfigFile;
+  private File vm2PropsFile;
+  private File shellConfigFile;
+  private File shellPropsFile;
+  private File subDir;
+  private File subManagerConfigFile;
 
   @Override
-  protected void preTearDownCliCommandTestBase() throws Exception {
-    deleteTestFiles();
-    invokeInEveryVM(new SerializableRunnable() {
-
-      @Override
-      public void run() {
-        try {
-          deleteTestFiles();
-        } catch (IOException e) {
-          fail("error", e);
-        }
-      }
-    });
+  protected final void postSetUpCliCommandTestBase() throws Exception {
+    this.managerConfigFile = this.temporaryFolder.newFile("Manager-cache.xml");
+    this.managerPropsFile = this.temporaryFolder.newFile("Manager-gf.properties");
+    this.vm1ConfigFile = this.temporaryFolder.newFile("VM1-cache.xml");
+    this.vm1PropsFile = this.temporaryFolder.newFile("VM1-gf.properties");
+    this.vm2ConfigFile = this.temporaryFolder.newFile("VM2-cache.xml");
+    this.vm2PropsFile = this.temporaryFolder.newFile("VM2-gf.properties");
+    this.shellConfigFile = this.temporaryFolder.newFile("Shell-cache.xml");
+    this.shellPropsFile = this.temporaryFolder.newFile("Shell-gf.properties");
+    this.subDir = this.temporaryFolder.newFolder(getName());
+    this.subManagerConfigFile = new File(this.subDir, this.managerConfigFile.getName());
   }
 
   @Test
-  public void testDescribeConfig() throws ClassNotFoundException, IOException {
+  public void testDescribeConfig() throws Exception {
     setUpJmxManagerOnVm0ThenConnect(null);
     final String controllerName = "Member2";
 
-    /***
+    /*
      * Create properties for the controller VM
      */
     final Properties localProps = new Properties();
-    localProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
-    localProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "info");
-    localProps.setProperty(DistributionConfig.STATISTIC_SAMPLING_ENABLED_NAME, "true");
-    localProps.setProperty(DistributionConfig.ENABLE_TIME_STATISTICS_NAME, "true");
-    localProps.setProperty(DistributionConfig.NAME_NAME, controllerName);
-    localProps.setProperty(DistributionConfig.GROUPS_NAME, "G1");
+    localProps.setProperty(MCAST_PORT_NAME, "0");
+    localProps.setProperty(LOG_LEVEL_NAME, "info");
+    localProps.setProperty(STATISTIC_SAMPLING_ENABLED_NAME, "true");
+    localProps.setProperty(ENABLE_TIME_STATISTICS_NAME, "true");
+    localProps.setProperty(NAME_NAME, controllerName);
+    localProps.setProperty(GROUPS_NAME, "G1");
     getSystem(localProps);
     Cache cache = getCache();
-    int ports[] = AvailablePortHelper.getRandomAvailableTCPPorts(1);
+
+    int ports[] = getRandomAvailableTCPPorts(1);
     CacheServer cs = getCache().addCacheServer();
     cs.setPort(ports[0]);
     cs.setMaxThreads(10);
     cs.setMaxConnections(9);
     cs.start();
+    try {
 
-    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
-    List<String> jvmArgs = runtimeBean.getInputArguments();
+      RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
+      List<String> jvmArgs = runtimeBean.getInputArguments();
 
-    getLogWriter().info("#SB Actual JVM Args : ");
+      getLogWriter().info("#SB Actual JVM Args : ");
 
-    for (String jvmArg : jvmArgs) {
-      getLogWriter().info("#SB JVM " + jvmArg);
-    }
+      for (String jvmArg : jvmArgs) {
+        getLogWriter().info("#SB JVM " + jvmArg);
+      }
 
-    InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem();
-    DistributionConfig config = system.getConfig();
-    config.setArchiveFileSizeLimit(1000);
+      InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem();
+      DistributionConfig config = system.getConfig();
+      config.setArchiveFileSizeLimit(1000);
 
-    String command = CliStrings.DESCRIBE_CONFIG + " --member=" + controllerName;
-    CommandProcessor cmdProcessor = new CommandProcessor();
-    cmdProcessor.createCommandStatement(command, Collections.EMPTY_MAP).process();
+      String command = CliStrings.DESCRIBE_CONFIG + " --member=" + controllerName;
+      CommandProcessor cmdProcessor = new CommandProcessor();
+      cmdProcessor.createCommandStatement(command, Collections.EMPTY_MAP).process();
 
-    CommandResult cmdResult = executeCommand(command);
+      CommandResult cmdResult = executeCommand(command);
 
-    String resultStr = commandResultToString(cmdResult);
-    getLogWriter().info("#SB Hiding the defaults\n" + resultStr);
+      String resultStr = commandResultToString(cmdResult);
+      getLogWriter().info("#SB Hiding the defaults\n" + resultStr);
 
-    assertEquals(true, cmdResult.getStatus().equals(Status.OK));
-    assertEquals(true, resultStr.contains("G1"));
-    assertEquals(true, resultStr.contains(controllerName));
-    assertEquals(true, resultStr.contains("archive-file-size-limit"));
-    assertEquals(true, !resultStr.contains("copy-on-read"));
+      assertEquals(true, cmdResult.getStatus().equals(Status.OK));
+      assertEquals(true, resultStr.contains("G1"));
+      assertEquals(true, resultStr.contains(controllerName));
+      assertEquals(true, resultStr.contains("archive-file-size-limit"));
+      assertEquals(true, !resultStr.contains("copy-on-read"));
 
-    cmdResult = executeCommand(command + " --" + CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS
+ "=false");
-    resultStr = commandResultToString(cmdResult);
-    getLogWriter().info("#SB No hiding of defaults\n" + resultStr);
+      cmdResult = executeCommand(command + " --" + CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS
+ "=false");
+      resultStr = commandResultToString(cmdResult);
 
-    assertEquals(true, cmdResult.getStatus().equals(Status.OK));
-    assertEquals(true, resultStr.contains("is-server"));
-    assertEquals(true, resultStr.contains(controllerName));
-    assertEquals(true, resultStr.contains("copy-on-read"));
+      getLogWriter().info("#SB No hiding of defaults\n" + resultStr);
+
+      assertEquals(true, cmdResult.getStatus().equals(Status.OK));
+      assertEquals(true, resultStr.contains("is-server"));
+      assertEquals(true, resultStr.contains(controllerName));
+      assertEquals(true, resultStr.contains("copy-on-read"));
 
-    cs.stop();
+    } finally {
+      cs.stop();
+    }
   }
 
   @Test
-  public void testExportConfig() throws IOException {
+  public void testExportConfig() throws Exception {
     Properties localProps = new Properties();
-    localProps.setProperty(DistributionConfig.NAME_NAME, "Manager");
-    localProps.setProperty(DistributionConfig.GROUPS_NAME, "Group1");
+    localProps.setProperty(NAME_NAME, "Manager");
+    localProps.setProperty(GROUPS_NAME, "Group1");
     setUpJmxManagerOnVm0ThenConnect(localProps);
 
     // Create a cache in another VM (VM1)
     Host.getHost(0).getVM(1).invoke(new SerializableRunnable() {
       public void run() {
         Properties localProps = new Properties();
-        localProps.setProperty(DistributionConfig.NAME_NAME, "VM1");
-        localProps.setProperty(DistributionConfig.GROUPS_NAME, "Group2");
+        localProps.setProperty(NAME_NAME, "VM1");
+        localProps.setProperty(GROUPS_NAME, "Group2");
         getSystem(localProps);
         getCache();
       }
@@ -184,8 +186,8 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     Host.getHost(0).getVM(2).invoke(new SerializableRunnable() {
       public void run() {
         Properties localProps = new Properties();
-        localProps.setProperty(DistributionConfig.NAME_NAME, "VM2");
-        localProps.setProperty(DistributionConfig.GROUPS_NAME, "Group2");
+        localProps.setProperty(NAME_NAME, "VM2");
+        localProps.setProperty(GROUPS_NAME, "Group2");
         getSystem(localProps);
         getCache();
       }
@@ -193,47 +195,47 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
 
     // Create a cache in the local VM
     localProps = new Properties();
-    localProps.setProperty(DistributionConfig.NAME_NAME, "Shell");
+    localProps.setProperty(NAME_NAME, "Shell");
     getSystem(localProps);
     Cache cache = getCache();
 
     // Test export config for all members
     deleteTestFiles();
-    CommandResult cmdResult = executeCommand("export config");
+    CommandResult cmdResult = executeCommand("export config --dir=" + this.temporaryFolder.getRoot().getAbsolutePath());
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
-    assertTrue(this.managerConfigFile.exists());
-    assertTrue(this.managerPropsFile.exists());
-    assertTrue(this.vm1ConfigFile.exists());
-    assertTrue(this.vm1PropsFile.exists());
-    assertTrue(this.vm2ConfigFile.exists());
-    assertTrue(this.vm2PropsFile.exists());
-    assertTrue(this.shellConfigFile.exists());
-    assertTrue(this.shellPropsFile.exists());
+    assertTrue(this.managerConfigFile + " should exist", this.managerConfigFile.exists());
+    assertTrue(this.managerPropsFile + " should exist", this.managerPropsFile.exists());
+    assertTrue(this.vm1ConfigFile + " should exist", this.vm1ConfigFile.exists());
+    assertTrue(this.vm1PropsFile + " should exist", this.vm1PropsFile.exists());
+    assertTrue(this.vm2ConfigFile + " should exist", this.vm2ConfigFile.exists());
+    assertTrue(this.vm2PropsFile + " should exist", this.vm2PropsFile.exists());
+    assertTrue(this.shellConfigFile + " should exist", this.shellConfigFile.exists());
+    assertTrue(this.shellPropsFile + " should exist", this.shellPropsFile.exists());
 
     // Test exporting member
     deleteTestFiles();
-    cmdResult = executeCommand("export config --member=Manager");
+    cmdResult = executeCommand("export config --member=Manager --dir=" + this.temporaryFolder.getRoot().getAbsolutePath());
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
-    assertTrue(this.managerConfigFile.exists());
-    assertFalse(this.vm1ConfigFile.exists());
-    assertFalse(this.vm2ConfigFile.exists());
-    assertFalse(this.shellConfigFile.exists());
+    assertTrue(this.managerConfigFile + " should exist", this.managerConfigFile.exists());
+    assertFalse(this.vm1ConfigFile + " should not exist", this.vm1ConfigFile.exists());
+    assertFalse(this.vm2ConfigFile + " should not exist", this.vm2ConfigFile.exists());
+    assertFalse(this.shellConfigFile + " should not exist", this.shellConfigFile.exists());
 
     // Test exporting group
     deleteTestFiles();
-    cmdResult = executeCommand("export config --group=Group2");
+    cmdResult = executeCommand("export config --group=Group2 --dir=" + this.temporaryFolder.getRoot().getAbsolutePath());
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
-    assertFalse(this.managerConfigFile.exists());
-    assertTrue(this.vm1ConfigFile.exists());
-    assertTrue(this.vm2ConfigFile.exists());
-    assertFalse(this.shellConfigFile.exists());
+    assertFalse(this.managerConfigFile + " should not exist", this.managerConfigFile.exists());
+    assertTrue(this.vm1ConfigFile + " should exist", this.vm1ConfigFile.exists());
+    assertTrue(this.vm2ConfigFile + " should exist", this.vm2ConfigFile.exists());
+    assertFalse(this.shellConfigFile + " should not exist", this.shellConfigFile.exists());
 
     // Test export to directory
     deleteTestFiles();
-    cmdResult = executeCommand("export config --dir=" + subDir.getAbsolutePath());
+    cmdResult = executeCommand("export config --dir=" + this.subDir.getAbsolutePath());
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
     assertFalse(this.managerConfigFile.exists());
@@ -246,30 +248,32 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     String configToMatch = stringWriter.toString();
 
     deleteTestFiles();
-    cmdResult = executeCommand("export config --member=Shell");
+    cmdResult = executeCommand("export config --member=Shell --dir=" + this.temporaryFolder.getRoot().getAbsolutePath());
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
     char[] fileContents = new char[configToMatch.length()];
-    try {
-      FileReader reader = new FileReader(shellConfigFile);
-      reader.read(fileContents);
-    } catch (Exception ex) {
-      fail("Unable to read file contents for comparison", ex);
-    }
+    FileReader reader = new FileReader(this.shellConfigFile);
+    reader.read(fileContents);
 
     assertEquals(configToMatch, new String(fileContents));
   }
 
   @Test
-  public void testAlterRuntimeConfig() throws ClassNotFoundException, IOException {
+  public void testAlterRuntimeConfig() throws Exception {
     final String controller = "controller";
+    String directory = this.temporaryFolder.newFolder(controller).getAbsolutePath();
+    String statFilePath = new File(directory, "stat.gfs").getAbsolutePath();
+
     setUpJmxManagerOnVm0ThenConnect(null);
+
     Properties localProps = new Properties();
-    localProps.setProperty(DistributionConfig.NAME_NAME, controller);
-    localProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "error");
+    localProps.setProperty(NAME_NAME, controller);
+    localProps.setProperty(LOG_LEVEL_NAME, "error");
     getSystem(localProps);
+
     final GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
     final DistributionConfig config = cache.getSystem().getConfig();
+
     CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG);
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__MEMBER, controller);
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL, "info");
@@ -277,13 +281,16 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT, "32");
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT, "49");
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE, "2000");
-    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, "stat.gfs");
+    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, statFilePath);
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED, "true");
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "10");
+
     CommandResult cmdResult = executeCommand(csb.getCommandString());
     String resultString = commandResultToString(cmdResult);
+
     getLogWriter().info("Result\n");
     getLogWriter().info(resultString);
+
     assertEquals(true, cmdResult.getStatus().equals(Status.OK));
     assertEquals(LogWriterImpl.INFO_LEVEL, config.getLogLevel());
     assertEquals(50, config.getLogFileSizeLimit());
@@ -293,27 +300,29 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     assertEquals(true, config.getStatisticSamplingEnabled());
     assertEquals(10, config.getLogDiskSpaceLimit());
 
-
     CommandProcessor commandProcessor = new CommandProcessor();
     Result result = commandProcessor.createCommandStatement("alter runtime", Collections.EMPTY_MAP).process();
   }
 
   @Test
-  public void testAlterRuntimeConfigRandom() {
+  public void testAlterRuntimeConfigRandom() throws Exception {
     final String member1 = "VM1";
     final String controller = "controller";
+
     setUpJmxManagerOnVm0ThenConnect(null);
+
     Properties localProps = new Properties();
-    localProps.setProperty(DistributionConfig.NAME_NAME, controller);
-    localProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "error");
+    localProps.setProperty(NAME_NAME, controller);
+    localProps.setProperty(LOG_LEVEL_NAME, "error");
     getSystem(localProps);
+
     final GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
     final DistributionConfig config = cache.getSystem().getConfig();
 
     Host.getHost(0).getVM(1).invoke(new SerializableRunnable() {
       public void run() {
         Properties localProps = new Properties();
-        localProps.setProperty(DistributionConfig.NAME_NAME, member1);
+        localProps.setProperty(NAME_NAME, member1);
         getSystem(localProps);
         Cache cache = getCache();
       }
@@ -322,8 +331,10 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG);
     CommandResult cmdResult = executeCommand(csb.getCommandString());
     String resultAsString = commandResultToString(cmdResult);
+
     getLogWriter().info("#SB Result\n");
     getLogWriter().info(resultAsString);
+
     assertEquals(true, cmdResult.getStatus().equals(Status.ERROR));
     assertTrue(resultAsString.contains(CliStrings.ALTER_RUNTIME_CONFIG__RELEVANT__OPTION__MESSAGE));
 
@@ -331,45 +342,56 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "2000000000");
     cmdResult = executeCommand(csb.getCommandString());
     resultAsString = commandResultToString(cmdResult);
+
     getLogWriter().info("#SB Result\n");
     getLogWriter().info(resultAsString);
-    assertEquals(true, cmdResult.getStatus().equals(Status.ERROR));
 
+    assertEquals(true, cmdResult.getStatus().equals(Status.ERROR));
   }
 
   @Test
-  public void testAlterRuntimeConfigOnAllMembers() {
+  public void testAlterRuntimeConfigOnAllMembers() throws Exception {
     final String member1 = "VM1";
     final String controller = "controller";
+
+    String controllerDirectory = this.temporaryFolder.newFolder(controller).getAbsolutePath();
+    String controllerStatFilePath = new File(controllerDirectory, "stat.gfs").getAbsolutePath();
+
     setUpJmxManagerOnVm0ThenConnect(null);
+
     Properties localProps = new Properties();
-    localProps.setProperty(DistributionConfig.NAME_NAME, controller);
-    localProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "error");
+    localProps.setProperty(NAME_NAME, controller);
+    localProps.setProperty(LOG_LEVEL_NAME, "error");
     getSystem(localProps);
+
     final GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
     final DistributionConfig config = cache.getSystem().getConfig();
 
     Host.getHost(0).getVM(1).invoke(new SerializableRunnable() {
       public void run() {
         Properties localProps = new Properties();
-        localProps.setProperty(DistributionConfig.NAME_NAME, member1);
+        localProps.setProperty(NAME_NAME, member1);
         getSystem(localProps);
         Cache cache = getCache();
       }
     });
+
     CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG);
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL, "info");
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__FILE__SIZE__LIMIT, "50");
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__DISK__SPACE__LIMIT, "32");
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__ARCHIVE__FILE__SIZE__LIMIT, "49");
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLE__RATE, "2000");
-    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, "stat.gfs");
+    csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__ARCHIVE__FILE, controllerStatFilePath);
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED, "true");
     csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "10");
+
     CommandResult cmdResult = executeCommand(csb.getCommandString());
     String resultString = commandResultToString(cmdResult);
+
     getLogWriter().info("#SB Result\n");
     getLogWriter().info(resultString);
+
     assertEquals(true, cmdResult.getStatus().equals(Status.OK));
     assertEquals(LogWriterImpl.INFO_LEVEL, config.getLogLevel());
     assertEquals(50, config.getLogFileSizeLimit());
@@ -384,7 +406,8 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     Host.getHost(0).getVM(1).invoke(new SerializableRunnable() {
       public void run() {
         GemFireCacheImpl cacheVM1 = (GemFireCacheImpl) getCache();
-        final DistributionConfig configVM1 = cacheVM1.getSystem().getConfig();
+        DistributionConfig configVM1 = cacheVM1.getSystem().getConfig();
+
         assertEquals(LogWriterImpl.INFO_LEVEL, configVM1.getLogLevel());
         assertEquals(50, configVM1.getLogFileSizeLimit());
         assertEquals(49, configVM1.getArchiveFileSizeLimit());
@@ -399,51 +422,51 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
 
   /**
    * Asserts that altering the runtime config correctly updates the shared configuration.
-   * <p>
-   * Disabled: this test frequently fails during unit test runs. See ticket #52204
    */
-  public void disabledtestAlterUpdatesSharedConfig() {
-    disconnectAllFromDS();
-
-    final String groupName = "testAlterRuntimeConfigSharedConfigGroup";
+  @Test
+  public void testAlterUpdatesSharedConfig() throws Exception {
+    final String groupName = getName();
 
     // Start the Locator and wait for shared configuration to be available
-    final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+    final int locatorPort = getRandomAvailablePort(SOCKET);
+    final String locatorDirectory = this.temporaryFolder.newFolder("Locator").getAbsolutePath();
+
     Host.getHost(0).getVM(3).invoke(new SerializableRunnable() {
       @Override
       public void run() {
+        final File locatorLogFile = new File(locatorDirectory, "locator-" + locatorPort +
".log");
 
-        final File locatorLogFile = new File("locator-" + locatorPort + ".log");
         final Properties locatorProps = new Properties();
-        locatorProps.setProperty(DistributionConfig.NAME_NAME, "Locator");
-        locatorProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
-        locatorProps.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "true");
+        locatorProps.setProperty(NAME_NAME, "Locator");
+        locatorProps.setProperty(MCAST_PORT_NAME, "0");
+        locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION_NAME, "true");
+        locatorProps.setProperty(CLUSTER_CONFIGURATION_DIR, locatorDirectory);
+
         try {
-          final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
locatorLogFile, null,
-              locatorProps);
+          final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
locatorLogFile, null, locatorProps);
 
           WaitCriterion wc = new WaitCriterion() {
             @Override
             public boolean done() {
               return locator.isSharedConfigurationRunning();
             }
-
             @Override
             public String description() {
               return "Waiting for shared configuration to be started";
             }
           };
           waitForCriterion(wc, 5000, 500, true);
-        } catch (IOException ioex) {
-          fail("Unable to create a locator with a shared configuration");
+
+        } catch (IOException e) {
+          fail("Unable to create a locator with a shared configuration", e);
         }
       }
     });
 
     // Start the default manager
     Properties managerProps = new Properties();
-    managerProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
-    managerProps.setProperty(DistributionConfig.LOCATORS_NAME, "localhost:" + locatorPort);
+    managerProps.setProperty(MCAST_PORT_NAME, "0");
+    managerProps.setProperty(LOCATORS_NAME, "localhost:" + locatorPort);
     setUpJmxManagerOnVm0ThenConnect(managerProps);
 
     // Create a cache in VM 1
@@ -451,18 +474,15 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     vm.invoke(new SerializableCallable() {
       @Override
       public Object call() throws Exception {
-        //Make sure no previous shared config is screwing up this test.
-        FileUtil.delete(new File("ConfigDiskDir_Locator"));
-        FileUtil.delete(new File("cluster_config"));
         Properties localProps = new Properties();
-        localProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
-        localProps.setProperty(DistributionConfig.LOCATORS_NAME, "localhost:" + locatorPort);
-        localProps.setProperty(DistributionConfig.LOG_LEVEL_NAME, "error");
-        localProps.setProperty(DistributionConfig.GROUPS_NAME, groupName);
+        localProps.setProperty(MCAST_PORT_NAME, "0");
+        localProps.setProperty(LOCATORS_NAME, "localhost:" + locatorPort);
+        localProps.setProperty(LOG_LEVEL_NAME, "error");
+        localProps.setProperty(GROUPS_NAME, groupName);
         getSystem(localProps);
 
         assertNotNull(getCache());
-        assertEquals("error", basicGetSystem().getConfig().getAttribute(DistributionConfig.LOG_LEVEL_NAME));
+        assertEquals("error", basicGetSystem().getConfig().getAttribute(LOG_LEVEL_NAME));
         return null;
       }
     });
@@ -472,6 +492,7 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     commandStringBuilder.addOption(CliStrings.ALTER_RUNTIME_CONFIG__GROUP, groupName);
     commandStringBuilder.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__LEVEL, "fine");
     CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
+
     assertEquals(Result.Status.OK, cmdResult.getStatus());
 
     // Make sure the shared config was updated
@@ -479,13 +500,15 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
       @Override
       public void run() {
         SharedConfiguration sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
-        Properties gemfireProperties;
+        Properties gemfireProperties = null;
+
         try {
           gemfireProperties = sharedConfig.getConfiguration(groupName).getGemfireProperties();
-          assertEquals("fine", gemfireProperties.get(DistributionConfig.LOG_LEVEL_NAME));
         } catch (Exception e) {
           fail("Error occurred in cluster configuration service", e);
         }
+
+        assertEquals("fine", gemfireProperties.get(LOG_LEVEL_NAME));
       }
     });
   }
@@ -500,6 +523,6 @@ public class ConfigCommandsDUnitTest extends CliCommandTestBase {
     this.shellConfigFile.delete();
     this.shellPropsFile.delete();
 
-    FileUtils.deleteDirectory(this.subDir);
+    deleteDirectory(this.subDir);
   }
 }


Mime
View raw message