Search in sources :

Example 1 with HeadlessGfsh

use of org.apache.geode.management.internal.cli.HeadlessGfsh in project geode by apache.

the class GetCommandOnRegionWithCacheLoaderDuringCacheMissDUnitTest method postSetUpCliCommandTestBase.

@Override
public final void postSetUpCliCommandTestBase() throws Exception {
    Properties managerDistributedSystemProperties = createDistributedSystemProperties(GEMFIRE_MANAGER_NAME);
    // vm 0
    HeadlessGfsh gfsh = setUpJmxManagerOnVm0ThenConnect(managerDistributedSystemProperties);
    // --
    // locator/manager
    // controller vm -- gfsh
    assertNotNull(gfsh);
    assertTrue(gfsh.isConnectedAndReady());
    // vm 1 -- server
    setupGemFire();
    verifyGemFireSetup(createPeer(getHost(0).getVM(0), managerDistributedSystemProperties));
}
Also used : HeadlessGfsh(org.apache.geode.management.internal.cli.HeadlessGfsh) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties)

Example 2 with HeadlessGfsh

use of org.apache.geode.management.internal.cli.HeadlessGfsh in project geode by apache.

the class MiscellaneousCommandsDUnitTest method testShutDownWithoutTimeout.

// GEODE-1706
@Category(FlakyTest.class)
@Test
public void testShutDownWithoutTimeout() {
    addIgnoredException("EntryDestroyedException");
    setupForShutDown();
    ThreadUtils.sleep(2500);
    String command = "shutdown";
    CommandResult cmdResult = executeCommand(command);
    if (cmdResult != null) {
        String cmdResultStr = commandResultToString(cmdResult);
        getLogWriter().info("testShutDownWithoutTimeout cmdResultStr=" + cmdResultStr);
    }
    verifyShutDown();
    final HeadlessGfsh defaultShell = getDefaultShell();
    // Need for the Gfsh HTTP enablement during shutdown to properly assess the
    // state of the connection.
    waitForCriterion(new WaitCriterion() {

        public boolean done() {
            return !defaultShell.isConnectedAndReady();
        }

        public String description() {
            return "Waits for the shell to disconnect!";
        }
    }, 1000, 250, true);
    assertFalse(defaultShell.isConnectedAndReady());
}
Also used : HeadlessGfsh(org.apache.geode.management.internal.cli.HeadlessGfsh) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 3 with HeadlessGfsh

use of org.apache.geode.management.internal.cli.HeadlessGfsh in project geode by apache.

the class MiscellaneousCommandsDUnitTest method testShutDownWithTimeout.

@Ignore("Disabled for 52350")
@Test
public void testShutDownWithTimeout() {
    setupForShutDown();
    ThreadUtils.sleep(2500);
    addIgnoredException("EntryDestroyedException");
    String command = "shutdown --time-out=15";
    CommandResult cmdResult = executeCommand(command);
    if (cmdResult != null) {
        String cmdResultStr = commandResultToString(cmdResult);
        getLogWriter().info("testShutDownWithTIMEOUT cmdResultStr=" + cmdResultStr);
    }
    verifyShutDown();
    final HeadlessGfsh defaultShell = getDefaultShell();
    // Need for the Gfsh HTTP enablement during shutdown to properly assess the state of the
    // connection.
    waitForCriterion(new WaitCriterion() {

        public boolean done() {
            return !defaultShell.isConnectedAndReady();
        }

        public String description() {
            return "Waits for the shell to disconnect!";
        }
    }, 1000, 250, false);
    assertFalse(defaultShell.isConnectedAndReady());
}
Also used : HeadlessGfsh(org.apache.geode.management.internal.cli.HeadlessGfsh) Ignore(org.junit.Ignore) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 4 with HeadlessGfsh

use of org.apache.geode.management.internal.cli.HeadlessGfsh in project geode by apache.

the class MultiUserDUnitTest method testMultiUser.

