Search in sources :

Example 1 with Properties

use of org.apache.qpid.protonj2.types.messaging.Properties in project qpid-protonj2 by apache.

the class ClientMessageSupport method convertFromOutsideMessage.

// ----- Internal Implementation
private static <E> ClientMessage<E> convertFromOutsideMessage(Message<E> source) throws ClientException {
    Header header = new Header();
    header.setDurable(source.durable());
    header.setPriority(source.priority());
    header.setTimeToLive(source.timeToLive());
    header.setFirstAcquirer(source.firstAcquirer());
    header.setDeliveryCount(source.deliveryCount());
    Properties properties = new Properties();
    properties.setMessageId(source.messageId());
    properties.setUserId(source.userId() != null ? new Binary(source.userId()) : null);
    properties.setTo(source.to());
    properties.setSubject(source.subject());
    properties.setReplyTo(source.replyTo());
    properties.setCorrelationId(source.correlationId());
    properties.setContentType(source.contentType());
    properties.setContentEncoding(source.contentEncoding());
    properties.setAbsoluteExpiryTime(source.absoluteExpiryTime());
    properties.setCreationTime(source.creationTime());
    properties.setGroupId(source.groupId());
    properties.setGroupSequence(source.groupSequence());
    properties.setReplyToGroupId(source.replyToGroupId());
    final MessageAnnotations messageAnnotations;
    if (source.hasAnnotations()) {
        messageAnnotations = new MessageAnnotations(new LinkedHashMap<>());
        source.forEachAnnotation((key, value) -> {
            messageAnnotations.getValue().put(Symbol.valueOf(key), value);
        });
    } else {
        messageAnnotations = null;
    }
    final ApplicationProperties applicationProperties;
    if (source.hasProperties()) {
        applicationProperties = new ApplicationProperties(new LinkedHashMap<>());
        source.forEachProperty((key, value) -> {
            applicationProperties.getValue().put(key, value);
        });
    } else {
        applicationProperties = null;
    }
    final Footer footer;
    if (source.hasFooters()) {
        footer = new Footer(new LinkedHashMap<>());
        source.forEachFooter((key, value) -> {
            footer.getValue().put(Symbol.valueOf(key), value);
        });
    } else {
        footer = null;
    }
    ClientMessage<E> message = new ClientMessage<>(createSectionFromValue(source.body()));
    message.header(header);
    message.properties(properties);
    message.annotations(messageAnnotations);
    message.applicationProperties(applicationProperties);
    message.footer(footer);
    return message;
}
Also used : Header(org.apache.qpid.protonj2.types.messaging.Header) MessageAnnotations(org.apache.qpid.protonj2.types.messaging.MessageAnnotations) Footer(org.apache.qpid.protonj2.types.messaging.Footer) ApplicationProperties(org.apache.qpid.protonj2.types.messaging.ApplicationProperties) Binary(org.apache.qpid.protonj2.types.Binary) Properties(org.apache.qpid.protonj2.types.messaging.Properties) ApplicationProperties(org.apache.qpid.protonj2.types.messaging.ApplicationProperties) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with Properties

use of org.apache.qpid.protonj2.types.messaging.Properties in project qpid-protonj2 by apache.

the class StreamSenderTest method testStreamSenderWritesFooterAfterStreamClosed.

