use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project vertx-proton by vert-x3.
the class TrackerSubscriberWhiteboxVerificationTckTest method createServer.
private TestServer createServer() throws Exception {
return new TestServer(vertx, (connection) -> {
connection.openHandler(res -> {
LOG.trace("Client connected: " + connection.getRemoteContainer());
connection.open();
}).closeHandler(c -> {
LOG.trace("Client closing amqp connection: " + connection.getRemoteContainer());
connection.close();
connection.disconnect();
}).disconnectHandler(c -> {
LOG.trace("Client socket disconnected: " + connection.getRemoteContainer());
connection.disconnect();
}).sessionOpenHandler(session -> session.open());
connection.receiverOpenHandler(receiver -> {
if (!server.getDetachLink()) {
LOG.trace("Receiving from client to: " + receiver.getRemoteTarget().getAddress());
// This is rather naive, for example use only, proper
receiver.setTarget(receiver.getRemoteTarget());
// servers should ensure that they advertise their own
// Target settings that actually reflect what is in place.
// The request may have also been for a dynamic address.
receiver.handler((delivery, msg) -> {
String address = msg.getAddress();
if (address == null) {
address = receiver.getRemoteTarget().getAddress();
}
Section body = msg.getBody();
String content = "unknown";
if (body instanceof AmqpValue) {
content = (String) ((AmqpValue) body).getValue();
}
LOG.trace("message to:" + address + ", body: " + content);
});
receiver.closeHandler(s -> {
s.result().close();
});
}
receiver.open();
if (server.getDetachLink()) {
receiver.setCondition(new ErrorCondition(Symbol.getSymbol("Failed Subscriber Requested"), ""));
receiver.close();
}
});
});
}
use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project vertx-proton by vert-x3.
the class ProtonClientTest method remoteCloseDefaultSessionTestImpl.
private void remoteCloseDefaultSessionTestImpl(TestContext context, boolean sessionError) throws InterruptedException, ExecutionException {
server.close();
Async async = context.async();
ProtonServer protonServer = null;
try {
protonServer = createServer(serverConnection -> {
Promise<ProtonSession> sessionPromise = Promise.<ProtonSession>promise();
// Expect a session to open, when the sender is created by the client
serverConnection.sessionOpenHandler(serverSession -> {
LOG.trace("Server session open");
serverSession.open();
sessionPromise.complete(serverSession);
});
// Expect a receiver link, then close the session after opening it.
serverConnection.receiverOpenHandler(serverReceiver -> {
LOG.trace("Server receiver open");
serverReceiver.open();
context.assertTrue(sessionPromise.future().succeeded(), "Session future not [yet] succeeded");
LOG.trace("Server session close");
ProtonSession s = sessionPromise.future().result();
if (sessionError) {
ErrorCondition error = new ErrorCondition();
error.setCondition(AmqpError.INTERNAL_ERROR);
error.setDescription("error description");
s.setCondition(error);
}
s.close();
});
serverConnection.openHandler(result -> {
LOG.trace("Server connection open");
serverConnection.open();
});
});
// ===== Client Handling =====
ProtonClient client = ProtonClient.create(vertx);
client.connect("localhost", protonServer.actualPort(), res -> {
context.assertTrue(res.succeeded());
ProtonConnection connection = res.result();
connection.openHandler(x -> {
context.assertTrue(x.succeeded(), "Connection open failed");
LOG.trace("Client connection opened");
// Create a sender to provoke creation (and subsequent
// closure of by the server) the connections default session
connection.createSender(null).open();
});
connection.closeHandler(x -> {
LOG.trace("Connection close handler called (as espected): " + x.cause());
async.complete();
});
connection.open();
});
async.awaitSuccess();
} finally {
if (protonServer != null) {
protonServer.close();
}
}
}
use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project vertx-proton by vert-x3.
the class ProtonClientTest method doMaxMessageSizeTestImpl.
private void doMaxMessageSizeTestImpl(TestContext context, final int maxFrameSize, final int maxMessageSize, final int dataPayloadSize) throws Exception {
server.close();
Async serverSenderOpenAsync = context.async();
Async serverSenderCreditCheck = context.async();
Async clientReceiverOpenAsync = context.async();
Async serverSenderDetachCheck = context.async();
Async maxMessageSizeExceededHandlerFired = context.async();
AtomicInteger messageCount = new AtomicInteger();
AtomicInteger handlerCount = new AtomicInteger();
final UnsignedLong receiverMaxMsgSize = UnsignedLong.valueOf(maxMessageSize);
final UnsignedLong serverMaxMsgSize = UnsignedLong.valueOf(5 * receiverMaxMsgSize.longValue());
ProtonServer protonServer = null;
try {
protonServer = createServer((serverConnection) -> {
serverConnection.openHandler(result -> {
serverConnection.open();
});
serverConnection.sessionOpenHandler(session -> {
session.open();
});
serverConnection.senderOpenHandler(serverSender -> {
context.assertEquals(receiverMaxMsgSize, serverSender.getRemoteMaxMessageSize(), "unexpected remote max message size at server");
context.assertNull(serverSender.getMaxMessageSize(), "Expected no value to be set");
serverSender.setMaxMessageSize(serverMaxMsgSize);
context.assertEquals(serverMaxMsgSize, serverSender.getMaxMessageSize(), "Expected value to now be set");
serverSender.sendQueueDrainHandler(ss -> {
if (!serverSenderCreditCheck.isCompleted()) {
context.assertTrue(serverSender.getCredit() > 3, "Unexpectedly low credit: " + serverSender.getCredit());
serverSenderCreditCheck.complete();
sendMessagesForMaxMessageSizeTest(dataPayloadSize, serverSender);
}
});
serverSender.detachHandler(res -> {
ErrorCondition remoteCondition = serverSender.getRemoteCondition();
context.assertNotNull(remoteCondition);
context.assertEquals(remoteCondition.getCondition(), LinkError.MESSAGE_SIZE_EXCEEDED);
context.assertTrue(res.failed());
serverSender.detach();
serverSenderDetachCheck.complete();
});
LOG.trace("Server sender opened");
serverSender.open();
serverSenderOpenAsync.complete();
});
});
// ===== Client Handling =====
ProtonClient client = ProtonClient.create(vertx);
ProtonClientOptions options = new ProtonClientOptions();
options.setMaxFrameSize(maxFrameSize);
client.connect(options, "localhost", protonServer.actualPort(), res -> {
context.assertTrue(res.succeeded());
ProtonConnection connection = res.result();
connection.openHandler(x -> {
LOG.trace("Client connection opened");
final ProtonReceiver receiver = connection.createReceiver("some-address");
context.assertNull(receiver.getMaxMessageSize(), "Expected no value to be set");
receiver.setMaxMessageSize(receiverMaxMsgSize);
context.assertEquals(receiverMaxMsgSize, receiver.getMaxMessageSize(), "Expected value to now be set");
receiver.openHandler(y -> {
LOG.trace("Client link opened");
context.assertEquals(serverMaxMsgSize, receiver.getRemoteMaxMessageSize(), "unexpected remote max message size at client");
clientReceiverOpenAsync.complete();
receiver.handler((delivery, message) -> {
validateMessage(context, messageCount.incrementAndGet(), "small-first-message", message);
});
receiver.maxMessageSizeExceededHandler(recv -> {
handlerCount.incrementAndGet();
maxMessageSizeExceededHandlerFired.complete();
});
});
receiver.open();
}).open();
});
serverSenderOpenAsync.awaitSuccess();
clientReceiverOpenAsync.awaitSuccess();
serverSenderCreditCheck.awaitSuccess();
maxMessageSizeExceededHandlerFired.awaitSuccess();
serverSenderDetachCheck.awaitSuccess();
context.assertEquals(1, handlerCount.get(), "Unexpected number of handler executions");
context.assertEquals(1, messageCount.get(), "Unexpected number of deliveries");
} finally {
if (protonServer != null) {
protonServer.close();
}
}
}
use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project vertx-proton by vert-x3.
the class MessagePublisherVerificationTckTest method createServer.
private TestServer createServer() throws Exception {
return new TestServer(vertx, (connection) -> {
connection.openHandler(res -> {
LOG.trace("Client connected: " + connection.getRemoteContainer());
connection.open();
}).closeHandler(c -> {
LOG.trace("Client closing amqp connection: " + connection.getRemoteContainer());
connection.close();
connection.disconnect();
}).disconnectHandler(c -> {
LOG.trace("Client socket disconnected: " + connection.getRemoteContainer());
connection.disconnect();
}).sessionOpenHandler(session -> session.open());
connection.senderOpenHandler(sender -> {
if (!server.getDetachLink()) {
LOG.trace("Sending to client from: " + sender.getRemoteSource().getAddress());
// This is rather naive, for example use only, proper
sender.setSource(sender.getRemoteSource());
// servers should ensure that they advertise their own
// Source settings that actually reflect what is in place.
// The request may have also been for a dynamic address.
AtomicLong count = new AtomicLong();
AtomicLong outstanding = new AtomicLong();
sender.sendQueueDrainHandler(s -> {
while (!s.sendQueueFull()) {
LOG.trace("Sending message to client");
Message m = message("Hello World from Server!" + count.incrementAndGet());
outstanding.incrementAndGet();
s.send(m, delivery -> {
LOG.trace("The message was received by the client.");
});
}
});
sender.closeHandler(s -> {
s.result().close();
});
}
sender.open();
if (server.getDetachLink()) {
sender.setCondition(new ErrorCondition(Symbol.getSymbol("Failed Publisher Requested"), ""));
sender.close();
}
});
});
}
use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project vertx-proton by vert-x3.
the class ProtonReceiverImpl method handleMaxMessageSizeExceeded.
private void handleMaxMessageSizeExceeded(final UnsignedLong maxMessageSize, final Receiver receiver) {
try {
LOG.debug("delivery received exceeding max-message-size of " + maxMessageSize + " bytes");
if (maxMessageSizeExceededHandler != null) {
maxMessageSizeExceededHandler.handle(this);
}
} finally {
// Detach link if handler has not sent a detach frame already
if (!receiver.detached() && isOpen()) {
LOG.debug("detaching link with error condition " + LinkError.MESSAGE_SIZE_EXCEEDED);
setCondition(new ErrorCondition(LinkError.MESSAGE_SIZE_EXCEEDED, "exceeded max-message-size of " + maxMessageSize + " bytes "));
detach();
}
}
}
Aggregations