You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by pr...@apache.org on 2017/11/22 21:42:45 UTC
[geode] branch develop updated: GEODE-3539: Add missing test
coverage to 'list disk-stores' and 'describe disk-stores' commands
This is an automated email from the ASF dual-hosted git repository.
prhomberg 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 f3a0219 GEODE-3539: Add missing test coverage to 'list disk-stores' and 'describe disk-stores' commands
f3a0219 is described below
commit f3a021991d239dfc05357d6250d937a90d971f32
Author: Patrick Rhomberg <Pu...@users.noreply.github.com>
AuthorDate: Wed Nov 22 13:42:43 2017 -0800
GEODE-3539: Add missing test coverage to 'list disk-stores' and 'describe disk-stores' commands
* Refactor cumbersome DUnit test to individual IntegrationTests
---
.../DescribeDiskStoreCommandIntegrationTest.java | 108 +++++++++++
.../ListAndDescribeDiskStoreCommandsDUnitTest.java | 205 ---------------------
.../ListDiskStoreCommandIntegrationTest.java | 69 +++++++
.../cli/commands/CommandOverHttpDUnitTest.java | 3 +-
4 files changed, 178 insertions(+), 207 deletions(-)
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DescribeDiskStoreCommandIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DescribeDiskStoreCommandIntegrationTest.java
new file mode 100644
index 0000000..3edc944
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DescribeDiskStoreCommandIntegrationTest.java
@@ -0,0 +1,108 @@
+/*
+ * 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 java.util.Arrays;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+import org.apache.geode.test.junit.rules.GfshCommandRule;
+import org.apache.geode.test.junit.rules.GfshCommandRule.PortType;
+import org.apache.geode.test.junit.rules.ServerStarterRule;
+
+@Category(IntegrationTest.class)
+public class DescribeDiskStoreCommandIntegrationTest {
+ private static final String REGION_NAME = "test-region";
+ private static final String MEMBER_NAME = "testServer";
+ private static final String DISK_STORE_NAME = "testDiskStore";
+
+ private static final List<String> expectedData = Arrays.asList("Disk Store ID", "Disk Store Name",
+ "Member ID", "Member Name", "Allow Force Compaction", "Auto Compaction",
+ "Compaction Threshold", "Max Oplog Size", "Queue Size", "Time Interval", "Write Buffer Size",
+ "Disk Usage Warning Percentage", "Disk Usage Critical Percentage ",
+ "PDX Serialization Meta-Data Stored", "Disk Directory", "Size");
+
+ @ClassRule
+ public static ServerStarterRule server =
+ new ServerStarterRule().withRegion(RegionShortcut.REPLICATE, REGION_NAME)
+ .withName(MEMBER_NAME).withJMXManager().withAutoStart();
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ server.getCache().createDiskStoreFactory().create(DISK_STORE_NAME);
+ gfsh.connectAndVerify(server.getJmxPort(), PortType.jmxManager);
+
+ }
+
+ @ClassRule
+ public static GfshCommandRule gfsh = new GfshCommandRule();
+
+ @Before
+ public void setTimeout() {
+ gfsh.setTimeout(1);
+ }
+
+ @Test
+ public void commandFailsWithoutOptions() throws Exception {
+ String cmd = "describe disk-store";
+ gfsh.executeAndAssertThat(cmd).statusIsError().containsOutput("You should specify option (",
+ "--name", "--member", ") for this command");
+
+ }
+
+ @Test
+ public void commandFailsWithOnlyMember() throws Exception {
+ String cmd = "describe disk-store --member=" + MEMBER_NAME;
+ gfsh.executeAndAssertThat(cmd).statusIsError().containsOutput("You should specify option (",
+ "--name", ") for this command");
+ }
+
+ @Test
+ public void commandFailsWithOnlyName() throws Exception {
+ String cmd = "describe disk-store --name=" + DISK_STORE_NAME;
+ gfsh.executeAndAssertThat(cmd).statusIsError().containsOutput("You should specify option (",
+ "--member", ") for this command");
+ }
+
+ @Test
+ public void commandFailsWithBadMember() throws Exception {
+ String cmd = "describe disk-store --member=invalid-member-name --name=" + DISK_STORE_NAME;
+ gfsh.executeAndAssertThat(cmd).statusIsError().containsOutput("Member",
+ "could not be found. Please verify the member name or ID and try again.");
+ }
+
+ @Test
+ public void commandFailsWithBadName() throws Exception {
+ String cmd = "describe disk-store --name=invalid-diskstore-name --member=" + MEMBER_NAME;
+ gfsh.executeAndAssertThat(cmd).statusIsError().containsOutput("A disk store with name",
+ "was not found on member");
+ }
+
+ @Test
+ public void commandSucceedsWithNameAndMember() throws Exception {
+ String cmd = "describe disk-store --name=" + DISK_STORE_NAME + " --member=" + MEMBER_NAME;
+ gfsh.executeAndAssertThat(cmd).statusIsSuccess()
+ .containsOutput(expectedData.toArray(new String[0]));
+ }
+}
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
deleted file mode 100644
index 0e9468c..0000000
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListAndDescribeDiskStoreCommandsDUnitTest.java
+++ /dev/null
@@ -1,205 +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.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 static org.assertj.core.api.Assertions.assertThat;
-
-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.distributed.ConfigurationProperties;
-import org.apache.geode.management.cli.Result;
-import org.apache.geode.management.internal.cli.i18n.CliStrings;
-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.apache.geode.test.junit.categories.FlakyTest;
-
-/**
- * The ListAndDescribeDiskStoreCommandsDUnitTest class is a test suite of functional tests cases
- * testing the proper functioning of the 'list disk-store' and 'describe disk-store' commands.
- * </p>
- *
- * @see org.apache.geode.management.internal.cli.commands.CliCommandTestBase
- * @see ListDiskStoresCommand
- * @see org.apache.geode.management.internal.cli.commands.DescribeDiskStoreCommand
- *
- * @since GemFire 7.0
- */
-@Category({DistributedTest.class, FlakyTest.class}) // GEODE-3530
-@SuppressWarnings("serial")
-public class ListAndDescribeDiskStoreCommandsDUnitTest extends CliCommandTestBase {
-
- @Override
- public final void postSetUpCliCommandTestBase() throws Exception {
- setUpJmxManagerOnVm0ThenConnect(null);
- setupGemFire();
- }
-
- @Test
- public void testListDiskStore() throws Exception {
- final Result result = executeCommand(CliStrings.LIST_DISK_STORE);
-
- assertNotNull(result);
- getLogWriter().info(toString(result));
- assertEquals(Result.Status.OK, result.getStatus());
- }
-
- @Test
- public void testDescribeDiskStore() throws Exception {
- final Result result = executeCommand(
- CliStrings.DESCRIBE_DISK_STORE + " --member=producerServer --name=producerData");
-
- assertNotNull(result);
- getLogWriter().info(toString(result));
- assertEquals(Result.Status.OK, result.getStatus());
- }
-
- @Test
- public void testDescribeDiskStoreWithInvalidMemberName() throws Exception {
- final Result commandResult = executeCommand(
- CliStrings.DESCRIBE_DISK_STORE + " --member=badMemberName --name=producerData");
-
- assertNotNull(commandResult);
- assertEquals(Result.Status.ERROR, commandResult.getStatus());
- assertEquals(CliStrings.format(CliStrings.MEMBER_NOT_FOUND_ERROR_MESSAGE, "badMemberName"),
- toString(commandResult));
- }
-
- @Test
- public void testDescribeDiskStoreWithInvalidDiskStoreName() {
- final Result commandResult = executeCommand(
- CliStrings.DESCRIBE_DISK_STORE + " --member=producerServer --name=badDiskStoreName");
-
- assertNotNull(commandResult);
- assertEquals(Result.Status.ERROR, commandResult.getStatus());
- assertThat(toString(commandResult)).contains(
- "A disk store with name (badDiskStoreName) was not found on member (producerServer).");
- }
-
- private static String toString(final Result result) {
- assert result != null : "The Result object from the command execution cannot be null!";
-
- final StringBuilder buffer = new StringBuilder(System.getProperty("line.separator"));
-
- while (result.hasNextLine()) {
- buffer.append(result.nextLine());
- buffer.append(System.getProperty("line.separator"));
- }
-
- return buffer.toString().trim();
- }
-
- private Peer createPeer(final Properties distributedSystemConfiguration, final VM vm) {
- return new Peer(distributedSystemConfiguration, vm);
- }
-
- private void setupGemFire() throws Exception {
- final VM vm1 = getHost(0).getVM(1);
- final VM vm2 = getHost(0).getVM(2);
-
- final Peer peer1 = createPeer(createDistributedSystemProperties("consumerServer"), vm1);
- final Peer peer2 = createPeer(createDistributedSystemProperties("producerServer"), vm2);
-
- createPersistentRegion(peer1, "consumers", "consumerData");
- createPersistentRegion(peer1, "observers", "observerData");
- createPersistentRegion(peer2, "producer", "producerData");
- createPersistentRegion(peer2, "producer-factory", "producerData");
- }
-
- private Properties createDistributedSystemProperties(final String gemfireName) {
- final Properties distributedSystemProperties = new Properties();
-
- distributedSystemProperties.setProperty(ConfigurationProperties.LOG_LEVEL, getDUnitLogLevel());
- distributedSystemProperties.setProperty(NAME, gemfireName);
-
- return distributedSystemProperties;
- }
-
- private void createPersistentRegion(final Peer peer, final String regionName,
- final String diskStoreName) throws Exception {
- peer.run(new SerializableRunnable("Creating Persistent Region for Member " + peer.getName()) {
- @Override
- public void run() {
- getSystem(peer.getDistributedSystemConfiguration());
-
- final Cache cache = getCache();
-
- DiskStore diskStore = cache.findDiskStore(diskStoreName);
-
- if (diskStore == null) {
- final DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
- diskStoreFactory.setDiskDirs(getDiskDirs());
- diskStore = diskStoreFactory.create(diskStoreName);
- }
-
- final RegionFactory regionFactory = cache.createRegionFactory();
-
- regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
- regionFactory.setDiskStoreName(diskStore.getName());
- regionFactory.setScope(Scope.DISTRIBUTED_NO_ACK);
- regionFactory.create(regionName);
- }
- });
- }
-
- private static class Peer implements Serializable {
-
- private final Properties distributedSystemConfiguration;
- private final VM vm;
-
- protected Peer(final Properties distributedSystemConfiguration, final VM vm) {
- assert distributedSystemConfiguration != null : "The GemFire distributed system configuration properties cannot be null!";
- this.distributedSystemConfiguration = distributedSystemConfiguration;
- this.vm = vm;
- }
-
- public Properties getDistributedSystemConfiguration() {
- return distributedSystemConfiguration;
- }
-
- public String getName() {
- return getDistributedSystemConfiguration().getProperty(NAME);
- }
-
- public VM getVm() {
- return vm;
- }
-
- public void run(final SerializableRunnableIF runnable) throws Exception {
- if (getVm() == null) {
- runnable.run();
- } else {
- getVm().invoke(runnable);
- }
- }
- }
-}
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListDiskStoreCommandIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListDiskStoreCommandIntegrationTest.java
new file mode 100644
index 0000000..25ac49c
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ListDiskStoreCommandIntegrationTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.Before;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.DiskStore;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+import org.apache.geode.test.junit.rules.GfshCommandRule;
+import org.apache.geode.test.junit.rules.GfshCommandRule.PortType;
+import org.apache.geode.test.junit.rules.ServerStarterRule;
+
+@Category(IntegrationTest.class)
+public class ListDiskStoreCommandIntegrationTest {
+ private static final String REGION_NAME = "test-region";
+ private static final String MEMBER_NAME = "testServer";
+ private static final String DISK_STORE_NAME = "testDiskStore";
+
+ @ClassRule
+ public static ServerStarterRule server =
+ new ServerStarterRule().withRegion(RegionShortcut.REPLICATE, REGION_NAME)
+ .withName(MEMBER_NAME).withJMXManager().withAutoStart();
+
+ @Rule
+ public GfshCommandRule gfsh = new GfshCommandRule();
+
+ @Before
+ public void setTimeout() {
+ gfsh.setTimeout(1);
+ }
+
+ @Test
+ public void commandSucceedsWhenConnected() throws Exception {
+ Cache cache = server.getCache();
+ DiskStore ds = cache.createDiskStoreFactory().create(DISK_STORE_NAME);
+
+ gfsh.connectAndVerify(server.getJmxPort(), PortType.jmxManager);
+ gfsh.executeAndAssertThat("list disk-stores").statusIsSuccess()
+ .tableHasColumnWithValuesContaining("Member Name", MEMBER_NAME)
+ .tableHasColumnWithValuesContaining("Member Id", server.getCache().getMyId().getId())
+ .tableHasColumnWithValuesContaining("Disk Store Name", DISK_STORE_NAME)
+ .tableHasColumnWithValuesContaining("Disk Store ID", ds.getDiskStoreUUID().toString());
+ }
+
+ @Test
+ public void commandFailsWhenNotConnected() throws Exception {
+ gfsh.executeAndAssertThat("list disk-stores").statusIsError().containsOutput("Command",
+ "was found but is not currently available");
+ }
+}
diff --git a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java
index 4073b00..4844e35 100644
--- a/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java
+++ b/geode-web/src/test/java/org/apache/geode/management/internal/cli/commands/CommandOverHttpDUnitTest.java
@@ -29,8 +29,7 @@ import org.apache.geode.test.junit.runners.SuiteRunner;
*/
@Category({DistributedTest.class, SecurityTest.class})
@RunWith(SuiteRunner.class)
-@Suite.SuiteClasses({GemfireDataCommandsDUnitTest.class,
- ListAndDescribeDiskStoreCommandsDUnitTest.class, QueueCommandsDUnitTest.class,
+@Suite.SuiteClasses({GemfireDataCommandsDUnitTest.class, QueueCommandsDUnitTest.class,
ShellCommandsDUnitTest.class, ShowStackTraceDUnitTest.class})
public class CommandOverHttpDUnitTest {
@ClassRule
--
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].