use of org.apache.geode.management.internal.cli.util.CommandStringBuilder 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.util.CommandStringBuilder 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"));
}
use of org.apache.geode.management.internal.cli.util.CommandStringBuilder 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));
}
use of org.apache.geode.management.internal.cli.util.CommandStringBuilder in project geode by apache.
the class ExportLogsDUnitTest method startAndEndDateCanIncludeLogs.
@Test
public void startAndEndDateCanIncludeLogs() throws Exception {
ZonedDateTime now = LocalDateTime.now().atZone(ZoneId.systemDefault());
ZonedDateTime yesterday = now.minusDays(1);
ZonedDateTime tomorrow = now.plusDays(1);
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(ONLY_DATE_FORMAT);
CommandStringBuilder commandStringBuilder = new CommandStringBuilder("export logs");
commandStringBuilder.addOption("start-time", dateTimeFormatter.format(yesterday));
commandStringBuilder.addOption("end-time", dateTimeFormatter.format(tomorrow));
commandStringBuilder.addOption("log-level", "debug");
gfshConnector.executeAndVerifyCommand(commandStringBuilder.toString());
Set<String> acceptedLogLevels = Stream.of("info", "error", "debug").collect(toSet());
verifyZipFileContents(acceptedLogLevels);
}
use of org.apache.geode.management.internal.cli.util.CommandStringBuilder in project geode by apache.
the class DiskStoreCommandsDUnitTest method testCreateDiskStore.
// GEODE-1206: random ports, BindException
@Category(FlakyTest.class)
@Test
public void testCreateDiskStore() {
final String diskStore1Name = "testCreateDiskStore1";
final String diskStore2Name = "testCreateDiskStore2";
Properties localProps = new Properties();
localProps.setProperty(GROUPS, "Group0");
setUpJmxManagerOnVm0ThenConnect(localProps);
CommandResult cmdResult = executeCommand(CliStrings.LIST_DISK_STORE);
assertEquals(Result.Status.OK, cmdResult.getStatus());
assertTrue(commandResultToString(cmdResult).contains("No Disk Stores Found"));
final VM vm1 = Host.getHost(0).getVM(1);
final String vm1Name = "VM" + vm1.getPid();
final File diskStore1Dir1 = new File(new File(".").getAbsolutePath(), diskStore1Name + ".1");
this.filesToBeDeleted.add(diskStore1Dir1.getAbsolutePath());
final File diskStore1Dir2 = new File(new File(".").getAbsolutePath(), diskStore1Name + ".2");
this.filesToBeDeleted.add(diskStore1Dir2.getAbsolutePath());
vm1.invoke(new SerializableRunnable() {
public void run() {
diskStore1Dir1.mkdirs();
diskStore1Dir2.mkdirs();
Properties localProps = new Properties();
localProps.setProperty(NAME, vm1Name);
localProps.setProperty(GROUPS, "Group1");
getSystem(localProps);
getCache();
}
});
final VM vm2 = Host.getHost(0).getVM(2);
final String vm2Name = "VM" + vm2.getPid();
final File diskStore2Dir = new File(new File(".").getAbsolutePath(), diskStore2Name);
this.filesToBeDeleted.add(diskStore2Dir.getAbsolutePath());
vm2.invoke(new SerializableRunnable() {
public void run() {
diskStore2Dir.mkdirs();
Properties localProps = new Properties();
localProps.setProperty(NAME, vm2Name);
localProps.setProperty(GROUPS, "Group2");
getSystem(localProps);
getCache();
}
});
CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_DISK_STORE);
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__NAME, diskStore1Name);
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__GROUP, "Group1");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__ALLOW_FORCE_COMPACTION, "true");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__AUTO_COMPACT, "false");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__COMPACTION_THRESHOLD, "67");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__MAX_OPLOG_SIZE, "355");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__QUEUE_SIZE, "5321");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__TIME_INTERVAL, "2023");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__WRITE_BUFFER_SIZE, "3110");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__DIRECTORY_AND_SIZE, diskStore1Dir1.getAbsolutePath() + "#1452637463," + diskStore1Dir2.getAbsolutePath());
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
String stringResult = commandResultToString(cmdResult);
assertEquals(3, countLinesInString(stringResult, false));
assertEquals(false, stringResult.contains("ERROR"));
assertTrue(stringContainsLine(stringResult, vm1Name + ".*Success"));
// Verify that the disk store was created on the correct member
cmdResult = executeCommand(CliStrings.LIST_DISK_STORE);
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
assertEquals(3, countLinesInString(stringResult, false));
assertTrue(stringContainsLine(stringResult, vm1Name + ".*" + diskStore1Name + " .*"));
assertFalse(stringContainsLine(stringResult, vm2Name + ".*" + diskStore1Name + " .*"));
// Verify that the disk store files were created in the correct directory.
assertEquals(diskStore1Dir1.listFiles().length, 2);
// Verify that all of the attributes of the disk store were set correctly.
commandStringBuilder = new CommandStringBuilder(CliStrings.DESCRIBE_DISK_STORE);
commandStringBuilder.addOption(CliStrings.DESCRIBE_DISK_STORE__MEMBER, vm1Name);
commandStringBuilder.addOption(CliStrings.DESCRIBE_DISK_STORE__NAME, diskStore1Name);
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
assertTrue(stringContainsLine(stringResult, "Allow Force Compaction.*Yes"));
assertTrue(stringContainsLine(stringResult, "Auto Compaction.*No"));
assertTrue(stringContainsLine(stringResult, "Compaction Threshold.*67"));
assertTrue(stringContainsLine(stringResult, "Max Oplog Size.*355"));
assertTrue(stringContainsLine(stringResult, "Queue Size.*5321"));
assertTrue(stringContainsLine(stringResult, "Time Interval.*2023"));
assertTrue(stringContainsLine(stringResult, "Write Buffer Size.*3110"));
assertTrue(stringContainsLine(stringResult, ".*" + diskStore1Name + ".1 .*1452637463"));
assertTrue(stringContainsLine(stringResult, ".*" + diskStore1Name + ".2 .*" + Integer.MAX_VALUE));
commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_DISK_STORE);
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__NAME, diskStore2Name);
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__GROUP, "Group2");
commandStringBuilder.addOption(CliStrings.CREATE_DISK_STORE__DIRECTORY_AND_SIZE, diskStore2Dir.getAbsolutePath());
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
assertEquals(3, countLinesInString(stringResult, false));
assertTrue(stringContainsLine(stringResult, vm2Name + ".*Success"));
// Verify that the second disk store was created correctly.
cmdResult = executeCommand(CliStrings.LIST_DISK_STORE);
assertEquals(Result.Status.OK, cmdResult.getStatus());
stringResult = commandResultToString(cmdResult);
assertEquals(4, countLinesInString(stringResult, false));
assertTrue(stringContainsLine(stringResult, vm1Name + ".*" + diskStore1Name + " .*"));
assertFalse(stringContainsLine(stringResult, vm2Name + ".*" + diskStore1Name + " .*"));
assertFalse(stringContainsLine(stringResult, vm1Name + ".*" + diskStore2Name + " .*"));
assertTrue(stringContainsLine(stringResult, vm2Name + ".*" + diskStore2Name + " .*"));
}
Aggregations