[GitHub] geode pull request #317: [GEODE-2196] Add test for exportClusterConfig.

2016-12-15 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/geode/pull/317


---
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.
---


[GitHub] geode pull request #317: [GEODE-2196] Add test for exportClusterConfig.

2016-12-15 Thread jaredjstewart
Github user jaredjstewart commented on a diff in the pull request:

https://github.com/apache/geode/pull/317#discussion_r92668393
  
--- Diff: 
geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
 ---
@@ -85,21 +91,16 @@ public void connect(String... options) throws Exception 
{
 // javax.naming.CommunicationException [Root exception is 
java.rmi.NoSuchObjectException: no
 // such object in table]" Exception.
 // Tried to wait on jmx connector server being ready, but it doesn't 
work.
-// Add the retry logic here to try at most 10 times for connection.
-CommandResult result = null;
-for (int i = 0; i < 50; i++) {
-  System.out.println("trying to connect, attempt " + i);
+Awaitility.await().atMost(2, TimeUnit.MINUTES).pollDelay(2, 
TimeUnit.SECONDS).until(() -> {
   gfsh.executeCommand(connectCommand.toString());
-  result = (CommandResult) gfsh.getResult();
-  System.out.println(gfsh.outputString);
-  if (!gfsh.outputString.contains("no such object in table")) {
-break;
-  }
-  Thread.currentThread().sleep(2000);
-}
+  return !gfsh.outputString.contains("no such object in table");
+});
+
+CommandResult result = (CommandResult) gfsh.getResult();
--- End diff --

Oh, I mistakenly assumed it would only give the most recent result.  I 
pushed another try :)


---
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.
---


[GitHub] geode pull request #317: [GEODE-2196] Add test for exportClusterConfig.

2016-12-15 Thread jinmeiliao
Github user jinmeiliao commented on a diff in the pull request:

https://github.com/apache/geode/pull/317#discussion_r92666840
  
--- Diff: 
geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
 ---
