use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.
the class SenderTest method testSendBlockedForCreditFailsWhenConnectionDrops.
@Test
public void testSendBlockedForCreditFailsWhenConnectionDrops() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.dropAfterLastHandler(25);
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 (ClientConnectionRemotelyClosedException cliEx) {
// Expected send to throw indicating that the remote closed unexpectedly
}
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 doTestSentMessageGetsAutoSettledAfterRemoteSettles.
private void doTestSentMessageGetsAutoSettledAfterRemoteSettles(boolean trySend) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.remoteFlow().withDeliveryCount(0).withLinkCredit(10).withIncomingWindow(1024).withOutgoingWindow(10).withNextIncomingId(0).withNextOutgoingId(1).queue();
peer.expectAttach().ofReceiver().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();
Sender sender = session.openSender("test-queue");
sender.openFuture().get(10, TimeUnit.SECONDS);
// This ensures that the flow to sender is processed before we try-send
Receiver receiver = session.openReceiver("test-queue", new ReceiverOptions().creditWindow(0));
receiver.openFuture().get(10, TimeUnit.SECONDS);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withNonNullPayload().respond().withSettled(true).withState().accepted();
peer.expectDetach().respond();
peer.expectClose().respond();
Message<String> message = Message.create("Hello World");
final Tracker tracker;
if (trySend) {
tracker = sender.trySend(message);
} else {
tracker = sender.send(message);
}
assertNotNull(tracker);
assertNotNull(tracker.settlementFuture().get(5, TimeUnit.SECONDS));
assertEquals(tracker.remoteState().getType(), DeliveryState.Type.ACCEPTED);
sender.closeAsync();
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 testTrySendWhenNoCreditAvailable.
@Test
public void testTrySendWhenNoCreditAvailable() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.expectDetach().respond();
peer.expectClose().respond();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Sender test started, peer listening on: {}", remoteURI);
Client container = Client.create();
ConnectionOptions options = new ConnectionOptions();
options.sendTimeout(1);
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), options);
Session session = connection.openSession();
Sender sender = session.openSender("test-queue");
sender.openFuture().get(10, TimeUnit.SECONDS);
Message<String> message = Message.create("Hello World");
assertNull(sender.trySend(message));
sender.closeAsync().get(10, TimeUnit.SECONDS);
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 testCreateSenderWithDefaultSourceAndTargetOptions.
@Test
public void testCreateSenderWithDefaultSourceAndTargetOptions() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().withSource().withAddress(notNullValue()).withDistributionMode(nullValue()).withDefaultTimeout().withDurable(TerminusDurability.NONE).withExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH).withDefaultOutcome(nullValue()).withCapabilities(nullValue()).withFilter(nullValue()).withOutcomes("amqp:accepted:list", "amqp:rejected:list", "amqp:released:list", "amqp:modified:list").also().withTarget().withAddress("test-queue").withCapabilities(nullValue()).withDurable(nullValue()).withExpiryPolicy(nullValue()).withDefaultTimeout().withDynamic(anyOf(nullValue(), equalTo(false))).withDynamicNodeProperties(nullValue()).and().respond();
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();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
Session session = connection.openSession();
Sender sender = session.openSender("test-queue").openFuture().get();
sender.close();
session.close();
connection.close();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.
the class SenderTest method doTestOpenSenderWaitFailsWhenConnectionDrops.
private void doTestOpenSenderWaitFailsWhenConnectionDrops(boolean timeout) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender();
peer.dropAfterLastHandler(10);
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");
Thread.sleep(10);
try {
if (timeout) {
sender.openFuture().get(10, TimeUnit.SECONDS);
} else {
sender.openFuture().get();
}
fail("Should not complete the open future without an error");
} catch (ExecutionException exe) {
Throwable cause = exe.getCause();
LOG.trace("Caught exception caused by: {}", exe);
assertTrue(cause instanceof ClientConnectionRemotelyClosedException);
}
connection.closeAsync().get(10, TimeUnit.SECONDS);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations