use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class SenderTest method testSendCompletesWhenCreditEventuallyOffered.
@Test
public void testSendCompletesWhenCreditEventuallyOffered() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().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(200);
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);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
// Expect a transfer but only after the flow which is delayed to allow the
// client time to block on credit.
peer.expectTransfer().withNonNullPayload();
peer.remoteFlow().withDeliveryCount(0).withLinkCredit(1).withIncomingWindow(1024).withOutgoingWindow(10).withNextIncomingId(0).withNextOutgoingId(1).later(30);
peer.expectDetach().respond();
peer.expectClose().respond();
Message<String> message = Message.create("Hello World");
try {
LOG.debug("Attempting send with sender: {}", sender);
sender.send(message);
} catch (ClientSendTimedOutException ex) {
fail("Should not throw a send timed out exception");
}
sender.closeAsync().get(10, TimeUnit.SECONDS);
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 SenderTest method doTestCloseOrDetachSenderTimesOutWhenNoCloseResponseReceived.
private void doTestCloseOrDetachSenderTimesOutWhenNoCloseResponseReceived(boolean close, boolean timeout) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.expectDetach();
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.closeTimeout(10);
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);
try {
if (close) {
if (timeout) {
sender.closeAsync().get(10, TimeUnit.SECONDS);
} else {
sender.closeAsync().get();
}
} else {
if (timeout) {
sender.detachAsync().get(10, TimeUnit.SECONDS);
} else {
sender.detachAsync().get();
}
}
fail("Should not complete the close or detach future without an error");
} catch (ExecutionException exe) {
Throwable cause = exe.getCause();
assertTrue(cause instanceof ClientOperationTimedOutException);
}
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 SenderTest method testCreateSenderWithUserConfiguredSourceAndTargetOptions.
@Test
public void testCreateSenderWithUserConfiguredSourceAndTargetOptions() throws Exception {
final Map<String, Object> filtersToObject = new HashMap<>();
filtersToObject.put("x-opt-filter", "a = b");
final Map<String, String> filters = new HashMap<>();
filters.put("x-opt-filter", "a = b");
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().withSource().withAddress(notNullValue()).withDistributionMode("copy").withTimeout(128).withDurable(TerminusDurability.UNSETTLED_STATE).withExpiryPolicy(TerminusExpiryPolicy.CONNECTION_CLOSE).withDefaultOutcome(new Released()).withCapabilities("QUEUE").withFilter(filtersToObject).withOutcomes("amqp:accepted:list", "amqp:rejected:list").also().withTarget().withAddress("test-queue").withCapabilities("QUEUE").withDurable(TerminusDurability.CONFIGURATION).withExpiryPolicy(TerminusExpiryPolicy.SESSION_END).withTimeout(42).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();
SenderOptions senderOptions = new SenderOptions();
senderOptions.sourceOptions().capabilities("QUEUE");
senderOptions.sourceOptions().distributionMode(DistributionMode.COPY);
senderOptions.sourceOptions().timeout(128);
senderOptions.sourceOptions().durabilityMode(DurabilityMode.UNSETTLED_STATE);
senderOptions.sourceOptions().expiryPolicy(ExpiryPolicy.CONNECTION_CLOSE);
senderOptions.sourceOptions().defaultOutcome(DeliveryState.released());
senderOptions.sourceOptions().filters(filters);
senderOptions.sourceOptions().outcomes(DeliveryState.Type.ACCEPTED, DeliveryState.Type.REJECTED);
senderOptions.targetOptions().capabilities("QUEUE");
senderOptions.targetOptions().durabilityMode(DurabilityMode.CONFIGURATION);
senderOptions.targetOptions().expiryPolicy(ExpiryPolicy.SESSION_CLOSE);
senderOptions.targetOptions().timeout(42);
Sender sender = session.openSender("test-queue", senderOptions).openFuture().get();
sender.close();
session.close();
connection.close();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class SenderTest method doTestSenderSendingSettledCompletesTrackerAcknowledgeFuture.
private void doTestSenderSendingSettledCompletesTrackerAcknowledgeFuture(boolean trySend) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().withSenderSettleModeSettled().withReceiverSettlesFirst().respond().withSenderSettleModeSettled().withReceivervSettlesFirst();
peer.remoteFlow().withLinkCredit(10).queue();
// Open a receiver to ensure sender link has processed
peer.expectAttach().respond();
// the inbound flow frame we sent previously before send.
peer.expectFlow();
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()).openFuture().get();
Session session = connection.openSession().openFuture().get();
SenderOptions options = new SenderOptions().deliveryMode(DeliveryMode.AT_MOST_ONCE);
Sender sender = session.openSender("test-qos", options);
assertEquals("test-qos", sender.address());
session.openReceiver("dummy").openFuture().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withNonNullPayload();
peer.expectDetach().respond();
peer.expectClose().respond();
final Message<String> message = Message.create("Hello World");
final Tracker tracker;
if (trySend) {
tracker = sender.trySend(message);
} else {
tracker = sender.send(message);
}
assertNotNull(tracker);
assertTrue(tracker.settlementFuture().isDone());
assertTrue(tracker.settlementFuture().get().settled());
assertFalse(tracker.settlementFuture().get().remoteSettled());
sender.closeAsync().get(10, TimeUnit.SECONDS);
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 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);
}
}
Aggregations