@@ -85,21 +91,16 @@ public void connect(String... options) throws Exception 
{
 // javax.naming.CommunicationException [Root exception is 
java.rmi.NoSuchObjectException: no
 // such object in table]" Exception.
 // Tried to wait on jmx connector server being ready, but it doesn't 
work.
-// Add the retry logic here to try at most 10 times for connection.
-CommandResult result = null;
-for (int i = 0; i < 50; i++) {
-  System.out.println("trying to connect, attempt " + i);
+Awaitility.await().atMost(2, TimeUnit.MINUTES).pollDelay(2, 
TimeUnit.SECONDS).until(() -> {
   gfsh.executeCommand(connectCommand.toString());
-  result = (CommandResult) gfsh.getResult();
-  System.out.println(gfsh.outputString);
-  if (!gfsh.outputString.contains("no such object in table")) {
-break;
-  }
-  Thread.currentThread().sleep(2000);
-}
+  return !gfsh.outputString.contains("no such object in table");
+});
+
+CommandResult result = (CommandResult) gfsh.getResult();
--- End diff --

the getResult call needs to be inside the awaitility loop. The result is 
put in a queue everytime a command is called. If you only call it outside the 
loop, the result you got is the first command result in the loop.


---
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.
---


[GitHub] geode pull request #317: [GEODE-2196] Add test for exportClusterConfig.

2016-12-15 Thread jaredjstewart
Github user jaredjstewart commented on a diff in the pull request:

https://github.com/apache/geode/pull/317#discussion_r92651688
  
--- Diff: 
geode-core/src/test/java/org/apache/geode/test/dunit/rules/ConfigGroup.java ---
@@ -0,0 +1,102 @@
+/*
+ * 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
+ * thisright 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
+ * this 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.test.dunit.rules;
--- End diff --

Moved to `org.apache.geode.management.internal.configuration`.


---
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.
---


[GitHub] geode pull request #317: [GEODE-2196] Add test for exportClusterConfig.

2016-12-15 Thread jaredjstewart
Github user jaredjstewart commented on a diff in the pull request:

https://github.com/apache/geode/pull/317#discussion_r92650337
  
--- Diff: 
geode-core/src/test/java/org/apache/geode/test/dunit/rules/GfshShellConnectionRule.java
 ---
@@ -85,19 +91,17 @@ public void connect(String... options) throws Exception 
{
 // javax.naming.CommunicationException [Root exception is 
java.rmi.NoSuchObjectException: no
 // such object in table]" Exception.
 // Tried to wait on jmx connector server being ready, but it doesn't 
work.
-// Add the retry logic here to try at most 10 times for connection.
-CommandResult result = null;
-for (int i = 0; i < 50; i++) {
-  System.out.println("trying to connect, attempt " + i);
+Awaitility.await().atMost(2, TimeUnit.MINUTES).pollDelay(2, 
TimeUnit.SECONDS).until(() -> {
   gfsh.executeCommand(connectCommand.toString());
-  result = (CommandResult) gfsh.getResult();
-  System.out.println(gfsh.outputString);
-  if (!gfsh.outputString.contains("no such object in table")) {
-break;
-  }
-  Thread.currentThread().sleep(2000);
-}
-connected = (result.getStatus() == Result.Status.OK);
+  CommandResult result = (CommandResult) gfsh.getResult();
+  return !gfsh.outputString.contains("no such object in table")
--- End diff --

Thanks for catching this.  I modified the commit to behave as intended.


---
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.
---


[GitHub] geode pull request #317: [GEODE-2196] Add test for exportClusterConfig.

2016-12-14 Thread jinmeiliao
Github user jinmeiliao commented on a diff in the pull request:

https://github.com/apache/geode/pull/317#discussion_r92544631
  
--- Diff: 
geode-core/src/test/java/org/apache/geode/test/dunit/rules/LocatorServerStartupRule.java
 ---
@@ -44,32 +46,32 @@
   /**
* This is only available in each Locator/Server VM, not in the 
controller (test) VM.
*/
-  public static ServerStarterRule serverStarter;
+  public static transient ServerStarterRule serverStarter;
--- End diff --

I think all static variables are transient by default.


---
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.
---


[GitHub] geode pull request #317: [GEODE-2196] Add test for exportClusterConfig.

2016-12-14 Thread jinmeiliao
Github user jinmeiliao commented on a diff in the pull request:

https://github.com/apache/geode/pull/317#discussion_r92544756
  
--- Diff: 
geode-core/src/test/java/org/apache/geode/test/dunit/rules/Locator.java ---
@@ -0,0 +1,28 @@
+/*
+ * 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.test.dunit.rules;
+
+import org.apache.geode.test.dunit.VM;
+
+import java.io.File;
+
+public class Locator extends Member {
--- End diff --

Why are we not using Member for both locator/server? The child class does 
not provide anything else the abstract class doesn't do.


---
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.
---


[GitHub] geode pull request #317: [GEODE-2196] Add test for exportClusterConfig.

2016-12-14 Thread jinmeiliao
Github user jinmeiliao commented on a diff in the pull request:

https://github.com/apache/geode/pull/317#discussion_r92544538
  
--- Diff: 
geode-core/src/test/java/org/apache/geode/test/dunit/rules/ClusterConfig.java 
---
@@ -0,0 +1,183 @@
+/*
+ * 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.test.dunit.rules;
--- End diff --

Do we want to put this in the rules package or should we moved into the 
cluster config test package?


---
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.
---


[GitHub] geode pull request #317: [GEODE-2196] Add test for exportClusterConfig.

2016-12-14 Thread jinmeiliao
Github user jinmeiliao commented on a diff in the pull request:

https://github.com/apache/geode/pull/317#discussion_r92544596
  
--- Diff: 
geode-core/src/test/java/org/apache/geode/test/dunit/rules/ConfigGroup.java ---
@@ -0,0 +1,102 @@
+/*
+ * 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
+ * thisright 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
+ * this 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.test.dunit.rules;
--- End diff --

Same as before, probably move to another more specific package


---
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.
---


[GitHub] geode pull request #317: [GEODE-2196] Add test for exportClusterConfig.

2016-12-14 Thread jinmeiliao
Github user jinmeiliao commented on a diff in the pull request:

https://github.com/apache/geode/pull/317#discussion_r92545081
  
--- Diff: 
geode-core/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigImportDUnitTest.java
 ---
@@ -0,0 +1,144 @@
+/*
+ * 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.configuration;
+
+import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.geode.management.cli.Result;
+import org.apache.geode.management.internal.cli.result.CommandResult;
+import org.apache.geode.test.dunit.rules.ClusterConfig;
+import org.apache.geode.test.dunit.rules.ConfigGroup;
+import org.apache.geode.test.dunit.rules.GfshShellConnectionRule;
+import org.apache.geode.test.dunit.rules.Locator;
+import org.apache.geode.test.dunit.rules.Server;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+@Category(DistributedTest.class)
+public class ClusterConfigImportDUnitTest extends ClusterConfigBaseTest {
+  private GfshShellConnectionRule gfshConnector;
+
+  public static final ClusterConfig INITIAL_CONFIG = new ClusterConfig(new 
ConfigGroup("cluster"));
+
+  private Locator locator;
+
+  @Before
+  public void before() throws Exception {
+super.before();
+locator = lsRule.startLocatorVM(0, locatorProps);
+INITIAL_CONFIG.verify(locator);
+
+gfshConnector = new GfshShellConnectionRule(locator);
+gfshConnector.connect();
+assertThat(gfshConnector.isConnected()).isTrue();
+  }
+
+
+  @After
+  public void after() throws Exception {
+if (gfshConnector != null) {
+  gfshConnector.close();
+}
+  }
+
+  @Test
+  public void testImportWithRunningServer() throws Exception {
+Server server1 = lsRule.startServerVM(1, serverProps, 
locator.getPort());
+
+CommandResult result = gfshConnector.executeCommand(
+"import cluster-configuration --zip-file-name=" + 
EXPORTED_CLUSTER_CONFIG_PATH);
+
+assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
+  }
+
+  @Test
+  public void testImportClusterConfig() throws Exception {
+CommandResult result = gfshConnector.executeCommand(
+"import cluster-configuration --zip-file-name=" + 
EXPORTED_CLUSTER_CONFIG_PATH);
+assertThat(result.getStatus()).isEqualTo(Result.Status.OK);
+
+// verify that the previous folder is backed up to 
"cluster_configxx".
+assertThat(locator.getWorkingDir().listFiles())
+.filteredOn((File file) -> 
!file.getName().equals("cluster_config"))
+.filteredOn((File file) -> 
file.getName().startsWith("cluster_config")).isNotEmpty();
+CONFIG_FROM_ZIP.verify(locator);
+
+// start server1 with no group
+Server server1 = lsRule.startServerVM(1, serverProps, 
locator.getPort());
+new ClusterConfig(CLUSTER).verify(server1);
+
+// start server2 in group1
+serverProps.setProperty(GROUPS, "group1");
+Server server2 = lsRule.startServerVM(2, serverProps, 
locator.getPort());
+new ClusterConfig(CLUSTER, GROUP1).verify(server2);
+
+// start server3 in group1 and group2
+serverProps.setProperty(GROUPS, "group1,group2");
+Server server3 = lsRule.startServerVM(3, serverProps, 
locator.getPort());
+new ClusterConfig(CLUSTER, GROUP1, GROUP2).verify(server3);
+  }
+
+  @Test
+  public void testExportClusterConfig() throws Exception {
   

[GitHub] geode pull request #317: [GEODE-2196] Add test for exportClusterConfig.

2016-12-14 Thread jaredjstewart
GitHub user jaredjstewart opened a pull request:

https://github.com/apache/geode/pull/317

[GEODE-2196] Add test for exportClusterConfig.

- Break ClusterConfigDUnitTest out into multiple test classes.
- Refactor ClusterConfigDUnitTest.ExpectedConfig into a standalone 
ClusterConfig class.
- Refactor GfshShellConnectionRule to use Awaitility instead of Thread.sleep

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/jaredjstewart/geode addExportClusterConfigTest

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/geode/pull/317.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #317


commit 371ca74550e10bae5562dc300129d54318e22811
Author: Jared Stewart 
Date:   2016-12-15T00:39:07Z

[GEODE-2196] Add test for exportClusterConfig.

- Break ClusterConfigDUnitTest out into multiple test classes.
- Refactor ClusterConfigDUnitTest.ExpectedConfig into a standalone 
ClusterConfig class.
- Refactor GfshShellConnectionRule to use Awaitility instead of Thread.sleep




---
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.
---