use of org.apache.qpid.protonj2.client.exceptions.ClientTransactionNotActiveException 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.ClientTransactionNotActiveException in project qpid-protonj2 by apache.
the class TransactionsTest method testExceptionOnBeginWhenCoordinatorLinkClosedAfterDeclare.
@Test
public void testExceptionOnBeginWhenCoordinatorLinkClosedAfterDeclare() 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.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 {
session.commitTransaction();
fail("Commit should have failed due to no active transaction.");
} catch (ClientTransactionNotActiveException expected) {
// Expect this as the begin failed on coordinator close
}
try {
session.rollbackTransaction();
fail("Rollback should have failed due to no active transaction.");
} catch (ClientTransactionNotActiveException expected) {
// Expect this as the begin failed on coordinator close
}
session.closeAsync();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations