You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bs...@apache.org on 2017/08/15 23:10:17 UTC
[06/50] [abbrv] geode git commit: GEODE-3436: revert recent
refactoring of GFSH commands
http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DestroyRegionCommandDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DestroyRegionCommandDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DestroyRegionCommandDUnitTest.java
deleted file mode 100644
index e178d8c..0000000
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DestroyRegionCommandDUnitTest.java
+++ /dev/null
@@ -1,388 +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.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
-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.USE_CLUSTER_CONFIGURATION;
-import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
-import static org.awaitility.Awaitility.waitAtMost;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.text.MessageFormat;
-import java.util.Properties;
-import java.util.concurrent.Callable;
-import java.util.concurrent.TimeUnit;
-
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.PartitionAttributesFactory;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionFactory;
-import org.apache.geode.cache.RegionShortcut;
-import org.apache.geode.cache.Scope;
-import org.apache.geode.distributed.Locator;
-import org.apache.geode.distributed.internal.ClusterConfigurationService;
-import org.apache.geode.distributed.internal.InternalLocator;
-import org.apache.geode.internal.AvailablePort;
-import org.apache.geode.internal.AvailablePortHelper;
-import org.apache.geode.management.cli.Result;
-import org.apache.geode.management.internal.MBeanJMXAdapter;
-import org.apache.geode.management.internal.ManagementConstants;
-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.Host;
-import org.apache.geode.test.dunit.VM;
-import org.apache.geode.test.junit.categories.DistributedTest;
-
-@Category(DistributedTest.class)
-public class DestroyRegionCommandDUnitTest extends CliCommandTestBase {
- @Test
- public void testDestroyDistributedRegion() {
- setUpJmxManagerOnVm0ThenConnect(null);
-
- for (int i = 1; i <= 2; i++) {
- Host.getHost(0).getVM(i).invoke(() -> {
- final Cache cache = getCache();
-
- RegionFactory<Object, Object> factory = cache.createRegionFactory(RegionShortcut.PARTITION);
- factory.create("Customer");
-
- PartitionAttributesFactory paFactory = new PartitionAttributesFactory();
- paFactory.setColocatedWith("Customer");
- factory.setPartitionAttributes(paFactory.create());
- factory.create("Order");
- });
- }
-
- waitForRegionMBeanCreation("/Customer", 2);
- waitForRegionMBeanCreation("/Order", 2);
-
- // Test failure when region not found
- String command = "destroy region --name=DOESNOTEXIST";
- getLogWriter().info("testDestroyRegion command=" + command);
- CommandResult cmdResult = executeCommand(command);
- String strr = commandResultToString(cmdResult);
- getLogWriter().info("testDestroyRegion strr=" + strr);
- assertTrue(stringContainsLine(strr, "Could not find.*\"DOESNOTEXIST\".*"));
- assertEquals(Result.Status.ERROR, cmdResult.getStatus());
-
- // Test unable to destroy with co-location
- command = "destroy region --name=/Customer";
- getLogWriter().info("testDestroyRegion command=" + command);
- cmdResult = executeCommand(command);
- strr = commandResultToString(cmdResult);
- getLogWriter().info("testDestroyRegion strr=" + strr);
- assertEquals(Result.Status.ERROR, cmdResult.getStatus());
-
- // Test success
- command = "destroy region --name=/Order";
- getLogWriter().info("testDestroyRegion command=" + command);
- cmdResult = executeCommand(command);
- strr = commandResultToString(cmdResult);
- assertTrue(stringContainsLine(strr, ".*Order.*destroyed successfully.*"));
- getLogWriter().info("testDestroyRegion strr=" + strr);
- assertEquals(Result.Status.OK, cmdResult.getStatus());
-
- command = "destroy region --name=/Customer";
- getLogWriter().info("testDestroyRegion command=" + command);
- cmdResult = executeCommand(command);
- strr = commandResultToString(cmdResult);
- assertTrue(stringContainsLine(strr, ".*Customer.*destroyed successfully.*"));
- getLogWriter().info("testDestroyRegion strr=" + strr);
- assertEquals(Result.Status.OK, cmdResult.getStatus());
- }
-
- @Test
- public void testDestroyLocalRegions() {
- setUpJmxManagerOnVm0ThenConnect(null);
-
- for (int i = 1; i <= 3; i++) {
- Host.getHost(0).getVM(i).invoke(() -> {
- final Cache cache = getCache();
-
- RegionFactory<Object, Object> factory = cache.createRegionFactory(RegionShortcut.REPLICATE);
- factory.setScope(Scope.LOCAL);
- factory.create("Customer");
- });
- }
-
- waitForRegionMBeanCreation("/Customer", 3);
-
- // Test failure when region not found
- String command = "destroy region --name=DOESNOTEXIST";
- getLogWriter().info("testDestroyRegion command=" + command);
- CommandResult cmdResult = executeCommand(command);
- String strr = commandResultToString(cmdResult);
- getLogWriter().info("testDestroyRegion strr=" + strr);
- assertTrue(stringContainsLine(strr, "Could not find.*\"DOESNOTEXIST\".*"));
- assertEquals(Result.Status.ERROR, cmdResult.getStatus());
-
- command = "destroy region --name=/Customer";
- getLogWriter().info("testDestroyRegion command=" + command);
- cmdResult = executeCommand(command);
- strr = commandResultToString(cmdResult);
- assertTrue(stringContainsLine(strr, ".*Customer.*destroyed successfully.*"));
- getLogWriter().info("testDestroyRegion strr=" + strr);
- assertEquals(Result.Status.OK, cmdResult.getStatus());
-
- for (int i = 1; i <= 3; i++) {
- final int x = i;
- Host.getHost(0).getVM(i).invoke(() -> {
- assertNull("Region still exists in VM " + x, getCache().getRegion("Customer"));
- });
- }
- }
-
- @Test
- public void testDestroyLocalAndDistributedRegions() {
- setUpJmxManagerOnVm0ThenConnect(null);
-
- for (int i = 1; i <= 2; i++) {
- Host.getHost(0).getVM(i).invoke(() -> {
- final Cache cache = getCache();
- RegionFactory<Object, Object> factory = cache.createRegionFactory(RegionShortcut.PARTITION);
- factory.create("Customer");
- factory.create("Customer-2");
- factory.create("Customer_3");
- });
- }
-
- Host.getHost(0).getVM(3).invoke(() -> {
- final Cache cache = getCache();
- RegionFactory<Object, Object> factory = cache.createRegionFactory(RegionShortcut.REPLICATE);
- factory.setScope(Scope.LOCAL);
- factory.create("Customer");
- factory.create("Customer-2");
- factory.create("Customer_3");
- });
-
- waitForRegionMBeanCreation("/Customer", 3);
-
- // Test failure when region not found
- String command = "destroy region --name=DOESNOTEXIST";
- getLogWriter().info("testDestroyRegion command=" + command);
- CommandResult cmdResult = executeCommand(command);
- String strr = commandResultToString(cmdResult);
- getLogWriter().info("testDestroyRegion strr=" + strr);
- assertTrue(stringContainsLine(strr, "Could not find.*\"DOESNOTEXIST\".*"));
- assertEquals(Result.Status.ERROR, cmdResult.getStatus());
-
- command = "destroy region --name=/Customer";
- getLogWriter().info("testDestroyRegion command=" + command);
- cmdResult = executeCommand(command);
- strr = commandResultToString(cmdResult);
- assertTrue(stringContainsLine(strr, ".*Customer.*destroyed successfully.*"));
- getLogWriter().info("testDestroyRegion strr=" + strr);
- assertEquals(Result.Status.OK, cmdResult.getStatus());
-
- command = "destroy region --name=/Customer_3";
- getLogWriter().info("testDestroyRegion command=" + command);
- cmdResult = executeCommand(command);
- strr = commandResultToString(cmdResult);
- assertTrue(stringContainsLine(strr, ".*Customer_3.*destroyed successfully.*"));
- getLogWriter().info("testDestroyRegion strr=" + strr);
- assertEquals(Result.Status.OK, cmdResult.getStatus());
-
- command = "destroy region --name=/Customer-2";
- getLogWriter().info("testDestroyRegion command=" + command);
- cmdResult = executeCommand(command);
- strr = commandResultToString(cmdResult);
- assertTrue(stringContainsLine(strr, ".*Customer-2.*destroyed successfully.*"));
- getLogWriter().info("testDestroyRegion strr=" + strr);
- assertEquals(Result.Status.OK, cmdResult.getStatus());
-
- for (int i = 1; i <= 3; i++) {
- final int x = i;
- Host.getHost(0).getVM(i).invoke(() -> {
- assertNull("Region still exists in VM " + x, getCache().getRegion("Customer"));
- assertNull("Region still exists in VM " + x, getCache().getRegion("Customer-2"));
- assertNull("Region still exists in VM " + x, getCache().getRegion("Customer_3"));
- });
- }
- }
-
- @Test
- public void testDestroyRegionWithSharedConfig() {
- disconnectAllFromDS();
-
- final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
- jmxPort = ports[0];
- httpPort = ports[1];
- try {
- jmxHost = InetAddress.getLocalHost().getHostName();
- } catch (UnknownHostException ignore) {
- jmxHost = "localhost";
- }
-
-
- final String regionName = "testRegionSharedConfigRegion";
- final String regionPath = "/" + regionName;
- final String groupName = "testRegionSharedConfigGroup";
-
- // Start the Locator and wait for shared configuration to be available
- final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
-
- final Properties locatorProps = new Properties();
- locatorProps.setProperty(NAME, "Locator");
- locatorProps.setProperty(MCAST_PORT, "0");
- locatorProps.setProperty(LOG_LEVEL, "fine");
- locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
- 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(() -> {
- final File locatorLogFile = new File("locator-" + locatorPort + ".log");
- try {
- final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
- locatorLogFile, null, locatorProps);
-
- waitAtMost(5, TimeUnit.SECONDS).until(locator::isSharedConfigurationRunning);
- } catch (IOException ioex) {
- fail("Unable to create a locator with a shared configuration");
- }
- });
-
- connect(jmxHost, jmxPort, httpPort, getDefaultShell());
-
- // Create a cache in VM 1
- VM vm = Host.getHost(0).getVM(1);
- vm.invoke(() -> {
- Properties localProps = new Properties();
- localProps.setProperty(MCAST_PORT, "0");
- localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
- localProps.setProperty(GROUPS, groupName);
- getSystem(localProps);
- assertNotNull(getCache());
- });
-
- // Test creating the region
- CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_REGION);
- commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGION, regionName);
- commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, "REPLICATE");
- commandStringBuilder.addOption(CliStrings.CREATE_REGION__STATISTICSENABLED, "true");
- commandStringBuilder.addOption(CliStrings.GROUP, groupName);
- CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
- assertEquals(Result.Status.OK, cmdResult.getStatus());
-
- // Make sure that the region has been registered with the Manager MXBean
- waitForRegionMBeanCreation(regionPath, 1);
-
- // Make sure the region exists in the shared config
- Host.getHost(0).getVM(0).invoke(() -> {
- ClusterConfigurationService sharedConfig =
- ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
- try {
- assertTrue(
- sharedConfig.getConfiguration(groupName).getCacheXmlContent().contains(regionName));
- } catch (Exception e) {
- fail("Error occurred in cluster configuration service");
- }
- });
-
- // Test destroying the region
- commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_REGION);
- commandStringBuilder.addOption(CliStrings.DESTROY_REGION__REGION, regionName);
- cmdResult = executeCommand(commandStringBuilder.toString());
- getLogWriter().info("#SB" + commandResultToString(cmdResult));
- assertEquals(Result.Status.OK, cmdResult.getStatus());
-
- // Make sure the region was removed from the shared config
- Host.getHost(0).getVM(0).invoke(() -> {
- ClusterConfigurationService sharedConfig =
- ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
- try {
- assertFalse(
- sharedConfig.getConfiguration(groupName).getCacheXmlContent().contains(regionName));
- } catch (Exception e) {
- fail("Error occurred in cluster configuration service");
- }
- });
-
-
- // Restart the data vm to make sure the region is not existing any more
- vm = Host.getHost(0).getVM(1);
- vm.invoke(() -> {
- Cache cache = getCache();
- assertNotNull(cache);
- cache.close();
- assertTrue(cache.isClosed());
-
- Properties localProps = new Properties();
- localProps.setProperty(MCAST_PORT, "0");
- localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
- localProps.setProperty(GROUPS, groupName);
- localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
- getSystem(localProps);
- cache = getCache();
- assertNotNull(cache);
- Region region = cache.getRegion(regionName);
- assertNull(region);
-
- return null;
- });
- }
-
- private void waitForRegionMBeanCreation(final String regionPath, final int mbeanCount) {
- Host.getHost(0).getVM(0).invoke(() -> {
- waitAtMost(5, TimeUnit.SECONDS).until(newRegionMBeanIsCreated(regionPath, mbeanCount));
- });
- }
-
- private Callable<Boolean> newRegionMBeanIsCreated(final String regionPath, final int mbeanCount) {
- return () -> {
- try {
- MBeanServer mbeanServer = MBeanJMXAdapter.mbeanServer;
- String queryExp =
- MessageFormat.format(ManagementConstants.OBJECTNAME__REGION_MXBEAN, regionPath, "*");
- ObjectName queryExpON = new ObjectName(queryExp);
- return mbeanServer.queryNames(null, queryExpON).size() == mbeanCount;
- } catch (MalformedObjectNameException mone) {
- getLogWriter().error(mone);
- fail(mone.getMessage());
- return false;
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java
index 1002f5d..07cdb11 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java
@@ -36,23 +36,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import java.io.File;
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.StringTokenizer;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.TimeUnit;
-
import org.apache.commons.io.FileUtils;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.CacheFactory;
import org.apache.geode.cache.DataPolicy;
@@ -92,26 +76,28 @@ 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;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
/**
* The DiskStoreCommandsDUnitTest class is a distributed test suite of test cases for testing the
* disk store commands that are part of Gfsh.
* </p>
*
- * @see org.apache.geode.management.internal.cli.commands.AlterOfflineDiskStoreCommand
- * @see org.apache.geode.management.internal.cli.commands.BackupDiskStoreCommand
- * @see org.apache.geode.management.internal.cli.commands.CompactDiskStoreCommand
- * @see org.apache.geode.management.internal.cli.commands.CompactOfflineDiskStoreCommand
- * @see org.apache.geode.management.internal.cli.commands.CreateDiskStoreCommand
- * @see org.apache.geode.management.internal.cli.commands.DescribeDiskStoreCommand
- * @see org.apache.geode.management.internal.cli.commands.DescribeOfflineDiskStoreCommand
- * @see org.apache.geode.management.internal.cli.commands.DestroyDiskStoreCommand
- * @see org.apache.geode.management.internal.cli.commands.ExportOfflineDiskStoreCommand
- * @see ListDiskStoresCommand
- * @see org.apache.geode.management.internal.cli.commands.RevokeMissingDiskStoreCommand
- * @see org.apache.geode.management.internal.cli.commands.ShowMissingDiskStoreCommand
- * @see org.apache.geode.management.internal.cli.commands.UpgradeOfflineDiskStoreCommand
- * @see org.apache.geode.management.internal.cli.commands.ValidateDiskStoreCommand
+ * @see org.apache.geode.management.internal.cli.commands.DiskStoreCommands
* @see org.junit.Assert
* @see org.junit.Test
* @since GemFire 7.0
http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsJUnitTest.java
index f8cd657..1902656 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsJUnitTest.java
@@ -14,10 +14,7 @@
*/
package org.apache.geode.management.internal.cli.commands;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
+import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
@@ -52,11 +49,10 @@ import org.apache.geode.test.junit.categories.UnitTest;
/**
* The DiskStoreCommandsJUnitTest class is a test suite of test cases testing the contract and
- * functionality of the command classes relating to disk stores that implement commands in the
- * GemFire shell (gfsh) that access and modify disk stores in GemFire.
+ * functionality of the DiskStoreCommands class implementing commands in the GemFire shell (gfsh)
+ * that access and modify disk stores in GemFire.
*
- * @see org.apache.geode.management.internal.cli.commands.DescribeDiskStoreCommand
- * @see ListDiskStoresCommand
+ * @see org.apache.geode.management.internal.cli.commands.DiskStoreCommands
* @see org.apache.geode.management.internal.cli.domain.DiskStoreDetails
* @see org.apache.geode.management.internal.cli.functions.DescribeDiskStoreFunction
* @see org.apache.geode.management.internal.cli.functions.ListDiskStoresFunction
@@ -65,7 +61,6 @@ import org.apache.geode.test.junit.categories.UnitTest;
* @see org.jmock.lib.legacy.ClassImposteriser
* @see org.junit.Assert
* @see org.junit.Test
- *
* @since GemFire 7.0
*/
@Category(UnitTest.class)
@@ -89,14 +84,9 @@ public class DiskStoreCommandsJUnitTest {
mockContext = null;
}
- private DescribeDiskStoreCommand createDescribeDiskStoreCommand(final InternalCache cache,
- final DistributedMember distributedMember, final Execution functionExecutor) {
- return new TestDescribeDiskStoreCommand(cache, distributedMember, functionExecutor);
- }
-
- private ListDiskStoresCommand createListDiskStoreCommand(final InternalCache cache,
+ private DiskStoreCommands createDiskStoreCommands(final InternalCache cache,
final DistributedMember distributedMember, final Execution functionExecutor) {
- return new TestListDiskStoresCommand(cache, distributedMember, functionExecutor);
+ return new TestDiskStoreCommands(cache, distributedMember, functionExecutor);
}
private DiskStoreDetails createDiskStoreDetails(final String memberId,
@@ -133,15 +123,15 @@ public class DiskStoreCommandsJUnitTest {
oneOf(mockFunctionExecutor).execute(with(aNonNull(DescribeDiskStoreFunction.class)));
will(returnValue(mockResultCollector));
oneOf(mockResultCollector).getResult();
- will(returnValue(Collections.singletonList(expectedDiskStoredDetails)));
+ will(returnValue(Arrays.asList(expectedDiskStoredDetails)));
}
});
- final DescribeDiskStoreCommand describeCommand =
- createDescribeDiskStoreCommand(mockCache, mockMember, mockFunctionExecutor);
+ final DiskStoreCommands commands =
+ createDiskStoreCommands(mockCache, mockMember, mockFunctionExecutor);
final DiskStoreDetails actualDiskStoreDetails =
- describeCommand.getDiskStoreDescription(memberId, diskStoreName);
+ commands.getDiskStoreDescription(memberId, diskStoreName);
assertNotNull(actualDiskStoreDetails);
assertEquals(expectedDiskStoredDetails, actualDiskStoreDetails);
@@ -166,11 +156,10 @@ public class DiskStoreCommandsJUnitTest {
}
});
- final DescribeDiskStoreCommand describeCommand =
- createDescribeDiskStoreCommand(mockCache, mockMember, null);
+ final DiskStoreCommands commands = createDiskStoreCommands(mockCache, mockMember, null);
try {
- describeCommand.getDiskStoreDescription(memberId, diskStoreName);
+ commands.getDiskStoreDescription(memberId, diskStoreName);
} catch (MemberNotFoundException expected) {
assertEquals(CliStrings.format(CliStrings.MEMBER_NOT_FOUND_ERROR_MESSAGE, memberId),
expected.getMessage());
@@ -203,11 +192,11 @@ public class DiskStoreCommandsJUnitTest {
}
});
- final DescribeDiskStoreCommand describeCommand =
- createDescribeDiskStoreCommand(mockCache, mockMember, mockFunctionExecutor);
+ final DiskStoreCommands commands =
+ createDiskStoreCommands(mockCache, mockMember, mockFunctionExecutor);
try {
- describeCommand.getDiskStoreDescription(memberId, diskStoreName);
+ commands.getDiskStoreDescription(memberId, diskStoreName);
} catch (DiskStoreNotFoundException expected) {
assertEquals("expected", expected.getMessage());
throw expected;
@@ -239,11 +228,11 @@ public class DiskStoreCommandsJUnitTest {
}
});
- final DescribeDiskStoreCommand describeCommand =
- createDescribeDiskStoreCommand(mockCache, mockMember, mockFunctionExecutor);
+ final DiskStoreCommands commands =
+ createDiskStoreCommands(mockCache, mockMember, mockFunctionExecutor);
try {
- describeCommand.getDiskStoreDescription(memberId, diskStoreName);
+ commands.getDiskStoreDescription(memberId, diskStoreName);
} catch (RuntimeException expected) {
assertEquals("expected", expected.getMessage());
throw expected;
@@ -276,15 +265,15 @@ public class DiskStoreCommandsJUnitTest {
oneOf(mockFunctionExecutor).execute(with(aNonNull(DescribeDiskStoreFunction.class)));
will(returnValue(mockResultCollector));
oneOf(mockResultCollector).getResult();
- will(returnValue(Collections.singletonList(new Object())));
+ will(returnValue(Arrays.asList(new Object())));
}
});
- final DescribeDiskStoreCommand describeCommand =
- createDescribeDiskStoreCommand(mockCache, mockMember, mockFunctionExecutor);
+ final DiskStoreCommands commands =
+ createDiskStoreCommands(mockCache, mockMember, mockFunctionExecutor);
try {
- describeCommand.getDiskStoreDescription(memberId, diskStoreName);
+ commands.getDiskStoreDescription(memberId, diskStoreName);
} catch (RuntimeException expected) {
assertEquals(
CliStrings.format(CliStrings.UNEXPECTED_RETURN_TYPE_EXECUTING_COMMAND_ERROR_MESSAGE,
@@ -319,7 +308,7 @@ public class DiskStoreCommandsJUnitTest {
final List<DiskStoreDetails> expectedDiskStores =
Arrays.asList(diskStoreDetails1, diskStoreDetails2, diskStoreDetails3, diskStoreDetails4);
- final List<Set<DiskStoreDetails>> results = new ArrayList<>();
+ final List<Set<DiskStoreDetails>> results = new ArrayList<Set<DiskStoreDetails>>();
results.add(CollectionUtils.asSet(diskStoreDetails4, diskStoreDetails3));
results.add(CollectionUtils.asSet(diskStoreDetails1, diskStoreDetails2));
@@ -334,11 +323,11 @@ public class DiskStoreCommandsJUnitTest {
}
});
- final ListDiskStoresCommand listCommand =
- createListDiskStoreCommand(mockCache, mockDistributedMember, mockFunctionExecutor);
+ final DiskStoreCommands commands =
+ createDiskStoreCommands(mockCache, mockDistributedMember, mockFunctionExecutor);
final List<DiskStoreDetails> actualDiskStores =
- listCommand.getDiskStoreListing(Collections.singleton(mockDistributedMember));
+ commands.getDiskStoreListing(commands.getNormalMembers(mockCache));
Assert.assertNotNull(actualDiskStores);
assertEquals(expectedDiskStores, actualDiskStores);
@@ -360,11 +349,11 @@ public class DiskStoreCommandsJUnitTest {
}
});
- final ListDiskStoresCommand listCommand =
- createListDiskStoreCommand(mockCache, mockDistributedMember, mockFunctionExecutor);
+ final DiskStoreCommands commands =
+ createDiskStoreCommands(mockCache, mockDistributedMember, mockFunctionExecutor);
try {
- listCommand.getDiskStoreListing(Collections.singleton(mockDistributedMember));
+ commands.getDiskStoreListing(commands.getNormalMembers(mockCache));
} catch (RuntimeException expected) {
assertEquals("expected", expected.getMessage());
throw expected;
@@ -387,9 +376,9 @@ public class DiskStoreCommandsJUnitTest {
final DiskStoreDetails diskStoreDetails =
createDiskStoreDetails("memberOne", "cacheServerDiskStore");
- final List<DiskStoreDetails> expectedDiskStores = Collections.singletonList(diskStoreDetails);
+ final List<DiskStoreDetails> expectedDiskStores = Arrays.asList(diskStoreDetails);
- final List<Object> results = new ArrayList<>();
+ final List<Object> results = new ArrayList<Object>();
results.add(CollectionUtils.asSet(diskStoreDetails));
results.add(new FunctionInvocationTargetException("expected"));
@@ -404,23 +393,23 @@ public class DiskStoreCommandsJUnitTest {
}
});
- final ListDiskStoresCommand listCommand =
- createListDiskStoreCommand(mockCache, mockDistributedMember, mockFunctionExecutor);
+ final DiskStoreCommands commands =
+ createDiskStoreCommands(mockCache, mockDistributedMember, mockFunctionExecutor);
final List<DiskStoreDetails> actualDiskStores =
- listCommand.getDiskStoreListing(Collections.singleton(mockDistributedMember));
+ commands.getDiskStoreListing(commands.getNormalMembers(mockCache));
Assert.assertNotNull(actualDiskStores);
assertEquals(expectedDiskStores, actualDiskStores);
}
- private static class TestDescribeDiskStoreCommand extends DescribeDiskStoreCommand {
+ private static class TestDiskStoreCommands extends DiskStoreCommands {
private final InternalCache cache;
private final DistributedMember distributedMember;
private final Execution functionExecutor;
- TestDescribeDiskStoreCommand(final InternalCache cache,
+ public TestDiskStoreCommands(final InternalCache cache,
final DistributedMember distributedMember, final Execution functionExecutor) {
assert cache != null : "The Cache cannot be null!";
this.cache = cache;
@@ -444,37 +433,12 @@ public class DiskStoreCommandsJUnitTest {
Assert.assertNotNull(members);
return this.functionExecutor;
}
- }
-
- private static class TestListDiskStoresCommand extends ListDiskStoresCommand {
-
- private final InternalCache cache;
- private final DistributedMember distributedMember;
- private final Execution functionExecutor;
-
- TestListDiskStoresCommand(final InternalCache cache, final DistributedMember distributedMember,
- final Execution functionExecutor) {
- assert cache != null : "The Cache cannot be null!";
- this.cache = cache;
- this.distributedMember = distributedMember;
- this.functionExecutor = functionExecutor;
- }
@Override
- public InternalCache getCache() {
- return this.cache;
- }
-
- @Override
- public Set<DistributedMember> getMembers(final InternalCache cache) {
+ protected Set<DistributedMember> getNormalMembers(final InternalCache cache) {
assertSame(getCache(), cache);
return Collections.singleton(this.distributedMember);
}
-
- @Override
- public Execution getMembersFunctionExecutor(final Set<DistributedMember> members) {
- Assert.assertNotNull(members);
- return this.functionExecutor;
- }
}
+
}
http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java
index e3b6ad4..da60c7a 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/GfshCommandJUnitTest.java
@@ -14,6 +14,14 @@
*/
package org.apache.geode.management.internal.cli.commands;
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_BIND_ADDRESS;
+import static org.apache.geode.distributed.ConfigurationProperties.HTTP_SERVICE_PORT;
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.LOG_FILE;
+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.START_DEV_REST_API;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -27,6 +35,7 @@ import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Properties;
import java.util.Set;
import org.jmock.Expectations;
@@ -42,6 +51,7 @@ import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionService;
import org.apache.geode.distributed.DistributedMember;
import org.apache.geode.distributed.DistributedSystem;
+import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.lang.StringUtils;
import org.apache.geode.internal.util.CollectionUtils;
@@ -399,15 +409,216 @@ public class GfshCommandJUnitTest {
@Test
public void testAddGemFirePropertyFileToCommandLine() {
- StartMemberCommand startMemberCommand = new StartMemberCommand();
-
final List<String> commandLine = new ArrayList<>();
assertTrue(commandLine.isEmpty());
- startMemberCommand.addGemFirePropertyFile(commandLine, null);
+ StartMemberUtils.addGemFirePropertyFile(commandLine, null);
assertTrue(commandLine.isEmpty());
- startMemberCommand.addGemFirePropertyFile(commandLine, new File("/path/to/gemfire.properties"));
+ StartMemberUtils.addGemFirePropertyFile(commandLine, new File("/path/to/gemfire.properties"));
assertFalse(commandLine.isEmpty());
assertTrue(commandLine.contains("-DgemfirePropertyFile=/path/to/gemfire.properties"));
}
+ @Test
+ public void testAddGemFireSystemPropertiesToCommandLine() {
+ final List<String> commandLine = new ArrayList<>();
+ assertTrue(commandLine.isEmpty());
+ StartMemberUtils.addGemFireSystemProperties(commandLine, new Properties());
+ assertTrue(commandLine.isEmpty());
+
+ final Properties gemfireProperties = new Properties();
+ gemfireProperties.setProperty(LOCATORS, "localhost[11235]");
+ gemfireProperties.setProperty(LOG_LEVEL, "config");
+ gemfireProperties.setProperty(LOG_FILE, org.apache.commons.lang.StringUtils.EMPTY);
+ gemfireProperties.setProperty(MCAST_PORT, "0");
+ gemfireProperties.setProperty(NAME, "machine");
+ StartMemberUtils.addGemFireSystemProperties(commandLine, gemfireProperties);
+
+ assertFalse(commandLine.isEmpty());
+ assertEquals(4, commandLine.size());
+
+ for (final String propertyName : gemfireProperties.stringPropertyNames()) {
+ final String propertyValue = gemfireProperties.getProperty(propertyName);
+ if (org.apache.commons.lang.StringUtils.isBlank(propertyValue)) {
+ for (final String systemProperty : commandLine) {
+ assertFalse(systemProperty.startsWith(
+ "-D" + DistributionConfig.GEMFIRE_PREFIX + "".concat(propertyName).concat("=")));
+ }
+ } else {
+ assertTrue(commandLine.contains("-D" + DistributionConfig.GEMFIRE_PREFIX
+ + "".concat(propertyName).concat("=").concat(propertyValue)));
+ }
+ }
+ }
+
+ @Test
+ public void testAddGemFireSystemPropertiesToCommandLineWithRestAPI() {
+ final List<String> commandLine = new ArrayList<>();
+ assertTrue(commandLine.isEmpty());
+ StartMemberUtils.addGemFireSystemProperties(commandLine, new Properties());
+ assertTrue(commandLine.isEmpty());
+ final Properties gemfireProperties = new Properties();
+ gemfireProperties.setProperty(LOCATORS, "localhost[11235]");
+ gemfireProperties.setProperty(LOG_LEVEL, "config");
+ gemfireProperties.setProperty(LOG_FILE, StringUtils.EMPTY);
+ gemfireProperties.setProperty(MCAST_PORT, "0");
+ gemfireProperties.setProperty(NAME, "machine");
+ gemfireProperties.setProperty(START_DEV_REST_API, "true");
+ gemfireProperties.setProperty(HTTP_SERVICE_PORT, "8080");
+ gemfireProperties.setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost");
+
+ StartMemberUtils.addGemFireSystemProperties(commandLine, gemfireProperties);
+
+ assertFalse(commandLine.isEmpty());
+ assertEquals(7, commandLine.size());
+
+ for (final String propertyName : gemfireProperties.stringPropertyNames()) {
+ final String propertyValue = gemfireProperties.getProperty(propertyName);
+ if (StringUtils.isBlank(propertyValue)) {
+ for (final String systemProperty : commandLine) {
+ assertFalse(systemProperty.startsWith(
+ "-D" + DistributionConfig.GEMFIRE_PREFIX + "".concat(propertyName).concat("=")));
+ }
+ } else {
+ assertTrue(commandLine.contains("-D" + DistributionConfig.GEMFIRE_PREFIX
+ + "".concat(propertyName).concat("=").concat(propertyValue)));
+ }
+ }
+ }
+
+ @Test
+ public void testAddInitialHeapToCommandLine() {
+ final List<String> commandLine = new ArrayList<>();
+ assertTrue(commandLine.isEmpty());
+ StartMemberUtils.addInitialHeap(commandLine, null);
+ assertTrue(commandLine.isEmpty());
+ StartMemberUtils.addInitialHeap(commandLine, org.apache.commons.lang.StringUtils.EMPTY);
+ assertTrue(commandLine.isEmpty());
+ StartMemberUtils.addInitialHeap(commandLine, " ");
+ assertTrue(commandLine.isEmpty());
+ StartMemberUtils.addInitialHeap(commandLine, "512M");
+ assertFalse(commandLine.isEmpty());
+ assertEquals("-Xms512M", commandLine.get(0));
+ }
+
+ @Test
+ public void testAddJvmArgumentsAndOptionsToCommandLine() {
+ final List<String> commandLine = new ArrayList<>();
+ assertTrue(commandLine.isEmpty());
+ StartMemberUtils.addJvmArgumentsAndOptions(commandLine, null);
+ assertTrue(commandLine.isEmpty());
+ StartMemberUtils.addJvmArgumentsAndOptions(commandLine, new String[] {});
+ assertTrue(commandLine.isEmpty());
+ StartMemberUtils.addJvmArgumentsAndOptions(commandLine,
+ new String[] {"-DmyProp=myVal", "-d64", "-server", "-Xprof"});
+ assertFalse(commandLine.isEmpty());
+ assertEquals(4, commandLine.size());
+ assertEquals("-DmyProp=myVal", commandLine.get(0));
+ assertEquals("-d64", commandLine.get(1));
+ assertEquals("-server", commandLine.get(2));
+ assertEquals("-Xprof", commandLine.get(3));
+ }
+
+ @Test
+ public void testAddMaxHeapToCommandLine() {
+ final List<String> commandLine = new ArrayList<>();
+ assertTrue(commandLine.isEmpty());
+ StartMemberUtils.addMaxHeap(commandLine, null);
+ assertTrue(commandLine.isEmpty());
+ StartMemberUtils.addMaxHeap(commandLine, org.apache.commons.lang.StringUtils.EMPTY);
+ assertTrue(commandLine.isEmpty());
+ StartMemberUtils.addMaxHeap(commandLine, " ");
+ assertTrue(commandLine.isEmpty());
+ StartMemberUtils.addMaxHeap(commandLine, "1024M");
+ assertFalse(commandLine.isEmpty());
+ assertEquals(3, commandLine.size());
+ assertEquals("-Xmx1024M", commandLine.get(0));
+ assertEquals("-XX:+UseConcMarkSweepGC", commandLine.get(1));
+ assertEquals(
+ "-XX:CMSInitiatingOccupancyFraction=" + StartMemberUtils.CMS_INITIAL_OCCUPANCY_FRACTION,
+ commandLine.get(2));
+ }
+
+ @Test(expected = AssertionError.class)
+ public void testReadPidWithNull() {
+ try {
+ StartMemberUtils.readPid(null);
+ } catch (AssertionError expected) {
+ assertEquals("The file from which to read the process ID (pid) cannot be null!",
+ expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test
+ public void testReadPidWithNonExistingFile() {
+ assertEquals(StartMemberUtils.INVALID_PID,
+ StartMemberUtils.readPid(new File("/path/to/non_existing/pid.file")));
+ }
+
+ @Test
+ public void testGetSystemClasspath() {
+ assertEquals(System.getProperty("java.class.path"), StartMemberUtils.getSystemClasspath());
+ }
+
+ @Test
+ public void testToClasspath() {
+ final boolean EXCLUDE_SYSTEM_CLASSPATH = false;
+ final boolean INCLUDE_SYSTEM_CLASSPATH = true;
+ String[] jarFilePathnames =
+ {"/path/to/user/libs/A.jar", "/path/to/user/libs/B.jar", "/path/to/user/libs/C.jar"};
+ String[] userClasspaths = {"/path/to/classes:/path/to/libs/1.jar:/path/to/libs/2.jar",
+ "/path/to/ext/libs/1.jar:/path/to/ext/classes:/path/to/ext/lib/10.jar"};
+ String expectedClasspath = StartMemberUtils.GEODE_JAR_PATHNAME.concat(File.pathSeparator)
+ .concat(toClasspath(userClasspaths)).concat(File.pathSeparator)
+ .concat(toClasspath(jarFilePathnames));
+ assertEquals(expectedClasspath,
+ StartMemberUtils.toClasspath(EXCLUDE_SYSTEM_CLASSPATH, jarFilePathnames, userClasspaths));
+ expectedClasspath = StartMemberUtils.GEODE_JAR_PATHNAME.concat(File.pathSeparator)
+ .concat(toClasspath(userClasspaths)).concat(File.pathSeparator)
+ .concat(System.getProperty("java.class.path")).concat(File.pathSeparator)
+ .concat(toClasspath(jarFilePathnames));
+ assertEquals(expectedClasspath,
+ StartMemberUtils.toClasspath(INCLUDE_SYSTEM_CLASSPATH, jarFilePathnames, userClasspaths));
+ expectedClasspath = StartMemberUtils.GEODE_JAR_PATHNAME.concat(File.pathSeparator)
+ .concat(System.getProperty("java.class.path"));
+ assertEquals(expectedClasspath,
+ StartMemberUtils.toClasspath(INCLUDE_SYSTEM_CLASSPATH, null, (String[]) null));
+ assertEquals(StartMemberUtils.GEODE_JAR_PATHNAME,
+ StartMemberUtils.toClasspath(EXCLUDE_SYSTEM_CLASSPATH, null, (String[]) null));
+ assertEquals(StartMemberUtils.GEODE_JAR_PATHNAME,
+ StartMemberUtils.toClasspath(EXCLUDE_SYSTEM_CLASSPATH, new String[0], ""));
+ }
+
+ @Test
+ public void testToClassPathOrder() {
+ String userClasspathOne = "/path/to/user/lib/a.jar:/path/to/user/classes";
+ String userClasspathTwo =
+ "/path/to/user/lib/x.jar:/path/to/user/lib/y.jar:/path/to/user/lib/z.jar";
+
+ String expectedClasspath = StartMemberUtils.getGemFireJarPath().concat(File.pathSeparator)
+ .concat(userClasspathOne).concat(File.pathSeparator).concat(userClasspathTwo)
+ .concat(File.pathSeparator).concat(System.getProperty("java.class.path"))
+ .concat(File.pathSeparator).concat(StartMemberUtils.CORE_DEPENDENCIES_JAR_PATHNAME)
+ .concat(File.pathSeparator).concat(StartMemberUtils.CORE_DEPENDENCIES_JAR_PATHNAME);
+
+ String actualClasspath =
+ StartMemberUtils.toClasspath(true,
+ new String[] {StartMemberUtils.CORE_DEPENDENCIES_JAR_PATHNAME,
+ StartMemberUtils.CORE_DEPENDENCIES_JAR_PATHNAME},
+ userClasspathOne, userClasspathTwo);
+
+ assertEquals(expectedClasspath, actualClasspath);
+ }
+
+ private String toClasspath(final String... jarFilePathnames) {
+ String classpath = org.apache.commons.lang.StringUtils.EMPTY;
+ if (jarFilePathnames != null) {
+ for (final String jarFilePathname : jarFilePathnames) {
+ classpath +=
+ (classpath.isEmpty() ? org.apache.commons.lang.StringUtils.EMPTY : File.pathSeparator);
+ classpath += jarFilePathname;
+ }
+ }
+ return classpath;
+ }
}
http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsJUnitTest.java
new file mode 100644
index 0000000..0d1f340
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/IndexCommandsJUnitTest.java
@@ -0,0 +1,223 @@
+/*
+ * 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.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.lib.concurrent.Synchroniser;
+import org.jmock.lib.legacy.ClassImposteriser;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.execute.Execution;
+import org.apache.geode.cache.execute.FunctionInvocationTargetException;
+import org.apache.geode.cache.execute.ResultCollector;
+import org.apache.geode.distributed.DistributedMember;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.execute.AbstractExecution;
+import org.apache.geode.internal.util.CollectionUtils;
+import org.apache.geode.management.internal.cli.domain.IndexDetails;
+import org.apache.geode.management.internal.cli.functions.ListIndexFunction;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+/**
+ * The IndexCommandsJUnitTest class is a test suite of test cases testing the contract and
+ * functionality of the IndexCommands class.
+ * </p>
+ *
+ * @see org.apache.geode.management.internal.cli.commands.IndexCommands
+ * @see org.apache.geode.management.internal.cli.domain.IndexDetails
+ * @see org.apache.geode.management.internal.cli.functions.ListIndexFunction
+ * @see org.jmock.Expectations
+ * @see org.jmock.Mockery
+ * @see org.jmock.lib.legacy.ClassImposteriser
+ * @see org.junit.Assert
+ * @see org.junit.Test
+ * @since GemFire 7.0
+ */
+@Category(UnitTest.class)
+public class IndexCommandsJUnitTest {
+
+ private Mockery mockContext;
+
+ @Before
+ public void setup() {
+ mockContext = new Mockery() {
+ {
+ setImposteriser(ClassImposteriser.INSTANCE);
+ setThreadingPolicy(new Synchroniser());
+ }
+ };
+ }
+
+ @After
+ public void tearDown() {
+ mockContext.assertIsSatisfied();
+ mockContext = null;
+ }
+
+ private IndexCommands createIndexCommands(final InternalCache cache,
+ final Execution functionExecutor) {
+ return new TestIndexCommands(cache, functionExecutor);
+ }
+
+ private IndexDetails createIndexDetails(final String memberId, final String regionPath,
+ final String indexName) {
+ return new IndexDetails(memberId, regionPath, indexName);
+ }
+
+ @Test
+ public void testGetIndexListing() {
+ final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
+
+ final AbstractExecution mockFunctionExecutor =
+ mockContext.mock(AbstractExecution.class, "Function Executor");
+
+ final ResultCollector mockResultCollector =
+ mockContext.mock(ResultCollector.class, "ResultCollector");
+
+ final IndexDetails indexDetails1 = createIndexDetails("memberOne", "/Employees", "empIdIdx");
+ final IndexDetails indexDetails2 =
+ createIndexDetails("memberOne", "/Employees", "empLastNameIdx");
+ final IndexDetails indexDetails3 = createIndexDetails("memberTwo", "/Employees", "empDobIdx");
+
+ final List<IndexDetails> expectedIndexDetails =
+ Arrays.asList(indexDetails1, indexDetails2, indexDetails3);
+
+ final List<Set<IndexDetails>> results = new ArrayList<Set<IndexDetails>>(2);
+
+ results.add(CollectionUtils.asSet(indexDetails2, indexDetails1));
+ results.add(CollectionUtils.asSet(indexDetails3));
+
+ mockContext.checking(new Expectations() {
+ {
+ oneOf(mockFunctionExecutor).setIgnoreDepartedMembers(with(equal(true)));
+ oneOf(mockFunctionExecutor).execute(with(aNonNull(ListIndexFunction.class)));
+ will(returnValue(mockResultCollector));
+ oneOf(mockResultCollector).getResult();
+ will(returnValue(results));
+ }
+ });
+
+ final IndexCommands commands = createIndexCommands(mockCache, mockFunctionExecutor);
+
+ final List<IndexDetails> actualIndexDetails = commands.getIndexListing();
+
+ assertNotNull(actualIndexDetails);
+ assertEquals(expectedIndexDetails, actualIndexDetails);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void testGetIndexListingThrowsRuntimeException() {
+ final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
+
+ final Execution mockFunctionExecutor = mockContext.mock(Execution.class, "Function Executor");
+
+ mockContext.checking(new Expectations() {
+ {
+ oneOf(mockFunctionExecutor).execute(with(aNonNull(ListIndexFunction.class)));
+ will(throwException(new RuntimeException("expected")));
+ }
+ });
+
+ final IndexCommands commands = createIndexCommands(mockCache, mockFunctionExecutor);
+
+ try {
+ commands.getIndexListing();
+ } catch (RuntimeException expected) {
+ assertEquals("expected", expected.getMessage());
+ throw expected;
+ }
+ }
+
+ @Test
+ public void testGetIndexListingReturnsFunctionInvocationTargetExceptionInResults() {
+ final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
+
+ final AbstractExecution mockFunctionExecutor =
+ mockContext.mock(AbstractExecution.class, "Function Executor");
+
+ final ResultCollector mockResultCollector =
+ mockContext.mock(ResultCollector.class, "ResultCollector");
+
+ final IndexDetails indexDetails = createIndexDetails("memberOne", "/Employees", "empIdIdx");
+
+ final List<IndexDetails> expectedIndexDetails = Arrays.asList(indexDetails);
+
+ final List<Object> results = new ArrayList<Object>(2);
+
+ results.add(CollectionUtils.asSet(indexDetails));
+ results.add(new FunctionInvocationTargetException("expected"));
+
+ mockContext.checking(new Expectations() {
+ {
+ oneOf(mockFunctionExecutor).setIgnoreDepartedMembers(with(equal(true)));
+ oneOf(mockFunctionExecutor).execute(with(aNonNull(ListIndexFunction.class)));
+ will(returnValue(mockResultCollector));
+ oneOf(mockResultCollector).getResult();
+ will(returnValue(results));
+ }
+ });
+
+ final IndexCommands commands = createIndexCommands(mockCache, mockFunctionExecutor);
+
+ final List<IndexDetails> actualIndexDetails = commands.getIndexListing();
+
+ assertNotNull(actualIndexDetails);
+ assertEquals(expectedIndexDetails, actualIndexDetails);
+ }
+
+ private static class TestIndexCommands extends IndexCommands {
+
+ private final InternalCache cache;
+ private final Execution functionExecutor;
+
+ protected TestIndexCommands(final InternalCache cache, final Execution functionExecutor) {
+ assert cache != null : "The InternalCache cannot be null!";
+ assert functionExecutor != null : "The function executor cannot be null!";
+ this.cache = cache;
+ this.functionExecutor = functionExecutor;
+ }
+
+ @Override
+ public InternalCache getCache() {
+ return this.cache;
+ }
+
+ @Override
+ public Set<DistributedMember> getMembers(final InternalCache cache) {
+ assertSame(getCache(), cache);
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Execution getMembersFunctionExecutor(final Set<DistributedMember> members) {
+ Assert.assertNotNull(members);
+ return functionExecutor;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListAndDescribeDiskStoreCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListAndDescribeDiskStoreCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListAndDescribeDiskStoreCommandsDUnitTest.java
index 1fe0bd1..8d4be8b 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListAndDescribeDiskStoreCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListAndDescribeDiskStoreCommandsDUnitTest.java
@@ -14,25 +14,7 @@
*/
package org.apache.geode.management.internal.cli.commands;
-import static org.apache.geode.distributed.ConfigurationProperties.NAME;
-import static org.apache.geode.test.dunit.Assert.assertEquals;
-import static org.apache.geode.test.dunit.Assert.assertNotNull;
-import static org.apache.geode.test.dunit.Host.getHost;
-import static org.apache.geode.test.dunit.LogWriterUtils.getDUnitLogLevel;
-import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
-
-import java.io.Serializable;
-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.DataPolicy;
-import org.apache.geode.cache.DiskStore;
-import org.apache.geode.cache.DiskStoreFactory;
-import org.apache.geode.cache.RegionFactory;
-import org.apache.geode.cache.Scope;
+import org.apache.geode.cache.*;
import org.apache.geode.distributed.ConfigurationProperties;
import org.apache.geode.management.cli.Result;
import org.apache.geode.management.internal.cli.i18n.CliStrings;
@@ -40,6 +22,18 @@ import org.apache.geode.test.dunit.SerializableRunnable;
import org.apache.geode.test.dunit.SerializableRunnableIF;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.junit.categories.DistributedTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.Serializable;
+import java.util.Properties;
+
+import static org.apache.geode.test.dunit.Assert.assertEquals;
+import static org.apache.geode.test.dunit.Assert.assertNotNull;
+import static org.apache.geode.test.dunit.Host.getHost;
+import static org.apache.geode.test.dunit.LogWriterUtils.getDUnitLogLevel;
+import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
+import static org.apache.geode.distributed.ConfigurationProperties.*;
/**
* The ListAndDescribeDiskStoreCommandsDUnitTest class is a test suite of functional tests cases
@@ -47,9 +41,7 @@ import org.apache.geode.test.junit.categories.DistributedTest;
* </p>
*
* @see org.apache.geode.management.internal.cli.commands.CliCommandTestBase
- * @see ListDiskStoresCommand
- * @see org.apache.geode.management.internal.cli.commands.DescribeDiskStoreCommand
- *
+ * @see org.apache.geode.management.internal.cli.commands.DiskStoreCommands
* @since GemFire 7.0
*/
@Category(DistributedTest.class)
http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandDUnitTest.java
index 6dc23ce..5ff0a67 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandDUnitTest.java
@@ -23,22 +23,7 @@ import static org.apache.geode.test.dunit.Assert.assertTrue;
import static org.apache.geode.test.dunit.LogWriterUtils.getDUnitLogLevel;
import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-import java.util.Random;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicLong;
-
import org.apache.commons.lang.StringUtils;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
import org.apache.geode.cache.Cache;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.Region;
@@ -58,18 +43,27 @@ import org.apache.geode.test.dunit.SerializableRunnable;
import org.apache.geode.test.dunit.SerializableRunnableIF;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.junit.categories.DistributedTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.Random;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
/**
* The ListIndexCommandDUnitTest class is distributed test suite of test cases for testing the
* index-based GemFire shell (Gfsh) commands.
*
* @see org.apache.geode.management.internal.cli.commands.CliCommandTestBase
- * @see org.apache.geode.management.internal.cli.commands.ClearDefinedIndexesCommand
- * @see org.apache.geode.management.internal.cli.commands.CreateDefinedIndexesCommand
- * @see org.apache.geode.management.internal.cli.commands.CreateIndexCommand
- * @see org.apache.geode.management.internal.cli.commands.DefineIndexCommand
- * @see org.apache.geode.management.internal.cli.commands.DestroyIndexCommand
- * @see org.apache.geode.management.internal.cli.commands.ListIndexCommand
+ * @see org.apache.geode.management.internal.cli.commands.IndexCommands
* @since GemFire 7.0
*/
@SuppressWarnings("unused")
@@ -696,7 +690,7 @@ public class ListIndexCommandDUnitTest extends CliCommandTestBase {
}
}
- private enum CrudOperation {
+ private static enum CrudOperation {
CREATE, RETRIEVE, UPDATE, DELETE
}
}
http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandJUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandJUnitTest.java
deleted file mode 100644
index 8deb4ae..0000000
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListIndexCommandJUnitTest.java
+++ /dev/null
@@ -1,223 +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.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.lib.concurrent.Synchroniser;
-import org.jmock.lib.legacy.ClassImposteriser;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.cache.execute.Execution;
-import org.apache.geode.cache.execute.FunctionInvocationTargetException;
-import org.apache.geode.cache.execute.ResultCollector;
-import org.apache.geode.distributed.DistributedMember;
-import org.apache.geode.internal.cache.InternalCache;
-import org.apache.geode.internal.cache.execute.AbstractExecution;
-import org.apache.geode.internal.util.CollectionUtils;
-import org.apache.geode.management.internal.cli.domain.IndexDetails;
-import org.apache.geode.management.internal.cli.functions.ListIndexFunction;
-import org.apache.geode.test.junit.categories.UnitTest;
-
-/**
- * The ListIndexCommandJUnitTest class is a test suite of test cases testing the contract and
- * functionality of the ListIndexCommand class.
- * </p>
- *
- * @see org.apache.geode.management.internal.cli.commands.ClearDefinedIndexesCommand
- * @see org.apache.geode.management.internal.cli.commands.CreateDefinedIndexesCommand
- * @see org.apache.geode.management.internal.cli.commands.CreateIndexCommand
- * @see org.apache.geode.management.internal.cli.commands.DefineIndexCommand
- * @see org.apache.geode.management.internal.cli.commands.DestroyIndexCommand
- * @see org.apache.geode.management.internal.cli.commands.ListIndexCommand
- * @see org.apache.geode.management.internal.cli.domain.IndexDetails
- * @see org.apache.geode.management.internal.cli.functions.ListIndexFunction
- * @see org.jmock.Expectations
- * @see org.jmock.Mockery
- * @see org.jmock.lib.legacy.ClassImposteriser
- * @see org.junit.Assert
- * @see org.junit.Test
- * @since GemFire 7.0
- */
-@Category(UnitTest.class)
-public class ListIndexCommandJUnitTest {
- private Mockery mockContext;
-
- @Before
- public void setup() {
- mockContext = new Mockery() {
- {
- setImposteriser(ClassImposteriser.INSTANCE);
- setThreadingPolicy(new Synchroniser());
- }
- };
- }
-
- @After
- public void tearDown() {
- mockContext.assertIsSatisfied();
- mockContext = null;
- }
-
- private ListIndexCommand createListIndexCommand(final InternalCache cache,
- final Execution functionExecutor) {
- return new TestListIndexCommands(cache, functionExecutor);
- }
-
- private IndexDetails createIndexDetails(final String memberId, final String indexName) {
- return new IndexDetails(memberId, "/Employees", indexName);
- }
-
- @Test
- public void testGetIndexListing() {
- final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
-
- final AbstractExecution mockFunctionExecutor =
- mockContext.mock(AbstractExecution.class, "Function Executor");
-
- final ResultCollector mockResultCollector =
- mockContext.mock(ResultCollector.class, "ResultCollector");
-
- final IndexDetails indexDetails1 = createIndexDetails("memberOne", "empIdIdx");
- final IndexDetails indexDetails2 = createIndexDetails("memberOne", "empLastNameIdx");
- final IndexDetails indexDetails3 = createIndexDetails("memberTwo", "empDobIdx");
-
- final List<IndexDetails> expectedIndexDetails =
- Arrays.asList(indexDetails1, indexDetails2, indexDetails3);
-
- final List<Set<IndexDetails>> results = new ArrayList<Set<IndexDetails>>(2);
-
- results.add(CollectionUtils.asSet(indexDetails2, indexDetails1));
- results.add(CollectionUtils.asSet(indexDetails3));
-
- mockContext.checking(new Expectations() {
- {
- oneOf(mockFunctionExecutor).setIgnoreDepartedMembers(with(equal(true)));
- oneOf(mockFunctionExecutor).execute(with(aNonNull(ListIndexFunction.class)));
- will(returnValue(mockResultCollector));
- oneOf(mockResultCollector).getResult();
- will(returnValue(results));
- }
- });
-
- final ListIndexCommand commands = createListIndexCommand(mockCache, mockFunctionExecutor);
- final List<IndexDetails> actualIndexDetails = commands.getIndexListing();
-
- assertNotNull(actualIndexDetails);
- assertEquals(expectedIndexDetails, actualIndexDetails);
- }
-
- @Test(expected = RuntimeException.class)
- public void testGetIndexListingThrowsRuntimeException() {
- final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
- final Execution mockFunctionExecutor = mockContext.mock(Execution.class, "Function Executor");
-
- mockContext.checking(new Expectations() {
- {
- oneOf(mockFunctionExecutor).execute(with(aNonNull(ListIndexFunction.class)));
- will(throwException(new RuntimeException("expected")));
- }
- });
-
- final ListIndexCommand commands = createListIndexCommand(mockCache, mockFunctionExecutor);
-
- try {
- commands.getIndexListing();
- } catch (RuntimeException expected) {
- assertEquals("expected", expected.getMessage());
- throw expected;
- }
- }
-
- @Test
- public void testGetIndexListingReturnsFunctionInvocationTargetExceptionInResults() {
- final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
-
- final AbstractExecution mockFunctionExecutor =
- mockContext.mock(AbstractExecution.class, "Function Executor");
-
- final ResultCollector mockResultCollector =
- mockContext.mock(ResultCollector.class, "ResultCollector");
-
- final IndexDetails indexDetails = createIndexDetails("memberOne", "empIdIdx");
-
- final List<IndexDetails> expectedIndexDetails = Collections.singletonList(indexDetails);
-
- final List<Object> results = new ArrayList<Object>(2);
-
- results.add(CollectionUtils.asSet(indexDetails));
- results.add(new FunctionInvocationTargetException("expected"));
-
- mockContext.checking(new Expectations() {
- {
- oneOf(mockFunctionExecutor).setIgnoreDepartedMembers(with(equal(true)));
- oneOf(mockFunctionExecutor).execute(with(aNonNull(ListIndexFunction.class)));
- will(returnValue(mockResultCollector));
- oneOf(mockResultCollector).getResult();
- will(returnValue(results));
- }
- });
-
- final ListIndexCommand commands = createListIndexCommand(mockCache, mockFunctionExecutor);
-
- final List<IndexDetails> actualIndexDetails = commands.getIndexListing();
-
- assertNotNull(actualIndexDetails);
- assertEquals(expectedIndexDetails, actualIndexDetails);
- }
-
- private static class TestListIndexCommands extends ListIndexCommand {
- private final InternalCache cache;
- private final Execution functionExecutor;
-
- TestListIndexCommands(final InternalCache cache, final Execution functionExecutor) {
- assert cache != null : "The InternalCache cannot be null!";
- assert functionExecutor != null : "The function executor cannot be null!";
- this.cache = cache;
- this.functionExecutor = functionExecutor;
- }
-
- @Override
- public InternalCache getCache() {
- return this.cache;
- }
-
- @Override
- public Set<DistributedMember> getMembers(final InternalCache cache) {
- assertSame(getCache(), cache);
- return Collections.emptySet();
- }
-
- @Override
- public Execution getMembersFunctionExecutor(final Set<DistributedMember> members) {
- Assert.assertNotNull(members);
- return functionExecutor;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/LogLevelInterceptorTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/LogLevelInterceptorTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/LogLevelInterceptorTest.java
index 9188582..bcbe07c 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/LogLevelInterceptorTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/LogLevelInterceptorTest.java
@@ -18,20 +18,19 @@ package org.apache.geode.management.internal.cli.commands;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
+import org.apache.geode.management.cli.Result;
+import org.apache.geode.management.internal.cli.AbstractCliAroundInterceptor;
+import org.apache.geode.management.internal.cli.GfshParseResult;
+import org.apache.geode.test.junit.categories.UnitTest;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.mockito.Mockito;
-import org.apache.geode.management.cli.Result;
-import org.apache.geode.management.internal.cli.AbstractCliAroundInterceptor;
-import org.apache.geode.management.internal.cli.GfshParseResult;
-import org.apache.geode.test.junit.categories.UnitTest;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
@Category(UnitTest.class)
public class LogLevelInterceptorTest {
@@ -43,8 +42,8 @@ public class LogLevelInterceptorTest {
@Before
public void before() {
interceptors.add(new ExportLogsInterceptor());
- interceptors.add(new AlterRuntimeInterceptor());
- interceptors.add(new ChangeLogLevelCommand.ChangeLogLevelCommandInterceptor());
+ interceptors.add(new ConfigCommands.AlterRuntimeInterceptor());
+ interceptors.add(new MiscellaneousCommands.ChangeLogLevelInterceptor());
parseResult = Mockito.mock(GfshParseResult.class);
arguments = new HashMap<>();
http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommandsDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommandsDUnitTest.java
index 674a0b6..f0c2c2f 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommandsDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommandsDUnitTest.java
@@ -14,34 +14,9 @@
*/
package org.apache.geode.management.internal.cli.commands;
-import static org.apache.geode.distributed.ConfigurationProperties.GROUPS;
-import static org.apache.geode.distributed.ConfigurationProperties.LOG_FILE;
-import static org.apache.geode.distributed.ConfigurationProperties.LOG_LEVEL;
-import static org.apache.geode.distributed.ConfigurationProperties.NAME;
-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.IgnoredException.addIgnoredException;
-import static org.apache.geode.test.dunit.Invoke.invokeInEveryVM;
-import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
-import static org.apache.geode.test.dunit.Wait.waitForCriterion;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Properties;
+import static org.apache.geode.distributed.ConfigurationProperties.*;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheClosedException;
-import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.RegionFactory;
-import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.cache.*;
import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.internal.lang.ThreadUtils;
@@ -49,22 +24,27 @@ import org.apache.geode.management.cli.Result;
import org.apache.geode.management.cli.Result.Status;
import org.apache.geode.management.internal.cli.HeadlessGfsh;
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.result.CompositeResultData;
+import org.apache.geode.management.internal.cli.result.*;
import org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData;
-import org.apache.geode.management.internal.cli.result.ResultBuilder;
-import org.apache.geode.management.internal.cli.result.ResultData;
-import org.apache.geode.management.internal.cli.result.TabularResultData;
-import org.apache.geode.test.dunit.Host;
-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.dunit.*;
import org.apache.geode.test.junit.categories.DistributedTest;
import org.apache.geode.test.junit.categories.FlakyTest;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+
+import static org.apache.geode.test.dunit.Assert.*;
+import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
+import static org.apache.geode.test.dunit.Invoke.invokeInEveryVM;
+import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
+import static org.apache.geode.test.dunit.Wait.waitForCriterion;
/**
- * DUnit class for testing gemfire function commands : GC, Shutdown
+ * Dunit class for testing gemfire function commands : GC, Shutdown
*/
@Category(DistributedTest.class)
public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase {
@@ -95,15 +75,20 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase {
String command = "gc --group=Group1";
CommandResult cmdResult = executeCommand(command);
cmdResult.resetToFirstLine();
- String cmdResultStr = commandResultToString(cmdResult);
- getLogWriter().info("testGCForGroup cmdResultStr=" + cmdResultStr + "; cmdResult=" + cmdResult);
- assertEquals(Status.OK, cmdResult.getStatus());
- if (cmdResult.getType().equals(ResultData.TYPE_TABULAR)) {
- TabularResultData table = (TabularResultData) cmdResult.getResultData();
- List<String> memberNames = table.retrieveAllValues(CliStrings.GC__MSG__MEMBER_NAME);
- assertEquals(true, memberNames.size() == 1);
+ if (cmdResult != null) {
+ String cmdResultStr = commandResultToString(cmdResult);
+ getLogWriter()
+ .info("testGCForGroup cmdResultStr=" + cmdResultStr + "; cmdResult=" + cmdResult);
+ assertEquals(Result.Status.OK, cmdResult.getStatus());
+ if (cmdResult.getType().equals(ResultData.TYPE_TABULAR)) {
+ TabularResultData table = (TabularResultData) cmdResult.getResultData();
+ List<String> memberNames = table.retrieveAllValues(CliStrings.GC__MSG__MEMBER_NAME);
+ assertEquals(true, memberNames.size() == 1);
+ } else {
+ fail("testGCForGroup failed as CommandResult should be table type");
+ }
} else {
- fail("testGCForGroup failed as CommandResult should be table type");
+ fail("testGCForGroup failed as did not get CommandResult");
}
}
@@ -116,19 +101,23 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase {
public void testGCForMemberID() {
setUpJmxManagerOnVm0ThenConnect(null);
final VM vm1 = Host.getHost(0).getVM(1);
- final String vm1MemberId = vm1.invoke(this::getMemberId);
+ final String vm1MemberId = vm1.invoke(() -> getMemberId());
String command = "gc --member=" + vm1MemberId;
CommandResult cmdResult = executeCommand(command);
cmdResult.resetToFirstLine();
- String cmdResultStr = commandResultToString(cmdResult);
- getLogWriter().info("testGCForMemberID cmdResultStr=" + cmdResultStr);
- assertEquals(Status.OK, cmdResult.getStatus());
- if (cmdResult.getType().equals(ResultData.TYPE_TABULAR)) {
- TabularResultData table = (TabularResultData) cmdResult.getResultData();
- List<String> memberNames = table.retrieveAllValues(CliStrings.GC__MSG__MEMBER_NAME);
- assertEquals(true, memberNames.size() == 1);
+ if (cmdResult != null) {
+ String cmdResultStr = commandResultToString(cmdResult);
+ getLogWriter().info("testGCForMemberID cmdResultStr=" + cmdResultStr);
+ assertEquals(Result.Status.OK, cmdResult.getStatus());
+ if (cmdResult.getType().equals(ResultData.TYPE_TABULAR)) {
+ TabularResultData table = (TabularResultData) cmdResult.getResultData();
+ List<String> memberNames = table.retrieveAllValues(CliStrings.GC__MSG__MEMBER_NAME);
+ assertEquals(true, memberNames.size() == 1);
+ } else {
+ fail("testGCForGroup failed as CommandResult should be table type");
+ }
} else {
- fail("testGCForGroup failed as CommandResult should be table type");
+ fail("testGCForCluster failed as did not get CommandResult");
}
}
@@ -139,7 +128,7 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase {
props.setProperty(LOG_FILE, "testShowLogDefault.log");
setUpJmxManagerOnVm0ThenConnect(props);
final VM vm1 = Host.getHost(0).getVM(0);
- final String vm1MemberId = vm1.invoke(this::getMemberId);
+ final String vm1MemberId = vm1.invoke(() -> getMemberId());
String command = "show log --member=" + vm1MemberId;
CommandResult cmdResult = executeCommand(command);
if (cmdResult != null) {
@@ -163,7 +152,7 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase {
try {
setUpJmxManagerOnVm0ThenConnect(props);
final VM vm1 = Host.getHost(0).getVM(0);
- final String vm1MemberId = vm1.invoke(this::getMemberId);
+ final String vm1MemberId = vm1.invoke(() -> getMemberId());
String command = "show log --member=" + vm1MemberId + " --lines=50";
CommandResult cmdResult = executeCommand(command);
if (cmdResult != null) {
@@ -185,20 +174,24 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase {
String command = "gc";
CommandResult cmdResult = executeCommand(command);
cmdResult.resetToFirstLine();
- String cmdResultStr = commandResultToString(cmdResult);
- getLogWriter()
- .info("testGCForEntireCluster cmdResultStr=" + cmdResultStr + "; cmdResult=" + cmdResult);
- assertEquals(Status.OK, cmdResult.getStatus());
- if (cmdResult.getType().equals(ResultData.TYPE_TABULAR)) {
- TabularResultData table = (TabularResultData) cmdResult.getResultData();
- List<String> memberNames = table.retrieveAllValues(CliStrings.GC__MSG__MEMBER_NAME);
- assertEquals(3, memberNames.size());
+ if (cmdResult != null) {
+ String cmdResultStr = commandResultToString(cmdResult);
+ getLogWriter()
+ .info("testGCForEntireCluster cmdResultStr=" + cmdResultStr + "; cmdResult=" + cmdResult);
+ assertEquals(Result.Status.OK, cmdResult.getStatus());
+ if (cmdResult.getType().equals(ResultData.TYPE_TABULAR)) {
+ TabularResultData table = (TabularResultData) cmdResult.getResultData();
+ List<String> memberNames = table.retrieveAllValues(CliStrings.GC__MSG__MEMBER_NAME);
+ assertEquals(3, memberNames.size());
+ } else {
+ fail("testGCForGroup failed as CommandResult should be table type");
+ }
} else {
- fail("testGCForGroup failed as CommandResult should be table type");
+ fail("testGCForGroup failed as did not get CommandResult");
}
}
- private void setupForGC() {
+ void setupForGC() {
disconnectAllFromDS();
final VM vm1 = Host.getHost(0).getVM(1);
@@ -314,6 +307,7 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase {
}
});
+
String command = "shutdown --time-out=15";
CommandResult cmdResult = executeCommand(command);
@@ -332,7 +326,7 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase {
});
}
- private void setupForChangeLogLevel() {
+ void setupForChangeLogLelvel() {
final VM vm0 = Host.getHost(0).getVM(0);
final VM vm1 = Host.getHost(0).getVM(1);
@@ -352,7 +346,7 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase {
});
}
- private void setupForShutDown() {
+ void setupForShutDown() {
final VM vm0 = Host.getHost(0).getVM(0);
final VM vm1 = Host.getHost(0).getVM(1);
@@ -373,7 +367,7 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase {
});
}
- private void verifyShutDown() {
+ void verifyShutDown() {
final VM vm0 = Host.getHost(0).getVM(0);
final VM vm1 = Host.getHost(0).getVM(1);
@@ -416,7 +410,7 @@ public class MiscellaneousCommandsDUnitTest extends CliCommandTestBase {
final VM vm0 = Host.getHost(0).getVM(0);
final VM vm1 = Host.getHost(0).getVM(1);
- setupForChangeLogLevel();
+ setupForChangeLogLelvel();
String serverName1 = (String) vm0.invoke(new SerializableCallable() {
@Override
http://git-wip-us.apache.org/repos/asf/geode/blob/645a32d0/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ShowStackTraceDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ShowStackTraceDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ShowStackTraceDUnitTest.java
index eaa4f80..51653a4 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ShowStackTraceDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ShowStackTraceDUnitTest.java
@@ -14,25 +14,14 @@
*/
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.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.test.dunit.Assert.assertFalse;
-import static org.apache.geode.test.dunit.Assert.assertTrue;
-import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
+import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.apache.geode.test.dunit.Assert.*;
+import static org.apache.geode.test.dunit.LogWriterUtils.*;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TemporaryFolder;
-
import org.apache.geode.management.cli.Result.Status;
import org.apache.geode.management.internal.cli.i18n.CliStrings;
import org.apache.geode.management.internal.cli.json.GfJsonException;
@@ -43,6 +32,10 @@ import org.apache.geode.test.dunit.SerializableRunnable;
import org.apache.geode.test.dunit.VM;
import org.apache.geode.test.junit.categories.DistributedTest;
import org.apache.geode.test.junit.rules.serializable.SerializableTemporaryFolder;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
/***
* DUnit test for 'show stack-trace' command
@@ -263,7 +256,7 @@ public class ShowStackTraceDUnitTest extends CliCommandTestBase {
assertTrue(exportCommandResult.getStatus().equals(Status.OK));
assertTrue(
((String) exportCommandResult.getResultData().getGfJsonObject().getJSONObject("content")
- .getJSONArray("message").get(0)).contains("Stack-trace(s) exported to file:"));
+ .getJSONArray("message").get(0)).contains("stack-trace(s) exported to file:"));
}
}