Search in sources :

Example 21 with CommandResult

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

the class ShellCommandsDUnitTest method testHistoryWithFileName.

@Test
public void testHistoryWithFileName() {
    Gfsh gfshInstance = Gfsh.getCurrentInstance();
    if (gfshInstance == null) {
        fail("In testHistory command gfshInstance is null");
    }
    // Generate a line of history
    executeCommand("help");
    String historyFileName = gfshInstance.getGfshConfig().getHistoryFileName();
    File historyFile = new File(historyFileName);
    historyFile.deleteOnExit();
    String fileName = historyFile.getParent();
    fileName = fileName + File.separator + getClass().getSimpleName() + "_" + getName() + "-exported.history";
    String command = "history --file=" + fileName;
    CommandResult cmdResult = executeCommand(command);
    printCommandOutput(cmdResult);
    if (cmdResult != null) {
        assertEquals(Result.Status.OK, cmdResult.getStatus());
    } else {
        fail("testHistory failed");
    }
    assertTrue(historyFile.exists());
    assertTrue(0L != historyFile.length());
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) 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) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 22 with CommandResult

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

the class ShowMetricsDUnitTest method testShowMetricsDefault.

/**
   * tests the default version of "show metrics"
   */
@Test
public void testShowMetricsDefault() {
    setUpJmxManagerOnVm0ThenConnect(null);
    createLocalSetUp();
    final VM vm1 = Host.getHost(0).getVM(1);
    final String vm1Name = "VM" + vm1.getPid();
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            Properties localProps = new Properties();
            localProps.setProperty(NAME, vm1Name);
            getSystem(localProps);
            Cache cache = getCache();
            RegionFactory<Integer, Integer> dataRegionFactory = cache.createRegionFactory(RegionShortcut.REPLICATE);
            Region region = dataRegionFactory.create("REGION1");
        }
    });
    SerializableCallable showMetricCmd = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            WaitCriterion wc = createMBeanWaitCriterion(1, "", null, 0);
            waitForCriterion(wc, 5000, 500, true);
            CommandProcessor commandProcessor = new CommandProcessor();
            Result result = commandProcessor.createCommandStatement("show metrics", Collections.EMPTY_MAP).process();
            String resultStr = commandResultToString((CommandResult) result);
            getLogWriter().info(resultStr);
            assertEquals(resultStr, true, result.getStatus().equals(Status.OK));
            return resultStr;
        }
    };
    // Invoke the command in the Manager VM
    final VM managerVm = Host.getHost(0).getVM(0);
    Object managerResultObj = managerVm.invoke(showMetricCmd);
    String managerResult = (String) managerResultObj;
    getLogWriter().info("#SB Manager");
    getLogWriter().info(managerResult);
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) Region(org.apache.geode.cache.Region) CommandProcessor(org.apache.geode.management.internal.cli.remote.CommandProcessor) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Cache(org.apache.geode.cache.Cache) Result(org.apache.geode.management.cli.Result) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 23 with CommandResult

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

the class ShowMetricsDUnitTest method testShowMetricsMember.

// GEODE-1764
@Category(FlakyTest.class)
@Test
public void testShowMetricsMember() throws ClassNotFoundException, IOException, InterruptedException {
    systemSetUp();
    Cache cache = getCache();
    final DistributedMember distributedMember = cache.getDistributedSystem().getDistributedMember();
    final String exportFileName = "memberMetricReport.csv";
    int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(1);
    CacheServer cs = getCache().addCacheServer();
    cs.setPort(ports[0]);
    cs.start();
    final int cacheServerPort = cs.getPort();
    SerializableCallable showMetricCmd = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            WaitCriterion wc = createMBeanWaitCriterion(3, "", distributedMember, 0);
            waitForCriterion(wc, 5000, 500, true);
            wc = createMBeanWaitCriterion(5, "", distributedMember, cacheServerPort);
            waitForCriterion(wc, 10000, 500, true);
            final String command = CliStrings.SHOW_METRICS + " --" + CliStrings.SHOW_METRICS__MEMBER + "=" + distributedMember.getId() + " --" + CliStrings.SHOW_METRICS__CACHESERVER__PORT + "=" + cacheServerPort + " --" + CliStrings.SHOW_METRICS__FILE + "=" + exportFileName;
            CommandProcessor commandProcessor = new CommandProcessor();
            Result result = commandProcessor.createCommandStatement(command, Collections.EMPTY_MAP).process();
            String resultAsString = commandResultToString((CommandResult) result);
            assertEquals(resultAsString, true, result.getStatus().equals(Status.OK));
            assertTrue(result.hasIncomingFiles());
            result.saveIncomingFiles(null);
            File file = new File(exportFileName);
            file.deleteOnExit();
            assertTrue(file.exists());
            file.delete();
            return resultAsString;
        }
    };
    // Invoke the command in the Manager VM
    final VM managerVm = Host.getHost(0).getVM(0);
    Object managerResultObj = managerVm.invoke(showMetricCmd);
    String managerResult = (String) managerResultObj;
    getLogWriter().info("#SB Manager");
    getLogWriter().info(managerResult);
    cs.stop();
}
Also used : Result(org.apache.geode.management.cli.Result) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedMember(org.apache.geode.distributed.DistributedMember) CacheServer(org.apache.geode.cache.server.CacheServer) CommandProcessor(org.apache.geode.management.internal.cli.remote.CommandProcessor) File(java.io.File) Cache(org.apache.geode.cache.Cache) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 24 with CommandResult

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

