Search in sources :

Example 1 with AmqpSequence

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);
    }
}
Also used : Tracker(org.apache.qpid.protonj2.client.Tracker) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) SenderOptions(org.apache.qpid.protonj2.client.SenderOptions) Connection(org.apache.qpid.protonj2.client.Connection) ArrayList(java.util.ArrayList) TransferPayloadCompositeMatcher(org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher) URI(java.net.URI) Sender(org.apache.qpid.protonj2.client.Sender) EncodedAmqpSequenceMatcher(org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpSequenceMatcher) ArrayList(java.util.ArrayList) List(java.util.List) Client(org.apache.qpid.protonj2.client.Client) Session(org.apache.qpid.protonj2.client.Session) Test(org.junit.jupiter.api.Test)

Example 2 with AmqpSequence

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) Data(org.apache.qpid.protonj2.types.messaging.Data) Section(org.apache.qpid.protonj2.types.messaging.Section) Test(org.junit.jupiter.api.Test)

Example 3 with AmqpSequence

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));
}
Also used : ArrayList(java.util.ArrayList) Data(org.apache.qpid.protonj2.types.messaging.Data) Section(org.apache.qpid.protonj2.types.messaging.Section) Test(org.junit.jupiter.api.Test)

Example 4 with AmqpSequence

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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) Data(org.apache.qpid.protonj2.types.messaging.Data) Section(org.apache.qpid.protonj2.types.messaging.Section) Test(org.junit.jupiter.api.Test)

Example 5 with AmqpSequence

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);
}
Also used : ListTypeDecoder(org.apache.qpid.protonj2.codec.decoders.primitives.ListTypeDecoder) AmqpSequence(org.apache.qpid.protonj2.types.messaging.AmqpSequence)

Aggregations

ArrayList (java.util.ArrayList)10 AmqpSequence (org.apache.qpid.protonj2.types.messaging.AmqpSequence)9 Test (org.junit.jupiter.api.Test)6 List (java.util.List)5 Data (org.apache.qpid.protonj2.types.messaging.Data)5 Section (org.apache.qpid.protonj2.types.messaging.Section)5 InputStream (java.io.InputStream)4 ProtonBuffer (org.apache.qpid.protonj2.buffer.ProtonBuffer)4 ProtonBufferInputStream (org.apache.qpid.protonj2.buffer.ProtonBufferInputStream)4 ListTypeDecoder (org.apache.qpid.protonj2.codec.decoders.primitives.ListTypeDecoder)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 URI (java.net.URI)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 AdvancedMessage (org.apache.qpid.protonj2.client.AdvancedMessage)1 Client (org.apache.qpid.protonj2.client.Client)1