@Test
public void testStreamSenderWritesFooterAfterStreamClosed() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().respond();
        peer.remoteFlow().withLinkCredit(10).queue();
        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();
        StreamSender sender = connection.openStreamSender("test-queue");
        StreamSenderMessage message = sender.beginMessage();
        final byte[] payload = new byte[] { 0, 1, 2, 3, 4, 5 };
        // First frame should include only the bits up to the body
        HeaderMatcher headerMatcher = new HeaderMatcher(true);
        headerMatcher.withDurable(true);
        headerMatcher.withPriority((byte) 1);
        headerMatcher.withTtl(65535);
        headerMatcher.withFirstAcquirer(true);
        headerMatcher.withDeliveryCount(2);
        ApplicationPropertiesMatcher apMatcher = new ApplicationPropertiesMatcher(true);
        apMatcher.withEntry("ap1", Matchers.equalTo(1));
        apMatcher.withEntry("ap2", Matchers.equalTo(2));
        apMatcher.withEntry("ap3", Matchers.equalTo(3));
        FooterMatcher footerMatcher = new FooterMatcher(false);
        footerMatcher.withEntry("f1", Matchers.equalTo(1));
        footerMatcher.withEntry("f2", Matchers.equalTo(2));
        footerMatcher.withEntry("f3", Matchers.equalTo(3));
        EncodedDataMatcher bodyMatcher = new EncodedDataMatcher(payload, true);
        TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
        payloadMatcher.setHeadersMatcher(headerMatcher);
        payloadMatcher.setApplicationPropertiesMatcher(apMatcher);
        payloadMatcher.setMessageContentMatcher(bodyMatcher);
        payloadMatcher.setFootersMatcher(footerMatcher);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        peer.expectTransfer().withPayload(payloadMatcher).withMore(false).accept();
        // Populate all Header values
        message.durable(true);
        message.priority((byte) 1);
        message.timeToLive(65535);
        message.firstAcquirer(true);
        message.deliveryCount(2);
        // Populate message application properties
        message.property("ap1", 1);
        message.property("ap2", 2);
        message.property("ap3", 3);
        // Populate message footers
        assertFalse(message.hasFooters());
        assertFalse(message.hasFooter("f1"));
        message.footer("f1", 1);
        message.footer("f2", 2);
        message.footer("f3", 3);
        assertTrue(message.hasFooter("f1"));
        assertTrue(message.hasFooters());
        OutputStreamOptions bodyOptions = new OutputStreamOptions().completeSendOnClose(true);
        OutputStream stream = message.body(bodyOptions);
        assertThrows(ClientUnsupportedOperationException.class, () -> message.encode(Collections.emptyMap()));
        stream.write(payload);
        stream.close();
        assertThrows(ClientIllegalStateException.class, () -> message.footer(new Footer(Collections.emptyMap())));
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        peer.expectDetach().respond();
        peer.expectEnd().respond();
        peer.expectClose().respond();
        assertNotNull(message.tracker());
        Wait.assertTrue(() -> message.tracker().settlementFuture().isDone());
        assertTrue(message.tracker().settlementFuture().get().settled());
        sender.closeAsync().get(10, TimeUnit.SECONDS);
        connection.closeAsync().get(10, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : HeaderMatcher(org.apache.qpid.protonj2.test.driver.matchers.messaging.HeaderMatcher) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Connection(org.apache.qpid.protonj2.client.Connection) EncodedDataMatcher(org.apache.qpid.protonj2.test.driver.matchers.types.EncodedDataMatcher) TransferPayloadCompositeMatcher(org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher) URI(java.net.URI) ApplicationPropertiesMatcher(org.apache.qpid.protonj2.test.driver.matchers.messaging.ApplicationPropertiesMatcher) OutputStreamOptions(org.apache.qpid.protonj2.client.OutputStreamOptions) Footer(org.apache.qpid.protonj2.types.messaging.Footer) StreamSender(org.apache.qpid.protonj2.client.StreamSender) StreamSenderMessage(org.apache.qpid.protonj2.client.StreamSenderMessage) Client(org.apache.qpid.protonj2.client.Client) FooterMatcher(org.apache.qpid.protonj2.test.driver.matchers.messaging.FooterMatcher) Test(org.junit.jupiter.api.Test)

Example 3 with Properties

use of org.apache.qpid.protonj2.types.messaging.Properties in project qpid-protonj2 by apache.

the class StreamSenderTest method testStreamSenderMessageWithDeliveryAnnotations.

@Test
public void testStreamSenderMessageWithDeliveryAnnotations() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofSender().respond();
        peer.remoteFlow().withLinkCredit(10).queue();
        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();
        // Populate delivery annotations
        final Map<String, Object> deliveryAnnotations = new HashMap<>();
        deliveryAnnotations.put("da1", 1);
        deliveryAnnotations.put("da2", 2);
        deliveryAnnotations.put("da3", 3);
        StreamSender sender = connection.openStreamSender("test-queue");
        StreamSenderMessage message = sender.beginMessage(deliveryAnnotations);
        final byte[] payload = new byte[] { 0, 1, 2, 3, 4, 5 };
        HeaderMatcher headerMatcher = new HeaderMatcher(true);
        headerMatcher.withDurable(true);
        headerMatcher.withPriority((byte) 1);
        headerMatcher.withTtl(65535);
        headerMatcher.withFirstAcquirer(true);
        headerMatcher.withDeliveryCount(2);
        PropertiesMatcher propertiesMatcher = new PropertiesMatcher(true);
        propertiesMatcher.withMessageId("ID:12345");
        propertiesMatcher.withUserId("user".getBytes(StandardCharsets.UTF_8));
        propertiesMatcher.withTo("the-management");
        propertiesMatcher.withSubject("amqp");
        propertiesMatcher.withReplyTo("the-minions");
        propertiesMatcher.withCorrelationId("abc");
        propertiesMatcher.withContentEncoding("application/json");
        propertiesMatcher.withContentType("gzip");
        propertiesMatcher.withAbsoluteExpiryTime(123);
        propertiesMatcher.withCreationTime(1);
        propertiesMatcher.withGroupId("disgruntled");
        propertiesMatcher.withGroupSequence(8192);
        propertiesMatcher.withReplyToGroupId("/dev/null");
        DeliveryAnnotationsMatcher daMatcher = new DeliveryAnnotationsMatcher(true);
        daMatcher.withEntry("da1", Matchers.equalTo(1));
        daMatcher.withEntry("da2", Matchers.equalTo(2));
        daMatcher.withEntry("da3", Matchers.equalTo(3));
        MessageAnnotationsMatcher maMatcher = new MessageAnnotationsMatcher(true);
        maMatcher.withEntry("ma1", Matchers.equalTo(1));
        maMatcher.withEntry("ma2", Matchers.equalTo(2));
        maMatcher.withEntry("ma3", Matchers.equalTo(3));
        ApplicationPropertiesMatcher apMatcher = new ApplicationPropertiesMatcher(true);
        apMatcher.withEntry("ap1", Matchers.equalTo(1));
        apMatcher.withEntry("ap2", Matchers.equalTo(2));
        apMatcher.withEntry("ap3", Matchers.equalTo(3));
        EncodedDataMatcher bodyMatcher = new EncodedDataMatcher(payload);
        TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
        payloadMatcher.setHeadersMatcher(headerMatcher);
        payloadMatcher.setDeliveryAnnotationsMatcher(daMatcher);
        payloadMatcher.setMessageAnnotationsMatcher(maMatcher);
        payloadMatcher.setPropertiesMatcher(propertiesMatcher);
        payloadMatcher.setApplicationPropertiesMatcher(apMatcher);
        payloadMatcher.setMessageContentMatcher(bodyMatcher);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        peer.expectTransfer().withPayload(payloadMatcher).withMore(false).accept();
        // Populate all Header values
        message.durable(true);
        assertEquals(true, message.durable());
        message.priority((byte) 1);
        assertEquals(1, message.priority());
        message.timeToLive(65535);
        assertEquals(65535, message.timeToLive());
        message.firstAcquirer(true);
        assertTrue(message.firstAcquirer());
        message.deliveryCount(2);
        assertEquals(2, message.deliveryCount());
        // Populate message annotations
        assertFalse(message.hasAnnotations());
        assertFalse(message.hasAnnotation("ma1"));
        message.annotation("ma1", 1);
        assertTrue(message.hasAnnotation("ma1"));
        assertEquals(1, message.annotation("ma1"));
        message.annotation("ma2", 2);
        assertEquals(2, message.annotation("ma2"));
        message.annotation("ma3", 3);
        assertEquals(3, message.annotation("ma3"));
        assertTrue(message.hasAnnotations());
        // Populate all Properties values
        message.messageId("ID:12345");
        assertEquals("ID:12345", message.messageId());
        message.userId("user".getBytes(StandardCharsets.UTF_8));
        assertArrayEquals("user".getBytes(StandardCharsets.UTF_8), message.userId());
        message.to("the-management");
        assertEquals("the-management", message.to());
        message.subject("amqp");
        assertEquals("amqp", message.subject());
        message.replyTo("the-minions");
        assertEquals("the-minions", message.replyTo());
        message.correlationId("abc");
        assertEquals("abc", message.correlationId());
        message.contentEncoding("application/json");
        assertEquals("application/json", message.contentEncoding());
        message.contentType("gzip");
        assertEquals("gzip", message.contentType());
        message.absoluteExpiryTime(123);
        assertEquals(123, message.absoluteExpiryTime());
        message.creationTime(1);
        assertEquals(1, message.creationTime());
        message.groupId("disgruntled");
        assertEquals("disgruntled", message.groupId());
        message.groupSequence(8192);
        assertEquals(8192, message.groupSequence());
        message.replyToGroupId("/dev/null");
        assertEquals("/dev/null", message.replyToGroupId());
        // Populate message application properties
        assertFalse(message.hasProperties());
        assertFalse(message.hasProperty("ma1"));
        message.property("ap1", 1);
        assertEquals(1, message.property("ap1"));
        assertTrue(message.hasProperty("ap1"));
        message.property("ap2", 2);
        assertEquals(2, message.property("ap2"));
        message.property("ap3", 3);
        assertEquals(3, message.property("ap3"));
        assertTrue(message.hasProperties());
        OutputStream stream = message.body();
        stream.write(payload);
        stream.close();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        peer.expectDetach().respond();
        peer.expectEnd().respond();
        peer.expectClose().respond();
        assertNotNull(message.tracker());
        Wait.assertTrue(() -> message.tracker().settlementFuture().isDone());
        assertTrue(message.tracker().settlementFuture().get().settled());
        sender.closeAsync().get(10, TimeUnit.SECONDS);
        connection.closeAsync().get(10, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : HeaderMatcher(org.apache.qpid.protonj2.test.driver.matchers.messaging.HeaderMatcher) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) DeliveryAnnotationsMatcher(org.apache.qpid.protonj2.test.driver.matchers.messaging.DeliveryAnnotationsMatcher) MessageAnnotationsMatcher(org.apache.qpid.protonj2.test.driver.matchers.messaging.MessageAnnotationsMatcher) HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) Connection(org.apache.qpid.protonj2.client.Connection) EncodedDataMatcher(org.apache.qpid.protonj2.test.driver.matchers.types.EncodedDataMatcher) TransferPayloadCompositeMatcher(org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher) URI(java.net.URI) ApplicationPropertiesMatcher(org.apache.qpid.protonj2.test.driver.matchers.messaging.ApplicationPropertiesMatcher) StreamSender(org.apache.qpid.protonj2.client.StreamSender) StreamSenderMessage(org.apache.qpid.protonj2.client.StreamSenderMessage) Client(org.apache.qpid.protonj2.client.Client) PropertiesMatcher(org.apache.qpid.protonj2.test.driver.matchers.messaging.PropertiesMatcher) ApplicationPropertiesMatcher(org.apache.qpid.protonj2.test.driver.matchers.messaging.ApplicationPropertiesMatcher) Test(org.junit.jupiter.api.Test)

