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);
}
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);
}
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"));
}
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());
}
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);
}
}
Aggregations