use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class MessageSendTest method testConvertMessageToAdvancedAndSendAMQPHeader.
@Test
public void testConvertMessageToAdvancedAndSendAMQPHeader() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.remoteFlow().withLinkCredit(10).queue();
// Open a receiver to ensure sender link has processed
peer.expectAttach().respond();
// the inbound flow frame we sent previously before send.
peer.expectFlow();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Sender test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort()).openFuture().get();
Session session = connection.openSession().openFuture().get();
SenderOptions options = new SenderOptions().deliveryMode(DeliveryMode.AT_MOST_ONCE);
Sender sender = session.openSender("test-qos", options);
// Gates send on remote flow having been sent and received
session.openReceiver("dummy").openFuture().get();
HeaderMatcher headerMatcher = new HeaderMatcher(false);
headerMatcher.withDurable(true);
headerMatcher.withPriority((byte) 1);
headerMatcher.withTtl(65535);
headerMatcher.withFirstAcquirer(true);
headerMatcher.withDeliveryCount(2);
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.setHeadersMatcher(headerMatcher);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withPayload(payloadMatcher).accept();
peer.expectDetach().respond();
peer.expectClose().respond();
final Message<String> message = Message.create();
final AdvancedMessage<String> advanced = message.toAdvancedMessage();
// Populate all Header values
Header header = new Header();
header.setDurable(true);
header.setPriority((byte) 1);
header.setTimeToLive(65535);
header.setFirstAcquirer(true);
header.setDeliveryCount(2);
advanced.header(header);
final Tracker tracker = sender.send(advanced);
assertNotNull(tracker);
assertNotNull(tracker.settlementFuture().isDone());
assertNotNull(tracker.settlementFuture().get().settled());
sender.closeAsync().get(10, TimeUnit.SECONDS);
connection.closeAsync().get(10, TimeUnit.SECONDS);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class ReceiverTest method doTestReceiveTimedCallFailsWhenReceiverDetachedOrClosed.
private void doTestReceiveTimedCallFailsWhenReceiverDetachedOrClosed(boolean close) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofReceiver().respond();
peer.expectFlow().withLinkCredit(10);
peer.expectDetach().withClosed(close).respond();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
Session session = connection.openSession();
Receiver receiver = session.openReceiver("test-queue").openFuture().get();
if (close) {
receiver.closeAsync();
} else {
receiver.detachAsync();
}
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
try {
receiver.receive(60, TimeUnit.SECONDS);
fail("Receive call should fail when link closed or detached.");
} catch (ClientIllegalStateException cliEx) {
LOG.debug("Receiver threw error on receive call", cliEx);
}
peer.expectClose().respond();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class ReceiverTest method testReceiveBlockedForMessageFailsWhenConnectionRemotelyClosed.
@Test
public void testReceiveBlockedForMessageFailsWhenConnectionRemotelyClosed() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofReceiver().respond();
peer.expectFlow().withLinkCredit(10);
peer.remoteClose().withErrorCondition(AmqpError.RESOURCE_DELETED.toString(), "Connection was deleted").afterDelay(25).queue();
peer.expectClose();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Receiver test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
Session session = connection.openSession();
Receiver receiver = session.openReceiver("test-queue");
receiver.openFuture().get();
try {
receiver.receive();
fail("Receive should have failed when Connection remotely closed.");
} catch (ClientConnectionRemotelyClosedException cliEx) {
// Expected
}
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class ReceiverTest method doTestCreateReceiverWithConfiguredQoS.
private void doTestCreateReceiverWithConfiguredQoS(DeliveryMode qos) throws Exception {
byte sndMode = qos == DeliveryMode.AT_MOST_ONCE ? SenderSettleMode.SETTLED.byteValue() : SenderSettleMode.UNSETTLED.byteValue();
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().withRole(Role.RECEIVER.getValue()).withSndSettleMode(sndMode).withRcvSettleMode(ReceiverSettleMode.FIRST.byteValue()).respond().withSndSettleMode(sndMode).withRcvSettleMode(ReceiverSettleMode.FIRST.byteValue());
peer.expectFlow();
peer.expectDetach().respond();
peer.expectClose().respond();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
connection.openFuture().get(10, TimeUnit.SECONDS);
Session session = connection.openSession();
session.openFuture().get(10, TimeUnit.SECONDS);
ReceiverOptions options = new ReceiverOptions().deliveryMode(qos);
Receiver receiver = session.openReceiver("test-qos", options);
receiver.openFuture().get(10, TimeUnit.SECONDS);
assertEquals("test-qos", receiver.address());
receiver.closeAsync().get(10, TimeUnit.SECONDS);
connection.closeAsync().get(10, TimeUnit.SECONDS);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class ReceiverTest method doTestOpenReceiverWaitFailsWhenConnectionDrops.
private void doTestOpenReceiverWaitFailsWhenConnectionDrops(boolean timeout) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofReceiver();
peer.expectFlow();
peer.dropAfterLastHandler(10);
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Sender test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
Session session = connection.openSession();
Receiver receiver = session.openReceiver("test-queue");
try {
if (timeout) {
receiver.openFuture().get(10, TimeUnit.SECONDS);
} else {
receiver.openFuture().get();
}
fail("Should not complete the open future without an error");
} catch (ExecutionException exe) {
Throwable cause = exe.getCause();
assertTrue(cause instanceof ClientIOException);
}
connection.closeAsync().get(10, TimeUnit.SECONDS);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations