use of org.jboss.as.controller.remote.RemoteProxyController in project wildfly-core by wildfly.
the class RemoteProxyControllerProtocolTestCase method testFailAfterPrepare.
@Test
public void testFailAfterPrepare() throws Exception {
final ModelNode node = new ModelNode();
final ModelController controller = new MockModelController() {
@Override
public ModelNode execute(ModelNode operation, OperationMessageHandler handler, OperationTransactionControl control, OperationAttachments attachments) {
control.operationPrepared(new OperationTransaction() {
@Override
public void commit() {
//
}
@Override
public void rollback() {
//
}
}, node);
// Fail after the commit or rollback was called
throw new IllegalStateException();
}
};
final ModelNode result = new ModelNode();
final RemoteProxyController proxyController = setupProxyHandlers(controller);
final CommitProxyOperationControl commitControl = new CommitProxyOperationControl() {
@Override
public void operationCompleted(OperationResponse response) {
super.operationCompleted(response);
result.set(response.getResponseNode());
}
};
proxyController.execute(node, null, commitControl, null, null);
commitControl.tx.commit();
// Needs to call operation-completed
Assert.assertEquals(2, commitControl.txCompletionStatus.get());
Assert.assertTrue(result.isDefined());
Assert.assertEquals("failed", result.get("outcome").asString());
Assert.assertTrue(result.hasDefined("failure-description"));
}
use of org.jboss.as.controller.remote.RemoteProxyController in project wildfly-core by wildfly.
the class RemoteProxyControllerProtocolTestCase method testClosesBeforePrepare.
@Test
public void testClosesBeforePrepare() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Exception> errorRef = new AtomicReference<Exception>();
MockModelController controller = new MockModelController() {
@Override
public ModelNode execute(ModelNode operation, OperationMessageHandler handler, OperationTransactionControl control, OperationAttachments attachments) {
try {
channels.getClientChannel().closeAsync();
channels.getClientChannel().awaitClosed();
} catch (InterruptedException e) {
// closing a channel will cancel the controller.execute()
} catch (Exception e) {
errorRef.set(e);
} finally {
latch.countDown();
// Ensure the channels are closed
IoUtils.safeClose(channels.getClientChannel());
}
return new ModelNode();
}
};
final RemoteProxyController proxyController = setupProxyHandlers(controller);
ModelNode operation = new ModelNode();
operation.get("test").set("123");
CommitProxyOperationControl commitControl = new CommitProxyOperationControl();
proxyController.execute(operation, OperationMessageHandler.DISCARD, commitControl, OperationAttachments.EMPTY, null);
Assert.assertNull(errorRef.get());
latch.await(15, TimeUnit.SECONDS);
Assert.assertEquals(1, commitControl.txCompletionStatus.get());
}
use of org.jboss.as.controller.remote.RemoteProxyController in project wildfly-core by wildfly.
the class RemoteProxyControllerProtocolTestCase method testOperationControlExceptionInController.
@Test
public void testOperationControlExceptionInController() throws Exception {
final MockModelController controller = new MockModelController() {
@Override
public ModelNode execute(ModelNode operation, OperationMessageHandler handler, OperationTransactionControl control, OperationAttachments attachments) {
throw new RuntimeException("Crap");
}
};
final RemoteProxyController proxyController = setupProxyHandlers(controller);
ModelNode operation = new ModelNode();
operation.get("test").set("123");
final AtomicBoolean prepared = new AtomicBoolean();
final AtomicBoolean completed = new AtomicBoolean();
final TestFuture<ModelNode> failure = new TestFuture<>();
proxyController.execute(operation, null, new ProxyOperationControl() {
@Override
public void operationPrepared(OperationTransaction transaction, ModelNode result) {
prepared.set(true);
}
@Override
public void operationFailed(ModelNode response) {
failure.done(response);
}
@Override
public void operationCompleted(OperationResponse response) {
completed.set(true);
}
}, null, null);
ModelNode result = failure.get();
assertEquals(FAILED, result.get(OUTCOME).asString());
assertEquals("java.lang.RuntimeException:Crap", result.get(FAILURE_DESCRIPTION).asString());
assertFalse(prepared.get());
assertFalse(completed.get());
}
use of org.jboss.as.controller.remote.RemoteProxyController in project wildfly-core by wildfly.
the class RemoteProxyControllerProtocolTestCase method testOperationControlFailed.
@Test
public void testOperationControlFailed() throws Exception {
final MockModelController controller = new MockModelController() {
@Override
public ModelNode execute(ModelNode operation, OperationMessageHandler handler, OperationTransactionControl control, OperationAttachments attachments) {
final ModelNode result = new ModelNode();
result.get(OUTCOME).set(FAILED);
result.get(FAILURE_DESCRIPTION).set("broken");
return result;
}
};
final RemoteProxyController proxyController = setupProxyHandlers(controller);
ModelNode operation = new ModelNode();
operation.get("test").set("123");
final AtomicBoolean prepared = new AtomicBoolean();
final AtomicBoolean completed = new AtomicBoolean();
final TestFuture<ModelNode> failure = new TestFuture<>();
proxyController.execute(operation, null, new ProxyOperationControl() {
@Override
public void operationPrepared(OperationTransaction transaction, ModelNode result) {
prepared.set(true);
}
@Override
public void operationFailed(ModelNode response) {
failure.done(response);
}
@Override
public void operationCompleted(OperationResponse response) {
completed.set(true);
}
}, null, null);
ModelNode result = failure.get();
assertEquals(FAILED, result.get(OUTCOME).asString());
assertEquals("broken", result.get(FAILURE_DESCRIPTION).asString());
assertFalse(prepared.get());
assertFalse(completed.get());
}
use of org.jboss.as.controller.remote.RemoteProxyController in project wildfly-core by wildfly.
the class RemoteProxyControllerProtocolTestCase method testOperationMessageHandler.
@Test
@Ignore("WFCORE-1125")
public void testOperationMessageHandler() throws Exception {
final MockModelController controller = new MockModelController() {
@Override
public ModelNode execute(ModelNode operation, OperationMessageHandler handler, ModelController.OperationTransactionControl control, OperationAttachments attachments) {
this.operation = operation;
handler.handleReport(MessageSeverity.INFO, "Test1");
handler.handleReport(MessageSeverity.INFO, "Test2");
control.operationPrepared(new OperationTransaction() {
@Override
public void rollback() {
}
@Override
public void commit() {
}
}, new ModelNode());
return new ModelNode();
}
};
final RemoteProxyController proxyController = setupProxyHandlers(controller);
ModelNode operation = new ModelNode();
operation.get("test").set("123");
final BlockingQueue<String> messages = new LinkedBlockingQueue<String>();
CommitProxyOperationControl commitControl = new CommitProxyOperationControl();
proxyController.execute(operation, new OperationMessageHandler() {
@Override
public void handleReport(MessageSeverity severity, String message) {
if (severity == MessageSeverity.INFO && message.startsWith("Test")) {
messages.add(message);
}
}
}, commitControl, null, null);
Assert.assertNotNull(commitControl.tx);
commitControl.tx.commit();
assertEquals("123", controller.getOperation().get("test").asString());
assertEquals("Test1", messages.take());
assertEquals("Test2", messages.take());
}
Aggregations