Example 4 with Properties

use of org.apache.qpid.protonj2.types.messaging.Properties in project qpid-protonj2 by apache.

the class StreamReceiverTest method testStreamReceiverMessageThrowsOnAnyMessageModificationAPI.

@Test
public void testStreamReceiverMessageThrowsOnAnyMessageModificationAPI() throws Exception {
    final byte[] body = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    final byte[] payload = createEncodedMessage(new Data(body));
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().withRole(Role.RECEIVER.getValue()).respond();
        peer.expectFlow();
        peer.remoteTransfer().withHandle(0).withDeliveryId(0).withDeliveryTag(new byte[] { 1 }).withMore(false).withMessageFormat(0).withPayload(payload).queue();
        peer.expectDisposition().withFirst(0).withState().accepted().withSettled(true);
        peer.start();
        URI remoteURI = peer.getServerURI();
        LOG.info("Test started, peer listening on: {}", remoteURI);
        final Client container = Client.create();
        final Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
        final StreamReceiver receiver = connection.openStreamReceiver("test-queue");
        final StreamDelivery delivery = receiver.receive();
        final StreamReceiverMessage message = delivery.message();
        assertThrows(ClientUnsupportedOperationException.class, () -> message.header(new Header()));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.properties(new Properties()));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.applicationProperties(new ApplicationProperties(null)));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.annotations(new MessageAnnotations(null)));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.footer(new Footer(null)));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.messageFormat(1));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.durable(true));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.priority((byte) 4));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.timeToLive(128));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.firstAcquirer(false));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.deliveryCount(10));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.messageId(10));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.correlationId(10));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.userId(new byte[] { 1 }));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.to("test"));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.subject("test"));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.replyTo("test"));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.contentType("test"));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.contentEncoding("test"));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.absoluteExpiryTime(10));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.creationTime(10));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.groupId("test"));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.groupSequence(10));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.replyToGroupId("test"));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.annotation("test", 1));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.removeAnnotation("test"));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.property("test", 1));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.removeProperty("test"));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.footer("test", 1));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.removeFooter("test"));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.body(InputStream.nullInputStream()));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.addBodySection(new AmqpValue<>("test")));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.bodySections(Collections.emptyList()));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.bodySections());
        assertThrows(ClientUnsupportedOperationException.class, () -> message.clearBodySections());
        assertThrows(ClientUnsupportedOperationException.class, () -> message.forEachBodySection((section) -> {
        }));
        assertThrows(ClientUnsupportedOperationException.class, () -> message.encode(Collections.emptyMap()));
        InputStream bodyStream = message.body();
        assertNotNull(bodyStream.readAllBytes());
        bodyStream.close();
        peer.expectDetach().respond();
        peer.expectEnd().respond();
        peer.expectClose().respond();
        receiver.closeAsync().get();
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) Properties(org.apache.qpid.protonj2.types.messaging.Properties) Random(java.util.Random) ImperativeClientTestCase(org.apache.qpid.protonj2.client.test.ImperativeClientTestCase) Future(java.util.concurrent.Future) ClientLinkRemotelyClosedException(org.apache.qpid.protonj2.client.exceptions.ClientLinkRemotelyClosedException) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Data(org.apache.qpid.protonj2.types.messaging.Data) Map(java.util.Map) URI(java.net.URI) ClientOperationTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException) Accepted(org.apache.qpid.protonj2.test.driver.codec.messaging.Accepted) EncodingCodes(org.apache.qpid.protonj2.codec.EncodingCodes) ReceiverOptions(org.apache.qpid.protonj2.client.ReceiverOptions) SenderOptions(org.apache.qpid.protonj2.client.SenderOptions) Binary(org.apache.qpid.protonj2.types.Binary) Footer(org.apache.qpid.protonj2.types.messaging.Footer) UUID(java.util.UUID) Assertions.assertNotSame(org.junit.jupiter.api.Assertions.assertNotSame) StreamReceiverMessage(org.apache.qpid.protonj2.client.StreamReceiverMessage) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Connection(org.apache.qpid.protonj2.client.Connection) Client(org.apache.qpid.protonj2.client.Client) ClientUnsupportedOperationException(org.apache.qpid.protonj2.client.exceptions.ClientUnsupportedOperationException) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) AmqpValue(org.apache.qpid.protonj2.types.messaging.AmqpValue) ApplicationProperties(org.apache.qpid.protonj2.types.messaging.ApplicationProperties) Wait(org.apache.qpid.protonj2.client.test.Wait) Symbol(org.apache.qpid.protonj2.types.Symbol) ArrayList(java.util.ArrayList) StreamReceiver(org.apache.qpid.protonj2.client.StreamReceiver) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) DeliveryState(org.apache.qpid.protonj2.client.DeliveryState) UnsignedInteger(org.apache.qpid.protonj2.types.UnsignedInteger) ConnectionOptions(org.apache.qpid.protonj2.client.ConnectionOptions) Role(org.apache.qpid.protonj2.types.transport.Role) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Header(org.apache.qpid.protonj2.types.messaging.Header) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Logger(org.slf4j.Logger) DeliveryAnnotations(org.apache.qpid.protonj2.test.driver.codec.messaging.DeliveryAnnotations) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) ClientIllegalStateException(org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException) IOException(java.io.IOException) ClientDeliveryAbortedException(org.apache.qpid.protonj2.client.exceptions.ClientDeliveryAbortedException) StreamReceiverOptions(org.apache.qpid.protonj2.client.StreamReceiverOptions) ErrorCondition(org.apache.qpid.protonj2.client.ErrorCondition) AmqpSequence(org.apache.qpid.protonj2.types.messaging.AmqpSequence) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) MessageAnnotations(org.apache.qpid.protonj2.types.messaging.MessageAnnotations) StreamDelivery(org.apache.qpid.protonj2.client.StreamDelivery) Collections(java.util.Collections) Timeout(org.junit.jupiter.api.Timeout) InputStream(java.io.InputStream) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) InputStream(java.io.InputStream) Connection(org.apache.qpid.protonj2.client.Connection) Data(org.apache.qpid.protonj2.types.messaging.Data) Properties(org.apache.qpid.protonj2.types.messaging.Properties) ApplicationProperties(org.apache.qpid.protonj2.types.messaging.ApplicationProperties) URI(java.net.URI) AmqpValue(org.apache.qpid.protonj2.types.messaging.AmqpValue) StreamDelivery(org.apache.qpid.protonj2.client.StreamDelivery) Header(org.apache.qpid.protonj2.types.messaging.Header) StreamReceiver(org.apache.qpid.protonj2.client.StreamReceiver) StreamReceiverMessage(org.apache.qpid.protonj2.client.StreamReceiverMessage) MessageAnnotations(org.apache.qpid.protonj2.types.messaging.MessageAnnotations) Footer(org.apache.qpid.protonj2.types.messaging.Footer) ApplicationProperties(org.apache.qpid.protonj2.types.messaging.ApplicationProperties) Client(org.apache.qpid.protonj2.client.Client) Test(org.junit.jupiter.api.Test)

