geode-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GEODE-3341) Refactor DiskStoreCommandsDUnitTest to use test rules
Date Thu, 16 Nov 2017 16:41:00 GMT

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

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

pdxrunner commented on a change in pull request #1062: GEODE-3341: Convert DiskStoreCommandsDUnitTest
to use gfsh rules
URL: https://github.com/apache/geode/pull/1062#discussion_r151469638
 
 

 ##########
 File path: geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/DiskStoreCommandsDUnitTest.java
 ##########
 @@ -12,1480 +12,283 @@
  * 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.START_LOCATOR;
-import static org.apache.geode.distributed.ConfigurationProperties.USE_CLUSTER_CONFIGURATION;
-import static org.apache.geode.test.dunit.Assert.fail;
-import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
-import static org.apache.geode.test.dunit.Wait.waitForCriterion;
-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.assertj.core.api.Assertions.assertThat;
 
 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 java.util.stream.Collectors;
+import java.util.stream.IntStream;
 
-import org.apache.commons.io.FileUtils;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
 
 import org.apache.geode.cache.Cache;
-import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.cache.DataPolicy;
-import org.apache.geode.cache.DiskStore;
-import org.apache.geode.cache.DiskStoreFactory;
-import org.apache.geode.cache.EvictionAction;
-import org.apache.geode.cache.EvictionAttributes;
-import org.apache.geode.cache.PartitionAttributes;
-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.cache.query.data.PortfolioPdx;
 import org.apache.geode.compression.SnappyCompressor;
-import org.apache.geode.distributed.DistributedSystemDisconnectedException;
 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.internal.cache.GemFireCacheImpl;
-import org.apache.geode.internal.cache.InternalCache;
-import org.apache.geode.internal.cache.PartitionedRegion;
 import org.apache.geode.internal.cache.SnapshotTestUtil;
-import org.apache.geode.internal.cache.persistence.PersistentMemberManager;
-import org.apache.geode.management.cli.Result;
-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.shell.Gfsh;
-import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
-import org.apache.geode.test.dunit.AsyncInvocation;
-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.rules.LocatorServerStartupRule;
+import org.apache.geode.test.dunit.rules.MemberVM;
 import org.apache.geode.test.junit.categories.DistributedTest;
-import org.apache.geode.test.junit.categories.FlakyTest;
+import org.apache.geode.test.junit.rules.GfshCommandRule;
 
