Search in sources :

Example 6 with Session

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

the class TransactionsTest method testExceptionOnCommitWhenCoordinatorLinkClosedAfterDischargeSent.

@Test
public void testExceptionOnCommitWhenCoordinatorLinkClosedAfterDischargeSent() throws Exception {
    final String errorMessage = "CoordinatorLinkClosed-breadcrumb";
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectCoordinatorAttach().respond();
        peer.remoteFlow().withLinkCredit(2).queue();
        peer.expectDeclare().accept();
        peer.expectDischarge();
        peer.remoteDetach().withClosed(true).withErrorCondition(AmqpError.RESOURCE_DELETED.toString(), errorMessage).queue();
        peer.expectDetach();
        peer.expectCoordinatorAttach().respond();
        peer.remoteFlow().withLinkCredit(2).queue();
        peer.expectDeclare().accept();
        peer.expectDischarge().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();
        try {
            session.commitTransaction();
            fail("Commit should have failed after link closed.");
        } catch (ClientTransactionRolledBackException expected) {
            // Expect this to time out.
            String message = expected.getMessage();
            assertTrue(message.contains(errorMessage));
        }
        session.beginTransaction();
        session.rollbackTransaction();
        session.closeAsync();
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) ClientTransactionRolledBackException(org.apache.qpid.protonj2.client.exceptions.ClientTransactionRolledBackException) 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 7 with Session

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

the class TransactionsTest method testExceptionOnBeginWhenCoordinatorLinkClosedAfterDeclareAllowsNewTransactionDeclaration.

@Test
public void testExceptionOnBeginWhenCoordinatorLinkClosedAfterDeclareAllowsNewTransactionDeclaration() throws Exception {
    final String errorMessage = "CoordinatorLinkClosed-breadcrumb";
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectCoordinatorAttach().respond();
        peer.remoteFlow().withLinkCredit(2).queue();
        peer.expectDeclare();
        peer.remoteDetach().withClosed(true).withErrorCondition(AmqpError.NOT_IMPLEMENTED.toString(), errorMessage).queue();
        peer.expectDetach();
        peer.expectCoordinatorAttach().respond();
        peer.remoteFlow().withLinkCredit(2).queue();
        peer.expectDeclare().accept();
        peer.expectDischarge().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();
        try {
            session.beginTransaction();
            fail("Begin should have failed after link closed.");
        } catch (ClientException expected) {
            // Expect this to time out.
            String message = expected.getMessage();
            assertTrue(message.contains(errorMessage));
        }
        // Try again and expect to return to normal state now.
        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) 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 8 with Session

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

the class TransactionsTest method testExceptionOnRollbackWhenCoordinatorRejectsDischarge.

@Test
public void testExceptionOnRollbackWhenCoordinatorRejectsDischarge() throws Exception {
    final String errorMessage = "Transaction aborted due to timeout";
    final byte[] txnId1 = new byte[] { 0, 1, 2, 3 };
    final byte[] txnId2 = new byte[] { 1, 1, 2, 3 };
    try (ProtonTestServer peer = new ProtonTestServer()) {
        peer.expectSASLAnonymousConnect();
        peer.expectOpen().respond();
        peer.expectBegin().respond();
        peer.expectCoordinatorAttach().respond();
        peer.remoteFlow().withLinkCredit(4).queue();
        peer.expectDeclare().accept(txnId1);
        peer.expectDischarge().withFail(true).withTxnId(txnId1).reject(TransactionErrors.TRANSACTION_TIMEOUT.toString(), "Transaction aborted due to timeout");
        peer.expectDeclare().accept(txnId2);
        peer.expectDischarge().withFail(false).withTxnId(txnId2).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();
        try {
            session.rollbackTransaction();
            fail("Commit should have failed after link closed.");
        } catch (ClientTransactionRolledBackException expected) {
            // Expect this to time out.
            String message = expected.getMessage();
            assertTrue(message.contains(errorMessage));
        }
        session.beginTransaction();
        session.commitTransaction();
        session.closeAsync();
        connection.closeAsync().get();
        peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
    }
}
Also used : ProtonTestServer(org.apache.qpid.protonj2.test.driver.ProtonTestServer) ClientTransactionRolledBackException(org.apache.qpid.protonj2.client.exceptions.ClientTransactionRolledBackException) 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 9 with Session

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

the class TransactionsTest method testCannotBeginSecondTransactionWhileFirstIsActive.

@Test
public void testCannotBeginSecondTransactionWhileFirstIsActive() 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().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();
        try {
            session.beginTransaction();
            fail("Should not be allowed to begin another transaction");
        } catch (ClientIllegalStateException cliEx) {
        // Expected
        }
        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) ClientIllegalStateException(org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException) 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 10 with Session

use of com.swiftmq.amqp.v100.client.Session 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)

Aggregations

Session (org.apache.qpid.protonj2.client.Session)167 Client (org.apache.qpid.protonj2.client.Client)165 Connection (org.apache.qpid.protonj2.client.Connection)165 URI (java.net.URI)163 ProtonTestServer (org.apache.qpid.protonj2.test.driver.ProtonTestServer)163 Test (org.junit.jupiter.api.Test)109 Sender (org.apache.qpid.protonj2.client.Sender)66 Receiver (org.apache.qpid.protonj2.client.Receiver)64 ExecutionException (java.util.concurrent.ExecutionException)35 ConnectionOptions (org.apache.qpid.protonj2.client.ConnectionOptions)35 Tracker (org.apache.qpid.protonj2.client.Tracker)32 ClientException (org.apache.qpid.protonj2.client.exceptions.ClientException)29 SenderOptions (org.apache.qpid.protonj2.client.SenderOptions)28 ReceiverOptions (org.apache.qpid.protonj2.client.ReceiverOptions)25 TransferPayloadCompositeMatcher (org.apache.qpid.protonj2.test.driver.matchers.transport.TransferPayloadCompositeMatcher)20 ClientConnectionRemotelyClosedException (org.apache.qpid.protonj2.client.exceptions.ClientConnectionRemotelyClosedException)18 HashMap (java.util.HashMap)17 ClientIllegalStateException (org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException)16 EncodedAmqpValueMatcher (org.apache.qpid.protonj2.test.driver.matchers.types.EncodedAmqpValueMatcher)14 Delivery (org.apache.qpid.protonj2.client.Delivery)13