use of org.jboss.as.test.shared.RetryTaskExecutor in project wildfly by wildfly.
the class SocketsAndInterfacesTestCase method testAddUpdateRemove.
@Test
public void testAddUpdateRemove() throws Exception {
if (testNic == null) {
logger.error("Could not look up non-default interface");
return;
}
// add interface
ModelNode op = createOpNode("interface=test123-interface", ADD);
op.get("nic").set(testNic.getName());
op.get("inet-address").set(testHost);
ModelNode result = executeOperation(op);
// add socket binding using created interface
op = createOpNode("socket-binding-group=standard-sockets/socket-binding=test123-binding", ADD);
op.get("interface").set("test123-interface");
op.get("port").set(TEST_PORT);
result = executeOperation(op);
// add a web connector so we can test the interface
op = createOpNode("subsystem=undertow/server=default-server/http-listener=test", ADD);
op.get("socket-binding").set("test123-binding");
result = executeOperation(op);
final URL url = new URL("http", testHost, TEST_PORT, "/");
Assert.assertTrue("Could not connect to created connector: " + url + "<>" + InetAddress.getByName(url.getHost()) + "..." + getNonDefaultNic() + ".>" + result, WebUtil.testHttpURL(url.toString()));
// change socket binding port
op = createOpNode("socket-binding-group=standard-sockets/socket-binding=test123-binding", WRITE_ATTRIBUTE_OPERATION);
op.get(NAME).set("port");
op.get(VALUE).set(TEST_PORT + 1);
result = executeOperation(op, false);
Assert.assertEquals(SUCCESS, result.get(OUTCOME).asString());
Assert.assertTrue(result.get(RESPONSE_HEADERS).get(PROCESS_STATE).asString().equals("reload-required"));
logger.trace("Restarting server.");
ServerReload.executeReloadAndWaitForCompletion(getModelControllerClient());
// wait until the connector is available on the new port
final String testUrl = new URL("http", testHost, TEST_PORT + 1, "/").toString();
RetryTaskExecutor<Boolean> rte = new RetryTaskExecutor<Boolean>();
rte.retryTask(new Callable<Boolean>() {
public Boolean call() throws Exception {
boolean available = WebUtil.testHttpURL(testUrl);
if (!available)
throw new Exception("Connector not available.");
return available;
}
});
logger.trace("Server is up.");
// check the connector is not listening on the old port
Assert.assertFalse("Could not connect to created connector.", WebUtil.testHttpURL(new URL("http", testHost, TEST_PORT, "/").toString()));
// try to remove the interface while the socket binding is still bound to it - should fail
op = createOpNode("interface=test123-interface", REMOVE);
result = executeOperation(op, false);
Assert.assertFalse("Removed interface with socket binding bound to it.", SUCCESS.equals(result.get(OUTCOME).asString()));
// try to remove socket binding while the connector is still using it - should fail
op = createOpNode("socket-binding-group=standard-sockets/socket-binding=test123-binding", REMOVE);
result = executeOperation(op, false);
Assert.assertFalse("Removed socked binding with connector still using it.", SUCCESS.equals(result.get(OUTCOME).asString()));
}
use of org.jboss.as.test.shared.RetryTaskExecutor in project wildfly by wildfly.
the class SSOTestBase method restartServer.
// Reload operation is not handled well by Arquillian
// See ARQ-791: JMX: Arquillian is unable to reconnect to JMX server if the connection is lost
public static void restartServer(final ModelControllerClient client) {
try {
applyUpdates(Arrays.asList(createOpNode(null, "reload")), client);
} catch (Exception e) {
throw new RuntimeException("Restart operation not successful. " + e.getMessage());
}
try {
RetryTaskExecutor<Boolean> rte = new RetryTaskExecutor<>();
rte.retryTask(new Callable<Boolean>() {
public Boolean call() throws Exception {
ModelNode readOp = createOpNode(null, READ_ATTRIBUTE_OPERATION);
readOp.get("name").set("server-state");
ModelNode result = client.execute(new OperationBuilder(readOp).build());
if (result.hasDefined("outcome") && "success".equals(result.get("outcome").asString())) {
if ((result.hasDefined("result")) && (result.get("result").asString().equals("running")))
return true;
}
log.trace("Server is down.");
throw new Exception("Connector not available.");
}
});
} catch (TimeoutException e) {
throw new RuntimeException("Timeout on restart operation. " + e.getMessage());
}
log.trace("Server is up.");
}
Aggregations