use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.
the class ShellCommandsDUnitTest method testEchoForSingleVariable.
@Test
public void testEchoForSingleVariable() {
Gfsh gfshInstance = Gfsh.getCurrentInstance();
if (gfshInstance == null) {
fail("In testEcho command gfshInstance is null");
}
gfshInstance.setEnvProperty("TESTSYS", "SYS_VALUE");
printAllEnvs(gfshInstance);
String command = "echo --string=${TESTSYS}";
CommandResult cmdResult = executeCommand(command);
printCommandOutput(cmdResult);
if (cmdResult != null) {
assertEquals(Result.Status.OK, cmdResult.getStatus());
String stringResult = commandResultToString(cmdResult);
assertTrue(stringResult.contains("SYS_VALUE"));
} else {
fail("testEchoForSingleVariable failed");
}
}
use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.
the class ShellCommandsDUnitTest method testEchoWithVariableAtEnd.
@Test
public void testEchoWithVariableAtEnd() {
Gfsh gfshInstance = Gfsh.getCurrentInstance();
if (gfshInstance == null) {
fail("In testEcho command gfshInstance is null");
}
getLogWriter().info("Gsh " + gfshInstance);
gfshInstance.setEnvProperty("TESTSYS", "SYS_VALUE");
printAllEnvs(gfshInstance);
String command = "echo --string=\"Hello World! This is ${TESTSYS}\"";
CommandResult cmdResult = executeCommand(command);
printCommandOutput(cmdResult);
if (cmdResult != null) {
assertEquals(Result.Status.OK, cmdResult.getStatus());
String stringResult = commandResultToString(cmdResult);
assertEquals("Hello World! This is SYS_VALUE", StringUtils.trim(stringResult));
} else {
fail("testEchoWithVariableAtEnd failed");
}
}
use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.
the class ShellCommandsDUnitTest method testEchoForSingleVariable2.
@Test
public void testEchoForSingleVariable2() {
Gfsh gfshInstance = Gfsh.getCurrentInstance();
if (gfshInstance == null) {
fail("In testEcho command gfshInstance is null");
}
gfshInstance.setEnvProperty("TESTSYS", "SYS_VALUE");
printAllEnvs(gfshInstance);
String command = "echo --string=\"${TESTSYS} ${TESTSYS}\"";
CommandResult cmdResult = executeCommand(command);
printCommandOutput(cmdResult);
if (cmdResult != null) {
assertEquals(Result.Status.OK, cmdResult.getStatus());
String stringResult = commandResultToString(cmdResult);
assertTrue(stringResult.contains("SYS_VALUE"));
} else {
fail("testEchoForSingleVariable2 failed");
}
}
use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.
the class ShellCommandsDUnitTest method testClearHistory.
@Test
public void testClearHistory() {
Gfsh gfshInstance = Gfsh.getCurrentInstance();
if (gfshInstance == null) {
fail("In testClearHistory command gfshInstance is null");
}
gfshInstance.setDebug(false);
// Generate a line of history
executeCommand("help");
String command = "history --clear";
CommandResult cmdResult = executeCommand(command);
printCommandOutput(cmdResult);
if (cmdResult != null) {
assertEquals(Result.Status.OK, cmdResult.getStatus());
getLogWriter().info("testClearHistory cmdResult=" + commandResultToString(cmdResult));
String resultString = commandResultToString(cmdResult);
getLogWriter().info("testClearHistory resultString=" + resultString);
assertTrue(resultString.contains(CliStrings.HISTORY__MSG__CLEARED_HISTORY));
assertTrue(gfshInstance.getGfshHistory().size() <= 1);
} else {
fail("testClearHistory failed");
}
}
use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.
the class LuceneIndexCommands method displayResults.
private Result displayResults(int pageSize, boolean keysOnly) throws Exception {
if (searchResults.size() == 0) {
return ResultBuilder.createInfoResult(LuceneCliStrings.LUCENE_SEARCH_INDEX__NO_RESULTS_MESSAGE);
}
Gfsh gfsh = initGfsh();
boolean pagination = searchResults.size() > pageSize;
int fromIndex = 0;
int toIndex = pageSize < searchResults.size() ? pageSize : searchResults.size();
int currentPage = 1;
int totalPages = (int) Math.ceil((float) searchResults.size() / pageSize);
boolean skipDisplay = false;
String step = null;
do {
if (!skipDisplay) {
CommandResult commandResult = (CommandResult) getResults(fromIndex, toIndex, keysOnly);
if (!pagination) {
return commandResult;
}
Gfsh.println();
while (commandResult.hasNextLine()) {
gfsh.printAsInfo(commandResult.nextLine());
}
gfsh.printAsInfo("\t\tPage " + currentPage + " of " + totalPages);
String message = ("Press n to move to next page, q to quit and p to previous page : ");
step = gfsh.interact(message);
}
switch(step) {
case "n":
{
if (currentPage == totalPages) {
gfsh.printAsInfo("No more results to display.");
step = gfsh.interact("Press p to move to last page and q to quit.");
skipDisplay = true;
continue;
}
if (skipDisplay) {
skipDisplay = false;
} else {
currentPage++;
int current = fromIndex;
fromIndex = toIndex;
toIndex = (pageSize + fromIndex >= searchResults.size()) ? searchResults.size() : pageSize + fromIndex;
}
break;
}
case "p":
{
if (currentPage == 1) {
gfsh.printAsInfo("At the top of the search results.");
step = gfsh.interact("Press n to move to the first page and q to quit.");
skipDisplay = true;
continue;
}
if (skipDisplay) {
skipDisplay = false;
} else {
currentPage--;
int current = fromIndex;
toIndex = fromIndex;
fromIndex = current - pageSize <= 0 ? 0 : current - pageSize;
}
break;
}
case "q":
return ResultBuilder.createInfoResult("Search complete.");
default:
Gfsh.println("Invalid option");
break;
}
} while (true);
}
Aggregations