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