use of org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpSequenceMatcher 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 org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpSequenceMatcher in project qpid-protonj2 by apache.
the class MessageSendTest method doTestSendMessageWithListPayloadArrivesWithAMQPSequenceBody.
private void doTestSendMessageWithListPayloadArrivesWithAMQPSequenceBody(boolean useSetter) 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);
final List<UUID> payload = new ArrayList<>();
payload.add(UUID.randomUUID());
payload.add(UUID.randomUUID());
payload.add(UUID.randomUUID());
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();
EncodedAmqpSequenceMatcher bodyMatcher = new EncodedAmqpSequenceMatcher(payload);
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.setMessageContentMatcher(bodyMatcher);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withPayload(payloadMatcher).accept();
peer.expectDetach().respond();
peer.expectClose().respond();
final Message<List<UUID>> message;
if (useSetter) {
message = Message.<List<UUID>>create().body(payload);
} else {
message = Message.create(payload);
}
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);
}
}
Aggregations