Search in sources :

Example 96 with Connection

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

the class SslConnectionTest method doTestCreateSslConnectionWithServerSendingPreemptiveData.

private void doTestCreateSslConnectionWithServerSendingPreemptiveData(boolean openSSL) throws Exception {
    ProtonTestServerOptions serverOptions = serverOptions();
    serverOptions.setSecure(true);
    serverOptions.setKeyStoreLocation(BROKER_JKS_KEYSTORE);
    serverOptions.setKeyStorePassword(PASSWORD);
    serverOptions.setVerifyHost(false);
    try (ProtonTestServer peer = new ProtonTestServer(serverOptions)) {
        peer.remoteHeader(AMQPHeader.getSASLHeader().toArray()).queue();
        peer.expectSASLHeader();
        peer.remoteSaslMechanisms().withMechanisms("ANONYMOUS").queue();
        peer.expectSaslInit().withMechanism("ANONYMOUS");
        peer.remoteSaslOutcome().withCode(SaslCode.OK.byteValue()).queue();
        peer.expectAMQPHeader().respondWithAMQPHeader();
        peer.expectOpen().respond();
        peer.expectClose().respond();
        peer.start();
        URI remoteURI = peer.getServerURI();
        ConnectionOptions clientOptions = connectionOptions();
        clientOptions.sslOptions().trustStoreLocation(CLIENT_JKS_TRUSTSTORE).trustStorePassword(PASSWORD).allowNativeSSL(openSSL);
        Client container = Client.create();
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), clientOptions);
        connection.openFuture().get(10, TimeUnit.SECONDS);
        assertTrue(peer.hasSecureConnection());
        connection.closeAsync().get(10, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) ProtonTestServerOptions(org.apache.qpid.protonj2.test.driver.ProtonTestServerOptions) Connection(org.apache.qpid.protonj2.client.Connection) ConnectionOptions(org.apache.qpid.protonj2.client.ConnectionOptions) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI)

Example 97 with Connection

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

the class SslConnectionTest method testCreateAndCloseSslConnection.

private void testCreateAndCloseSslConnection(boolean openSSL) throws Exception {
    ProtonTestServerOptions serverOptions = serverOptions();
    serverOptions.setSecure(true);
    serverOptions.setKeyStoreLocation(BROKER_JKS_KEYSTORE);
    serverOptions.setKeyStorePassword(PASSWORD);
    serverOptions.setVerifyHost(false);
    try (ProtonTestServer peer = new ProtonTestServer(serverOptions)) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectClose().respond();
        peer.start();
        URI remoteURI = peer.getServerURI();
        ConnectionOptions clientOptions = connectionOptions();
        clientOptions.sslOptions().trustStoreLocation(CLIENT_JKS_TRUSTSTORE).trustStorePassword(PASSWORD).allowNativeSSL(openSSL);
        Client container = Client.create();
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), clientOptions);
        connection.openFuture().get(10, TimeUnit.SECONDS);
        assertTrue(peer.hasSecureConnection());
        assertFalse(peer.isConnectionVerified());
        connection.closeAsync().get(10, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) ProtonTestServerOptions(org.apache.qpid.protonj2.test.driver.ProtonTestServerOptions) Connection(org.apache.qpid.protonj2.client.Connection) ConnectionOptions(org.apache.qpid.protonj2.client.ConnectionOptions) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI)

Example 98 with Connection

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

the class StreamReceiverTest method doTestCreateReceiverAndCloseOrDetachWithErrorSync.

private void doTestCreateReceiverAndCloseOrDetachWithErrorSync(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.close(ErrorCondition.create("amqp-resource-deleted", "an error message", null));
        } else {
            receiver.detach(ErrorCondition.create("amqp-resource-deleted", "an error message", null));
        }
        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 99 with Connection

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

the class StreamReceiverTest method doTestCreateReceiverAndCloseOrDetachLink.

private void doTestCreateReceiverAndCloseOrDetachLink(boolean close) throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectAttach().ofReceiver().respond();
        peer.expectFlow().withLinkCredit(10);
        peer.expectDetach().withClosed(close).respond();
        peer.expectEnd().respond();
        peer.expectClose().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");
        receiver.openFuture().get(10, TimeUnit.SECONDS);
        assertSame(container, receiver.client());
        assertSame(connection, receiver.connection());
        if (close) {
            receiver.closeAsync().get(10, TimeUnit.SECONDS);
        } else {
            receiver.detachAsync().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) 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 100 with Connection

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

the class StreamReceiverTest method testStreamDeliveryRawInputStreamReadBytesSignalsEOFOnEmptyCompleteTransfer.

@Test
public void testStreamDeliveryRawInputStreamReadBytesSignalsEOFOnEmptyCompleteTransfer() throws Exception {
    final byte[] payload1 = createEncodedMessage(new Data(new byte[] { 0, 1, 2, 3, 4, 5 }));
    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(true).withMessageFormat(0).withPayload(payload1).queue();
        peer.expectDisposition().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);
        assertFalse(delivery.completed());
        assertFalse(delivery.aborted());
        final InputStream stream = delivery.rawInputStream();
        assertNotNull(stream);
        assertEquals(payload1.length, stream.available());
        final byte[] deliveryBytes1 = new byte[payload1.length];
        stream.read(deliveryBytes1);
        assertArrayEquals(payload1, deliveryBytes1);
        assertEquals(0, stream.available());
        peer.remoteTransfer().withHandle(0).withDeliveryId(0).withDeliveryTag(new byte[] { 1 }).withMore(false).later(50);
        // Should block until more data arrives.
        final byte[] deliveryBytes2 = new byte[payload1.length];
        assertEquals(-1, stream.read(deliveryBytes2));
        assertEquals(0, stream.available());
        assertTrue(delivery.completed());
        assertFalse(delivery.aborted());
        stream.close();
        peer.expectDetach().respond();
        peer.expectEnd().respond();
        peer.expectClose().respond();
        receiver.close();
        connection.closeAsync().get();
        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) InputStream(java.io.InputStream) Connection(org.apache.qpid.protonj2.client.Connection) Data(org.apache.qpid.protonj2.types.messaging.Data) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) 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