Search in sources :

Example 16 with Gfsh

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");
    }
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 17 with Gfsh

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");
    }
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 18 with Gfsh

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");
    }
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 19 with Gfsh

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");
    }
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 20 with Gfsh

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);
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) ConverterHint(org.apache.geode.management.cli.ConverterHint) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult)

Aggregations

Gfsh (org.apache.geode.management.internal.cli.shell.Gfsh)40 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)14 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)13 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)13 Test (org.junit.Test)13 IOException (java.io.IOException)11 CliMetaData (org.apache.geode.management.cli.CliMetaData)7 CliCommand (org.springframework.shell.core.annotation.CliCommand)7 TreeSet (java.util.TreeSet)6 ConnectToLocatorResult (org.apache.geode.management.internal.cli.domain.ConnectToLocatorResult)6 File (java.io.File)5 MalformedURLException (java.net.MalformedURLException)5 Result (org.apache.geode.management.cli.Result)5 AuthenticationFailedException (org.apache.geode.security.AuthenticationFailedException)5 ConverterHint (org.apache.geode.management.cli.ConverterHint)3 JmxOperationInvoker (org.apache.geode.management.internal.cli.shell.JmxOperationInvoker)3 ConnectionEndpoint (org.apache.geode.management.internal.cli.util.ConnectionEndpoint)3 HttpOperationInvoker (org.apache.geode.management.internal.web.shell.HttpOperationInvoker)3 RestHttpOperationInvoker (org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker)3 ExitShellRequest (org.springframework.shell.core.ExitShellRequest)3