Search in sources :

Example 26 with CommandResult

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

the class ShowStackTraceDUnitTest method testExportStacktrace.

/***
   * Tests the default behavior of the show stack-trace command
   *
   * @throws ClassNotFoundException
   * @throws IOException
   */
@Test
public void testExportStacktrace() throws ClassNotFoundException, IOException {
    setupSystem();
    File allStacktracesFile = workDirectory.newFile("allStackTraces.txt");
    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
    csb.addOption(CliStrings.EXPORT_STACKTRACE__FILE, allStacktracesFile.getCanonicalPath());
    String commandString = csb.toString();
    getLogWriter().info("CommandString : " + commandString);
    CommandResult commandResult = executeCommand(commandString);
    getLogWriter().info("Output : \n" + commandResultToString(commandResult));
    assertTrue(commandResult.getStatus().equals(Status.OK));
    File mgrStacktraceFile = workDirectory.newFile("managerStacktrace.txt");
    csb = new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
    csb.addOption(CliStrings.EXPORT_STACKTRACE__FILE, mgrStacktraceFile.getCanonicalPath());
    csb.addOption(CliStrings.EXPORT_STACKTRACE__MEMBER, "Manager");
    commandString = csb.toString();
    getLogWriter().info("CommandString : " + commandString);
    commandResult = executeCommand(commandString);
    getLogWriter().info("Output : \n" + commandResultToString(commandResult));
    assertTrue(commandResult.getStatus().equals(Status.OK));
    File serverStacktraceFile = workDirectory.newFile("serverStacktrace.txt");
    csb = new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
    csb.addOption(CliStrings.EXPORT_STACKTRACE__FILE, serverStacktraceFile.getCanonicalPath());
    csb.addOption(CliStrings.EXPORT_STACKTRACE__MEMBER, "Server");
    commandString = csb.toString();
    getLogWriter().info("CommandString : " + commandString);
    commandResult = executeCommand(commandString);
    getLogWriter().info("Output : \n" + commandResultToString(commandResult));
    assertTrue(commandResult.getStatus().equals(Status.OK));
    File groupStacktraceFile = workDirectory.newFile("groupstacktrace.txt");
    csb = new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
    csb.addOption(CliStrings.EXPORT_STACKTRACE__FILE, groupStacktraceFile.getCanonicalPath());
    csb.addOption(CliStrings.EXPORT_STACKTRACE__GROUP, "G2");
    commandString = csb.toString();
    getLogWriter().info("CommandString : " + commandString);
    commandResult = executeCommand(commandString);
    getLogWriter().info("Output : \n" + commandResultToString(commandResult));
    assertTrue(commandResult.getStatus().equals(Status.OK));
    File wrongStackTraceFile = workDirectory.newFile("wrongStackTrace.txt");
    csb = new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
    csb.addOption(CliStrings.EXPORT_STACKTRACE__FILE, wrongStackTraceFile.getCanonicalPath());
    csb.addOption(CliStrings.EXPORT_STACKTRACE__MEMBER, "WrongMember");
    commandString = csb.toString();
    getLogWriter().info("CommandString : " + commandString);
    commandResult = executeCommand(commandString);
    getLogWriter().info("Output : \n" + commandResultToString(commandResult));
    assertFalse(commandResult.getStatus().equals(Status.OK));
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) File(java.io.File) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 27 with CommandResult

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

the class ExportLogsDUnitTest method testExportedZipFileTooBig.

@Test
public void testExportedZipFileTooBig() throws Exception {
    CommandResult result = gfshConnector.executeCommand("export logs --file-size-limit=10k");
    assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
}
Also used : CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 28 with CommandResult

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

the class DiskStoreCommandsDUnitTest method testOfflineDiskStorePdxCommands.

@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.*"));
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PortfolioPdx(org.apache.geode.cache.query.data.PortfolioPdx) Properties(java.util.Properties) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DiskStore(org.apache.geode.cache.DiskStore) 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) CacheFactory(org.apache.geode.cache.CacheFactory) File(java.io.File) 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 29 with CommandResult

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

the class DiskStoreCommandsDUnitTest method testExportOfflineDiskStore.

@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<String, String>();
    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");
    }
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) RegionFactory(org.apache.geode.cache.RegionFactory) HashMap(java.util.HashMap) 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) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache) 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 30 with CommandResult

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

the class DiskStoreCommandsDUnitTest method testMissingDiskStoreCommandWithColocation.

@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.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);
                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");
        }
    });
    // 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();
        }
    });
    // 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();
        }
    });
    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
            }
        }
    });
    // 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.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 : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) IOException(java.io.IOException) Properties(java.util.Properties) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) 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) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) 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) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

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