use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class MessageSendTest method testSendMessageWithDeliveryAnnotationsPopulated.
@Test
public void testSendMessageWithDeliveryAnnotationsPopulated() 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();
DeliveryAnnotationsMatcher daMatcher = new DeliveryAnnotationsMatcher(true);
daMatcher.withEntry("one", Matchers.equalTo(1));
daMatcher.withEntry("two", Matchers.equalTo(2));
daMatcher.withEntry("three", Matchers.equalTo(3));
EncodedAmqpValueMatcher bodyMatcher = new EncodedAmqpValueMatcher("Hello World");
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.setDeliveryAnnotationsMatcher(daMatcher);
payloadMatcher.setMessageContentMatcher(bodyMatcher);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withPayload(payloadMatcher).accept();
peer.expectDetach().respond();
peer.expectClose().respond();
final Message<String> message = Message.create("Hello World");
// Populate delivery annotations
Map<String, Object> deliveryAnnotations = new HashMap<>();
deliveryAnnotations.put("one", 1);
deliveryAnnotations.put("two", 2);
deliveryAnnotations.put("three", 3);
final Tracker tracker = sender.send(message, deliveryAnnotations);
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 MessageSendTest method testSendMessageWithPropertiesValuesPopulated.
@Test
public void testSendMessageWithPropertiesValuesPopulated() 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();
PropertiesMatcher propertiesMatcher = new PropertiesMatcher(true);
propertiesMatcher.withMessageId("ID:12345");
propertiesMatcher.withUserId("user".getBytes(StandardCharsets.UTF_8));
propertiesMatcher.withTo("the-management");
propertiesMatcher.withSubject("amqp");
propertiesMatcher.withReplyTo("the-minions");
propertiesMatcher.withCorrelationId("abc");
propertiesMatcher.withContentEncoding("application/json");
propertiesMatcher.withContentEncoding("gzip");
propertiesMatcher.withAbsoluteExpiryTime(123);
propertiesMatcher.withCreationTime(1);
propertiesMatcher.withGroupId("disgruntled");
propertiesMatcher.withGroupSequence(8192);
propertiesMatcher.withReplyToGroupId("/dev/null");
EncodedAmqpValueMatcher bodyMatcher = new EncodedAmqpValueMatcher("Hello World");
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.setPropertiesMatcher(propertiesMatcher);
payloadMatcher.setMessageContentMatcher(bodyMatcher);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withPayload(payloadMatcher).accept();
peer.expectDetach().respond();
peer.expectClose().respond();
final Message<String> message = Message.create("Hello World");
// Populate all Properties values
message.messageId("ID:12345");
message.userId("user".getBytes(StandardCharsets.UTF_8));
message.to("the-management");
message.subject("amqp");
message.replyTo("the-minions");
message.correlationId("abc");
message.contentEncoding("application/json");
message.contentEncoding("gzip");
message.absoluteExpiryTime(123);
message.creationTime(1);
message.groupId("disgruntled");
message.groupSequence(8192);
message.replyToGroupId("/dev/null");
final Tracker tracker = sender.send(message);
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 MessageSendTest method testSendMessageWithMessageAnnotationsPopulated.
@Test
public void testSendMessageWithMessageAnnotationsPopulated() 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();
MessageAnnotationsMatcher maMatcher = new MessageAnnotationsMatcher(true);
maMatcher.withEntry("one", Matchers.equalTo(1));
maMatcher.withEntry("two", Matchers.equalTo(2));
maMatcher.withEntry("three", Matchers.equalTo(3));
EncodedAmqpValueMatcher bodyMatcher = new EncodedAmqpValueMatcher("Hello World");
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.setMessageAnnotationsMatcher(maMatcher);
payloadMatcher.setMessageContentMatcher(bodyMatcher);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withPayload(payloadMatcher).accept();
peer.expectDetach().respond();
peer.expectClose().respond();
final Message<String> message = Message.create("Hello World");
// Populate message annotations
message.annotation("one", 1);
message.annotation("two", 2);
message.annotation("three", 3);
final Tracker tracker = sender.send(message);
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 MessageSendTest method testSendMessageWithMultipleAmqpSequenceSections.
@Test
public void testSendMessageWithMultipleAmqpSequenceSections() 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();
List<String> list1 = new ArrayList<>();
list1.add("1");
List<String> list2 = new ArrayList<>();
list2.add("21");
list2.add("22");
List<String> list3 = new ArrayList<>();
list3.add("31");
list3.add("32");
list3.add("33");
EncodedAmqpSequenceMatcher bodyMatcher1 = new EncodedAmqpSequenceMatcher(list1, true);
EncodedAmqpSequenceMatcher bodyMatcher2 = new EncodedAmqpSequenceMatcher(list2, true);
EncodedAmqpSequenceMatcher bodyMatcher3 = new EncodedAmqpSequenceMatcher(list3, false);
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.addMessageContentMatcher(bodyMatcher1);
payloadMatcher.addMessageContentMatcher(bodyMatcher2);
payloadMatcher.addMessageContentMatcher(bodyMatcher3);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withPayload(payloadMatcher).accept();
peer.expectDetach().respond();
peer.expectClose().respond();
final AdvancedMessage<List<String>> message = AdvancedMessage.create();
message.addBodySection(new AmqpSequence<>(list1));
message.addBodySection(new AmqpSequence<>(list2));
message.addBodySection(new AmqpSequence<>(list3));
final Tracker tracker = sender.send(message);
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 ConnectionTest method testRemotelyCloseConnectionDuringSessionCreation.
@Test
public void testRemotelyCloseConnectionDuringSessionCreation() throws Exception {
final String BREAD_CRUMB = "ErrorMessageBreadCrumb";
try (ProtonTestServer peer = new ProtonTestServer(testServerOptions())) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin();
peer.remoteClose().withErrorCondition(AmqpError.NOT_ALLOWED.toString(), BREAD_CRUMB).queue();
peer.expectClose();
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(), connectionOptions());
connection.openFuture().get();
Session session = connection.openSession();
try {
session.openFuture().get();
fail("Open should throw error when waiting for remote open and connection remotely closed.");
} catch (ExecutionException error) {
LOG.info("Session open failed with error: ", error);
assertNotNull(error.getMessage(), "Expected exception to have a message");
assertTrue(error.getMessage().contains(BREAD_CRUMB), "Expected breadcrumb to be present in message");
assertNotNull(error.getCause(), "Execution error should convey the cause");
assertTrue(error.getCause() instanceof ClientConnectionRemotelyClosedException);
}
session.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations