use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class SenderTest method testCreateAnonymousSenderWhenRemoteDoesNotOfferSupportForIt.
@Test
public void testCreateAnonymousSenderWhenRemoteDoesNotOfferSupportForIt() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().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.openAnonymousSender();
fail("Should not be able to open an anonymous sender when remote does not offer anonymous relay");
} catch (ClientUnsupportedOperationException unsupported) {
LOG.info("Caught expected error: ", unsupported);
}
connection.closeAsync();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class SenderTest method testSendBlockedForCreditFailsWhenLinkRemotelyClosed.
@Test
public void testSendBlockedForCreditFailsWhenLinkRemotelyClosed() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.remoteDetach().withErrorCondition(AmqpError.RESOURCE_DELETED.toString(), "Link was deleted").afterDelay(25).queue();
peer.expectDetach();
peer.expectClose().respond();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Sender test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
Session session = connection.openSession();
Sender sender = session.openSender("test-queue");
sender.openFuture().get();
Message<String> message = Message.create("Hello World");
try {
sender.send(message);
fail("Send should have timed out.");
} catch (ClientResourceRemotelyClosedException cliEx) {
// Expected send to throw indicating that the remote closed the link
}
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class SenderTest method testAwaitSettlementFailedOnConnectionDropped.
@Test
public void testAwaitSettlementFailedOnConnectionDropped() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().withTarget().withAddress("test").and().respond();
peer.remoteFlow().withLinkCredit(1).queue();
peer.expectTransfer();
peer.dropAfterLastHandler(30);
peer.start();
URI remoteURI = peer.getServerURI();
Message<String> message = Message.create("test-message");
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
Session session = connection.openSession();
Sender sender = session.openSender("test");
Tracker tracker = null;
try {
tracker = sender.send(message);
} catch (ClientConnectionRemotelyClosedException cliEx) {
fail("Send should not fail with remotely closed error after remote drops");
}
// the drop completes waiting callers.
try {
tracker.awaitSettlement();
fail("Wait for settlement should fail with remotely closed error after remote drops");
} catch (ClientConnectionRemotelyClosedException cliRCEx) {
}
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class SenderTest method testSenderOpenRejectedByRemote.
@Test
public void testSenderOpenRejectedByRemote() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().respond().withNullTarget();
peer.remoteDetach().withErrorCondition(AmqpError.UNAUTHORIZED_ACCESS.toString(), "Cannot read from this address").queue();
peer.expectDetach();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Sender test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
connection.openFuture().get(10, TimeUnit.SECONDS);
Session session = connection.openSession();
session.openFuture().get(10, TimeUnit.SECONDS);
Sender sender = session.openSender("test-queue");
try {
sender.openFuture().get(10, TimeUnit.SECONDS);
fail("Open of sender should fail due to remote indicating pending close.");
} catch (ExecutionException exe) {
assertNotNull(exe.getCause());
assertTrue(exe.getCause() instanceof ClientLinkRemotelyClosedException);
ClientLinkRemotelyClosedException linkClosed = (ClientLinkRemotelyClosedException) exe.getCause();
assertNotNull(linkClosed.getErrorCondition());
assertEquals(AmqpError.UNAUTHORIZED_ACCESS.toString(), linkClosed.getErrorCondition().condition());
}
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
// Should not result in any close being sent now, already closed.
sender.closeAsync().get(10, TimeUnit.SECONDS);
peer.expectClose().respond();
connection.closeAsync().get(10, TimeUnit.SECONDS);
peer.waitForScriptToComplete(1, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class SessionTest method doTestSessionCloseTimeoutWhenNoRemoteEndArrives.
private void doTestSessionCloseTimeoutWhenNoRemoteEndArrives(boolean timeout) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectEnd();
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());
SessionOptions options = new SessionOptions();
options.closeTimeout(75);
Session session = connection.openSession(options).openFuture().get();
try {
if (timeout) {
session.closeAsync().get(10, TimeUnit.SECONDS);
} else {
session.closeAsync().get();
}
fail("Close should throw an error if the Session end doesn't arrive in time");
} catch (Throwable error) {
LOG.info("Session close failed with error: ", error);
}
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations