Search in sources :

Example 56 with Connection

use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.

the class StreamReceiverTest method doTestCreateReceiverAndCloseOrDetachWithErrorAsync.

private void doTestCreateReceiverAndCloseOrDetachWithErrorAsync(boolean close) throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofReceiver().respond();
        peer.expectFlow();
        peer.expectDetach().withError("amqp-resource-deleted", "an error message").withClosed(close).respond();
        peer.expectEnd().respond();
        peer.expectClose().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());
        StreamReceiver receiver = connection.openStreamReceiver("test-queue");
        receiver.openFuture().get(10, TimeUnit.SECONDS);
        if (close) {
            receiver.closeAsync(ErrorCondition.create("amqp-resource-deleted", "an error message", null)).get();
        } else {
            receiver.detachAsync(ErrorCondition.create("amqp-resource-deleted", "an error message", null)).get();
        }
        connection.closeAsync().get(10, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) StreamReceiver(org.apache.qpid.protonj2.client.StreamReceiver) Connection(org.apache.qpid.protonj2.client.Connection) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI)

Example 57 with Connection

use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.

the class StreamReceiverTest method testStreamDeliveryUsesUnsettledDeliveryOnOpen.

@Test
public void testStreamDeliveryUsesUnsettledDeliveryOnOpen() throws Exception {
    final byte[] payload = createEncodedMessage(new AmqpValue<>("Hello World"));
    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.remoteDisposition().withRole(Role.SENDER.getValue()).withFirst(0).withSettled(true).withState(Accepted.getInstance()).queue();
        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 StreamReceiverOptions options = new StreamReceiverOptions().autoAccept(false);
        final StreamReceiver receiver = connection.openStreamReceiver("test-queue", options);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        final StreamDelivery delivery = receiver.receive();
        Wait.assertTrue("Should eventually be remotely settled", delivery::remoteSettled);
        Wait.assertTrue(() -> {
            return delivery.remoteState() == DeliveryState.accepted();
        });
        peer.expectDetach().respond();
        peer.expectEnd().respond();
        peer.expectClose().respond();
        receiver.close();
        connection.close();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : StreamDelivery(org.apache.qpid.protonj2.client.StreamDelivery) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) StreamReceiver(org.apache.qpid.protonj2.client.StreamReceiver) StreamReceiverOptions(org.apache.qpid.protonj2.client.StreamReceiverOptions) Connection(org.apache.qpid.protonj2.client.Connection) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 58 with Connection

use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.

the class StreamReceiverTest method testDrainCompletesWhenReceiverHasNoCredit.

