Search in sources :

Example 36 with Connection

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

the class TransactionsTest method testDeclareTransactionAfterConnectionDrops.

@Test
public void testDeclareTransactionAfterConnectionDrops() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.dropAfterLastHandler();
        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());
        Session session = connection.openSession().openFuture().get();
        peer.waitForScriptToComplete();
        try {
            session.beginTransaction();
            fail("Should have failed to discharge transaction");
        } catch (ClientException cliEx) {
            // Expected error as connection was dropped
            LOG.debug("Client threw error on begin after connection drop", cliEx);
        }
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) Connection(org.apache.qpid.protonj2.client.Connection) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) Session(org.apache.qpid.protonj2.client.Session) Test(org.junit.jupiter.api.Test)

Example 37 with Connection

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

the class TransactionsTest method testBeginAndCommitTransactions.

@Test
public void testBeginAndCommitTransactions() throws Exception {
    final byte[] txnId1 = new byte[] { 0, 1, 2, 3 };
    final byte[] txnId2 = new byte[] { 1, 1, 2, 3 };
    final byte[] txnId3 = new byte[] { 2, 1, 2, 3 };
    final byte[] txnId4 = new byte[] { 3, 1, 2, 3 };
    final byte[] txnId5 = new byte[] { 4, 1, 2, 3 };
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectCoordinatorAttach().respond();
        peer.remoteFlow().withLinkCredit(10).queue();
        peer.expectDeclare().accept(txnId1);
        peer.expectDischarge().withFail(false).withTxnId(txnId1).accept();
        peer.expectDeclare().accept(txnId2);
        peer.expectDischarge().withFail(false).withTxnId(txnId2).accept();
        peer.expectDeclare().accept(txnId3);
        peer.expectDischarge().withFail(false).withTxnId(txnId3).accept();
        peer.expectDeclare().accept(txnId4);
        peer.expectDischarge().withFail(false).withTxnId(txnId4).accept();
        peer.expectDeclare().accept(txnId5);
        peer.expectDischarge().withFail(false).withTxnId(txnId5).accept();
        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());
        Session session = connection.openSession().openFuture().get();
        for (int i = 0; i < 5; ++i) {
            LOG.info("Transaction declare and discharge cycle: {}", i);
            session.beginTransaction();
            session.commitTransaction();
        }
        session.closeAsync();
        connection.closeAsync().get(10, TimeUnit.SECONDS);
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) Connection(org.apache.qpid.protonj2.client.Connection) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) Session(org.apache.qpid.protonj2.client.Session) Test(org.junit.jupiter.api.Test)

Example 38 with Connection

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

the class TransactionsTest method testTimedOutExceptionOnBeginWithNoResponse.

@Test
public void testTimedOutExceptionOnBeginWithNoResponse() throws Exception {
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectCoordinatorAttach().respond();
        peer.remoteFlow().withLinkCredit(2).queue();
        peer.expectDeclare();
        peer.expectDetach().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();
        ConnectionOptions options = new ConnectionOptions().requestTimeout(50);
        Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), options);
        Session session = connection.openSession().openFuture().get();
        try {
            session.beginTransaction();
            fail("Begin should have timed out after no response.");
        } catch (ClientTransactionDeclarationException expected) {
        // Expect this to time out.
        }
        try {
            session.commitTransaction();
            fail("Commit should have failed due to no active transaction.");
        } catch (ClientIllegalStateException expected) {
        // Expect this to fail since transaction not declared
        }
        try {
            session.rollbackTransaction();
            fail("Rollback should have failed due to no active transaction.");
        } catch (ClientIllegalStateException expected) {
        // Expect this to fail since transaction not declared
        }
        session.closeAsync();
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ClientTransactionDeclarationException(org.apache.qpid.protonj2.client.exceptions.ClientTransactionDeclarationException) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) Connection(org.apache.qpid.protonj2.client.Connection) ClientIllegalStateException(org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException) ConnectionOptions(org.apache.qpid.protonj2.client.ConnectionOptions) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) Session(org.apache.qpid.protonj2.client.Session) Test(org.junit.jupiter.api.Test)

Example 39 with Connection

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

the class TransactionsTest method testExceptionOnBeginWhenCoordinatorLinkRefused.

@Test
public void testExceptionOnBeginWhenCoordinatorLinkRefused() throws Exception {
    final String errorMessage = "CoordinatorLinkRefusal-breadcrumb";
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectCoordinatorAttach().reject(true, AmqpError.NOT_IMPLEMENTED.toString(), errorMessage);
        peer.expectDetach();
        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());
        Session session = connection.openSession().openFuture().get();
        try {
            session.beginTransaction();
            fail("Begin should have failed after link closed.");
        } catch (ClientTransactionDeclarationException expected) {
            // Expect this to time out.
            String message = expected.getMessage();
            assertTrue(message.contains(errorMessage));
        }
        try {
            session.commitTransaction();
            fail("Commit should have failed due to no active transaction.");
        } catch (ClientTransactionNotActiveException expected) {
        // Expect this as the begin failed on coordinator rejected
        }
        try {
            session.rollbackTransaction();
            fail("Rollback should have failed due to no active transaction.");
        } catch (ClientTransactionNotActiveException expected) {
        // Expect this as the begin failed on coordinator rejected
        }
        session.closeAsync();
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ClientTransactionDeclarationException(org.apache.qpid.protonj2.client.exceptions.ClientTransactionDeclarationException) ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) ClientTransactionNotActiveException(org.apache.qpid.protonj2.client.exceptions.ClientTransactionNotActiveException) Connection(org.apache.qpid.protonj2.client.Connection) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) Session(org.apache.qpid.protonj2.client.Session) Test(org.junit.jupiter.api.Test)

Example 40 with Connection

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

the class TransactionsTest method testCoordinatorLinkSupportedOutcomes.

@Test
public void testCoordinatorLinkSupportedOutcomes() throws Exception {
    final byte[] txnId = new byte[] { 0, 1, 2, 3 };
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectCoordinatorAttach().withSource().withOutcomes(Accepted.DESCRIPTOR_SYMBOL.toString(), Rejected.DESCRIPTOR_SYMBOL.toString(), Released.DESCRIPTOR_SYMBOL.toString(), Modified.DESCRIPTOR_SYMBOL.toString()).and().respond();
        peer.remoteFlow().withLinkCredit(2).queue();
        peer.expectDeclare().accept(txnId);
        peer.expectDischarge().withFail(false).withTxnId(txnId).accept();
        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());
        Session session = connection.openSession().openFuture().get();
        session.beginTransaction();
        session.commitTransaction();
        session.closeAsync();
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) Connection(org.apache.qpid.protonj2.client.Connection) Client(org.apache.qpid.protonj2.client.Client) URI(java.net.URI) Session(org.apache.qpid.protonj2.client.Session) 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