use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.
the class SenderTest method testConcurrentSendWaitingOnSplitFramedSendToCompleteIsSentAfterCreditUpdated.
@Test
void testConcurrentSendWaitingOnSplitFramedSendToCompleteIsSentAfterCreditUpdated() 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("Test started, peer listening on: {}", remoteURI);
Client container = Client.create();
ConnectionOptions options = new ConnectionOptions().maxFrameSize(1024);
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), options);
Sender sender = connection.openSender("test-queue");
final byte[] payload = new byte[1536];
Arrays.fill(payload, (byte) 1);
final CountDownLatch send1Started = new CountDownLatch(1);
final CountDownLatch send2Completed = new CountDownLatch(1);
final AtomicBoolean sendFailed = new AtomicBoolean();
ForkJoinPool.commonPool().execute(() -> {
try {
LOG.info("Test send 1 is preparing to fire:");
ForkJoinPool.commonPool().execute(() -> send1Started.countDown());
sender.send(Message.create(payload));
} catch (Exception e) {
LOG.info("Test send 1 failed with error: ", e);
sendFailed.set(true);
}
});
ForkJoinPool.commonPool().execute(() -> {
try {
assertTrue(send1Started.await(10, TimeUnit.SECONDS));
LOG.info("Test send 2 is preparing to fire:");
Tracker tracker = sender.send(Message.create(payload));
tracker.awaitSettlement(10, TimeUnit.SECONDS);
send2Completed.countDown();
} catch (Exception e) {
LOG.info("Test send 2 failed with error: ", e);
sendFailed.set(true);
}
});
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.remoteFlow().withIncomingWindow(1).withDeliveryCount(0).withNextIncomingId(1).withLinkCredit(1).now();
peer.expectTransfer().withNonNullPayload().withMore(true);
peer.remoteFlow().withIncomingWindow(1).withDeliveryCount(0).withNextIncomingId(2).withLinkCredit(1).queue();
peer.expectTransfer().withNonNullPayload().withMore(false).respond().withSettled(true).withState().accepted();
peer.remoteFlow().withIncomingWindow(1).withDeliveryCount(1).withNextIncomingId(3).withLinkCredit(1).queue();
peer.expectTransfer().withNonNullPayload().withMore(true);
peer.remoteFlow().withIncomingWindow(1).withDeliveryCount(1).withNextIncomingId(4).withLinkCredit(1).queue();
peer.expectTransfer().withNonNullPayload().withMore(false).respond().withSettled(true).withState().accepted();
assertTrue(send2Completed.await(10, TimeUnit.SECONDS));
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectDetach().respond();
peer.expectClose().respond();
assertFalse(sendFailed.get());
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 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.Connection 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.Connection 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.Connection 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);
}
}
Aggregations