Search in sources :

Example 71 with CommandResult

use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.

the class DiskStoreCommandsDUnitTest method testMissingDiskStore.

// GEODE-2102
@Category(FlakyTest.class)
@Test
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.getPid();
    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();
        }
    });
    // 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.getPid();
        vm.invoke(new SerializableRunnable() {

            public void run() {
                Cache cache = getCache();
                File diskStoreDirFile = new File(diskStoreName + vm.getPid());
                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");
        }
    });
    // 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();
        }
    });
    // 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();
        }
    });
    // 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
            }
        }
    });
    // 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);
        }
    });
    // 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.getPid()));
    // 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.getPid();
        vm.invoke(new SerializableRunnable() {

            public void run() {
                try {
                    FileUtils.deleteDirectory((new File(diskStoreName + vm.getPid())));
                } catch (IOException iex) {
                // There's nothing else we can do
                }
            }
        });
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) IOException(java.io.IOException) Properties(java.util.Properties) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) PersistentMemberManager(org.apache.geode.internal.cache.persistence.PersistentMemberManager) StringTokenizer(java.util.StringTokenizer) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) RegionFactory(org.apache.geode.cache.RegionFactory) VM(org.apache.geode.test.dunit.VM) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) File(java.io.File) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 72 with CommandResult

use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.

the class DiskStoreCommandsDUnitTest method testCreateDiskStore.

