Search in sources :

Example 1 with ClientTransactionDeclarationException

use of org.apache.qpid.protonj2.client.exceptions.ClientTransactionDeclarationException 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 2 with ClientTransactionDeclarationException

use of org.apache.qpid.protonj2.client.exceptions.ClientTransactionDeclarationException 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 3 with ClientTransactionDeclarationException

use of org.apache.qpid.protonj2.client.exceptions.ClientTransactionDeclarationException in project qpid-protonj2 by apache.

the class ClientLocalTransactionContext method beginNewTransaction.

// ------ Internals of Transaction State management
private void beginNewTransaction(ClientFuture<Session> beginFuture) {
    TransactionController txnController = getOrCreateNewTxnController();
    currentTxn = txnController.newTransaction();
    currentTxn.setLinkedResource(this);
    currentTxn.getAttachments().set(DECLARE_FUTURE_NAME, beginFuture);
    cachedReceiverOutcome = null;
    cachedSenderOutcome = null;
    if (session.options().requestTimeout() > 0) {
        session.scheduleRequestTimeout(beginFuture, session.options().requestTimeout(), () -> {
            try {
                txnController.close();
            } catch (Exception ignore) {
            }
            return new ClientTransactionDeclarationException("Timed out waiting for Transaction declaration to complete");
        });
    }
    txnController.addCapacityAvailableHandler(controller -> {
        try {
            txnController.declare(currentTxn);
        } catch (EngineFailedException efe) {
            beginFuture.failed(ClientExceptionSupport.createOrPassthroughFatal(efe));
        }
    });
}
Also used : ClientTransactionDeclarationException(org.apache.qpid.protonj2.client.exceptions.ClientTransactionDeclarationException) EngineFailedException(org.apache.qpid.protonj2.engine.exceptions.EngineFailedException) TransactionController(org.apache.qpid.protonj2.engine.TransactionController) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) EngineFailedException(org.apache.qpid.protonj2.engine.exceptions.EngineFailedException) ClientTransactionDeclarationException(org.apache.qpid.protonj2.client.exceptions.ClientTransactionDeclarationException) ClientOperationTimedOutException(org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException) ClientIllegalStateException(org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException) ClientTransactionRolledBackException(org.apache.qpid.protonj2.client.exceptions.ClientTransactionRolledBackException) ClientTransactionNotActiveException(org.apache.qpid.protonj2.client.exceptions.ClientTransactionNotActiveException)

Example 4 with ClientTransactionDeclarationException

use of org.apache.qpid.protonj2.client.exceptions.ClientTransactionDeclarationException in project qpid-protonj2 by apache.

the class ClientLocalTransactionContext method handleTransactionDeclareFailed.

private void handleTransactionDeclareFailed(Transaction<TransactionController> transaction) {
    ClientFuture<Session> future = transaction.getAttachments().get(DECLARE_FUTURE_NAME);
    LOG.trace("Declare of transaction:{} failed", transaction);
    ClientException cause = ClientExceptionSupport.convertToNonFatalException(transaction.getCondition());
    future.failed(new ClientTransactionDeclarationException(cause.getMessage(), cause));
}
Also used : ClientTransactionDeclarationException(org.apache.qpid.protonj2.client.exceptions.ClientTransactionDeclarationException) ClientException(org.apache.qpid.protonj2.client.exceptions.ClientException) Session(org.apache.qpid.protonj2.client.Session)

Example 5 with ClientTransactionDeclarationException

use of org.apache.qpid.protonj2.client.exceptions.ClientTransactionDeclarationException in project qpid-protonj2 by apache.

the class TransactionsTest method testTimedOutExceptionOnBeginWithNoResponseThenRecoverWithNextBeginAndDelayedDetachResponse.

@Test
public void testTimedOutExceptionOnBeginWithNoResponseThenRecoverWithNextBeginAndDelayedDetachResponse() 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().afterDelay(20);
        peer.start();
        URI remoteURI = peer.getServerURI();
        LOG.info("Test started, peer listening on: {}", remoteURI);
        Client container = Client.create();
        ConnectionOptions options = new ConnectionOptions().requestTimeout(150);
        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
        }
        peer.waitForScriptToComplete(500, TimeUnit.SECONDS);
        peer.expectCoordinatorAttach().respond();
        peer.remoteFlow().withLinkCredit(2).queue();
        peer.expectDeclare().accept();
        peer.expectDischarge().accept();
        peer.expectEnd().respond();
        peer.expectClose().respond();
        session.beginTransaction();
        session.commitTransaction();
        session.closeAsync();
        connection.closeAsync().get();
        peer.waitForScriptToComplete(500, 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)

Aggregations

ClientTransactionDeclarationException (org.apache.qpid.protonj2.client.exceptions.ClientTransactionDeclarationException)6 Session (org.apache.qpid.protonj2.client.Session)5 URI (java.net.URI)4 Client (org.apache.qpid.protonj2.client.Client)4 Connection (org.apache.qpid.protonj2.client.Connection)4 ClientIllegalStateException (org.apache.qpid.protonj2.client.exceptions.ClientIllegalStateException)4 ProtonTestServer (org.apache.qpid.protonj2.test.driver.ProtonTestServer)4 Test (org.junit.jupiter.api.Test)4 ConnectionOptions (org.apache.qpid.protonj2.client.ConnectionOptions)3 ClientException (org.apache.qpid.protonj2.client.exceptions.ClientException)2 ClientTransactionNotActiveException (org.apache.qpid.protonj2.client.exceptions.ClientTransactionNotActiveException)2 ClientOperationTimedOutException (org.apache.qpid.protonj2.client.exceptions.ClientOperationTimedOutException)1 ClientTransactionRolledBackException (org.apache.qpid.protonj2.client.exceptions.ClientTransactionRolledBackException)1 TransactionController (org.apache.qpid.protonj2.engine.TransactionController)1 EngineFailedException (org.apache.qpid.protonj2.engine.exceptions.EngineFailedException)1