Example 5 with Properties

use of org.apache.qpid.protonj2.types.messaging.Properties in project qpid-protonj2 by apache.

the class StreamReceiverTest method tryReadReceiverRemoteProperties.

private void tryReadReceiverRemoteProperties(boolean attachResponse) throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().withRole(Role.RECEIVER.getValue());
        peer.expectFlow();
        peer.start();
        URI remoteURI = peer.getServerURI();
        LOG.info("Test started, peer listening on: {}", remoteURI);
        Client container = Client.create();
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
        StreamReceiverOptions options = new StreamReceiverOptions().openTimeout(150, TimeUnit.MILLISECONDS);
        StreamReceiver receiver = connection.openStreamReceiver("test-receiver", options);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        Map<String, Object> expectedProperties = new HashMap<>();
        expectedProperties.put("TEST", "test-property");
        if (attachResponse) {
            peer.expectDetach().respond();
            peer.expectEnd().respond();
            peer.respondToLastAttach().withPropertiesMap(expectedProperties).later(10);
        } else {
            peer.expectDetach();
            peer.expectEnd();
        }
        if (attachResponse) {
            assertNotNull(receiver.properties(), "Remote should have responded with a remote properties value");
            assertEquals(expectedProperties, receiver.properties());
        } else {
            try {
                receiver.properties();
                fail("Should failed to get remote state due to no attach response");
            } catch (ClientException ex) {
                LOG.debug("Caught expected exception from blocking call", ex);
            }
        }
        try {
            receiver.closeAsync().get();
        } catch (ExecutionException ex) {
            LOG.debug("Caught unexpected exception from close call", ex);
            fail("Should not fail to close when connection not closed and detach sent");
        }
        peer.expectClose().respond();
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) StreamReceiver(org.apache.qpid.protonj2.client.StreamReceiver) HashMap(java.util.HashMap) StreamReceiverOptions(org.apache.qpid.protonj2.client.StreamReceiverOptions) Connection(org.apache.qpid.protonj2.client.Connection) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) Client(org.apache.qpid.protonj2.client.Client) ExecutionException(java.util.concurrent.ExecutionException) URI(java.net.URI)