// GEODE-1579
@Category(FlakyTest.class)
@Test
public void testMultiUser() throws IOException, JSONException, InterruptedException {
    IgnoredException.addIgnoredException("java.util.zip.ZipException: zip file is empty");
    Properties properties = new Properties();
    properties.put(NAME, MultiUserDUnitTest.class.getSimpleName());
    properties.put(SECURITY_MANAGER, TestSecurityManager.class.getName());
    // set up vm_0 the secure jmx manager
    Object[] results = setUpJMXManagerOnVM(0, properties, "org/apache/geode/management/internal/security/cacheServer.json");
    String gfshDir = this.gfshDir;
    // set up vm_1 as a gfsh vm, data-reader will login and log out constantly in this vm until the
    // test is done.
    VM vm1 = Host.getHost(0).getVM(1);
    AsyncInvocation vm1Invoke = vm1.invokeAsync("run as data-reader", () -> {
        String shellId = getClass().getSimpleName() + "_vm1";
        HeadlessGfsh shell = new HeadlessGfsh(shellId, 30, gfshDir);
        while (true) {
            connect((String) results[0], (Integer) results[1], (Integer) results[2], shell, "data-reader", "1234567");
            Awaitility.waitAtMost(5, TimeUnit.MILLISECONDS);
            shell.executeCommand("disconnect");
        }
    });
    VM vm2 = Host.getHost(0).getVM(2);
    // set up vm_2 as a gfsh vm, and then connect as "stranger" and try to execute the commands and
    // assert errors comes back are NotAuthorized
    AsyncInvocation vm2Invoke = vm2.invokeAsync("run as guest", () -> {
        String shellId = getClass().getSimpleName() + "_vm2";
        HeadlessGfsh shell = new HeadlessGfsh(shellId, 30, gfshDir);
        connect((String) results[0], (Integer) results[1], (Integer) results[2], shell, "stranger", "1234567");
        List<TestCommand> allCommands = TestCommand.getCommands();
        for (TestCommand command : allCommands) {
            LogService.getLogger().info("executing: " + command.getCommand());
            if (command.getPermission() == null) {
                continue;
            }
            CommandResult result = executeCommand(shell, command.getCommand());
            int errorCode = ((ErrorResultData) result.getResultData()).getErrorCode();
            // those commands
            if (errorCode == ResultBuilder.ERRORCODE_USER_ERROR) {
                LogService.getLogger().info("Skip user error: " + result.getContent());
                continue;
            }
            assertEquals("Not an expected result: " + result.toString(), ResultBuilder.ERRORCODE_UNAUTHORIZED, ((ErrorResultData) result.getResultData()).getErrorCode());
            String resultMessage = result.getContent().toString();
            String permString = command.getPermission().toString();
            assertTrue(resultMessage + " does not contain " + permString, resultMessage.contains(permString));
        }
        LogService.getLogger().info("vm 2 done!");
    });
    VM vm3 = Host.getHost(0).getVM(3);
    IgnoredException.addIgnoredException("java.lang.IllegalArgumentException: Region doesnt exist: {0}", vm3);
    IgnoredException.addIgnoredException("java.lang.ClassNotFoundException: myApp.myListener", vm3);
    // set up vm_3 as another gfsh vm, and then connect as "super-user" and try to execute the
    // commands and assert we don't get a NotAuthorized Exception
    AsyncInvocation vm3Invoke = vm3.invokeAsync("run as superUser", () -> {
        String shellId = getClass().getSimpleName() + "_vm3";
        HeadlessGfsh shell = new HeadlessGfsh(shellId, 30, gfshDir);
        connect((String) results[0], (Integer) results[1], (Integer) results[2], shell, "super-user", "1234567");
        List<TestCommand> allCommands = TestCommand.getCommands();
        for (TestCommand command : allCommands) {
            LogService.getLogger().info("executing: " + command.getCommand());
            if (command.getPermission() == null) {
                continue;
            }
            CommandResult result = executeCommand(shell, command.getCommand());
            if (result.getResultData().getStatus() == Status.OK) {
                continue;
            }
            assertNotEquals("Did not expect an Unauthorized exception: " + result.toString(), ResultBuilder.ERRORCODE_UNAUTHORIZED, ((ErrorResultData) result.getResultData()).getErrorCode());
        }
        LogService.getLogger().info("vm 3 done!");
    });
    // only wait until vm2 and vm3 are done. vm1 will close when test finishes
    vm2Invoke.join();
    vm3Invoke.join();
    vm2Invoke.checkException();
    vm3Invoke.checkException();
    IgnoredException.removeAllExpectedExceptions();
}
Also used : HeadlessGfsh(org.apache.geode.management.internal.cli.HeadlessGfsh) Properties(java.util.Properties) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) VM(org.apache.geode.test.dunit.VM) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) TestSecurityManager(org.apache.geode.security.TestSecurityManager) Category(org.junit.experimental.categories.Category) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 5 with HeadlessGfsh

use of org.apache.geode.management.internal.cli.HeadlessGfsh in project geode by apache.

the class CliCommandTestBase method createShell.

/**
   * Create a HeadlessGfsh object.
   *
   * @return The created shell.
   */
protected HeadlessGfsh createShell() {
    try {
        Gfsh.SUPPORT_MUTLIPLESHELL = true;
        String shellId = getClass().getSimpleName() + "_" + getName();
        HeadlessGfsh shell = new HeadlessGfsh(shellId, 30, this.gfshDir);
        // Added to avoid trimming of the columns
        info("Started testable shell: " + shell);
        return shell;
    } catch (ClassNotFoundException e) {
        throw new AssertionError(e);
    } catch (IOException e) {
        throw new AssertionError(e);
    }
}
Also used : HeadlessGfsh(org.apache.geode.management.internal.cli.HeadlessGfsh) IOException(java.io.IOException)

Aggregations

HeadlessGfsh (org.apache.geode.management.internal.cli.HeadlessGfsh)11 Properties (java.util.Properties)5 VM (org.apache.geode.test.dunit.VM)4 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)4 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)4 Test (org.junit.Test)4 InternalCache (org.apache.geode.internal.cache.InternalCache)3 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)3 Category (org.junit.experimental.categories.Category)3 File (java.io.File)2 UnknownHostException (java.net.UnknownHostException)2 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)2 InternalLocator (org.apache.geode.distributed.internal.InternalLocator)2 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)2 IOException (java.io.IOException)1 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)1 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)1 Region (org.apache.geode.cache.Region)1 RegionFactory (org.apache.geode.cache.RegionFactory)1 DistributedRegionMXBean (org.apache.geode.management.DistributedRegionMXBean)1