// GEODE-1206: random ports, BindException
@Category(FlakyTest.class)
@Test
public void testCreateDiskStore() {
    final String diskStore1Name = "testCreateDiskStore1";
    final String diskStore2Name = "testCreateDiskStore2";
    Properties localProps = new Properties();
    localProps.setProperty(GROUPS, "Group0");
    setUpJmxManagerOnVm0ThenConnect(localProps);
    CommandResult cmdResult = executeCommand(CliStrings.LIST_DISK_STORE);
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    assertTrue(commandResultToString(cmdResult).contains("No Disk Stores Found"));
    final VM vm1 = Host.getHost(0).getVM(1);
    final String vm1Name = "VM" + vm1.getPid();
    final File diskStore1Dir1 = new File(new File(".").getAbsolutePath(), diskStore1Name + ".1");
    this.filesToBeDeleted.add(diskStore1Dir1.getAbsolutePath());
    final File diskStore1Dir2 = new File(new File(".").getAbsolutePath(), diskStore1Name + ".2");
    this.filesToBeDeleted.add(diskStore1Dir2.getAbsolutePath());
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            diskStore1Dir1.mkdirs();
            diskStore1Dir2.mkdirs();
            Properties localProps = new Properties();
            localProps.setProperty(NAME, vm1Name);
            localProps.setProperty(GROUPS, "Group1");
            getSystem(localProps);
            getCache();
        }
    });
    final VM vm2 = Host.getHost(0).getVM(2);
    final String vm2Name = "VM" + vm2.getPid();
    final File diskStore2Dir = new File(new File(".").getAbsolutePath(), diskStore2Name);
    this.filesToBeDeleted.add(diskStore2Dir.getAbsolutePath());
    vm2.invoke(new SerializableRunnable() {

        public void run() {
            diskStore2Dir.mkdirs();
            Properties localProps = new Properties();
            localProps.setProperty(NAME, vm2Name);
            localProps.setProperty(GROUPS, "Group2");
            getSystem(localProps);
            getCache();
        }
    });
    CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_DISK_STORE);
    commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__NAME, diskStore1Name);
    commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__GROUP, "Group1");
    commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__ALLOW_FORCE_COMPACTION, "true");
    commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__AUTO_COMPACT, "false");
    commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__COMPACTION_THRESHOLD, "67");
    commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__MAX_OPLOG_SIZE, "355");
    commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__QUEUE_SIZE, "5321");
    commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__TIME_INTERVAL, "2023");
    commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__WRITE_BUFFER_SIZE, "3110");
    commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__DIRECTORY_AND_SIZE, diskStore1Dir1.getAbsolutePath() + "#1452637463," + diskStore1Dir2.getAbsolutePath());
    cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    String stringResult = commandResultToString(cmdResult);
    assertEquals(3, countLinesInString(stringResult, false));
    assertEquals(false, stringResult.contains("ERROR"));
    assertTrue(stringContainsLine(stringResult, vm1Name + ".*Success"));
    // Verify that the disk store was created on the correct member
    cmdResult = executeCommand(CliStrings.LIST_DISK_STORE);
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    stringResult = commandResultToString(cmdResult);
    assertEquals(3, countLinesInString(stringResult, false));
    assertTrue(stringContainsLine(stringResult, vm1Name + ".*" + diskStore1Name + " .*"));
    assertFalse(stringContainsLine(stringResult, vm2Name + ".*" + diskStore1Name + " .*"));
    // Verify that the disk store files were created in the correct directory.
    assertEquals(diskStore1Dir1.listFiles().length, 2);
    // Verify that all of the attributes of the disk store were set correctly.
    commandStringBuilder = new CommandStringBuilder(CliStrings.DESCRIBE_DISK_STORE);
    commandStringBuilder.addOption(CliStrings.DESCRIBE_DISK_STORE__MEMBER, vm1Name);
    commandStringBuilder.addOption(CliStrings.DESCRIBE_DISK_STORE__NAME, diskStore1Name);
    cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    stringResult = commandResultToString(cmdResult);
    assertTrue(stringContainsLine(stringResult, "Allow Force Compaction.*Yes"));
    assertTrue(stringContainsLine(stringResult, "Auto Compaction.*No"));
    assertTrue(stringContainsLine(stringResult, "Compaction Threshold.*67"));
    assertTrue(stringContainsLine(stringResult, "Max Oplog Size.*355"));
    assertTrue(stringContainsLine(stringResult, "Queue Size.*5321"));
    assertTrue(stringContainsLine(stringResult, "Time Interval.*2023"));
    assertTrue(stringContainsLine(stringResult, "Write Buffer Size.*3110"));
    assertTrue(stringContainsLine(stringResult, ".*" + diskStore1Name + ".1 .*1452637463"));
    assertTrue(stringContainsLine(stringResult, ".*" + diskStore1Name + ".2 .*" + Integer.MAX_VALUE));
    commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_DISK_STORE);
    commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__NAME, diskStore2Name);
    commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__GROUP, "Group2");
    commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__DIRECTORY_AND_SIZE, diskStore2Dir.getAbsolutePath());
    cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    stringResult = commandResultToString(cmdResult);
    assertEquals(3, countLinesInString(stringResult, false));
    assertTrue(stringContainsLine(stringResult, vm2Name + ".*Success"));
    // Verify that the second disk store was created correctly.
    cmdResult = executeCommand(CliStrings.LIST_DISK_STORE);
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    stringResult = commandResultToString(cmdResult);
    assertEquals(4, countLinesInString(stringResult, false));
    assertTrue(stringContainsLine(stringResult, vm1Name + ".*" + diskStore1Name + " .*"));
    assertFalse(stringContainsLine(stringResult, vm2Name + ".*" + diskStore1Name + " .*"));
    assertFalse(stringContainsLine(stringResult, vm1Name + ".*" + diskStore2Name + " .*"));
    assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + diskStore2Name + " .*"));
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Properties(java.util.Properties) File(java.io.File) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 73 with CommandResult

use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.

the class DiskStoreCommandsDUnitTest method testDestroyDiskStore.

