Search in sources :

Example 16 with DeliveryAnnotations

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());
    }
}
Also used : ProtonBuffer(org.apache.qpid.protonj2.buffer.ProtonBuffer) HashMap(java.util.HashMap) ProtonBufferInputStream(org.apache.qpid.protonj2.buffer.ProtonBufferInputStream) InputStream(java.io.InputStream) Symbol(org.apache.qpid.protonj2.types.Symbol) DeliveryAnnotations(org.apache.qpid.protonj2.types.messaging.DeliveryAnnotations) ProtonBufferInputStream(org.apache.qpid.protonj2.buffer.ProtonBufferInputStream)

Example 17 with DeliveryAnnotations

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());
}
Also used : ProtonBuffer(org.apache.qpid.protonj2.buffer.ProtonBuffer) Modified(org.apache.qpid.protonj2.types.messaging.Modified) HashMap(java.util.HashMap) ProtonBufferInputStream(org.apache.qpid.protonj2.buffer.ProtonBufferInputStream) InputStream(java.io.InputStream) Symbol(org.apache.qpid.protonj2.types.Symbol) DeliveryAnnotations(org.apache.qpid.protonj2.types.messaging.DeliveryAnnotations) ProtonBufferInputStream(org.apache.qpid.protonj2.buffer.ProtonBufferInputStream)

Example 18 with DeliveryAnnotations

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);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) DeliveryAnnotationsMatcher(org.apache.qpid.protonj2.test.driver.matchers.messaging.DeliveryAnnotationsMatcher) HashMap(java.util.HashMap) Connection(org.apache.qpid.protonj2.client.Connection) EncodedAmqpValueMatcher(org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpValueMatcher) Receiver(org.apache.qpid.protonj2.client.Receiver) StreamTracker(org.apache.qpid.protonj2.client.StreamTracker) TransferPayloadCompositeMatcher(org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher) URI(java.net.URI) StreamSender(org.apache.qpid.protonj2.client.StreamSender) ReceiverOptions(org.apache.qpid.protonj2.client.ReceiverOptions) Client(org.apache.qpid.protonj2.client.Client)

Example 19 with DeliveryAnnotations

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);
    }
}
Also used : Tracker(org.apache.qpid.protonj2.client.Tracker) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) DeliveryAnnotationsMatcher(org.apache.qpid.protonj2.test.driver.matchers.messaging.DeliveryAnnotationsMatcher) HashMap(java.util.HashMap) Connection(org.apache.qpid.protonj2.client.Connection) EncodedAmqpValueMatcher(org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpValueMatcher) Receiver(org.apache.qpid.protonj2.client.Receiver) TransferPayloadCompositeMatcher(org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher) URI(java.net.URI) Sender(org.apache.qpid.protonj2.client.Sender) ReceiverOptions(org.apache.qpid.protonj2.client.ReceiverOptions) Client(org.apache.qpid.protonj2.client.Client) Session(org.apache.qpid.protonj2.client.Session)

Aggregations

DeliveryAnnotations (org.apache.qpid.protonj2.types.messaging.DeliveryAnnotations)11 ProtonBuffer (org.apache.qpid.protonj2.buffer.ProtonBuffer)10 HashMap (java.util.HashMap)9 InputStream (java.io.InputStream)7 ProtonBufferInputStream (org.apache.qpid.protonj2.buffer.ProtonBufferInputStream)7 URI (java.net.URI)6 Client (org.apache.qpid.protonj2.client.Client)6 Connection (org.apache.qpid.protonj2.client.Connection)6 ProtonTestServer (org.apache.qpid.protonj2.test.driver.ProtonTestServer)6 DeliveryAnnotationsMatcher (org.apache.qpid.protonj2.test.driver.matchers.messaging.DeliveryAnnotationsMatcher)6 TransferPayloadCompositeMatcher (org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher)6 Tracker (org.apache.qpid.protonj2.client.Tracker)5 EncodedAmqpValueMatcher (org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpValueMatcher)5 Symbol (org.apache.qpid.protonj2.types.Symbol)5 Sender (org.apache.qpid.protonj2.client.Sender)4 Session (org.apache.qpid.protonj2.client.Session)4 SenderOptions (org.apache.qpid.protonj2.client.SenderOptions)3 ApplicationPropertiesMatcher (org.apache.qpid.protonj2.test.driver.matchers.messaging.ApplicationPropertiesMatcher)3 HeaderMatcher (org.apache.qpid.protonj2.test.driver.matchers.messaging.HeaderMatcher)3 MessageAnnotationsMatcher (org.apache.qpid.protonj2.test.driver.matchers.messaging.MessageAnnotationsMatcher)3