use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.
the class SenderTest method doTestCreateSenderAndCloseOrDetachWithErrorSync.
private void doTestCreateSenderAndCloseOrDetachWithErrorSync(boolean close) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.expectDetach().withError("amqp-resource-deleted", "an error message").withClosed(close).respond();
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());
connection.openFuture().get(10, TimeUnit.SECONDS);
Session session = connection.openSession();
session.openFuture().get(10, TimeUnit.SECONDS);
Sender sender = session.openSender("test-queue");
sender.openFuture().get(10, TimeUnit.SECONDS);
if (close) {
sender.close(ErrorCondition.create("amqp-resource-deleted", "an error message", null));
} else {
sender.detach(ErrorCondition.create("amqp-resource-deleted", "an error message", null));
}
connection.closeAsync().get(10, TimeUnit.SECONDS);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Connection 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.Connection 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.Connection in project qpid-protonj2 by apache.
the class SenderTest method testWaitForAcceptedReturnsOnRemoteAcceptance.
@Test
void testWaitForAcceptedReturnsOnRemoteAcceptance() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.remoteFlow().withLinkCredit(2).queue();
peer.expectTransfer().withNonNullPayload().withMore(false).respond().withSettled(true).withState().accepted();
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());
Sender sender = connection.openSender("test-queue").openFuture().get();
Tracker tracker = sender.send(Message.create("Hello World"));
tracker.awaitAccepted();
assertTrue(tracker.remoteSettled());
assertTrue(tracker.remoteState().isAccepted());
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectDetach().respond();
peer.expectClose().respond();
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 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);
}
}
Aggregations