@Test
public void testDestroyDiskStore() {
    final String diskStore1Name = "testDestroyDiskStore1";
    final String diskStore2Name = "testDestroyDiskStore2";
    final String region1Name = "testDestroyDiskStoreRegion1";
    final String region2Name = "testDestroyDiskStoreRegion2";
    Properties localProps = new Properties();
    localProps.setProperty(GROUPS, "Group0");
    setUpJmxManagerOnVm0ThenConnect(localProps);
    CommandResult cmdResult = executeCommand(CliStrings.LIST_DISK_STORE);
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    assertTrue(commandResultToString(cmdResult).contains("No Disk Stores Found"));
    final VM vm1 = Host.getHost(0).getVM(1);
    final String vm1Name = "VM" + vm1.getPid();
    final File diskStore1Dir1 = new File(new File(".").getAbsolutePath(), diskStore1Name + ".1");
    this.filesToBeDeleted.add(diskStore1Dir1.getAbsolutePath());
    final File diskStore2Dir1 = new File(new File(".").getAbsolutePath(), diskStore2Name + ".1");
    this.filesToBeDeleted.add(diskStore2Dir1.getAbsolutePath());
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            diskStore1Dir1.mkdirs();
            diskStore2Dir1.mkdirs();
            Properties localProps = new Properties();
            localProps.setProperty(NAME, vm1Name);
            localProps.setProperty(GROUPS, "Group1,Group2");
            getSystem(localProps);
            Cache cache = getCache();
            DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
            diskStoreFactory.setDiskDirs(new File[] { diskStore1Dir1 });
            diskStoreFactory.create(diskStore1Name);
            diskStoreFactory.setDiskDirs(new File[] { diskStore2Dir1 });
            diskStoreFactory.create(diskStore2Name);
        }
    });
    final VM vm2 = Host.getHost(0).getVM(2);
    final String vm2Name = "VM" + vm2.getPid();
    final File diskStore1Dir2 = new File(new File(".").getAbsolutePath(), diskStore1Name + ".2");
    this.filesToBeDeleted.add(diskStore1Dir2.getAbsolutePath());
    final File diskStore2Dir2 = new File(new File(".").getAbsolutePath(), diskStore2Name + ".2");
    this.filesToBeDeleted.add(diskStore2Dir2.getAbsolutePath());
    vm2.invoke(new SerializableRunnable() {

        public void run() {
            diskStore1Dir2.mkdirs();
            diskStore2Dir2.mkdirs();
            Properties localProps = new Properties();
            localProps.setProperty(NAME, vm2Name);
            localProps.setProperty(GROUPS, "Group2");
            getSystem(localProps);
            Cache cache = getCache();
            DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
            diskStoreFactory.setDiskDirs(new File[] { diskStore1Dir2 });
            diskStoreFactory.create(diskStore1Name);
            RegionFactory regionFactory = cache.createRegionFactory();
            regionFactory.setDiskStoreName(diskStore1Name);
            regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
            regionFactory.create(region1Name);
            regionFactory.create(region2Name);
            diskStoreFactory.setDiskDirs(new File[] { diskStore2Dir2 });
            diskStoreFactory.create(diskStore2Name);
        }
    });
    // TEST DELETING ON 1 MEMBER
    CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_DISK_STORE);
    commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__NAME, diskStore1Name);
    commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__GROUP, "Group1");
    cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    String stringResult = commandResultToString(cmdResult);
    assertEquals(3, countLinesInString(stringResult, false));
    assertEquals(false, stringResult.contains("ERROR"));
    assertTrue(stringContainsLine(stringResult, vm1Name + ".*Success"));
    // Verify that the disk store was destroyed on the correct member
    cmdResult = executeCommand(CliStrings.LIST_DISK_STORE);
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    stringResult = commandResultToString(cmdResult);
    assertEquals(5, countLinesInString(stringResult, false));
    assertFalse(stringContainsLine(stringResult, vm1Name + ".*" + diskStore1Name + " .*"));
    assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + diskStore1Name + " .*"));
    // Verify that the disk store files were deleted from the correct directory.
    assertEquals(0, diskStore1Dir1.listFiles().length);
    assertEquals(4, diskStore1Dir2.listFiles().length);
    // TEST DELETING ON 2 MEMBERS
    commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_DISK_STORE);
    commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__NAME, diskStore2Name);
    commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__GROUP, "Group2");
    cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    stringResult = commandResultToString(cmdResult);
    assertEquals(4, countLinesInString(stringResult, false));
    assertEquals(false, stringResult.contains("ERROR"));
    assertTrue(stringContainsLine(stringResult, vm1Name + ".*Success"));
    assertTrue(stringContainsLine(stringResult, vm2Name + ".*Success"));
    // Verify that the disk store was destroyed on the correct member
    cmdResult = executeCommand(CliStrings.LIST_DISK_STORE);
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    stringResult = commandResultToString(cmdResult);
    assertEquals(3, countLinesInString(stringResult, false));
    assertFalse(stringContainsLine(stringResult, vm1Name + ".*" + diskStore2Name + " .*"));
    assertFalse(stringContainsLine(stringResult, vm2Name + ".*" + diskStore2Name + " .*"));
    // Verify that the disk store files were deleted from the correct directories.
    assertEquals(0, diskStore2Dir1.listFiles().length);
    assertEquals(0, diskStore2Dir2.listFiles().length);
    // TEST FOR DISK STORE IN USE
    commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_DISK_STORE);
    commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__NAME, diskStore1Name);
    commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__GROUP, "Group2");
    cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    stringResult = commandResultToString(cmdResult);
    assertEquals(4, countLinesInString(stringResult, false));
    assertEquals(false, stringResult.contains("ERROR"));
    assertTrue(stringContainsLine(stringResult, vm1Name + ".*Disk store not found on this member"));
    assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + region1Name + ".*" + region2Name + ".*"));
    // TEST DELETING ON ALL MEMBERS
    vm2.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion(region1Name);
            region.destroyRegion();
            region = cache.getRegion(region2Name);
            region.destroyRegion();
        }
    });
    commandStringBuilder = new CommandStringBuilder(CliStrings.DESTROY_DISK_STORE);
    commandStringBuilder.addOption(CliStrings.DESTROY_DISK_STORE__NAME, diskStore1Name);
    cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    stringResult = commandResultToString(cmdResult);
    assertEquals(5, countLinesInString(stringResult, false));
    assertEquals(false, stringResult.contains("ERROR"));
    assertTrue(stringContainsLine(stringResult, "Manager.*Disk store not found on this member"));
    assertTrue(stringContainsLine(stringResult, vm1Name + ".*Disk store not found on this member"));
    assertTrue(stringContainsLine(stringResult, vm2Name + ".*Success"));
    // Verify that there are no disk stores left.
    cmdResult = executeCommand(CliStrings.LIST_DISK_STORE);
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    assertTrue(commandResultToString(cmdResult).contains("No Disk Stores Found"));
    // Verify that the disk store files were deleted from the correct directory.
    assertEquals(0, diskStore1Dir2.listFiles().length);
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) Properties(java.util.Properties) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 74 with CommandResult

