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