@Test
public void testDrainCompletesWhenReceiverHasNoCredit() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().withRole(Role.RECEIVER.getValue()).respond();
        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());
        StreamReceiver receiver = connection.openStreamReceiver("test-queue", new StreamReceiverOptions().creditWindow(0));
        receiver.openFuture().get(5, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        Future<StreamReceiver> draining = receiver.drain();
        draining.get(5, TimeUnit.SECONDS);
        // Close things down
        peer.expectClose().respond();
        connection.closeAsync().get(5, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(1, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) StreamReceiver(org.apache.qpid.protonj2.client.StreamReceiver) StreamReceiverOptions(org.apache.qpid.protonj2.client.StreamReceiverOptions) Connection(org.apache.qpid.protonj2.client.Connection) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 59 with Connection

use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.

the class StreamReceiverTest method testStreamDeliveryHandlesInvalidApplicationPropertiesEncoding.

@Test
public void testStreamDeliveryHandlesInvalidApplicationPropertiesEncoding() throws Exception {
    final byte[] payload = createInvalidApplicationPropertiesEncoding();
    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.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 StreamReceiverOptions options = new StreamReceiverOptions().autoAccept(false);
        final StreamReceiver receiver = connection.openStreamReceiver("test-queue", options);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
        peer.expectDisposition().withState().rejected("decode-error", "failed reading message header");
        final StreamDelivery delivery = receiver.receive();
        final StreamReceiverMessage message = delivery.message();
        assertThrows(ClientException.class, () -> message.applicationProperties());
        assertThrows(ClientException.class, () -> message.body());
        delivery.reject("decode-error", "failed reading message header");
        peer.expectDetach().respond();
        peer.expectEnd().respond();
        peer.expectClose().respond();
        receiver.close();
        connection.close();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : StreamDelivery(org.apache.qpid.protonj2.client.StreamDelivery) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) StreamReceiver(org.apache.qpid.protonj2.client.StreamReceiver) StreamReceiverOptions(org.apache.qpid.protonj2.client.StreamReceiverOptions) StreamReceiverMessage(org.apache.qpid.protonj2.client.StreamReceiverMessage) Connection(org.apache.qpid.protonj2.client.Connection) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 60 with Connection

use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.

the class StreamReceiverTest method testReadApplicationPropertiesStreamReceiverMessage.

@Test
public void testReadApplicationPropertiesStreamReceiverMessage() throws Exception {
    final Map<String, Object> propertiesMap = new HashMap<>();
    final ApplicationProperties appProperties = new ApplicationProperties(propertiesMap);
    propertiesMap.put("property1", UnsignedInteger.MAX_VALUE);
    propertiesMap.put("property2", UnsignedInteger.ONE);
    propertiesMap.put("property3", UnsignedInteger.ZERO);
    final byte[] payload = createEncodedMessage(appProperties);
    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();
        assertNotNull(delivery);
        assertTrue(delivery.completed());
        assertFalse(delivery.aborted());
        StreamReceiverMessage message = delivery.message();
        assertNotNull(message);
        assertTrue(message.hasProperties());
        assertFalse(message.hasFooters());
        assertFalse(message.hasAnnotations());
        assertFalse(message.hasProperty("property"));
        assertEquals(UnsignedInteger.MAX_VALUE, message.property("property1"));
        assertEquals(UnsignedInteger.ONE, message.property("property2"));
        assertEquals(UnsignedInteger.ZERO, message.property("property3"));
        message.forEachProperty((key, value) -> {
            assertTrue(propertiesMap.containsKey(key));
            assertEquals(value, propertiesMap.get(key));
        });
        peer.expectDetach().respond();
        peer.expectEnd().respond();
        peer.expectClose().respond();
        receiver.closeAsync().get();
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) HashMap(java.util.HashMap) Connection(org.apache.qpid.protonj2.client.Connection) URI(java.net.URI) StreamDelivery(org.apache.qpid.protonj2.client.StreamDelivery) StreamReceiver(org.apache.qpid.protonj2.client.StreamReceiver) StreamReceiverMessage(org.apache.qpid.protonj2.client.StreamReceiverMessage) ApplicationProperties(org.apache.qpid.protonj2.types.messaging.ApplicationProperties) Client(org.apache.qpid.protonj2.client.Client) Test(org.junit.jupiter.api.Test)

Aggregations

Connection (org.apache.qpid.protonj2.client.Connection)368 Client (org.apache.qpid.protonj2.client.Client)367 URI (java.net.URI)354 ProtonTestServer (org.apache.qpid.protonj2.test.driver.ProtonTestServer)352 Test (org.junit.jupiter.api.Test)250 Session (org.apache.qpid.protonj2.client.Session)166 ConnectionOptions (org.apache.qpid.protonj2.client.ConnectionOptions)112 Sender (org.apache.qpid.protonj2.client.Sender)89 Receiver (org.apache.qpid.protonj2.client.Receiver)79 ExecutionException (java.util.concurrent.ExecutionException)72 StreamReceiver (org.apache.qpid.protonj2.client.StreamReceiver)65 ClientException (org.apache.qpid.protonj2.client.exceptions.ClientException)60 StreamSender (org.apache.qpid.protonj2.client.StreamSender)49 StreamDelivery (org.apache.qpid.protonj2.client.StreamDelivery)46 TransferPayloadCompositeMatcher (org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher)44 Tracker (org.apache.qpid.protonj2.client.Tracker)41 StreamSenderMessage (org.apache.qpid.protonj2.client.StreamSenderMessage)38 ReceiverOptions (org.apache.qpid.protonj2.client.ReceiverOptions)34 SenderOptions (org.apache.qpid.protonj2.client.SenderOptions)33 OutputStream (java.io.OutputStream)31