Search in sources :

Example 1 with CommandProcessor

use of org.apache.geode.management.internal.cli.remote.CommandProcessor in project geode by apache.

the class ShowDeadlockDUnitTest method testDistributedDeadlockWithFunction.

@Test
public void testDistributedDeadlockWithFunction() throws Exception {
    // Have two threads lock locks on different members in different orders.
    // This thread locks the lock member0 first, then member1.
    lockTheLocks(vm0, member1);
    // This thread locks the lock member1 first, then member0.
    lockTheLocks(vm1, member0);
    File outputFile = new File(temporaryFolder.getRoot(), "dependency.txt");
    String showDeadlockCommand = new CommandStringBuilder(CliStrings.SHOW_DEADLOCK).addOption(CliStrings.SHOW_DEADLOCK__DEPENDENCIES__FILE, outputFile.getName()).toString();
    CommandStatement showDeadlocksCommand = new CommandProcessor().createCommandStatement(showDeadlockCommand, Collections.emptyMap());
    Awaitility.await().atMost(1, TimeUnit.MINUTES).until(() -> {
        Result result = showDeadlocksCommand.process();
        try {
            result.saveIncomingFiles(temporaryFolder.getRoot().getAbsolutePath());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        String commandOutput = getResultAsString(result);
        assertEquals(true, commandOutput.startsWith(CliStrings.SHOW_DEADLOCK__DEADLOCK__DETECTED));
        assertEquals(true, result.getStatus().equals(Status.OK));
        assertTrue(outputFile.exists());
    });
}
Also used : CommandStatement(org.apache.geode.management.cli.CommandStatement) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) CommandProcessor(org.apache.geode.management.internal.cli.remote.CommandProcessor) IOException(java.io.IOException) File(java.io.File) Result(org.apache.geode.management.cli.Result) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 2 with CommandProcessor

use of org.apache.geode.management.internal.cli.remote.CommandProcessor in project geode by apache.

the class ShowDeadlockDUnitTest method testNoDeadlock.

@Test
public void testNoDeadlock() throws Exception {
    GemFireDeadlockDetector detect = new GemFireDeadlockDetector();
    assertEquals(null, detect.find().findCycle());
    File outputFile = new File(temporaryFolder.getRoot(), "dependency.txt");
    String showDeadlockCommand = new CommandStringBuilder(CliStrings.SHOW_DEADLOCK).addOption(CliStrings.SHOW_DEADLOCK__DEPENDENCIES__FILE, outputFile.getName()).toString();
    Result result = new CommandProcessor().createCommandStatement(showDeadlockCommand, Collections.emptyMap()).process();
    String commandOutput = getResultAsString(result);
    assertEquals(true, result.hasIncomingFiles());
    assertEquals(true, result.getStatus().equals(Status.OK));
    assertEquals(true, commandOutput.startsWith(CliStrings.SHOW_DEADLOCK__NO__DEADLOCK));
    result.saveIncomingFiles(temporaryFolder.getRoot().getAbsolutePath());
    assertTrue(outputFile.exists());
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) GemFireDeadlockDetector(org.apache.geode.distributed.internal.deadlock.GemFireDeadlockDetector) CommandProcessor(org.apache.geode.management.internal.cli.remote.CommandProcessor) File(java.io.File) Result(org.apache.geode.management.cli.Result) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 3 with CommandProcessor

use of org.apache.geode.management.internal.cli.remote.CommandProcessor in project geode by apache.

the class ShowMetricsDUnitTest method testShowMetricsRegionFromMember.

@Test
public void testShowMetricsRegionFromMember() throws ClassNotFoundException, IOException, InterruptedException {
    systemSetUp();
    Cache cache = getCache();
    final DistributedMember distributedMember = cache.getDistributedSystem().getDistributedMember();
    final String exportFileName = "regionOnAMemberReport.csv";
    final String regionName = "REGION1";
    SerializableCallable showMetricCmd = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            WaitCriterion wc = createMBeanWaitCriterion(4, regionName, distributedMember, 0);
            waitForCriterion(wc, 5000, 500, true);
            CommandProcessor commandProcessor = new CommandProcessor();
            Result result = commandProcessor.createCommandStatement("show metrics --region=" + regionName + " --member=" + distributedMember.getName() + " --file=" + exportFileName, 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);
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) CommandProcessor(org.apache.geode.management.internal.cli.remote.CommandProcessor) File(java.io.File) 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 4 with CommandProcessor

use of org.apache.geode.management.internal.cli.remote.CommandProcessor 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 5 with CommandProcessor

use of org.apache.geode.management.internal.cli.remote.CommandProcessor 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)

Aggregations

CommandProcessor (org.apache.geode.management.internal.cli.remote.CommandProcessor)13 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)13 Test (org.junit.Test)13 Result (org.apache.geode.management.cli.Result)12 File (java.io.File)7 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)7 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)7 Cache (org.apache.geode.cache.Cache)5 Properties (java.util.Properties)4 DistributedMember (org.apache.geode.distributed.DistributedMember)4 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)4 CacheServer (org.apache.geode.cache.server.CacheServer)2 DistributionConfig (org.apache.geode.distributed.internal.DistributionConfig)2 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)2 IOException (java.io.IOException)1 RuntimeMXBean (java.lang.management.RuntimeMXBean)1 Region (org.apache.geode.cache.Region)1 RegionFactory (org.apache.geode.cache.RegionFactory)1 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)1 Locator (org.apache.geode.distributed.Locator)1