This is an automated email from the ASF dual-hosted git repository. khowe 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 18cc07f GEODE-3340: Refactor ConfigCommandsDUnitTest to use test rules 18cc07f is described below commit 18cc07faf16233da9af4cbdbf62e752c33a3ad01 Author: YehEmily <emilyyeh1...@gmail.com> AuthorDate: Tue Aug 1 10:30:09 2017 -0700 GEODE-3340: Refactor ConfigCommandsDUnitTest to use test rules Fixed merge conflicts This closes #679 --- .../cli/commands/ConfigCommandsDUnitTest.java | 566 --------------------- .../test/dunit/rules/LocatorServerStartupRule.java | 7 +- .../apache/geode/test/dunit/rules/MemberVM.java | 9 +- .../cli/commands/CommandOverHttpDUnitTest.java | 5 +- .../cli/commands/ConfigCommandDUnitTest.java | 242 +++++++++ 5 files changed, 258 insertions(+), 571 deletions(-) diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java deleted file mode 100644 index 20fa400..0000000 --- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandsDUnitTest.java +++ /dev/null @@ -1,566 +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.management.internal.cli.commands; - -import static org.apache.commons.io.FileUtils.deleteDirectory; -import static org.apache.geode.distributed.ConfigurationProperties.ARCHIVE_FILE_SIZE_LIMIT; -import static org.apache.geode.distributed.ConfigurationProperties.CLUSTER_CONFIGURATION_DIR; -import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION; -import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_TIME_STATISTICS; -import static org.apache.geode.distributed.ConfigurationProperties.GROUPS; -import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT; -import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER; -import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_BIND_ADDRESS; -import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_PORT; -import static org.apache.geode.distributed.ConfigurationProperties.JMX_MANAGER_START; -import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS; -import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL; -import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT; -import static org.apache.geode.distributed.ConfigurationProperties.NAME; -import static org.apache.geode.distributed.ConfigurationProperties.STATISTIC_SAMPLING_ENABLED; -import static org.apache.geode.internal.AvailablePort.SOCKET; -import static org.apache.geode.internal.AvailablePort.getRandomAvailablePort; -import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts; -import static org.apache.geode.test.dunit.Assert.assertEquals; -import static org.apache.geode.test.dunit.Assert.assertFalse; -import static org.apache.geode.test.dunit.Assert.assertNotNull; -import static org.apache.geode.test.dunit.Assert.assertTrue; -import static org.apache.geode.test.dunit.Assert.fail; -import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter; -import static org.apache.geode.test.dunit.Wait.waitForCriterion; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.Collections; -import java.util.List; -import java.util.Properties; - -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import org.apache.geode.cache.Cache; -import org.apache.geode.cache.server.CacheServer; -import org.apache.geode.distributed.Locator; -import org.apache.geode.distributed.internal.ClusterConfigurationService; -import org.apache.geode.distributed.internal.DistributionConfig; -import org.apache.geode.distributed.internal.InternalDistributedSystem; -import org.apache.geode.distributed.internal.InternalLocator; -import org.apache.geode.internal.AvailablePortHelper; -import org.apache.geode.internal.cache.GemFireCacheImpl; -import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator; -import org.apache.geode.internal.logging.LogWriterImpl; -import org.apache.geode.management.cli.Result; -import org.apache.geode.management.cli.Result.Status; -import org.apache.geode.management.internal.cli.i18n.CliStrings; -import org.apache.geode.management.internal.cli.remote.OnlineCommandProcessor; -import org.apache.geode.management.internal.cli.result.CommandResult; -import org.apache.geode.management.internal.cli.util.CommandStringBuilder; -import org.apache.geode.test.dunit.Host; -import org.apache.geode.test.dunit.IgnoredException; -import org.apache.geode.test.dunit.SerializableCallable; -import org.apache.geode.test.dunit.SerializableRunnable; -import org.apache.geode.test.dunit.VM; -import org.apache.geode.test.dunit.WaitCriterion; -import org.apache.geode.test.junit.categories.DistributedTest; -import org.apache.geode.test.junit.categories.FlakyTest; - -/** - * Dunit class for testing GemFire config commands : export config - * - * @since GemFire 7.0 - */ -@Category({DistributedTest.class, FlakyTest.class}) // GEODE-1449 GEODE-3530 -@SuppressWarnings("serial") -public class ConfigCommandsDUnitTest extends CliCommandTestBase { - - 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 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 Exception { - setUpJmxManagerOnVm0ThenConnect(null); - final String controllerName = "Member2"; - - /* - * Create properties for the controller VM - */ - final Properties localProps = new Properties(); - localProps.setProperty(MCAST_PORT, "0"); - localProps.setProperty(LOG_LEVEL, "info"); - localProps.setProperty(STATISTIC_SAMPLING_ENABLED, "true"); - localProps.setProperty(ENABLE_TIME_STATISTICS, "true"); - localProps.setProperty(NAME, controllerName); - localProps.setProperty(GROUPS, "G1"); - getSystem(localProps); - Cache cache = getCache(); - - 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(); - - getLogWriter().info("#SB Actual JVM Args : "); - - for (String jvmArg : jvmArgs) { - getLogWriter().info("#SB JVM " + jvmArg); - } - - InternalDistributedSystem system = (InternalDistributedSystem) cache.getDistributedSystem(); - DistributionConfig config = system.getConfig(); - config.setArchiveFileSizeLimit(1000); - - String command = CliStrings.DESCRIBE_CONFIG + " --member=" + controllerName; - OnlineCommandProcessor cmdProcessor = new OnlineCommandProcessor(); - cmdProcessor.executeCommand(command); - - CommandResult cmdResult = executeCommand(command); - - 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")); - - cmdResult = - executeCommand(command + " --" + CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS + "=false"); - resultStr = commandResultToString(cmdResult); - - 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")); - - } finally { - cs.stop(); - } - } - - @Test // FlakyTest: GEODE-1449 - public void testExportConfig() throws Exception { - Properties localProps = new Properties(); - localProps.setProperty(NAME, "Manager"); - localProps.setProperty(GROUPS, "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(NAME, "VM1"); - localProps.setProperty(GROUPS, "Group2"); - getSystem(localProps); - getCache(); - } - }); - - // Create a cache in a 3rd VM (VM2) - Host.getHost(0).getVM(2).invoke(new SerializableRunnable() { - public void run() { - Properties localProps = new Properties(); - localProps.setProperty(NAME, "VM2"); - localProps.setProperty(GROUPS, "Group2"); - getSystem(localProps); - getCache(); - } - }); - - // Create a cache in the local VM - localProps = new Properties(); - localProps.setProperty(NAME, "Shell"); - getSystem(localProps); - Cache cache = getCache(); - - // Test export config for all members - deleteTestFiles(); - CommandResult cmdResult = - executeCommand("export config --dir=" + this.temporaryFolder.getRoot().getAbsolutePath()); - assertEquals(Result.Status.OK, cmdResult.getStatus()); - - 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 --dir=" + this.temporaryFolder.getRoot().getAbsolutePath()); - assertEquals(Result.Status.OK, cmdResult.getStatus()); - - 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 --dir=" + this.temporaryFolder.getRoot().getAbsolutePath()); - assertEquals(Result.Status.OK, cmdResult.getStatus()); - - 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=" + this.subDir.getAbsolutePath()); - assertEquals(Result.Status.OK, cmdResult.getStatus()); - - assertFalse(this.managerConfigFile.exists()); - assertTrue(this.subManagerConfigFile.exists()); - - // Test the contents of the file - StringWriter stringWriter = new StringWriter(); - PrintWriter printWriter = new PrintWriter(stringWriter); - CacheXmlGenerator.generate(cache, printWriter, false, false, false); - String configToMatch = stringWriter.toString(); - - deleteTestFiles(); - cmdResult = executeCommand( - "export config --member=Shell --dir=" + this.temporaryFolder.getRoot().getAbsolutePath()); - assertEquals(Result.Status.OK, cmdResult.getStatus()); - - char[] fileContents = new char[configToMatch.length()]; - FileReader reader = new FileReader(this.shellConfigFile); - reader.read(fileContents); - - assertEquals(configToMatch, new String(fileContents)); - } - - @Test - 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(NAME, controller); - localProps.setProperty(LOG_LEVEL, "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.MEMBER, controller); - 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, 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()); - assertEquals(32, config.getArchiveDiskSpaceLimit()); - assertEquals(2000, config.getStatisticSampleRate()); - assertEquals("stat.gfs", config.getStatisticArchiveFile().getName()); - assertEquals(true, config.getStatisticSamplingEnabled()); - assertEquals(10, config.getLogDiskSpaceLimit()); - - OnlineCommandProcessor onlineCommandProcessor = new OnlineCommandProcessor(); - Result result = onlineCommandProcessor.executeCommand("alter runtime", Collections.EMPTY_MAP); - } - - @Test - public void testAlterRuntimeConfigRandom() throws Exception { - IgnoredException.addIgnoredException( - "java.lang.IllegalArgumentException: Could not set \"log-disk-space-limit\""); - final String member1 = "VM1"; - final String controller = "controller"; - - setUpJmxManagerOnVm0ThenConnect(null); - - Properties localProps = new Properties(); - localProps.setProperty(NAME, controller); - localProps.setProperty(LOG_LEVEL, "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(NAME, member1); - getSystem(localProps); - getCache(); - } - }); - - CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG); - CommandResult cmdResult = executeCommand(csb.getCommandString()); - String resultAsString = commandResultToString(cmdResult); - - assertEquals(true, cmdResult.getStatus().equals(Status.ERROR)); - assertTrue(resultAsString.contains(CliStrings.ALTER_RUNTIME_CONFIG__RELEVANT__OPTION__MESSAGE)); - - csb = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG); - csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "2000000000"); - cmdResult = executeCommand(csb.getCommandString()); - resultAsString = commandResultToString(cmdResult); - - assertEquals(true, cmdResult.getStatus().equals(Status.ERROR)); - assertTrue( - resultAsString.contains("Could not set \"log-disk-space-limit\" to \"2,000,000,000\"")); - } - - @Test - 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(NAME, controller); - localProps.setProperty(LOG_LEVEL, "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(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, - 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()); - assertEquals(49, config.getArchiveFileSizeLimit()); - assertEquals(32, config.getArchiveDiskSpaceLimit()); - assertEquals(2000, config.getStatisticSampleRate()); - assertEquals("stat.gfs", config.getStatisticArchiveFile().getName()); - assertEquals(true, config.getStatisticSamplingEnabled()); - assertEquals(10, config.getLogDiskSpaceLimit()); - - // Validate the changes in the vm1 - Host.getHost(0).getVM(1).invoke(new SerializableRunnable() { - public void run() { - GemFireCacheImpl cacheVM1 = (GemFireCacheImpl) getCache(); - DistributionConfig configVM1 = cacheVM1.getSystem().getConfig(); - - assertEquals(LogWriterImpl.INFO_LEVEL, configVM1.getLogLevel()); - assertEquals(50, configVM1.getLogFileSizeLimit()); - assertEquals(49, configVM1.getArchiveFileSizeLimit()); - assertEquals(32, configVM1.getArchiveDiskSpaceLimit()); - assertEquals(2000, configVM1.getStatisticSampleRate()); - assertEquals("stat.gfs", configVM1.getStatisticArchiveFile().getName()); - assertEquals(true, configVM1.getStatisticSamplingEnabled()); - assertEquals(10, configVM1.getLogDiskSpaceLimit()); - } - }); - } - - /** - * Asserts that altering the runtime config correctly updates the shared configuration. - */ - @Test - public void testAlterUpdatesSharedConfig() throws Exception { - final String groupName = getName(); - final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2); - jmxPort = ports[0]; - httpPort = ports[1]; - try { - jmxHost = InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException ignore) { - jmxHost = "localhost"; - } - - // Start the Locator and wait for shared configuration to be available - final int locatorPort = getRandomAvailablePort(SOCKET); - final String locatorDirectory = this.temporaryFolder.newFolder("Locator").getAbsolutePath(); - - final Properties locatorProps = new Properties(); - locatorProps.setProperty(NAME, "Locator"); - locatorProps.setProperty(MCAST_PORT, "0"); - locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true"); - locatorProps.setProperty(CLUSTER_CONFIGURATION_DIR, locatorDirectory); - locatorProps.setProperty(JMX_MANAGER, "true"); - locatorProps.setProperty(JMX_MANAGER_START, "true"); - locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost)); - locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort)); - locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort)); - - Host.getHost(0).getVM(0).invoke(new SerializableRunnable() { - @Override - public void run() { - final File locatorLogFile = new File(locatorDirectory, "locator-" + locatorPort + ".log"); - try { - 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 e) { - fail("Unable to create a locator with a shared configuration", e); - } - } - }); - - connect(jmxHost, jmxPort, httpPort, getDefaultShell()); - - // Create a cache in VM 1 - VM vm = Host.getHost(0).getVM(1); - vm.invoke(new SerializableCallable() { - @Override - public Object call() throws Exception { - Properties localProps = new Properties(); - localProps.setProperty(MCAST_PORT, "0"); - localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]"); - localProps.setProperty(LOG_LEVEL, "error"); - localProps.setProperty(GROUPS, groupName); - getSystem(localProps); - - assertNotNull(getCache()); - assertEquals("error", basicGetSystem().getConfig().getAttribute(LOG_LEVEL)); - return null; - } - }); - - // Test altering the runtime config - CommandStringBuilder commandStringBuilder = - new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG); - commandStringBuilder.addOption(CliStrings.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 - Host.getHost(0).getVM(0).invoke(new SerializableRunnable() { - @Override - public void run() { - ClusterConfigurationService sharedConfig = - ((InternalLocator) Locator.getLocator()).getSharedConfiguration(); - Properties gemfireProperties = null; - - try { - gemfireProperties = sharedConfig.getConfiguration(groupName).getGemfireProperties(); - } catch (Exception e) { - fail("Error occurred in cluster configuration service", e); - } - - assertEquals("fine", gemfireProperties.get(LOG_LEVEL)); - } - }); - } - - private void deleteTestFiles() throws IOException { - this.managerConfigFile.delete(); - this.managerPropsFile.delete(); - this.vm1ConfigFile.delete(); - this.vm1PropsFile.delete(); - this.vm2ConfigFile.delete(); - this.vm2PropsFile.delete(); - this.shellConfigFile.delete(); - this.shellPropsFile.delete(); - - deleteDirectory(this.subDir); - } -} diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java index 4fa4339..293f76e 100644 --- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java +++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java @@ -201,6 +201,10 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial } public MemberVM startServerAsEmbededLocator(int index) throws IOException { + return startServerAsEmbededLocator(index, new Properties()); + } + + public MemberVM startServerAsEmbededLocator(int index, Properties properties) throws IOException { String name = "server-" + index; VM serverVM = getVM(index); @@ -213,7 +217,8 @@ public class LocatorServerStartupRule extends ExternalResource implements Serial if (logFile) { serverStarter.withLogFile(); } - serverStarter.withEmbeddedLocator().withName(name).withJMXManager().withAutoStart(); + serverStarter.withEmbeddedLocator().withProperties(properties).withName(name).withJMXManager() + .withAutoStart(); serverStarter.before(); return serverStarter; }); diff --git a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MemberVM.java b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MemberVM.java index 14ccb6a..24a158d 100644 --- a/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MemberVM.java +++ b/geode-core/src/test/java/org/apache/geode/test/dunit/rules/MemberVM.java @@ -56,7 +56,7 @@ public class MemberVM<T extends Member> implements Member { } public T getMember() { - return (T) member; + return member; } @Override @@ -86,6 +86,13 @@ public class MemberVM<T extends Member> implements Member { return member.getName(); } + public int getEmbeddedLocatorPort() { + if (!(member instanceof Server)) { + throw new RuntimeException("member needs to be a server"); + } + return ((Server) member).getEmbeddedLocatorPort(); + } + public void stopMember() { this.invoke(LocatorServerStartupRule::stopMemberInThisVM); if (tempWorkingDir) { diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java index e74830c..a0488f5 100644 --- a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java +++ b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java @@ -26,9 +26,8 @@ import org.apache.geode.test.junit.runner.SuiteRunner; @Category({DistributedTest.class, SecurityTest.class}) @RunWith(SuiteRunner.class) -@Suite.SuiteClasses({ConfigCommandsDUnitTest.class, DeployWithGroupsDUnitTest.class, - DiskStoreCommandsDUnitTest.class, FunctionCommandsDUnitTest.class, - GemfireDataCommandsDUnitTest.class, +@Suite.SuiteClasses({DeployWithGroupsDUnitTest.class, DiskStoreCommandsDUnitTest.class, + FunctionCommandsDUnitTest.class, GemfireDataCommandsDUnitTest.class, GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest.class, ListAndDescribeDiskStoreCommandsDUnitTest.class, ListIndexCommandDUnitTest.class, MiscellaneousCommandsDUnitTest.class, QueueCommandsDUnitTest.class, diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandDUnitTest.java b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandDUnitTest.java new file mode 100644 index 0000000..46949b9 --- /dev/null +++ b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/ConfigCommandDUnitTest.java @@ -0,0 +1,242 @@ +/* + * 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.management.internal.cli.commands; + +import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_TIME_STATISTICS; +import static org.apache.geode.distributed.ConfigurationProperties.GROUPS; +import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL; +import static org.apache.geode.distributed.ConfigurationProperties.STATISTIC_SAMPLING_ENABLED; +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; +import java.util.stream.Collectors; + +import junitparams.JUnitParamsRunner; +import junitparams.Parameters; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.rules.TemporaryFolder; +import org.junit.runner.RunWith; + +import org.apache.geode.distributed.internal.ClusterConfigurationService; +import org.apache.geode.distributed.internal.DistributionConfig; +import org.apache.geode.distributed.internal.InternalDistributedSystem; +import org.apache.geode.internal.cache.InternalCache; +import org.apache.geode.internal.logging.LogWriterImpl; +import org.apache.geode.management.cli.Result; +import org.apache.geode.management.internal.cli.i18n.CliStrings; +import org.apache.geode.management.internal.cli.result.CommandResult; +import org.apache.geode.management.internal.cli.util.CommandStringBuilder; +import org.apache.geode.test.dunit.IgnoredException; +import org.apache.geode.test.dunit.rules.GfshShellConnectionRule; +import org.apache.geode.test.dunit.rules.LocatorServerStartupRule; +import org.apache.geode.test.dunit.rules.MemberVM; +import org.apache.geode.test.junit.categories.DistributedTest; + +@Category(DistributedTest.class) +@RunWith(JUnitParamsRunner.class) +public class ConfigCommandDUnitTest { + @Rule + public LocatorServerStartupRule startupRule = new LocatorServerStartupRule(); + + @Rule + public GfshShellConnectionRule gfsh = new GfshShellConnectionRule(); + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @Test + @Parameters({"true", "false"}) + public void testDescribeConfig(final boolean connectOverHttp) throws Exception { + Properties localProps = new Properties(); + localProps.setProperty(STATISTIC_SAMPLING_ENABLED, "true"); + localProps.setProperty(ENABLE_TIME_STATISTICS, "true"); + localProps.setProperty(GROUPS, "G1"); + MemberVM server0 = startupRule.startServerAsJmxManager(0, localProps); + + if (connectOverHttp) { + gfsh.connectAndVerify(server0.getHttpPort(), GfshShellConnectionRule.PortType.http); + } else { + gfsh.connectAndVerify(server0.getJmxPort(), GfshShellConnectionRule.PortType.jmxManger); + } + + server0.invoke(() -> { + InternalCache cache = LocatorServerStartupRule.serverStarter.getCache(); + InternalDistributedSystem system = cache.getInternalDistributedSystem(); + DistributionConfig config = system.getConfig(); + config.setArchiveFileSizeLimit(1000); + }); + + gfsh.executeAndVerifyCommand("describe config --member=" + server0.getName()); + String result = gfsh.getGfshOutput(); + + assertThat(result).containsPattern("enable-time-statistics\\s+: true"); + assertThat(result).containsPattern("groups\\s+: G1"); + assertThat(result).containsPattern("archive-file-size-limit\\s+: 1000"); + assertThat(result).containsPattern("name\\s+: server-0"); + assertThat(result).containsPattern("is-server\\s+: true"); + assertThat(result).doesNotContain("copy-on-read"); + + gfsh.executeAndVerifyCommand( + "describe config --member=" + server0.getName() + " --hide-defaults=false"); + result = gfsh.getGfshOutput(); + assertThat(result).contains("copy-on-read"); + } + + @Test + @Parameters({"true", "false"}) + public void testExportConfig(final boolean connectOverHttp) throws Exception { + Properties props = new Properties(); + props.setProperty(GROUPS, "Group1"); + + MemberVM server0 = startupRule.startServerAsEmbededLocator(0, props); + + if (connectOverHttp) { + gfsh.connectAndVerify(server0.getHttpPort(), GfshShellConnectionRule.PortType.http); + } else { + gfsh.connectAndVerify(server0.getJmxPort(), GfshShellConnectionRule.PortType.jmxManger); + } + + // start server1 and server2 in group2 + props.setProperty(GROUPS, "Group2"); + startupRule.startServerVM(1, props, server0.getEmbeddedLocatorPort()); + startupRule.startServerVM(2, props, server0.getEmbeddedLocatorPort()); + + // start server3 that has no group info + startupRule.startServerVM(3, server0.getEmbeddedLocatorPort()); + + // export all members' config into a folder + File tempDir = temporaryFolder.newFolder("all-members"); + gfsh.executeAndVerifyCommand("export config --dir=" + tempDir.getAbsolutePath()); + + List<String> expectedFiles = Arrays.asList("server-0-cache.xml", "server-1-cache.xml", + "server-2-cache.xml", "server-3-cache.xml", "server-0-gf.properties", + "server-1-gf.properties", "server-2-gf.properties", "server-3-gf.properties"); + + List<String> actualFiles = + Arrays.stream(tempDir.listFiles()).map(File::getName).collect(Collectors.toList()); + assertThat(actualFiles).hasSameElementsAs(expectedFiles); + tempDir.delete(); + + // export just one member's config + tempDir = temporaryFolder.newFolder("member0"); + gfsh.executeAndVerifyCommand( + "export config --member=server-0 --dir=" + tempDir.getAbsolutePath()); + + expectedFiles = Arrays.asList("server-0-cache.xml", "server-0-gf.properties"); + + actualFiles = + Arrays.stream(tempDir.listFiles()).map(File::getName).collect(Collectors.toList()); + assertThat(actualFiles).hasSameElementsAs(expectedFiles); + tempDir.delete(); + + // export group2 config into a folder + tempDir = temporaryFolder.newFolder("group2"); + gfsh.executeAndVerifyCommand("export config --group=Group2 --dir=" + tempDir.getAbsolutePath()); + + expectedFiles = Arrays.asList("server-1-cache.xml", "server-2-cache.xml", + "server-1-gf.properties", "server-2-gf.properties"); + + actualFiles = + Arrays.stream(tempDir.listFiles()).map(File::getName).collect(Collectors.toList()); + assertThat(actualFiles).hasSameElementsAs(expectedFiles); + tempDir.delete(); + } + + @Test + @Parameters({"true", "false"}) + public void testAlterRuntimeConfig(final boolean connectOverHttp) throws Exception { + IgnoredException.addIgnoredException( + "java.lang.IllegalArgumentException: Could not set \"log-disk-space-limit\""); + + Properties props = new Properties(); + props.setProperty(LOG_LEVEL, "error"); + MemberVM server0 = startupRule.startServerAsJmxManager(0, props); + + if (connectOverHttp) { + gfsh.connectAndVerify(server0.getHttpPort(), GfshShellConnectionRule.PortType.http); + } else { + gfsh.connectAndVerify(server0.getJmxPort(), GfshShellConnectionRule.PortType.jmxManger); + } + + CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_RUNTIME_CONFIG); + csb.addOption(CliStrings.MEMBER, server0.getName()); + 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, + temporaryFolder.newFile("stats.gfs")); + csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__STATISTIC__SAMPLING__ENABLED, "true"); + csb.addOption(CliStrings.ALTER_RUNTIME_CONFIG__LOG__DISK__SPACE__LIMIT, "10"); + + gfsh.executeAndVerifyCommand(csb.toString()); + + server0.invoke(() -> { + InternalCache cache = LocatorServerStartupRule.serverStarter.getCache(); + DistributionConfig config = cache.getInternalDistributedSystem().getConfig(); + assertThat(config.getLogLevel()).isEqualTo(LogWriterImpl.INFO_LEVEL); + assertThat(config.getLogFileSizeLimit()).isEqualTo(50); + assertThat(config.getArchiveDiskSpaceLimit()).isEqualTo(32); + assertThat(config.getStatisticSampleRate()).isEqualTo(2000); + assertThat(config.getStatisticArchiveFile().getName()).isEqualTo("stats.gfs"); + assertThat(config.getStatisticSamplingEnabled()).isTrue(); + assertThat(config.getLogDiskSpaceLimit()).isEqualTo(10); + }); + + CommandResult result = gfsh.executeCommand("alter runtime"); + assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR); + assertThat(gfsh.getGfshOutput()) + .contains(CliStrings.ALTER_RUNTIME_CONFIG__RELEVANT__OPTION__MESSAGE); + + result = gfsh.executeCommand("alter runtime --log-disk-space-limit=2000000000"); + assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR); + assertThat(gfsh.getGfshOutput()) + .contains("Could not set \"log-disk-space-limit\" to \"2,000,000,000\""); + } + + @Test + @Parameters({"true", "false"}) + public void testAlterUpdatesSharedConfig(final boolean connectOverHttp) throws Exception { + MemberVM locator = startupRule.startLocatorVM(0); + + if (connectOverHttp) { + gfsh.connectAndVerify(locator.getHttpPort(), GfshShellConnectionRule.PortType.http); + } else { + gfsh.connectAndVerify(locator.getJmxPort(), GfshShellConnectionRule.PortType.jmxManger); + } + + Properties props = new Properties(); + props.setProperty(GROUPS, "Group1"); + props.setProperty(LOG_LEVEL, "error"); + startupRule.startServerVM(1, props, locator.getPort()); + + String command = "alter runtime --group=Group1 --log-level=fine"; + gfsh.executeAndVerifyCommand(command); + + locator.invoke(() -> { + ClusterConfigurationService sharedConfig = + LocatorServerStartupRule.locatorStarter.getLocator().getSharedConfiguration(); + Properties properties = sharedConfig.getConfiguration("Group1").getGemfireProperties(); + assertThat(properties.get(LOG_LEVEL)).isEqualTo("fine"); + }); + } +} -- To stop receiving notification emails like this one, please contact ['"commits@geode.apache.org" <commits@geode.apache.org>'].