@Test
public void testSubsystemWithConnectorPropertyChange() throws Exception {
final int port = 12345;
KernelServices services = installInController(new AdditionalInitialization(){
@Override
protected void setupController(ControllerInitializer controllerInitializer) {
controllerInitializer.addSocketBinding("test", port);
}
@Override
protected void addExtraServices(ServiceTarget target) {
//Needed for initialization of the RealmAuthenticationProviderService
AbsolutePathService.addService(ServerEnvironment.CONTROLLER_TEMP_DIR, new File("target/temp" + System.currentTimeMillis()).getAbsolutePath(), target);
}
},readResource("remoting-with-threads.xml"));
CurrentConnectorAndController current = CurrentConnectorAndController.create(services, RemotingServices.SUBSYSTEM_ENDPOINT, RemotingServices.serverServiceName("test-connector"));
//Test that write property reloads the connector
ModelNode write = new ModelNode();
write.get(OPERATION_HEADERS, ALLOW_RESOURCE_SERVICE_RESTART).set(true);
write.get(OP).set(WRITE_ATTRIBUTE_OPERATION);
write.get(OP_ADDR).add(SUBSYSTEM, RemotingExtension.SUBSYSTEM_NAME).add(CommonAttributes.CONNECTOR, "test-connector").add(CommonAttributes.PROPERTY, "org.xnio.Options.WORKER_ACCEPT_THREADS");
write.get(NAME).set(VALUE);
write.get(VALUE).set(2);
ModelNode result = services.executeOperation(write);
assertFalse(result.get(FAILURE_DESCRIPTION).toString(), result.hasDefined(FAILURE_DESCRIPTION));
assertEquals(2, services.readWholeModel().get(SUBSYSTEM, RemotingExtension.SUBSYSTEM_NAME, CommonAttributes.CONNECTOR, "test-connector", CommonAttributes.PROPERTY, "org.xnio.Options.WORKER_ACCEPT_THREADS").require(VALUE).asInt());
current.updateCurrentEndpoint(true);
current.updateCurrentConnector(false);
//remove property
ModelNode remove = write.clone();
remove.get(OP).set(REMOVE);
remove.remove(NAME);
remove.remove(VALUE);
result = services.executeOperation(remove);
assertFalse(result.get(FAILURE_DESCRIPTION).toString(), result.hasDefined(FAILURE_DESCRIPTION));
assertFalse(services.readWholeModel().get(SUBSYSTEM, RemotingExtension.SUBSYSTEM_NAME, CommonAttributes.CONNECTOR, "test-connector", CommonAttributes.PROPERTY, "org.xnio.Options.WORKER_ACCEPT_THREADS").isDefined());
current.updateCurrentEndpoint(true);
current.updateCurrentConnector(false);
//TODO property
ModelNode add = remove.clone();
add.get(OP).set(ADD);
add.get(VALUE).set(1);
result = services.executeOperation(add);
assertFalse(result.get(FAILURE_DESCRIPTION).toString(), result.hasDefined(FAILURE_DESCRIPTION));
assertEquals(1, services.readWholeModel().get(SUBSYSTEM, RemotingExtension.SUBSYSTEM_NAME, CommonAttributes.CONNECTOR, "test-connector", CommonAttributes.PROPERTY, "org.xnio.Options.WORKER_ACCEPT_THREADS").require(VALUE).asInt());
current.updateCurrentEndpoint(true);
current.updateCurrentConnector(false);
}