use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class TransactionsTest method testBeginAndCommitTransactions.
@Test
public void testBeginAndCommitTransactions() throws Exception {
final byte[] txnId1 = new byte[] { 0, 1, 2, 3 };
final byte[] txnId2 = new byte[] { 1, 1, 2, 3 };
final byte[] txnId3 = new byte[] { 2, 1, 2, 3 };
final byte[] txnId4 = new byte[] { 3, 1, 2, 3 };
final byte[] txnId5 = new byte[] { 4, 1, 2, 3 };
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectCoordinatorAttach().respond();
peer.remoteFlow().withLinkCredit(10).queue();
peer.expectDeclare().accept(txnId1);
peer.expectDischarge().withFail(false).withTxnId(txnId1).accept();
peer.expectDeclare().accept(txnId2);
peer.expectDischarge().withFail(false).withTxnId(txnId2).accept();
peer.expectDeclare().accept(txnId3);
peer.expectDischarge().withFail(false).withTxnId(txnId3).accept();
peer.expectDeclare().accept(txnId4);
peer.expectDischarge().withFail(false).withTxnId(txnId4).accept();
peer.expectDeclare().accept(txnId5);
peer.expectDischarge().withFail(false).withTxnId(txnId5).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();
for (int i = 0; i < 5; ++i) {
LOG.info("Transaction declare and discharge cycle: {}", i);
session.beginTransaction();
session.commitTransaction();
}
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 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 com.swiftmq.amqp.v100.client.Session 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 com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class TransactionsTest method testCoordinatorLinkSupportedOutcomes.
@Test
public void testCoordinatorLinkSupportedOutcomes() throws Exception {
final byte[] txnId = new byte[] { 0, 1, 2, 3 };
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectCoordinatorAttach().withSource().withOutcomes(Accepted.DESCRIPTOR_SYMBOL.toString(), Rejected.DESCRIPTOR_SYMBOL.toString(), Released.DESCRIPTOR_SYMBOL.toString(), Modified.DESCRIPTOR_SYMBOL.toString()).and().respond();
peer.remoteFlow().withLinkCredit(2).queue();
peer.expectDeclare().accept(txnId);
peer.expectDischarge().withFail(false).withTxnId(txnId).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();
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 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