Search in sources :

Example 1 with RemoteProxyController

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"));
}
Also used : OperationTransaction(org.jboss.as.controller.ModelController.OperationTransaction) OperationAttachments(org.jboss.as.controller.client.OperationAttachments) OperationMessageHandler(org.jboss.as.controller.client.OperationMessageHandler) RemoteProxyController(org.jboss.as.controller.remote.RemoteProxyController) ModelNode(org.jboss.dmr.ModelNode) ModelController(org.jboss.as.controller.ModelController) OperationResponse(org.jboss.as.controller.client.OperationResponse) Test(org.junit.Test)

Example 2 with RemoteProxyController

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());
}
Also used : OperationAttachments(org.jboss.as.controller.client.OperationAttachments) OperationMessageHandler(org.jboss.as.controller.client.OperationMessageHandler) RemoteProxyController(org.jboss.as.controller.remote.RemoteProxyController) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) ModelNode(org.jboss.dmr.ModelNode) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with RemoteProxyController

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());
}
Also used : OperationTransaction(org.jboss.as.controller.ModelController.OperationTransaction) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OperationAttachments(org.jboss.as.controller.client.OperationAttachments) OperationMessageHandler(org.jboss.as.controller.client.OperationMessageHandler) ProxyOperationControl(org.jboss.as.controller.ProxyController.ProxyOperationControl) RemoteProxyController(org.jboss.as.controller.remote.RemoteProxyController) ModelNode(org.jboss.dmr.ModelNode) OperationResponse(org.jboss.as.controller.client.OperationResponse) Test(org.junit.Test)

Example 4 with RemoteProxyController

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());
}
Also used : OperationTransaction(org.jboss.as.controller.ModelController.OperationTransaction) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OperationAttachments(org.jboss.as.controller.client.OperationAttachments) OperationMessageHandler(org.jboss.as.controller.client.OperationMessageHandler) ProxyOperationControl(org.jboss.as.controller.ProxyController.ProxyOperationControl) RemoteProxyController(org.jboss.as.controller.remote.RemoteProxyController) ModelNode(org.jboss.dmr.ModelNode) OperationResponse(org.jboss.as.controller.client.OperationResponse) Test(org.junit.Test)

Example 5 with RemoteProxyController

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());
}
Also used : LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) OperationTransaction(org.jboss.as.controller.ModelController.OperationTransaction) MessageSeverity(org.jboss.as.controller.client.MessageSeverity) OperationAttachments(org.jboss.as.controller.client.OperationAttachments) OperationMessageHandler(org.jboss.as.controller.client.OperationMessageHandler) RemoteProxyController(org.jboss.as.controller.remote.RemoteProxyController) ModelNode(org.jboss.dmr.ModelNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

RemoteProxyController (org.jboss.as.controller.remote.RemoteProxyController)10 OperationAttachments (org.jboss.as.controller.client.OperationAttachments)8 OperationMessageHandler (org.jboss.as.controller.client.OperationMessageHandler)8 ModelNode (org.jboss.dmr.ModelNode)8 Test (org.junit.Test)8 OperationTransaction (org.jboss.as.controller.ModelController.OperationTransaction)7 OperationResponse (org.jboss.as.controller.client.OperationResponse)5 IOException (java.io.IOException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 ProxyOperationControl (org.jboss.as.controller.ProxyController.ProxyOperationControl)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 TransactionalProtocolOperationHandler (org.jboss.as.controller.remote.TransactionalProtocolOperationHandler)2 RemoteChannelPairSetup (org.jboss.as.controller.support.RemoteChannelPairSetup)2 ManagementChannelHandler (org.jboss.as.protocol.mgmt.ManagementChannelHandler)2 ManagementClientChannelStrategy (org.jboss.as.protocol.mgmt.ManagementClientChannelStrategy)2 ManagementChannelInitialization (org.jboss.as.protocol.mgmt.support.ManagementChannelInitialization)2 Channel (org.jboss.remoting3.Channel)2 CloseHandler (org.jboss.remoting3.CloseHandler)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1