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());
});
}
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());
}
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);
}
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);
}
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();
}
Aggregations