use of org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpValueMatcher in project qpid-protonj2 by apache.
the class StreamSenderTest method testSendCustomMessageWithMultipleAmqpValueSections.
@Test
public void testSendCustomMessageWithMultipleAmqpValueSections() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
// Hidden session for stream sender
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();
StreamSenderOptions options = new StreamSenderOptions();
options.deliveryMode(DeliveryMode.AT_MOST_ONCE);
options.writeBufferSize(Integer.MAX_VALUE);
StreamSender sender = connection.openStreamSender("test-qos", options);
// Create a custom message format send context and ensure that no early buffer writes take place
StreamSenderMessage message = sender.beginMessage();
assertEquals(sender, message.sender());
assertNull(message.tracker());
assertEquals(Header.DEFAULT_PRIORITY, message.priority());
assertEquals(Header.DEFAULT_DELIVERY_COUNT, message.deliveryCount());
assertEquals(Header.DEFAULT_FIRST_ACQUIRER, message.firstAcquirer());
assertEquals(Header.DEFAULT_TIME_TO_LIVE, message.timeToLive());
assertEquals(Header.DEFAULT_DURABILITY, message.durable());
message.messageFormat(17);
// Gates send on remote flow having been sent and received
session.openReceiver("dummy").openFuture().get();
HeaderMatcher headerMatcher = new HeaderMatcher(true);
headerMatcher.withDurable(true);
headerMatcher.withPriority((byte) 1);
headerMatcher.withTtl(65535);
headerMatcher.withFirstAcquirer(true);
headerMatcher.withDeliveryCount(2);
// Note: This is a specification violation but could be used by other message formats
// and we don't attempt to enforce at the Send Context what users write
EncodedAmqpValueMatcher bodyMatcher1 = new EncodedAmqpValueMatcher("one", true);
EncodedAmqpValueMatcher bodyMatcher2 = new EncodedAmqpValueMatcher("two", true);
EncodedAmqpValueMatcher bodyMatcher3 = new EncodedAmqpValueMatcher("three", false);
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.setHeadersMatcher(headerMatcher);
payloadMatcher.addMessageContentMatcher(bodyMatcher1);
payloadMatcher.addMessageContentMatcher(bodyMatcher2);
payloadMatcher.addMessageContentMatcher(bodyMatcher3);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withMore(false).withMessageFormat(17).withPayload(payloadMatcher).accept();
peer.expectDetach().respond();
peer.expectEnd().respond();
peer.expectClose().respond();
// Populate all Header values
Header header = new Header();
header.setDurable(true);
header.setPriority((byte) 1);
header.setTimeToLive(65535);
header.setFirstAcquirer(true);
header.setDeliveryCount(2);
message.header(header);
message.addBodySection(new AmqpValue<>("one"));
message.addBodySection(new AmqpValue<>("two"));
message.addBodySection(new AmqpValue<>("three"));
message.complete();
assertNotNull(message.tracker());
assertEquals(17, message.messageFormat());
Wait.assertTrue(() -> message.tracker().settlementFuture().isDone());
assertTrue(message.tracker().settlementFuture().get().settled());
assertThrows(ClientIllegalStateException.class, () -> message.addBodySection(new AmqpValue<>("three")));
assertThrows(ClientIllegalStateException.class, () -> message.body());
assertThrows(ClientIllegalStateException.class, () -> message.rawOutputStream());
assertThrows(ClientIllegalStateException.class, () -> message.abort());
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.EncodedAmqpValueMatcher in project qpid-protonj2 by apache.
the class MessageSendTest method testSendMessageWithMultipleAmqpValueSections.
@Test
public void testSendMessageWithMultipleAmqpValueSections() 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();
// Note: This is a specification violation but could be used by other message formats
// and we don't attempt to enforce at the AdvancedMessage API level what users do.
EncodedAmqpValueMatcher bodyMatcher1 = new EncodedAmqpValueMatcher("one", true);
EncodedAmqpValueMatcher bodyMatcher2 = new EncodedAmqpValueMatcher("two", true);
EncodedAmqpValueMatcher bodyMatcher3 = new EncodedAmqpValueMatcher("three", false);
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.addMessageContentMatcher(bodyMatcher1);
payloadMatcher.addMessageContentMatcher(bodyMatcher2);
payloadMatcher.addMessageContentMatcher(bodyMatcher3);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withMessageFormat(17).withPayload(payloadMatcher).accept();
peer.expectDetach().respond();
peer.expectClose().respond();
final AdvancedMessage<String> message = AdvancedMessage.create();
message.messageFormat(17);
message.addBodySection(new AmqpValue<>("one"));
message.addBodySection(new AmqpValue<>("two"));
message.addBodySection(new AmqpValue<>("three"));
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.EncodedAmqpValueMatcher in project qpid-protonj2 by apache.
the class MessageSendTest method testSendMessageWithFootersPopulated.
@Test
public void testSendMessageWithFootersPopulated() 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();
FooterMatcher footerMatcher = new FooterMatcher(false);
footerMatcher.withEntry("f1", Matchers.equalTo(1));
footerMatcher.withEntry("f2", Matchers.equalTo(2));
footerMatcher.withEntry("f3", Matchers.equalTo(3));
EncodedAmqpValueMatcher bodyMatcher = new EncodedAmqpValueMatcher("Hello World", true);
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.setMessageContentMatcher(bodyMatcher);
payloadMatcher.setFootersMatcher(footerMatcher);
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 footers
message.footer("f1", 1);
message.footer("f2", 2);
message.footer("f3", 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 org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpValueMatcher in project qpid-protonj2 by apache.
the class MessageSendTest method testSendMessageWithApplicationPropertiesPopulated.
@Test
public void testSendMessageWithApplicationPropertiesPopulated() 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();
ApplicationPropertiesMatcher apMatcher = new ApplicationPropertiesMatcher(true);
apMatcher.withEntry("one", Matchers.equalTo(1));
apMatcher.withEntry("two", Matchers.equalTo(2));
apMatcher.withEntry("three", Matchers.equalTo(3));
EncodedAmqpValueMatcher bodyMatcher = new EncodedAmqpValueMatcher("Hello World");
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.setApplicationPropertiesMatcher(apMatcher);
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 application properties
message.property("one", 1);
message.property("two", 2);
message.property("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 org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpValueMatcher in project qpid-protonj2 by apache.
the class MessageSendTest method testSendMessageWithHeaderValuesPopulated.
@Test
public void testSendMessageWithHeaderValuesPopulated() 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(true);
headerMatcher.withDurable(true);
headerMatcher.withPriority((byte) 1);
headerMatcher.withTtl(65535);
headerMatcher.withFirstAcquirer(true);
headerMatcher.withDeliveryCount(2);
EncodedAmqpValueMatcher bodyMatcher = new EncodedAmqpValueMatcher("Hello World");
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.setHeadersMatcher(headerMatcher);
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 Header values
message.durable(true);
message.priority((byte) 1);
message.timeToLive(65535);
message.firstAcquirer(true);
message.deliveryCount(2);
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