[ 
https://issues.apache.org/jira/browse/GEODE-3539?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16267789#comment-16267789
 ] 

ASF GitHub Bot commented on GEODE-3539:
---------------------------------------

PurelyApplied closed pull request #1070: GEODE-3539: Add test coverage to 
'alter disk-store'.
URL: https://github.com/apache/geode/pull/1070
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/AlterDiskStoreDUnitTest.java
 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/AlterDiskStoreDUnitTest.java
new file mode 100644
index 0000000000..566e88b616
--- /dev/null
+++ 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/AlterDiskStoreDUnitTest.java
@@ -0,0 +1,168 @@
+/*
+ * 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.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.junit.Before;
+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.DataPolicy;
+import org.apache.geode.cache.EvictionAction;
+import org.apache.geode.cache.EvictionAttributes;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.cache.Scope;
+import org.apache.geode.management.internal.cli.i18n.CliStrings;
+import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
+import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.rules.GfshCommandRule;
+import org.apache.geode.test.junit.rules.GfshCommandRule.PortType;
+
+@Category(DistributedTest.class)
+public class AlterDiskStoreDUnitTest {
+  private static final String regionName = "region1";
+  private static final String diskStoreName = "disk-store1";
+  private static final String diskDirName = "diskStoreDir";
+  private static final String aKey = "key1";
+
+  private static MemberVM locator;
+  private static MemberVM server1;
+
+  @Rule
+  public LocatorServerStartupRule startupRule = new LocatorServerStartupRule();
+
+  @Rule
+  public GfshCommandRule gfsh = new GfshCommandRule();
+
+  @Before
+  public void setupCluster() throws Exception {
+
+    File diskStoreDirFile = new File(getDiskDirPathString());
+
+    if (!diskStoreDirFile.exists()) {
+      diskStoreDirFile.mkdirs();
+    }
+
+    locator = startupRule.startLocatorVM(0);
+    server1 = startupRule.startServerVM(1, locator.getPort());
+    String diskDirPathString = getDiskDirPathString();
+    server1.invoke(() -> {
+      Cache cache = LocatorServerStartupRule.getCache();
+      cache.createDiskStoreFactory().setDiskDirs(new File[] {new 
File(diskDirPathString)})
+          
.setMaxOplogSize(1).setAllowForceCompaction(true).setAutoCompact(false)
+          .create(diskStoreName);
+
+      EvictionAttributes ea =
+          EvictionAttributes.createLRUEntryAttributes(1, 
EvictionAction.OVERFLOW_TO_DISK);
+
+      RegionFactory<String, String> regionFactory = 
cache.createRegionFactory();
+      Region<String, String> region = 
regionFactory.setDiskStoreName(diskStoreName)
+          
.setDiskSynchronous(true).setDataPolicy(DataPolicy.PERSISTENT_REPLICATE)
+          
.setScope(Scope.DISTRIBUTED_ACK).setEvictionAttributes(ea).create(regionName);
+      region.put(aKey, "value");
+    });
+  }
+
+  @Test
+  public void diskStoreIsLockedWhileMemberIsAlive() throws Exception {
+    gfsh.connectAndVerify(locator.getJmxPort(), PortType.jmxManager);
+    String commandString = commandToSetManyVariables();
+    
gfsh.executeAndAssertThat(commandString).statusIsError().containsOutput("Could 
not lock",
+        "Other JVMs might have created diskstore with same name using the same 
directory");
+  }
+
+  @Test
+  public void alterDiskStoreUpdatesValues() throws Exception {
+    startupRule.stopVM(1);
+
+    gfsh.connectAndVerify(locator.getJmxPort(), PortType.jmxManager);
+    String commandOne = commandToSetManyVariables();
+    
gfsh.executeAndAssertThat(commandOne).statusIsSuccess().containsOutput("concurrencyLevel=5",
+        "lruAction=local-destroy", 
"compressor=org.apache.geode.compression.SnappyCompressor",
+        "initialCapacity=6");
+
+    String commandTwo = commandToSetCompressorToNone();
+    
gfsh.executeAndAssertThat(commandTwo).statusIsSuccess().containsOutput("-compressor=none");
+  }
+
+  @Test
+  public void alterDiskStoreWithRemoveDoesRemoveRegion() throws IOException {
+    // Verify to start that there exists the data in the region
+    server1.invoke(() -> {
+      Region region = 
LocatorServerStartupRule.getCache().getRegion(regionName);
+      assertThat(region).isNotNull();
+      assertThat(region.get(aKey)).isNotNull();
+    });
+
+    // Halt the member and "alter" the disk store with the --remove option
+    startupRule.stopVM(1);
+    String cmd = commandWithRemoveAndNoOtherOption();
+    gfsh.executeAndAssertThat(cmd).statusIsSuccess().containsOutput("The 
region " + regionName
+        + " was successfully removed from the disk store " + diskStoreName);
+
+    // Restart the member and see that the disk store / region is gone.
+    startupRule.startServerVM(1, locator.getPort());
+    server1.invoke(() -> {
+      Region region = 
LocatorServerStartupRule.getCache().getRegion(regionName);
+      assertThat(region).isNull();
+    });
+  }
+
+  private String getDiskDirPathString() throws IOException {
+    return 
gfsh.getWorkingDir().toPath().resolve(diskDirName).toFile().getCanonicalPath();
+  }
+
+  private String commandWithRemoveAndNoOtherOption() throws IOException {
+    CommandStringBuilder csb = new 
CommandStringBuilder(CliStrings.ALTER_DISK_STORE);
+    csb.addOption(CliStrings.ALTER_DISK_STORE__DISKSTORENAME, diskStoreName);
+    csb.addOption(CliStrings.ALTER_DISK_STORE__REGIONNAME, regionName);
+    csb.addOption(CliStrings.ALTER_DISK_STORE__DISKDIRS, 
getDiskDirPathString());
+    csb.addOption(CliStrings.ALTER_DISK_STORE__REMOVE, "true");
+    return csb.toString();
+  }
+
+  private String commandToSetCompressorToNone() throws IOException {
+    CommandStringBuilder csb = new 
CommandStringBuilder(CliStrings.ALTER_DISK_STORE);
+    csb.addOption(CliStrings.ALTER_DISK_STORE__DISKSTORENAME, diskStoreName);
+    csb.addOption(CliStrings.ALTER_DISK_STORE__REGIONNAME, regionName);
+    csb.addOption(CliStrings.ALTER_DISK_STORE__DISKDIRS, 
getDiskDirPathString());
+    csb.addOption(CliStrings.ALTER_DISK_STORE__COMPRESSOR, "none");
+    return csb.toString();
+  }
+
+  private String commandToSetManyVariables() throws IOException {
+    CommandStringBuilder csb = new 
CommandStringBuilder(CliStrings.ALTER_DISK_STORE);
+    csb.addOption(CliStrings.ALTER_DISK_STORE__DISKSTORENAME, diskStoreName);
+    csb.addOption(CliStrings.ALTER_DISK_STORE__REGIONNAME, regionName);
+    csb.addOption(CliStrings.ALTER_DISK_STORE__DISKDIRS, 
getDiskDirPathString());
+    csb.addOption(CliStrings.ALTER_DISK_STORE__CONCURRENCY__LEVEL, "5");
+    csb.addOption(CliStrings.ALTER_DISK_STORE__INITIAL__CAPACITY, "6");
+    csb.addOption(CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ACTION, 
"local-destroy");
+    csb.addOption(CliStrings.ALTER_DISK_STORE__COMPRESSOR,
+        "org.apache.geode.compression.SnappyCompressor");
+    csb.addOption(CliStrings.ALTER_DISK_STORE__STATISTICS__ENABLED, "true");
+    return csb.toString();
+  }
+}
diff --git 
a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/AlterDiskStoreJUnitTest.java
 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/AlterDiskStoreJUnitTest.java
new file mode 100644
index 0000000000..0059458aea
--- /dev/null
+++ 
b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/AlterDiskStoreJUnitTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.mockito.Mockito.spy;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.management.internal.cli.i18n.CliStrings;
+import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
+import org.apache.geode.test.junit.categories.UnitTest;
+import org.apache.geode.test.junit.rules.GfshParserRule;
+
+@Category(UnitTest.class)
+public class AlterDiskStoreJUnitTest {
+  @Rule
+  public GfshParserRule gfsh = new GfshParserRule();
+
+  private GfshCommand command;
+
+  @Before
+  public void before() {
+    command = spy(AlterOfflineDiskStoreCommand.class);
+  }
+
+  @Test
+  public void removeOptionMustBeUsedAlone() throws Exception {
+    CommandStringBuilder csb = new 
CommandStringBuilder(CliStrings.ALTER_DISK_STORE);
+    csb.addOption(CliStrings.ALTER_DISK_STORE__DISKSTORENAME, "diskStoreName");
+    csb.addOption(CliStrings.ALTER_DISK_STORE__REGIONNAME, "regionName");
+    csb.addOption(CliStrings.ALTER_DISK_STORE__DISKDIRS, "./someDirectory");
+    csb.addOption(CliStrings.ALTER_DISK_STORE__CONCURRENCY__LEVEL, "5");
+    csb.addOption(CliStrings.ALTER_DISK_STORE__REMOVE, "true");
+    String commandString = csb.toString();
+
+    gfsh.executeAndAssertThat(command, commandString).statusIsError()
+        .containsOutput("Cannot use the --remove=true parameter with any other 
parameters");
+  }
+}
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 448579f3b0..1bc38f2475 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
@@ -238,33 +238,6 @@ public void testDestroyUpdatesSharedConfig() throws 
Exception {
     assertThat(diskStoreExistsInClusterConfig(locator)).isFalse();
   }
 
-  @Test
-  public void testAlterDiskStore() throws Exception {
-    Properties props = new Properties();
-    props.setProperty("groups", GROUP);
-    MemberVM locator = rule.startLocatorVM(0);
-    MemberVM server1 = rule.startServerVM(1, props, locator.getPort());
-
-    gfsh.connectAndVerify(locator);
-
-    createDiskStoreAndRegion(locator, 1);
-
-    String diskDirs = new File(server1.getWorkingDir(), 
DISKSTORE).getAbsolutePath();
-    gfsh.executeAndAssertThat(
-        String.format("alter disk-store --name=%s --region=%s --disk-dirs=%s 
--concurrency-level=5",
-            DISKSTORE, REGION_1, diskDirs))
-        .statusIsError().containsOutput("Could not lock");
-
-    server1.invoke(LocatorServerStartupRule::stopMemberInThisVM);
-
-    gfsh.executeAndAssertThat(String.format(
-        "alter disk-store --name=%s --region=%s --disk-dirs=%s 
--concurrency-level=5 --initial-capacity=6 --lru-action=local-destroy 
--compressor=%s --enable-statistics=true",
-        DISKSTORE, REGION_1, diskDirs, 
SnappyCompressor.class.getName())).statusIsSuccess()
-        .containsOutput("concurrencyLevel=16", "concurrencyLevel=5", 
"initialCapacity=16",
-            "initialCapacity=6", "lruAction=overflow-to-disk", 
"lruAction=local-destroy",
-            "compressor=none", "compressor=" + 
SnappyCompressor.class.getName(),
-            "statisticsEnabled=false", "statisticsEnabled=true");
-  }
 
   @Test
   public void testBackupDiskStore() throws Exception {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Add more test coverage for p2p commands
> ---------------------------------------
>
>                 Key: GEODE-3539
>                 URL: https://issues.apache.org/jira/browse/GEODE-3539
>             Project: Geode
>          Issue Type: Improvement
>          Components: gfsh
>            Reporter: Jinmei Liao
>
> Add more command tests that would eventually get rid of the legacy tests.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to