Aggregations

Test (org.junit.jupiter.api.Test)28 HashMap (java.util.HashMap)20 Properties (org.apache.qpid.protonj2.types.messaging.Properties)18 URI (java.net.URI)16 Client (org.apache.qpid.protonj2.client.Client)16 Connection (org.apache.qpid.protonj2.client.Connection)16 ProtonTestServer (org.apache.qpid.protonj2.test.driver.ProtonTestServer)16 Symbol (org.apache.qpid.protonj2.types.Symbol)12 ProtonBuffer (org.apache.qpid.protonj2.buffer.ProtonBuffer)11 ApplicationProperties (org.apache.qpid.protonj2.types.messaging.ApplicationProperties)11 InputStream (java.io.InputStream)9 Binary (org.apache.qpid.protonj2.types.Binary)9 ProtonBufferInputStream (org.apache.qpid.protonj2.buffer.ProtonBufferInputStream)8 ApplicationPropertiesMatcher (org.apache.qpid.protonj2.test.driver.matchers.messaging.ApplicationPropertiesMatcher)8 TransferPayloadCompositeMatcher (org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher)8 Session (org.apache.qpid.protonj2.client.Session)7 LinkedHashMap (java.util.LinkedHashMap)6 SenderOptions (org.apache.qpid.protonj2.client.SenderOptions)6 ClientException (org.apache.qpid.protonj2.client.exceptions.ClientException)6 HeaderMatcher (org.apache.qpid.protonj2.test.driver.matchers.messaging.HeaderMatcher)6