use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.

the class CreateAlterDestroyRegionCommandsDUnitTest method testCreateRegionWithBadCompressor.

/**
   * Asserts that the "compressor" option for the "create region" command fails for an unrecognized
   * compressorc.
   */
@Test
public void testCreateRegionWithBadCompressor() {
    setUpJmxManagerOnVm0ThenConnect(null);
    VM vm = Host.getHost(0).getVM(1);
    // Create a cache in vm 1
    vm.invoke(() -> {
        assertNotNull(getCache());
    });
    // Create a region with an unrecognized compressor
    CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_REGION);
    commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGION, "compressedRegion");
    commandStringBuilder.addOption(CliStrings.CREATE_REGION__REGIONSHORTCUT, "REPLICATE");
    commandStringBuilder.addOption(CliStrings.CREATE_REGION__COMPRESSOR, "BAD_COMPRESSOR");
    CommandResult cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.ERROR, cmdResult.getStatus());
    // Assert that our region was not created
    vm.invoke(() -> {
        Region region = getCache().getRegion("compressedRegion");
        assertNull(region);
    });
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) VM(org.apache.geode.test.dunit.VM) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 75 with CommandResult

use of org.apache.geode.management.internal.cli.result.CommandResult in project geode by apache.

the class CreateAlterDestroyRegionCommandsDUnitTest method deployJarFilesForRegionAlter.

/**
   * Deploys JAR files which contain classes to be instantiated by the "alter region" test.
   */
