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

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


The following commit(s) were added to refs/heads/develop by this push:
     new 3aa14ae  GEODE-3530 Refactor RebalanceCommandDistributedTest (#2130)
3aa14ae is described below

commit 3aa14aeeb7b9bf585df8b29fb460b97a998e7edb
Author: FSOUTHERLAND <[email protected]>
AuthorDate: Mon Jul 16 08:59:17 2018 -0700

    GEODE-3530 Refactor RebalanceCommandDistributedTest (#2130)
    
    * set up regions properly
    * used parameterization for http/jmx connect
---
 .../commands/RebalanceCommandDistributedTest.java  | 174 ++++++++-------------
 .../RebalanceCommandOverHttpDistributedTest.java   |  32 ----
 2 files changed, 68 insertions(+), 138 deletions(-)

diff --git 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandDistributedTest.java
 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandDistributedTest.java
index 19dcfde..2ac6a45 100644
--- 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandDistributedTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandDistributedTest.java
@@ -14,143 +14,105 @@
  */
 package org.apache.geode.management.internal.cli.commands;
 
-import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
-import static org.apache.geode.test.dunit.Wait.waitForCriterion;
-import static org.assertj.core.api.Assertions.assertThat;
 
-import org.junit.Before;
+import static org.apache.geode.test.junit.rules.GfshCommandRule.PortType.http;
+import static 
org.apache.geode.test.junit.rules.GfshCommandRule.PortType.jmxManager;
+
+import org.junit.BeforeClass;
 import org.junit.ClassRule;
 import org.junit.Test;
-import org.junit.contrib.java.lang.system.ProvideSystemProperty;
 import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
 
 import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.RegionFactory;
 import org.apache.geode.cache.RegionShortcut;
-import org.apache.geode.management.DistributedRegionMXBean;
-import org.apache.geode.management.ManagementService;
-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.dunit.VM;
-import org.apache.geode.test.dunit.WaitCriterion;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
 import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.categories.FlakyTest;
+import org.apache.geode.test.junit.rules.GfshCommandRule;
+import 
org.apache.geode.test.junit.runners.CategoryWithParameterizedRunnerFactory;
 
-@Category({DistributedTest.class, FlakyTest.class}) // GEODE-3530
+@Category({DistributedTest.class})
+@RunWith(Parameterized.class)
[email protected](CategoryWithParameterizedRunnerFactory.class)
 @SuppressWarnings("serial")
-public class RebalanceCommandDistributedTest extends CliCommandTestBase {
-
-  private static final String REBALANCE_REGION_NAME =
-      RebalanceCommandDistributedTest.class.getSimpleName() + "Region";
+public class RebalanceCommandDistributedTest {
 
   @ClassRule
-  public static ProvideSystemProperty provideSystemProperty =
-      new ProvideSystemProperty(CliCommandTestBase.USE_HTTP_SYSTEM_PROPERTY, 
"false");
+  public static ClusterStartupRule cluster = new ClusterStartupRule();
 
-  @Before
-  public void before() throws Exception {
-    setUpJmxManagerOnVm0ThenConnect(null);
-    setupTestRebalanceForEntireDS();
-  }
+  @ClassRule
+  public static GfshCommandRule gfsh = new GfshCommandRule();
 
-  @Test
-  public void testSimulateForEntireDSWithTimeout() {
-    // check if DistributedRegionMXBean is available so that command will not 
fail
-    final VM manager = Host.getHost(0).getVM(0);
-    manager.invoke(() -> checkRegionMBeans());
+  private static MemberVM locator, server1, server2;
 
-    getLogWriter().info("testSimulateForEntireDS verified MBean and executing 
command");
+  @Parameterized.Parameter
+  public static boolean useHttp;
 
-    String command = "rebalance --simulate=true --time-out=-1";
+  @Parameterized.Parameters(name = "useHttp={0}")
+  public static Object[] data() {
+    return new Object[] {true, false};
+  }
 
-    CommandResult cmdResult = executeCommand(command);
+  @BeforeClass
+  public static void before() throws Exception {
+    locator = cluster.startLocatorVM(0);
 
-    getLogWriter().info("testSimulateForEntireDS just after executing " + 
cmdResult);
+    int locatorPort = locator.getPort();
+    server1 = cluster.startServerVM(1, "localhost", locatorPort);
+    server2 = cluster.startServerVM(2, "localhost", locatorPort);
 
-    assertThat(cmdResult).isNotNull();
+    setUpRegions();
 
-    String stringResult = commandResultToString(cmdResult);
-    getLogWriter().info("testSimulateForEntireDS stringResult : " + 
stringResult);
-    assertThat(cmdResult.getStatus()).isEqualTo(Result.Status.OK);
+    if (useHttp) {
+      gfsh.connectAndVerify(locator.getHttpPort(), http);
+    } else {
+      gfsh.connectAndVerify(locator.getJmxPort(), jmxManager);
+    }
   }
 
-  private void checkRegionMBeans() {
-    WaitCriterion waitForManagerMBean = new WaitCriterion() {
-      @Override
-      public boolean done() {
-        final ManagementService service = 
ManagementService.getManagementService(getCache());
-        final DistributedRegionMXBean bean =
-            service.getDistributedRegionMXBean(Region.SEPARATOR + 
REBALANCE_REGION_NAME);
-        if (bean == null) {
-          getLogWriter().info("Still probing for checkRegionMBeans 
ManagerMBean");
-          return false;
-        } else {
-          // verify that bean is proper before executing tests
-          return bean.getMembers() != null && bean.getMembers().length > 1
-              && bean.getMemberCount() > 0
-              && service.getDistributedSystemMXBean().listRegions().length >= 
2;
-        }
-      }
-
-      @Override
-      public String description() {
-        return "Probing for testRebalanceCommandForSimulateWithNoMember 
ManagerMBean";
-      }
-    };
+  @Test
+  public void testSimulateForEntireDSWithTimeout() {
+    // check if DistributedRegionMXBean is available so that command will not 
fail
+    locator.waitUntilRegionIsReadyOnExactlyThisManyServers("/region-1", 2);
+    locator.waitUntilRegionIsReadyOnExactlyThisManyServers("/region-2", 1);
+    locator.waitUntilRegionIsReadyOnExactlyThisManyServers("/region-3", 1);
 
-    waitForCriterion(waitForManagerMBean, 2 * 60 * 1000, 2000, true);
+    String command = "rebalance --simulate=true --time-out=-1";
 
-    DistributedRegionMXBean bean = 
ManagementService.getManagementService(getCache())
-        .getDistributedRegionMXBean("/" + REBALANCE_REGION_NAME);
-    assertThat(bean).isNotNull();
+    gfsh.executeAndAssertThat(command).statusIsSuccess();
   }
 
-  private void setupTestRebalanceForEntireDS() {
-    VM vm1 = Host.getHost(0).getVM(1);
-    VM vm2 = Host.getHost(0).getVM(2);
-
-    vm1.invoke(new SerializableRunnable() {
-      @Override
-      public void run() {
-
-        // no need to close cache as it will be closed as part of teardown2
-        Cache cache = getCache();
-
-        RegionFactory<Integer, Integer> dataRegionFactory =
-            cache.createRegionFactory(RegionShortcut.PARTITION);
-        Region region = dataRegionFactory.create(REBALANCE_REGION_NAME);
-        for (int i = 0; i < 10; i++) {
-          region.put("key" + (i + 200), "value" + (i + 200));
-        }
-        region = dataRegionFactory.create(REBALANCE_REGION_NAME + "Another1");
-        for (int i = 0; i < 100; i++) {
-          region.put("key" + (i + 200), "value" + (i + 200));
-        }
+  private static void setUpRegions() {
+    server1.invoke(() -> {
+      Cache cache = ClusterStartupRule.getCache();
+      RegionFactory<Integer, Integer> dataRegionFactory =
+          cache.createRegionFactory(RegionShortcut.PARTITION);
+      Region region = dataRegionFactory.create("region-1");
+      for (int i = 0; i < 10; i++) {
+        region.put("key" + (i + 200), "value" + (i + 200));
+      }
+      region = dataRegionFactory.create("region-2");
+      for (int i = 0; i < 100; i++) {
+        region.put("key" + (i + 200), "value" + (i + 200));
       }
     });
-
-    vm2.invoke(new SerializableRunnable() {
-      @Override
-      public void run() {
-
-        // no need to close cache as it will be closed as part of teardown2
-        Cache cache = getCache();
-
-        RegionFactory<Integer, Integer> dataRegionFactory =
-            cache.createRegionFactory(RegionShortcut.PARTITION);
-        Region region = dataRegionFactory.create(REBALANCE_REGION_NAME);
-        for (int i = 0; i < 100; i++) {
-          region.put("key" + (i + 400), "value" + (i + 400));
-        }
-        region = dataRegionFactory.create(REBALANCE_REGION_NAME + "Another2");
-        for (int i = 0; i < 10; i++) {
-          region.put("key" + (i + 200), "value" + (i + 200));
-        }
+    server2.invoke(() -> {
+      // no need to close cache as it will be closed as part of teardown2
+      Cache cache = ClusterStartupRule.getCache();
+      RegionFactory<Integer, Integer> dataRegionFactory =
+          cache.createRegionFactory(RegionShortcut.PARTITION);
+      Region region = dataRegionFactory.create("region-1");
+      for (int i = 0; i < 100; i++) {
+        region.put("key" + (i + 400), "value" + (i + 400));
+      }
+      region = dataRegionFactory.create("region-3");
+      for (int i = 0; i < 10; i++) {
+        region.put("key" + (i + 200), "value" + (i + 200));
       }
     });
   }
-
 }
diff --git 
a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandOverHttpDistributedTest.java
 
b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandOverHttpDistributedTest.java
deleted file mode 100644
index 3f75f7b..0000000
--- 
a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/RebalanceCommandOverHttpDistributedTest.java
+++ /dev/null
@@ -1,32 +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 org.junit.ClassRule;
-import org.junit.contrib.java.lang.system.ProvideSystemProperty;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.categories.FlakyTest;
-import org.apache.geode.test.junit.categories.GfshTest;
-
-@Category({DistributedTest.class, FlakyTest.class, GfshTest.class}) // 
GEODE-3530
-@SuppressWarnings("serial")
-public class RebalanceCommandOverHttpDistributedTest extends 
RebalanceCommandDistributedTest {
-
-  @ClassRule
-  public static ProvideSystemProperty provideSystemProperty =
-      new ProvideSystemProperty(CliCommandTestBase.USE_HTTP_SYSTEM_PROPERTY, 
"true");
-}

Reply via email to