use of org.apache.qpid.protonj2.test.driver.codec.messaging.DeliveryAnnotations in project qpid-protonj2 by apache.
the class DeliveryAnnotationsTypeCodecTest method doTestEncodeDecodeArray.
private void doTestEncodeDecodeArray(boolean fromStream) throws IOException {
ProtonBuffer buffer = ProtonByteBufferAllocator.DEFAULT.allocate();
InputStream stream = new ProtonBufferInputStream(buffer);
DeliveryAnnotations[] array = new DeliveryAnnotations[3];
Map<Symbol, Object> map = new HashMap<>();
map.put(Symbol.valueOf("1"), Boolean.TRUE);
map.put(Symbol.valueOf("2"), Boolean.FALSE);
array[0] = new DeliveryAnnotations(new HashMap<>());
array[1] = new DeliveryAnnotations(map);
array[2] = new DeliveryAnnotations(map);
encoder.writeObject(buffer, encoderState, array);
final Object result;
if (fromStream) {
result = streamDecoder.readObject(stream, streamDecoderState);
} else {
result = decoder.readObject(buffer, decoderState);
}
assertTrue(result.getClass().isArray());
assertEquals(DeliveryAnnotations.class, result.getClass().getComponentType());
DeliveryAnnotations[] resultArray = (DeliveryAnnotations[]) result;
for (int i = 0; i < resultArray.length; ++i) {
assertNotNull(resultArray[i]);
assertTrue(resultArray[i] instanceof DeliveryAnnotations);
assertEquals(array[i].getValue(), resultArray[i].getValue());
}
}
use of org.apache.qpid.protonj2.test.driver.codec.messaging.DeliveryAnnotations in project qpid-protonj2 by apache.
the class DeliveryAnnotationsTypeCodecTest method doTestSkipValue.
private void doTestSkipValue(boolean fromStream) throws IOException {
ProtonBuffer buffer = ProtonByteBufferAllocator.DEFAULT.allocate();
InputStream stream = new ProtonBufferInputStream(buffer);
Map<Symbol, Object> map = new HashMap<>();
map.put(Symbol.valueOf("one"), 1);
map.put(Symbol.valueOf("two"), Boolean.TRUE);
map.put(Symbol.valueOf("three"), "test");
for (int i = 0; i < 10; ++i) {
encoder.writeObject(buffer, encoderState, new DeliveryAnnotations(map));
}
encoder.writeObject(buffer, encoderState, new Modified());
for (int i = 0; i < 10; ++i) {
if (fromStream) {
StreamTypeDecoder<?> typeDecoder = streamDecoder.readNextTypeDecoder(stream, streamDecoderState);
assertEquals(DeliveryAnnotations.class, typeDecoder.getTypeClass());
typeDecoder.skipValue(stream, streamDecoderState);
} else {
TypeDecoder<?> typeDecoder = decoder.readNextTypeDecoder(buffer, decoderState);
assertEquals(DeliveryAnnotations.class, typeDecoder.getTypeClass());
typeDecoder.skipValue(buffer, decoderState);
}
}
final Object result;
if (fromStream) {
result = streamDecoder.readObject(stream, streamDecoderState);
} else {
result = decoder.readObject(buffer, decoderState);
}
assertNotNull(result);
assertTrue(result instanceof Modified);
Modified modified = (Modified) result;
assertFalse(modified.isUndeliverableHere());
assertFalse(modified.isDeliveryFailed());
}
use of org.apache.qpid.protonj2.test.driver.codec.messaging.DeliveryAnnotations in project qpid-protonj2 by apache.
the class StreamSenderTest method doTestSendWhenCreditIsAvailable.
private void doTestSendWhenCreditIsAvailable(boolean trySend, boolean addDeliveryAnnotations) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.remoteFlow().withDeliveryCount(0).withLinkCredit(10).withIncomingWindow(1024).withOutgoingWindow(10).withNextIncomingId(0).withNextOutgoingId(1).queue();
peer.expectBegin().respond();
peer.expectAttach().ofReceiver().respond();
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());
StreamSender sender = connection.openStreamSender("test-queue");
sender.openFuture().get(10, TimeUnit.SECONDS);
// This ensures that the flow to sender is processed before we try-send
Receiver receiver = connection.openReceiver("test-queue", new ReceiverOptions().creditWindow(0));
receiver.openFuture().get(10, TimeUnit.SECONDS);
Map<String, Object> deliveryAnnotations = new HashMap<>();
deliveryAnnotations.put("da1", 1);
deliveryAnnotations.put("da2", 2);
deliveryAnnotations.put("da3", 3);
DeliveryAnnotationsMatcher daMatcher = new DeliveryAnnotationsMatcher(true);
daMatcher.withEntry("da1", Matchers.equalTo(1));
daMatcher.withEntry("da2", Matchers.equalTo(2));
daMatcher.withEntry("da3", Matchers.equalTo(3));
EncodedAmqpValueMatcher bodyMatcher = new EncodedAmqpValueMatcher("Hello World");
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
if (addDeliveryAnnotations) {
payloadMatcher.setDeliveryAnnotationsMatcher(daMatcher);
}
payloadMatcher.setMessageContentMatcher(bodyMatcher);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withNonNullPayload();
peer.expectDetach().respond();
peer.expectEnd().respond();
peer.expectClose().respond();
Message<String> message = Message.create("Hello World");
final StreamTracker tracker;
if (trySend) {
if (addDeliveryAnnotations) {
tracker = sender.trySend(message, deliveryAnnotations);
} else {
tracker = sender.trySend(message);
}
} else {
if (addDeliveryAnnotations) {
tracker = sender.send(message, deliveryAnnotations);
} else {
tracker = sender.send(message);
}
}
assertNotNull(tracker);
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.codec.messaging.DeliveryAnnotations in project qpid-protonj2 by apache.
the class SenderTest method doTestSendWhenCreditIsAvailable.
private void doTestSendWhenCreditIsAvailable(boolean trySend, boolean addDeliveryAnnotations) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.remoteFlow().withDeliveryCount(0).withLinkCredit(10).withIncomingWindow(1024).withOutgoingWindow(10).withNextIncomingId(0).withNextOutgoingId(1).queue();
peer.expectAttach().ofReceiver().respond();
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();
Sender sender = session.openSender("test-queue");
sender.openFuture().get(10, TimeUnit.SECONDS);
// This ensures that the flow to sender is processed before we try-send
Receiver receiver = session.openReceiver("test-queue", new ReceiverOptions().creditWindow(0));
receiver.openFuture().get(10, TimeUnit.SECONDS);
Map<String, Object> deliveryAnnotations = new HashMap<>();
deliveryAnnotations.put("da1", 1);
deliveryAnnotations.put("da2", 2);
deliveryAnnotations.put("da3", 3);
DeliveryAnnotationsMatcher daMatcher = new DeliveryAnnotationsMatcher(true);
daMatcher.withEntry("da1", Matchers.equalTo(1));
daMatcher.withEntry("da2", Matchers.equalTo(2));
daMatcher.withEntry("da3", Matchers.equalTo(3));
EncodedAmqpValueMatcher bodyMatcher = new EncodedAmqpValueMatcher("Hello World");
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
if (addDeliveryAnnotations) {
payloadMatcher.setDeliveryAnnotationsMatcher(daMatcher);
}
payloadMatcher.setMessageContentMatcher(bodyMatcher);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withPayload(payloadMatcher);
peer.expectDetach().respond();
peer.expectClose().respond();
Message<String> message = Message.create("Hello World");
final Tracker tracker;
if (trySend) {
if (addDeliveryAnnotations) {
tracker = sender.trySend(message, deliveryAnnotations);
} else {
tracker = sender.trySend(message);
}
} else {
if (addDeliveryAnnotations) {
tracker = sender.send(message, deliveryAnnotations);
} else {
tracker = sender.send(message);
}
}
assertNotNull(tracker);
sender.closeAsync().get(10, TimeUnit.SECONDS);
connection.closeAsync().get(10, TimeUnit.SECONDS);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations