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);
}
}
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);
}
}
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));
}
});
}
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));
}
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);
}
}
Aggregations