Search in sources :

Example 1 with OperationAttachments

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

the class ProxyControllerRegistrationUnitTestCase method setup.

@Before
public void setup() {
    root = ManagementResourceRegistration.Factory.forProcessType(ProcessType.HOST_CONTROLLER).createRegistration(new SimpleResourceDefinition(null, NonResolvingResourceDescriptionResolver.INSTANCE));
    proxyController = new ProxyController() {

        @Override
        public PathAddress getProxyNodeAddress() {
            return PathAddress.pathAddress(PROXY_ELEMENT);
        }

        @Override
        public void execute(ModelNode operation, OperationMessageHandler handler, ProxyOperationControl control, OperationAttachments attachments, BlockingTimeout blockingTimeout) {
            throw new UnsupportedOperationException();
        }
    };
    root.registerProxyController(PROXY_ELEMENT, proxyController);
}
Also used : OperationAttachments(org.jboss.as.controller.client.OperationAttachments) OperationMessageHandler(org.jboss.as.controller.client.OperationMessageHandler) PathAddress(org.jboss.as.controller.PathAddress) SimpleResourceDefinition(org.jboss.as.controller.SimpleResourceDefinition) ProxyController(org.jboss.as.controller.ProxyController) ModelNode(org.jboss.dmr.ModelNode) BlockingTimeout(org.jboss.as.controller.BlockingTimeout) Before(org.junit.Before)

Example 2 with OperationAttachments

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

the class TransactionalProtocolClientTestCase method testCancelBeforePrepared.

@Test
public void testCancelBeforePrepared() throws Exception {
    final BlockingOperationListener listener = new BlockingOperationListener();
    final CountDownLatch latch = new CountDownLatch(1);
    final TestOperationHandler handler = new TestOperationHandler() {

        @Override
        public void execute(ModelNode operation, OperationMessageHandler handler, OperationAttachments attachments) throws Exception {
            try {
                synchronized (this) {
                    latch.countDown();
                    wait();
                }
            } catch (InterruptedException e) {
            // 
            }
        }
    };
    // 
    final TestUpdateWrapper wrapper = createTestClient(0, handler);
    final Future<OperationResponse> futureResult = wrapper.execute(listener);
    latch.await();
    // Now the server side should for latch to countDown
    futureResult.cancel(false);
    // 
    OperationContext.ResultAction action = null;
    while (action == null) {
        action = wrapper.getResultAction();
        Thread.sleep(15);
    }
    wrapper.assertResultAction(OperationContext.ResultAction.ROLLBACK);
    final ModelNode result = futureResult.get().getResponseNode();
    Assert.assertEquals(FAILURE, result);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationAttachments(org.jboss.as.controller.client.OperationAttachments) OperationMessageHandler(org.jboss.as.controller.client.OperationMessageHandler) CountDownLatch(java.util.concurrent.CountDownLatch) ModelNode(org.jboss.dmr.ModelNode) OperationResponse(org.jboss.as.controller.client.OperationResponse) Test(org.junit.Test)

Example 3 with OperationAttachments

use of org.jboss.as.controller.client.OperationAttachments 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 4 with OperationAttachments

use of org.jboss.as.controller.client.OperationAttachments 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 5 with OperationAttachments

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

the class ModelControllerClientTestCase method testSynchronousAttachmentInputStreams.

@Test
public void testSynchronousAttachmentInputStreams() throws Exception {
    final byte[] firstBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    final byte[] secondBytes = new byte[] { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
    final byte[] thirdBytes = new byte[] { 1 };
    final CountDownLatch executeLatch = new CountDownLatch(1);
    final AtomicInteger size = new AtomicInteger();
    final AtomicReference<byte[]> firstResult = new AtomicReference<byte[]>();
    final AtomicReference<byte[]> secondResult = new AtomicReference<byte[]>();
    final AtomicReference<byte[]> thirdResult = new AtomicReference<byte[]>();
    MockModelController controller = new MockModelController() {

        @Override
        public ModelNode execute(ModelNode operation, OperationMessageHandler handler, OperationTransactionControl control, OperationAttachments attachments) {
            int streamIndex = 0;
            for (InputStream in : attachments.getInputStreams()) {
                try {
                    ArrayList<Integer> readBytes = new ArrayList<Integer>();
                    int b = in.read();
                    while (b != -1) {
                        readBytes.add(b);
                        b = in.read();
                    }
                    byte[] bytes = new byte[readBytes.size()];
                    for (int i = 0; i < bytes.length; i++) {
                        bytes[i] = (byte) readBytes.get(i).intValue();
                    }
                    if (streamIndex == 0) {
                        firstResult.set(bytes);
                    } else if (streamIndex == 1) {
                        secondResult.set(bytes);
                    } else if (streamIndex == 2) {
                        thirdResult.set(bytes);
                    }
                    streamIndex++;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            size.set(streamIndex);
            executeLatch.countDown();
            return new ModelNode();
        }
    };
    // Set the handler
    final ModelControllerClient client = setupTestClient(controller);
    try {
        ModelNode op = new ModelNode();
        op.get("operation").set("fake");
        op.get("name").set(123);
        OperationBuilder builder = new OperationBuilder(op);
        builder.addInputStream(new ByteArrayInputStream(firstBytes));
        builder.addInputStream(new ByteArrayInputStream(secondBytes));
        builder.addInputStream(new ByteArrayInputStream(thirdBytes));
        client.execute(builder.build());
        executeLatch.await();
        assertEquals(3, size.get());
        assertArrays(firstBytes, firstResult.get());
        assertArrays(secondBytes, secondResult.get());
        assertArrays(new byte[] { 1 }, thirdResult.get());
    } finally {
        IoUtils.safeClose(client);
    }
}
Also used : OperationBuilder(org.jboss.as.controller.client.OperationBuilder) FilterInputStream(java.io.FilterInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ByteArrayInputStream(java.io.ByteArrayInputStream) ModelNode(org.jboss.dmr.ModelNode) Test(org.junit.Test)

Aggregations

OperationAttachments (org.jboss.as.controller.client.OperationAttachments)18 OperationMessageHandler (org.jboss.as.controller.client.OperationMessageHandler)18 ModelNode (org.jboss.dmr.ModelNode)17 Test (org.junit.Test)14 OperationResponse (org.jboss.as.controller.client.OperationResponse)8 RemoteProxyController (org.jboss.as.controller.remote.RemoteProxyController)8 OperationTransaction (org.jboss.as.controller.ModelController.OperationTransaction)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 IOException (java.io.IOException)5 ModelControllerClient (org.jboss.as.controller.client.ModelControllerClient)5 ExistingChannelModelControllerClient (org.jboss.as.controller.client.impl.ExistingChannelModelControllerClient)5 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 ProxyOperationControl (org.jboss.as.controller.ProxyController.ProxyOperationControl)4 MessageSeverity (org.jboss.as.controller.client.MessageSeverity)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Ignore (org.junit.Ignore)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2