use of org.apache.qpid.protonj2.types.messaging.AmqpSequence 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.types.messaging.AmqpSequence in project qpid-protonj2 by apache.
the class ClientMessageTest method testAddMultipleBodySectionsWithNonDefaultMessageFormat.
@Test
public void testAddMultipleBodySectionsWithNonDefaultMessageFormat() {
ClientMessage<Object> message = ClientMessage.create().messageFormat(1);
List<Section<?>> expected = new ArrayList<>();
expected.add(new Data(new byte[] { 0 }));
expected.add(new AmqpValue<>("test"));
expected.add(new AmqpSequence<>(new ArrayList<>()));
assertDoesNotThrow(() -> message.bodySections(expected));
final AtomicInteger count = new AtomicInteger();
message.bodySections().forEach(value -> {
assertEquals(expected.get(count.get()), value);
count.incrementAndGet();
});
assertEquals(expected.size(), count.get());
}
use of org.apache.qpid.protonj2.types.messaging.AmqpSequence in project qpid-protonj2 by apache.
the class ClientMessageTest method testReplaceOriginalWithSetBodySectionDoesThrowValidationErrorIfInValid.
@Test
public void testReplaceOriginalWithSetBodySectionDoesThrowValidationErrorIfInValid() {
ClientMessage<Object> message = ClientMessage.create();
// AmqpValue
message.body("string");
List<Section<?>> expected = new ArrayList<>();
expected.add(new Data(new byte[] { 0 }));
expected.add(new AmqpValue<>("test"));
expected.add(new AmqpSequence<>(new ArrayList<>()));
assertThrows(IllegalArgumentException.class, () -> message.bodySections(expected));
}
use of org.apache.qpid.protonj2.types.messaging.AmqpSequence in project qpid-protonj2 by apache.
the class ClientMessageTest method testSetMultipleBodySectionsWithNonDefaultMessageFormat.
@Test
public void testSetMultipleBodySectionsWithNonDefaultMessageFormat() {
ClientMessage<Object> message = ClientMessage.create().messageFormat(1);
List<Section<?>> expected = new ArrayList<>();
expected.add(new Data(new byte[] { 0 }));
expected.add(new AmqpValue<>("test"));
expected.add(new AmqpSequence<>(new ArrayList<>()));
assertDoesNotThrow(() -> message.bodySections(expected));
final AtomicInteger count = new AtomicInteger();
message.bodySections().forEach(value -> {
assertEquals(expected.get(count.get()), value);
count.incrementAndGet();
});
assertEquals(expected.size(), count.get());
}
use of org.apache.qpid.protonj2.types.messaging.AmqpSequence in project qpid-protonj2 by apache.
the class AmqpSequenceTypeDecoder method readValue.
@SuppressWarnings("unchecked")
@Override
public AmqpSequence readValue(InputStream stream, StreamDecoderState state) throws DecodeException {
final StreamTypeDecoder<?> decoder = state.getDecoder().readNextTypeDecoder(stream, state);
final ListTypeDecoder valueDecoder = checkIsExpectedTypeAndCast(ListTypeDecoder.class, decoder);
final List<Object> result = valueDecoder.readValue(stream, state);
return new AmqpSequence<>(result);
}
Aggregations