use of com.swiftmq.amqp.v100.client.Connection 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.Connection in project qpid-protonj2 by apache.
the class WsConnectionTest method testWSConnectFailsDueToServerListeningOverTCP.
@Test
public void testWSConnectFailsDueToServerListeningOverTCP() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer(testServerOptions())) {
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("WebSocket Connect test started, peer listening on: {}", remoteURI);
Client container = Client.create();
ConnectionOptions options = connectionOptions();
try {
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), options);
connection.openFuture().get();
fail("Should fail to connect");
} catch (ExecutionException ex) {
LOG.info("Connection create failed due to: ", ex);
assertTrue(ex.getCause() instanceof ClientException);
}
peer.waitForScriptToCompleteIgnoreErrors();
}
}
use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.
the class StreamSenderTest method testRawOutputStreamFromMessageWritesUnmodifiedBytes.
@Test
void testRawOutputStreamFromMessageWritesUnmodifiedBytes() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.remoteFlow().withLinkCredit(1).queue();
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());
StreamSender sender = connection.openStreamSender("test-queue");
StreamSenderMessage message = sender.beginMessage();
OutputStream stream = message.rawOutputStream();
// Only one writer at a time can exist
assertThrows(ClientIllegalStateException.class, () -> message.rawOutputStream());
assertThrows(ClientIllegalStateException.class, () -> message.body());
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withMore(true).withPayload(new byte[] { 0, 1, 2, 3 });
peer.expectTransfer().withMore(false).withNullPayload();
peer.expectDetach().respond();
peer.expectEnd().respond();
peer.expectClose().respond();
stream.write(new byte[] { 0, 1, 2, 3 });
stream.flush();
stream.close();
sender.closeAsync().get();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Connection 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.Connection 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);
}
}
Aggregations