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