the class ShowStackTraceDUnitTest method testExportStacktraceWithNonTXTFile.

/***
   * Tests the behavior of the show stack-trace command to verify that files with any extension are
   * allowed Refer: GEODE-734
   *
   * @throws ClassNotFoundException
   * @throws IOException
   */
@Test
public void testExportStacktraceWithNonTXTFile() throws ClassNotFoundException, IOException {
    setupSystem();
    // Test non txt extension file is allowed
    File stacktracesFile = workDirectory.newFile("allStackTraces.log");
    CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
    commandStringBuilder.addOption(CliStrings.EXPORT_STACKTRACE__FILE, stacktracesFile.getCanonicalPath());
    String exportCommandString = commandStringBuilder.toString();
    getLogWriter().info("CommandString : " + exportCommandString);
    CommandResult exportCommandResult = executeCommand(exportCommandString);
    getLogWriter().info("Output : \n" + commandResultToString(exportCommandResult));
    assertTrue(exportCommandResult.getStatus().equals(Status.OK));
    // test file with-out any extension
    File allStacktracesFile = workDirectory.newFile("allStackTraces");
    commandStringBuilder = new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
    commandStringBuilder.addOption(CliStrings.EXPORT_STACKTRACE__FILE, allStacktracesFile.getCanonicalPath());
    exportCommandString = commandStringBuilder.toString();
    getLogWriter().info("CommandString : " + exportCommandString);
    exportCommandResult = executeCommand(exportCommandString);
    getLogWriter().info("Output : \n" + commandResultToString(exportCommandResult));
    assertTrue(exportCommandResult.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 25 with CommandResult

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

the class ShowStackTraceDUnitTest method testExportStacktraceFilePresentWithAbort.

/***
   * Tests the behavior of the show stack-trace command when file is already present and when
   * abort-if-file-exists option is set to true. As a result it should fail with ERROR status
   *
   * @throws ClassNotFoundException
   * @throws IOException
   */
@Test
public void testExportStacktraceFilePresentWithAbort() throws ClassNotFoundException, IOException, GfJsonException {
    setupSystem();
    File stacktracesFile = workDirectory.newFile("allStackTraces.log");
    CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
    commandStringBuilder.addOption(CliStrings.EXPORT_STACKTRACE__FILE, stacktracesFile.getCanonicalPath());
    commandStringBuilder.addOption(CliStrings.EXPORT_STACKTRACE__FAIL__IF__FILE__PRESENT, Boolean.TRUE.toString());
    String exportCommandString = commandStringBuilder.toString();
    getLogWriter().info("CommandString : " + exportCommandString);
    CommandResult exportCommandResult = executeCommand(exportCommandString);
    getLogWriter().info("Output : \n" + commandResultToString(exportCommandResult));
    assertTrue(exportCommandResult.getStatus().equals(Status.ERROR));
    assertTrue(((String) exportCommandResult.getResultData().getGfJsonObject().getJSONObject("content").getJSONArray("message").get(0)).contains("file " + stacktracesFile.getCanonicalPath() + " already present"));
}
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)

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