Github user YehEmily commented on a diff in the pull request: https://github.com/apache/geode/pull/665#discussion_r130960859 --- Diff: geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ExportConfigCommandDUnitTest.java --- @@ -0,0 +1,181 @@ +/* + * 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.GROUPS; +import static org.apache.geode.distributed.ConfigurationProperties.NAME; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Properties; + +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import org.apache.geode.cache.Cache; +import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator; +import org.apache.geode.management.cli.Result; +import org.apache.geode.management.internal.cli.result.CommandResult; +import org.apache.geode.test.dunit.Host; +import org.apache.geode.test.dunit.SerializableRunnable; +import org.apache.geode.test.junit.categories.DistributedTest; +import org.apache.geode.test.junit.categories.FlakyTest; + +@Category(DistributedTest.class) +public class ExportConfigCommandDUnitTest 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()); + } + + @Category(FlakyTest.class) // GEODE-1449 + @Test + 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 --- End diff -- I didn't know this at the time, but there is actually a separate JIRA ticket for refactoring all of the tests associated with all of these gfsh commands (see [GEODE-1359](https://issues.apache.org/jira/browse/GEODE-1359)). I'm going to roll back the changes to these tests and leave them for future work.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---