Search in sources :

Example 1 with MessageSeverity

use of org.jboss.as.controller.client.MessageSeverity in project wildfly-core by wildfly.

the class ModelControllerClientTestCase method testSynchronousOperationMessageHandler.

@Test
@Ignore("WFCORE-1125")
public void testSynchronousOperationMessageHandler() throws Exception {
    final CountDownLatch executeLatch = new CountDownLatch(1);
    MockModelController controller = new MockModelController() {

        @Override
        public ModelNode execute(ModelNode operation, OperationMessageHandler handler, OperationTransactionControl control, OperationAttachments attachments) {
            this.operation = operation;
            handler.handleReport(MessageSeverity.INFO, "Test1");
            handler.handleReport(MessageSeverity.INFO, "Test2");
            executeLatch.countDown();
            ModelNode result = new ModelNode();
            result.get("testing").set(operation.get("test"));
            return result;
        }
    };
    final ModelControllerClient client = setupTestClient(controller);
    try {
        ModelNode operation = new ModelNode();
        operation.get("test").set("123");
        final BlockingQueue<String> messages = new LinkedBlockingQueue<String>();
        ModelNode result = client.execute(operation, new OperationMessageHandler() {

            @Override
            public void handleReport(MessageSeverity severity, String message) {
                if (severity == MessageSeverity.INFO && message.startsWith("Test")) {
                    messages.add(message);
                }
            }
        });
        assertEquals("123", controller.getOperation().get("test").asString());
        assertEquals("123", result.get("testing").asString());
        assertEquals("Test1", messages.take());
        assertEquals("Test2", messages.take());
    } finally {
        IoUtils.safeClose(client);
    }
}
Also used : MessageSeverity(org.jboss.as.controller.client.MessageSeverity) OperationAttachments(org.jboss.as.controller.client.OperationAttachments) OperationMessageHandler(org.jboss.as.controller.client.OperationMessageHandler) ExistingChannelModelControllerClient(org.jboss.as.controller.client.impl.ExistingChannelModelControllerClient) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) CountDownLatch(java.util.concurrent.CountDownLatch) ModelNode(org.jboss.dmr.ModelNode) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with MessageSeverity

use of org.jboss.as.controller.client.MessageSeverity 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)

Example 3 with MessageSeverity

use of org.jboss.as.controller.client.MessageSeverity in project wildfly-core by wildfly.

the class ModelControllerClientTestCase method testCancelAsynchronousOperation.

@Test
public void testCancelAsynchronousOperation() throws Exception {
    final CountDownLatch executeLatch = new CountDownLatch(1);
    final CountDownLatch interrupted = new CountDownLatch(1);
    MockModelController controller = new MockModelController() {

        @Override
        public ModelNode execute(ModelNode operation, OperationMessageHandler handler, OperationTransactionControl control, OperationAttachments attachments) {
            this.operation = operation;
            executeLatch.countDown();
            try {
                log.debug("Waiting for interrupt");
                // Wait for this operation to be cancelled
                Thread.sleep(10000000);
                ModelNode result = new ModelNode();
                result.get("testing").set(operation.get("test"));
                return result;
            } catch (InterruptedException e) {
                interrupted.countDown();
                throw new RuntimeException(e);
            }
        }
    };
    // Set the handler
    final ModelControllerClient client = setupTestClient(controller);
    try {
        ModelNode operation = new ModelNode();
        operation.get("test").set("123");
        operation.get("operation").set("fake");
        final BlockingQueue<String> messages = new LinkedBlockingQueue<String>();
        AsyncFuture<ModelNode> resultFuture = client.executeAsync(operation, new OperationMessageHandler() {

            @Override
            public void handleReport(MessageSeverity severity, String message) {
                if (severity == MessageSeverity.INFO && message.startsWith("Test")) {
                    messages.add(message);
                }
            }
        });
        executeLatch.await();
        resultFuture.cancel(false);
        interrupted.await();
    } finally {
        IoUtils.safeClose(client);
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) MessageSeverity(org.jboss.as.controller.client.MessageSeverity) OperationAttachments(org.jboss.as.controller.client.OperationAttachments) OperationMessageHandler(org.jboss.as.controller.client.OperationMessageHandler) ExistingChannelModelControllerClient(org.jboss.as.controller.client.impl.ExistingChannelModelControllerClient) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Example 4 with MessageSeverity

use of org.jboss.as.controller.client.MessageSeverity in project wildfly-core by wildfly.

the class ModelControllerClientTestCase method testAsynchronousOperationWithMessageHandler.

@Test
@Ignore("WFCORE-1125")
public void testAsynchronousOperationWithMessageHandler() throws Exception {
    final CountDownLatch executeLatch = new CountDownLatch(1);
    MockModelController controller = new MockModelController() {

        @Override
        public ModelNode execute(ModelNode operation, OperationMessageHandler handler, OperationTransactionControl control, OperationAttachments attachments) {
            this.operation = operation;
            handler.handleReport(MessageSeverity.INFO, "Test1");
            handler.handleReport(MessageSeverity.INFO, "Test2");
            executeLatch.countDown();
            ModelNode result = new ModelNode();
            result.get("testing").set(operation.get("test"));
            return result;
        }
    };
    // Set the handler
    final ModelControllerClient client = setupTestClient(controller);
    try {
        ModelNode operation = new ModelNode();
        operation.get("test").set("123");
        operation.get("operation").set("fake");
        final BlockingQueue<String> messages = new LinkedBlockingQueue<String>();
        AsyncFuture<ModelNode> resultFuture = client.executeAsync(operation, new OperationMessageHandler() {

            @Override
            public void handleReport(MessageSeverity severity, String message) {
                if (severity == MessageSeverity.INFO && message.startsWith("Test")) {
                    messages.add(message);
                }
            }
        });
        ModelNode result = resultFuture.get();
        assertEquals("123", controller.getOperation().get("test").asString());
        assertEquals("123", result.get("testing").asString());
        assertEquals("Test1", messages.take());
        assertEquals("Test2", messages.take());
    } finally {
        IoUtils.safeClose(client);
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) MessageSeverity(org.jboss.as.controller.client.MessageSeverity) OperationAttachments(org.jboss.as.controller.client.OperationAttachments) OperationMessageHandler(org.jboss.as.controller.client.OperationMessageHandler) ExistingChannelModelControllerClient(org.jboss.as.controller.client.impl.ExistingChannelModelControllerClient) ModelControllerClient(org.jboss.as.controller.client.ModelControllerClient) ModelNode(org.jboss.dmr.ModelNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)4 MessageSeverity (org.jboss.as.controller.client.MessageSeverity)4 OperationAttachments (org.jboss.as.controller.client.OperationAttachments)4 OperationMessageHandler (org.jboss.as.controller.client.OperationMessageHandler)4 ModelNode (org.jboss.dmr.ModelNode)4 Test (org.junit.Test)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)3 ExistingChannelModelControllerClient (org.jboss.as.controller.client.impl.ExistingChannelModelControllerClient)3 Ignore (org.junit.Ignore)3 OperationTransaction (org.jboss.as.controller.ModelController.OperationTransaction)1 RemoteProxyController (org.jboss.as.controller.remote.RemoteProxyController)1