-/**
- * 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.junit.Assert
- * @see org.junit.Test
- * @since GemFire 7.0
- */
-@Category({DistributedTest.class, FlakyTest.class}) // GEODE-1206 GEODE-1406 GEODE-2102 GEODE-3530
-@SuppressWarnings("serial")
-public class DiskStoreCommandsDUnitTest extends CliCommandTestBase {
-
-  private final List<String> filesToBeDeleted = new CopyOnWriteArrayList<>();
-
-  @Test // FlakyTest: GEODE-2102
-  public void testMissingDiskStore() {
-    final String regionName = "testShowMissingDiskStoreRegion";
-
-    setUpJmxManagerOnVm0ThenConnect(null);
-
-    final VM vm0 = Host.getHost(0).getVM(0);
-    final VM vm1 = Host.getHost(0).getVM(1);
-    final String vm1Name = "VM" + vm1.getId();
-    final String diskStoreName = "DiskStoreCommandsDUnitTest";
-
-    // Default setup creates a cache in the Manager, now create a cache in VM1
-    vm1.invoke(new SerializableRunnable() {
-      public void run() {
-        Properties localProps = new Properties();
-        localProps.setProperty(NAME, vm1Name);
-        getSystem(localProps);
-        Cache cache = getCache();
-      }
-    });
+@Category(DistributedTest.class)
+public class DiskStoreCommandsDUnitTest {
 
-    // Create a disk store and region in the Manager (VM0) and VM1 VMs
-    for (final VM vm : (new VM[] {vm0, vm1})) {
-      final String vmName = "VM" + vm.getId();
-      vm.invoke(new SerializableRunnable() {
-        public void run() {
-          Cache cache = getCache();
-
-          File diskStoreDirFile = new File(diskStoreName + vm.getId());
-          diskStoreDirFile.mkdirs();
-
-          DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
-          diskStoreFactory.setDiskDirs(new File[] {diskStoreDirFile});
-          diskStoreFactory.setMaxOplogSize(1);
-          diskStoreFactory.setAllowForceCompaction(true);
-          diskStoreFactory.setAutoCompact(false);
-          diskStoreFactory.create(regionName);
-
-          RegionFactory regionFactory = cache.createRegionFactory();
-          regionFactory.setDiskStoreName(regionName);
-          regionFactory.setDiskSynchronous(true);
-          regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
-          regionFactory.setScope(Scope.DISTRIBUTED_ACK);
-          regionFactory.create(regionName);
-        }
-      });
-    }
-
-    // Add data to the region
-    vm0.invoke(new SerializableRunnable() {
-      public void run() {
-        Cache cache = getCache();
-        Region region = cache.getRegion(regionName);
-        region.put("A", "B");
-      }
-    });
+  private static final String REGION_1 = "REGION1";
+  private static final String DISKSTORE = "DISKSTORE";
+  private static final String GROUP = "GROUP1";
 
-    // Make sure that everything thus far is okay and there are no missing disk stores
-    CommandResult cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
-    assertEquals(Result.Status.OK, cmdResult.getStatus());
-    assertTrue(commandResultToString(cmdResult).contains("No missing disk store found"));
-
-    // Close the region in the Manager (VM0) VM
-    vm0.invoke(new SerializableRunnable() {
-      public void run() {
-        Cache cache = getCache();
-        Region region = cache.getRegion(regionName);
-        region.close();
-      }
-    });
+  @Rule
+  public LocatorServerStartupRule rule = new LocatorServerStartupRule();
 
-    // Add data to VM1 and then close the region
-    vm1.invoke(new SerializableRunnable() {
-      public void run() {
-        Cache cache = getCache();
-        Region region = cache.getRegion(regionName);
-        region.put("A", "C");
-        region.close();
-      }
-    });
+  @Rule
+  public GfshCommandRule gfsh = new GfshCommandRule();
 
-    // Add the region back to the Manager (VM0) VM
-    vm0.invokeAsync(new SerializableRunnable() {
-      public void run() {
-        Cache cache = getCache();
-
-        RegionFactory regionFactory = cache.createRegionFactory();
-        regionFactory.setDiskStoreName(regionName);
-        regionFactory.setDiskSynchronous(true);
-        regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
-        regionFactory.setScope(Scope.DISTRIBUTED_ACK);
-        try {
-          regionFactory.create(regionName);
-        } catch (DistributedSystemDisconnectedException ignore) {
-          // okay to ignore
-        }
-      }
-    });
+  @Rule
+  public TemporaryFolder tempDir = new TemporaryFolder();
 
-    // Wait for the region in the Manager (VM0) to come online
-    vm0.invoke(new SerializableRunnable() {
-      public void run() {
-        WaitCriterion waitCriterion = new WaitCriterion() {
-          public boolean done() {
-            Cache cache = getCache();
-            PersistentMemberManager memberManager =
-                ((InternalCache) cache).getPersistentMemberManager();
-            return !memberManager.getWaitingRegions().isEmpty();
-          }
-
-          public String description() {
-            return "Waiting for another persistent member to come online";
-          }
-        };
-        waitForCriterion(waitCriterion, 70000, 100, true);
-      }
-    });
+  private void createDiskStoreAndRegion(MemberVM jmxManager, int serverCount) {
+    gfsh.executeAndAssertThat(String.format("create disk-store --name=%s --dir=%s --group=%s",
+        DISKSTORE, DISKSTORE, GROUP));
 
-    // Validate that there is a missing disk store on VM1
-    cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
-    assertEquals(Result.Status.OK, cmdResult.getStatus());
-
-    String stringResult = commandResultToString(cmdResult);
-    System.out.println("command result=" + stringResult);
-    assertEquals(5, countLinesInString(stringResult, false));
-    assertTrue(stringContainsLine(stringResult, "Disk Store ID.*Host.*Directory"));
-    assertTrue(stringContainsLine(stringResult, ".*" + diskStoreName + vm1.getId()));
-
-    // Extract the id from the returned missing disk store
-    String line = getLineFromString(stringResult, 4);
-    assertFalse(line.contains("---------"));
-    StringTokenizer resultTokenizer = new StringTokenizer(line);
-    String id = resultTokenizer.nextToken();
-
-    // Remove the missing disk store and validate the result
-    cmdResult = executeCommand("revoke missing-disk-store --id=" + id);
-    assertNotNull(cmdResult);
-    assertEquals(Result.Status.OK, cmdResult.getStatus());
-    assertTrue(
-        commandResultToString(cmdResult).contains("Missing disk store successfully revoked"));
-
-    // Do our own cleanup so that the disk store directories can be removed
-    super.destroyDefaultSetup();
-    for (final VM vm : (new VM[] {vm0, vm1})) {
-      final String vmName = "VM" + vm.getId();
-      vm.invoke(new SerializableRunnable() {
-        public void run() {
-          try {
-            FileUtils.deleteDirectory((new File(diskStoreName + vm.getId())));
-          } catch (IOException iex) {
-            // There's nothing else we can do
-          }
-        }
-      });
-    }
-  }
+    List<String> diskStores =
+        IntStream.rangeClosed(1, serverCount).mapToObj(x -> DISKSTORE).collect(Collectors.toList());
+    gfsh.executeAndAssertThat("list disk-stores").statusIsSuccess()
+        .tableHasColumnWithValuesContaining("Disk Store Name", diskStores.toArray(new String[0]));
 
-  @Test
-  public void testMissingDiskStoreCommandWithColocation() {
-    final String regionName = "testShowPersistentRecoveryFailuresRegion";
-    final String childName = "childRegion";
-
-    setUpJmxManagerOnVm0ThenConnect(null);
-
-    final VM vm0 = Host.getHost(0).getVM(0);
-    final VM vm1 = Host.getHost(0).getVM(1);
-    final String vm1Name = "VM" + vm1.getId();
-    final String diskStoreName = "DiskStoreCommandsDUnitTest";
-
-    // Default setup creates a cache in the Manager, now create a cache in VM1
-    vm1.invoke(new SerializableRunnable() {
-      public void run() {
-        Properties localProps = new Properties();
-        localProps.setProperty(NAME, vm1Name);
-        getSystem(localProps);
-        Cache cache = getCache();
-      }
-    });
+    jmxManager.waitTillDiskstoreIsReady(DISKSTORE, serverCount);
 
-    // Create a disk store and region in the Manager (VM0) and VM1 VMs
-    for (final VM vm : (new VM[] {vm0, vm1})) {
-      final String vmName = "VM" + vm.getId();
-      vm.invoke(new SerializableRunnable() {
-        public void run() {
-          Cache cache = getCache();
-
-          File diskStoreDirFile = new File(diskStoreName + vm.getId());
-          diskStoreDirFile.mkdirs();
-
-          DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
-          diskStoreFactory.setDiskDirs(new File[] {diskStoreDirFile});
-          diskStoreFactory.setMaxOplogSize(1);
-          diskStoreFactory.setAllowForceCompaction(true);
-          diskStoreFactory.setAutoCompact(false);
-          diskStoreFactory.create(regionName);
-          diskStoreFactory.create(childName);
-
-          RegionFactory regionFactory = cache.createRegionFactory();
-          regionFactory.setDiskStoreName(regionName);
-          regionFactory.setDiskSynchronous(true);
-          regionFactory.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
-          regionFactory.create(regionName);
-
-          PartitionAttributes pa =
-              new PartitionAttributesFactory().setColocatedWith(regionName).create();
-          RegionFactory childRegionFactory = cache.createRegionFactory();
-          childRegionFactory.setPartitionAttributes(pa);
-          childRegionFactory.setDiskStoreName(childName);
-          childRegionFactory.setDiskSynchronous(true);
-          childRegionFactory.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
-          childRegionFactory.create(childName);
-        }
-      });
-    }
-
-    // Add data to the region
-    vm0.invoke(new SerializableRunnable() {
-      public void run() {
-        Cache cache = getCache();
-        Region region = cache.getRegion(regionName);
-        region.put("A", "a");
-        region.put("B", "b");
-      }
-    });
+    gfsh.executeAndAssertThat(String.format(
+        "create region --name=%s --type=REPLICATE_PERSISTENT --disk-store=%s --group=%s --eviction-action=overflow-to-disk",
+        REGION_1, DISKSTORE, GROUP)).statusIsSuccess();
+  }
 
-    // Make sure that everything thus far is okay and there are no missing disk stores
-    CommandResult cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
-    System.out.println("command result=\n" + commandResultToString(cmdResult));
-
-    assertEquals(Result.Status.OK, cmdResult.getStatus());
-    assertTrue(cmdResult.toString(),
-        commandResultToString(cmdResult).contains("No missing disk store found"));
-
-    // Close the regions in the Manager (VM0) VM
-    vm0.invoke(new SerializableRunnable() {
-      public void run() {
-        Cache cache = getCache();
-        Region region = cache.getRegion(childName);
-        region.close();
-        region = cache.getRegion(regionName);
-        region.close();
-      }
-    });
+  @Test
+  public void testMissingDiskStore() throws Exception {
+    Properties props = new Properties();
+    props.setProperty("groups", GROUP);
 
-    // Add data to VM1 and then close the region
-    vm1.invoke(new SerializableRunnable() {
-      public void run() {
-        Cache cache = getCache();
-        Region childRegion = cache.getRegion(childName);
-        PartitionedRegion parentRegion = (PartitionedRegion) (cache.getRegion(regionName));
-        try {
-          parentRegion.put("A", "C");
-        } catch (Exception e) {
-          // Ignore any exception on the put
-        }
-        childRegion.close();
-        parentRegion.close();
-      }
-    });
+    MemberVM locator = rule.startLocatorVM(0);
+    MemberVM server1 = rule.startServerVM(1, props, locator.getPort());
+    MemberVM server2 = rule.startServerVM(2, props, locator.getPort());
 
-    SerializableRunnable restartParentRegion =
-        new SerializableRunnable("Restart parent region on") {
-          public void run() {
-            Cache cache = getCache();
-
-            RegionFactory regionFactory = cache.createRegionFactory();
-            regionFactory.setDiskStoreName(regionName);
-            regionFactory.setDiskSynchronous(true);
-            regionFactory.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
-            try {
-              regionFactory.create(regionName);
-            } catch (Exception e) {
-              // okay to ignore
-            }
-          }
-        };
-
-    SerializableRunnable restartChildRegion = new SerializableRunnable("Restart child region")
{
-      public void run() {
-        Cache cache = getCache();
-
-        PartitionAttributes pa =
-            new PartitionAttributesFactory().setColocatedWith(regionName).create();
-        RegionFactory regionFactory = cache.createRegionFactory();
-        regionFactory.setPartitionAttributes(pa);
-        regionFactory.setDiskStoreName(childName);
-        regionFactory.setDiskSynchronous(true);
-        regionFactory.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
-        try {
-          regionFactory.create(childName);
-        } catch (Exception e) {
-          // okay to ignore
-          e.printStackTrace();
-        }
-      }
-    };
-
-    // Add the region back to the Manager (VM0) VM
-    AsyncInvocation async0 = vm0.invokeAsync(restartParentRegion);
-    AsyncInvocation async1 = vm1.invokeAsync(restartParentRegion);
-
-    // Wait for the region in the Manager (VM0) to come online
-    vm0.invoke(new SerializableRunnable("WaitForRegionInVm0") {
-      public void run() {
-        WaitCriterion waitCriterion = new WaitCriterion() {
-          public boolean done() {
-            Cache cache = getCache();
-            PersistentMemberManager memberManager =
-                ((GemFireCacheImpl) cache).getPersistentMemberManager();
-            return !memberManager.getWaitingRegions().isEmpty();
-          }
-
-          public String description() {
-            return "Waiting for another persistent member to come online";
-          }
-        };
-        try {
-          waitForCriterion(waitCriterion, 5000, 100, true);
-        } catch (AssertionError ae) {
-          // Ignore. waitForCriterion is expected to timeout in this test
-        }
-      }
-    });
+    gfsh.connectAndVerify(locator);
 
-    // Validate that there is a missing disk store on VM1
-    try {
-      cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
-      assertNotNull("Expect command result != null", cmdResult);
-      assertEquals(Result.Status.OK, cmdResult.getStatus());
-
-      String stringResult = commandResultToString(cmdResult);
-      System.out.println("command result=\n" + stringResult);
-      // Expect 2 result sections with header lines and 4 information lines in the first
section
-      assertEquals(6, countLinesInString(stringResult, false));
-      assertTrue(stringContainsLine(stringResult,
-          "Host.*Distributed Member.*Parent Region.*Missing Colocated Region"));
-      assertTrue(stringContainsLine(stringResult, ".*" + regionName + ".*" + childName));
-
-      AsyncInvocation async0b = vm0.invokeAsync(restartChildRegion);
-      try {
-        async0b.get(5000, TimeUnit.MILLISECONDS);
-      } catch (Exception e) {
-        // Expected timeout - Region recovery is still waiting on vm1 child region and disk-store
to
-        // come online
-      }
-
-      cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
-      assertNotNull("Expect command result != null", cmdResult);
-      assertEquals(Result.Status.OK, cmdResult.getStatus());
-
-      stringResult = commandResultToString(cmdResult);
-      System.out.println("command result=\n" + stringResult);
-
-      // Extract the id from the returned missing disk store
-      String line = getLineFromString(stringResult, 4);
-      assertFalse(line.contains("---------"));
-      StringTokenizer resultTokenizer = new StringTokenizer(line);
-      String id = resultTokenizer.nextToken();
-
-      AsyncInvocation async1b = vm1.invokeAsync(restartChildRegion);
-      try {
-        async1b.get(5000, TimeUnit.MILLISECONDS);
-      } catch (Exception e) {
-        e.printStackTrace();
-      }
-      cmdResult = executeCommand(CliStrings.SHOW_MISSING_DISK_STORE);
-      assertNotNull("Expect command result != null", cmdResult);
-      assertEquals(Result.Status.OK, cmdResult.getStatus());
-
-      stringResult = commandResultToString(cmdResult);
-      System.out.println("command result=\n" + stringResult);
-
-    } finally {
-      // Verify that the invokeAsync thread terminated
-      try {
-        async0.get(10000, TimeUnit.MILLISECONDS);
-        async1.get(10000, TimeUnit.MILLISECONDS);
-      } catch (Exception e) {
-        fail("Unexpected timeout waitiong for invokeAsync threads to terminate: " + e.getMessage());
-      }
-    }
-
-    // Do our own cleanup so that the disk store directories can be removed
-    super.destroyDefaultSetup();
-    for (final VM vm : (new VM[] {vm0, vm1})) {
-      final String vmName = "VM" + vm.getId();
-      vm.invoke(new SerializableRunnable() {
-        public void run() {
-          try {
-            FileUtils.deleteDirectory((new File(diskStoreName + vm.getId())));
-          } catch (IOException iex) {
-            // There's nothing else we can do
-          }
-        }
-      });
-    }
-  }
+    createDiskStoreAndRegion(locator, 2);
 
-  @Test
-  public void testDescribeOfflineDiskStore() {
-    setUpJmxManagerOnVm0ThenConnect(null);
-
-    final File diskStoreDir =
-        new File(new File(".").getAbsolutePath(), "DiskStoreCommandDUnitDiskStores");
-    diskStoreDir.mkdir();
-    this.filesToBeDeleted.add(diskStoreDir.getAbsolutePath());
-
-    final String diskStoreName1 = "DiskStore1";
-    final String region1 = "Region1";
-    final String region2 = "Region2";
-
-    final VM vm1 = Host.getHost(0).getVM(1);
-    vm1.invoke(new SerializableRunnable() {
-      public void run() {
-        final Cache cache = getCache();
-
-        DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
-        diskStoreFactory.setDiskDirs(new File[] {diskStoreDir});
-        final DiskStore diskStore1 = diskStoreFactory.create(diskStoreName1);
-        assertNotNull(diskStore1);
-
-        RegionFactory regionFactory =
-            cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
-        regionFactory.setDiskStoreName(diskStoreName1);
-        regionFactory.setDiskSynchronous(true);
-        regionFactory.create(region1);
-
-        regionFactory.setCompressor(SnappyCompressor.getDefaultInstance());
-        regionFactory.create(region2);
-
-        cache.close();
-        assertTrue(new File(diskStoreDir, "BACKUP" + diskStoreName1 + ".if").exists());
-      }
+    server1.invoke(() -> {
+      Cache cache = LocatorServerStartupRule.getCache();
+      Region r = cache.getRegion(REGION_1);
+      r.put("A", "B");
     });
 
-    CommandResult cmdResult = executeCommand("describe offline-disk-store --name=" + diskStoreName1
-        + " --disk-dirs=" + diskStoreDir.getAbsolutePath());
-    assertEquals(Result.Status.OK, cmdResult.getStatus());
-    String stringResult = commandResultToString(cmdResult);
-    assertEquals(3, countLinesInString(stringResult, false));
-    assertTrue(stringContainsLine(stringResult, ".*/" + region1
-        + ": -lru=none -concurrencyLevel=16 -initialCapacity=16 -loadFactor=0.75 -offHeap=false
-compressor=none -statisticsEnabled=false"));
-    assertTrue(stringContainsLine(stringResult, ".*/" + region2
-        + ": -lru=none -concurrencyLevel=16 -initialCapacity=16 -loadFactor=0.75 -offHeap=false
-compressor=org.apache.geode.compression.SnappyCompressor -statisticsEnabled=false"));
-
-    cmdResult = executeCommand("describe offline-disk-store --name=" + diskStoreName1
-        + " --disk-dirs=" + diskStoreDir.getAbsolutePath() + " --region=/" + region1);
-    stringResult = commandResultToString(cmdResult);
-    assertEquals(2, countLinesInString(stringResult, false));
-    assertTrue(stringContainsLine(stringResult, ".*/" + region1 + ": .*"));
-    assertFalse(stringContainsLine(stringResult, ".*/" + region2 + ": .*"));
-  }
+    gfsh.executeAndAssertThat("show missing-disk-stores")
+        .containsOutput("No missing disk store found");
 
-  @Test
-  public void testOfflineDiskStorePdxCommands() {
-    final Properties props = new Properties();
-    props.setProperty(MCAST_PORT, "0");
-    props.setProperty(START_LOCATOR,
-        "localhost[" + AvailablePortHelper.getRandomAvailableTCPPort() + "]");
-
-    final File diskStoreDir =
-        new File(new File(".").getAbsolutePath(), "DiskStoreCommandDUnitDiskStores");
-    diskStoreDir.mkdir();
-    this.filesToBeDeleted.add(diskStoreDir.getAbsolutePath());
-
-    final String diskStoreName1 = "DiskStore1";
-    final String region1 = "Region1";
-
-    final VM vm1 = Host.getHost(0).getVM(1);
-    vm1.invoke(new SerializableRunnable() {
-      public void run() {
-        final Cache cache =
-            new CacheFactory(props).setPdxPersistent(true).setPdxDiskStore(diskStoreName1).create();
-
-        DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
-        diskStoreFactory.setDiskDirs(new File[] {diskStoreDir});
-        final DiskStore diskStore1 = diskStoreFactory.create(diskStoreName1);
-        assertNotNull(diskStore1);
-
-        RegionFactory regionFactory =
-            cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
-        regionFactory.setDiskStoreName(diskStoreName1);
-        regionFactory.setDiskSynchronous(true);
-        Region r1 = regionFactory.create(region1);
-        r1.put("key-1", new PortfolioPdx(1));
-
-        cache.close();
-        assertTrue(new File(diskStoreDir, "BACKUP" + diskStoreName1 + ".if").exists());
-      }
-    });
-
-    CommandResult cmdResult = executeCommand("describe offline-disk-store --name=" + diskStoreName1
-        + " --disk-dirs=" + diskStoreDir.getAbsolutePath() + " --pdx=true");
-    String stringResult = commandResultToString(cmdResult);
-    assertTrue(stringContainsLine(stringResult, ".*PDX Types.*"));
-    assertTrue(stringContainsLine(stringResult,
-        ".*org\\.apache\\.geode\\.cache\\.query\\.data\\.PortfolioPdx.*"));
-    assertTrue(stringContainsLine(stringResult,
-        ".*org\\.apache\\.geode\\.cache\\.query\\.data\\.PositionPdx.*"));
-    assertTrue(stringContainsLine(stringResult, ".*PDX Enums.*"));
-    assertTrue(stringContainsLine(stringResult,
-        ".*org\\.apache\\.geode\\.cache\\.query\\.data\\.PortfolioPdx\\$Day.*"));
-  }
+    server1.invoke(LocatorServerStartupRule::stopMemberInThisVM);
 
-  @Test
-  public void testValidateDiskStore() {
-    setUpJmxManagerOnVm0ThenConnect(null);
-
-    final File diskStoreDir =
-        new File(new File(".").getAbsolutePath(), "DiskStoreCommandDUnitDiskStores");
-    diskStoreDir.mkdir();
-    this.filesToBeDeleted.add(diskStoreDir.getAbsolutePath());
-
-    final String diskStoreName1 = "DiskStore1";
-    final String region1 = "Region1";
-    final String region2 = "Region2";
-
-    final VM vm1 = Host.getHost(0).getVM(1);
-    vm1.invoke(new SerializableRunnable() {
-      public void run() {
-        final Cache cache = getCache();
-
-        DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
-        diskStoreFactory.setDiskDirs(new File[] {diskStoreDir});
-        final DiskStore diskStore1 = diskStoreFactory.create(diskStoreName1);
-        assertNotNull(diskStore1);
-
-        RegionFactory regionFactory =
-            cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
-        regionFactory.setDiskStoreName(diskStoreName1);
-        regionFactory.setDiskSynchronous(true);
-        regionFactory.create(region1);
-        regionFactory.create(region2);
-
-        cache.close();
-        assertTrue(new File(diskStoreDir, "BACKUP" + diskStoreName1 + ".if").exists());
-      }
+    server2.invoke(() -> {
+      Cache cache = LocatorServerStartupRule.getCache();
+      Region r = cache.getRegion(REGION_1);
+      r.put("A", "C");
     });
-    String command = "validate offline-disk-store --name=" + diskStoreName1 + " --disk-dirs="
-        + diskStoreDir.getAbsolutePath();
-    getLogWriter().info("testValidateDiskStore command: " + command);
-    CommandResult cmdResult = executeCommand(command);
-    if (cmdResult != null) {
-      String stringResult = commandResultToString(cmdResult);
-      getLogWriter().info("testValidateDiskStore cmdResult is stringResult " + stringResult);
-      assertEquals(Result.Status.OK, cmdResult.getStatus());
-      assertTrue(stringResult.contains("Total number of region entries in this disk store
is"));
-
-    } else {
-      getLogWriter().info("testValidateDiskStore cmdResult is null");
-      fail("Did not get CommandResult in testValidateDiskStore");
-    }
-  }
 
-  @Test
-  public void testExportOfflineDiskStore() throws Exception {
-    setUpJmxManagerOnVm0ThenConnect(null);
-
-    final File diskStoreDir =
-        new File(new File(".").getAbsolutePath(), "DiskStoreCommandDUnitDiskStores");
-    diskStoreDir.mkdir();
-    this.filesToBeDeleted.add(diskStoreDir.getAbsolutePath());
-    final File exportDir = new File(new File(".").getAbsolutePath(), "DiskStoreCommandDUnitExport");
-    exportDir.mkdir();
-    this.filesToBeDeleted.add(exportDir.getAbsolutePath());
-
-    final String diskStoreName1 = "DiskStore1";
-    final String region1 = "Region1";
-    final String region2 = "Region2";
-    final Map<String, String> entries = new HashMap<>();
-    entries.put("key1", "value1");
-    entries.put("key2", "value2");
-
-    final VM vm1 = Host.getHost(0).getVM(1);
-    vm1.invoke(new SerializableRunnable() {
-      public void run() {
-        final Cache cache = getCache();
-
-        DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
-        diskStoreFactory.setDiskDirs(new File[] {diskStoreDir});
-        final DiskStore diskStore1 = diskStoreFactory.create(diskStoreName1);
-        assertNotNull(diskStore1);
-
-        RegionFactory regionFactory =
-            cache.createRegionFactory(RegionShortcut.REPLICATE_PERSISTENT);
-        regionFactory.setDiskStoreName(diskStoreName1);
-        regionFactory.setDiskSynchronous(true);
-        Region r1 = regionFactory.create(region1);
-        r1.putAll(entries);
-        Region r2 = regionFactory.create(region2);
-        r2.putAll(entries);
-
-        cache.close();
-        assertTrue(new File(diskStoreDir, "BACKUP" + diskStoreName1 + ".if").exists());
-      }
-    });
-    String command = "export offline-disk-store --name=" + diskStoreName1 + " --disk-dirs="
-        + diskStoreDir.getAbsolutePath() + " --dir=" + exportDir;
-    getLogWriter().info("testExportDiskStore command" + command);
-    CommandResult cmdResult = executeCommand(command);
-    if (cmdResult != null) {
-      assertEquals(Result.Status.OK, cmdResult.getStatus());
-      String stringResult = commandResultToString(cmdResult);
-      SnapshotTestUtil.checkSnapshotEntries(exportDir, entries, diskStoreName1, region1);
-      SnapshotTestUtil.checkSnapshotEntries(exportDir, entries, diskStoreName1, region2);
-
-    } else {
-      getLogWriter().info("testExportOfflineDiskStore cmdResult is null");
-      fail("Did not get CommandResult in testExportOfflineDiskStore");
-    }
-  }
+    server2.invoke(LocatorServerStartupRule::stopMemberInThisVM);
 
-  /**
-   * Asserts that creating and destroying disk stores correctly updates the shared configuration.
-   */
-  @Test // FlakyTest: GEODE-1406
-  public void testCreateDestroyUpdatesSharedConfig() {
-    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 groupName = "testDiskStoreSharedConfigGroup";
-    final String diskStoreName = "testDiskStoreSharedConfigDiskStore";
-
-    // 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(new SerializableRunnable() {
-      @Override
-      public void run() {
-        final File locatorLogFile = new File("locator-" + locatorPort + ".log");
-        try {
-          final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort,
-              locatorLogFile, null, locatorProps);
-
-          WaitCriterion wc = new WaitCriterion() {
-            @Override
-            public boolean done() {
-              return locator.isSharedConfigurationRunning();
-            }
-
-            @Override
-            public String description() {
-              return "Waiting for shared configuration to be started";
-            }
-          };
-          waitForCriterion(wc, 5000, 500, true);
-        } catch (IOException ioex) {
-          fail("Unable to create a locator with a shared configuration");
-        }
-      }
-    });
+    props.setProperty("log-file", "");
+    rule.startServerVMAsync(1, props, locator.getPort());
 
 Review comment:
   To clarify my 2nd suggestion, I would keep the index based methods and add the MemberVM
based method for restarts. Or not, there will probably never be that many restart situations
so just following my 1st suggestion should be enough;

----------------------------------------------------------------
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:
users@infra.apache.org


> Refactor DiskStoreCommandsDUnitTest to use test rules
> -----------------------------------------------------
>
>                 Key: GEODE-3341
>                 URL: https://issues.apache.org/jira/browse/GEODE-3341
>             Project: Geode
>          Issue Type: Sub-task
>          Components: tests
>    Affects Versions: 1.2.0
>            Reporter: Emily Yeh
>            Assignee: Jens Deppe
>
> {{DiskStoreCommandsDUnitTest}} is using {{CliCommandTestBase}}, which is a deprecated
class. It should be refactored to use more current test rules.



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


Mime
View raw message