private void deployJarFilesForRegionAlter() throws IOException {
    ClassBuilder classBuilder = new ClassBuilder();
    final File jarFile1 = new File(new File(".").getAbsolutePath(), "testAlterRegion1.jar");
    this.filesToBeDeleted.add(jarFile1.getAbsolutePath());
    final File jarFile2 = new File(new File(".").getAbsolutePath(), "testAlterRegion2.jar");
    this.filesToBeDeleted.add(jarFile2.getAbsolutePath());
    final File jarFile3 = new File(new File(".").getAbsolutePath(), "testAlterRegion3.jar");
    this.filesToBeDeleted.add(jarFile3.getAbsolutePath());
    final File jarFile4 = new File(new File(".").getAbsolutePath(), "testAlterRegion4.jar");
    this.filesToBeDeleted.add(jarFile4.getAbsolutePath());
    final File jarFile5 = new File(new File(".").getAbsolutePath(), "testAlterRegion5.jar");
    this.filesToBeDeleted.add(jarFile5.getAbsolutePath());
    byte[] jarBytes = classBuilder.createJarFromClassContent("com/cadrdunit/RegionAlterCacheListenerA", "package com.cadrdunit;" + "import org.apache.geode.cache.util.CacheListenerAdapter;" + "public class RegionAlterCacheListenerA extends CacheListenerAdapter {}");
    writeJarBytesToFile(jarFile1, jarBytes);
    CommandResult cmdResult = executeCommand("deploy --jar=testAlterRegion1.jar");
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    jarBytes = classBuilder.createJarFromClassContent("com/cadrdunit/RegionAlterCacheListenerB", "package com.cadrdunit;" + "import org.apache.geode.cache.util.CacheListenerAdapter;" + "public class RegionAlterCacheListenerB extends CacheListenerAdapter {}");
    writeJarBytesToFile(jarFile2, jarBytes);
    cmdResult = executeCommand("deploy --jar=testAlterRegion2.jar");
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    jarBytes = classBuilder.createJarFromClassContent("com/cadrdunit/RegionAlterCacheListenerC", "package com.cadrdunit;" + "import org.apache.geode.cache.util.CacheListenerAdapter;" + "public class RegionAlterCacheListenerC extends CacheListenerAdapter {}");
    writeJarBytesToFile(jarFile3, jarBytes);
    cmdResult = executeCommand("deploy --jar=testAlterRegion3.jar");
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    jarBytes = classBuilder.createJarFromClassContent("com/cadrdunit/RegionAlterCacheLoader", "package com.cadrdunit;" + "import org.apache.geode.cache.CacheLoader;" + "import org.apache.geode.cache.CacheLoaderException;" + "import org.apache.geode.cache.LoaderHelper;" + "public class RegionAlterCacheLoader implements CacheLoader {" + "public void close() {}" + "public Object load(LoaderHelper helper) throws CacheLoaderException {return null;}}");
    writeJarBytesToFile(jarFile4, jarBytes);
    cmdResult = executeCommand("deploy --jar=testAlterRegion4.jar");
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    jarBytes = classBuilder.createJarFromClassContent("com/cadrdunit/RegionAlterCacheWriter", "package com.cadrdunit;" + "import org.apache.geode.cache.util.CacheWriterAdapter;" + "public class RegionAlterCacheWriter extends CacheWriterAdapter {}");
    writeJarBytesToFile(jarFile5, jarBytes);
    cmdResult = executeCommand("deploy --jar=testAlterRegion5.jar");
    assertEquals(Result.Status.OK, cmdResult.getStatus());
}
Also used : ClassBuilder(org.apache.geode.internal.ClassBuilder) File(java.io.File) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult)

Aggregations

CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)270 Test (org.junit.Test)222 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)208 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)131 Properties (java.util.Properties)94 VM (org.apache.geode.test.dunit.VM)80 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)71 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)67 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)45 File (java.io.File)44 Cache (org.apache.geode.cache.Cache)43 Region (org.apache.geode.cache.Region)39 Category (org.junit.experimental.categories.Category)33 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)32 InternalCache (org.apache.geode.internal.cache.InternalCache)29 DistributedMember (org.apache.geode.distributed.DistributedMember)26 ArrayList (java.util.ArrayList)16 RegionFactory (org.apache.geode.cache.RegionFactory)15 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)15 Gfsh (org.apache.geode.management.internal.cli.shell.Gfsh)14