use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.
the class StreamSenderTest method testCloseAfterSingleWriteEncodesAndCompletesTransferWhenNoStreamSizeConfigured.
@Test
void testCloseAfterSingleWriteEncodesAndCompletesTransferWhenNoStreamSizeConfigured() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.remoteFlow().withLinkCredit(1).queue();
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());
StreamSender sender = connection.openStreamSender("test-queue");
StreamSenderMessage tracker = sender.beginMessage();
// Populate all Header values
Header header = new Header();
header.setDurable(true);
header.setPriority((byte) 1);
header.setTimeToLive(65535);
header.setFirstAcquirer(true);
header.setDeliveryCount(2);
tracker.header(header);
OutputStreamOptions options = new OutputStreamOptions();
OutputStream stream = tracker.body(options);
HeaderMatcher headerMatcher = new HeaderMatcher(true);
headerMatcher.withDurable(true);
headerMatcher.withPriority((byte) 1);
headerMatcher.withTtl(65535);
headerMatcher.withFirstAcquirer(true);
headerMatcher.withDeliveryCount(2);
EncodedDataMatcher dataMatcher = new EncodedDataMatcher(new byte[] { 0, 1, 2, 3 });
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.setHeadersMatcher(headerMatcher);
payloadMatcher.setMessageContentMatcher(dataMatcher);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withPayload(payloadMatcher).withMore(false).accept();
peer.expectDetach().respond();
peer.expectEnd().respond();
peer.expectClose().respond();
// Stream won't output until some body bytes are written.
stream.write(new byte[] { 0, 1, 2, 3 });
stream.close();
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 StreamSenderTest method testConcurrentMessageSendWaitingOnSplitFramedSendToCompleteIsSentAfterCreditUpdated.
@Test
void testConcurrentMessageSendWaitingOnSplitFramedSendToCompleteIsSentAfterCreditUpdated() 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);
StreamSender sender = connection.openStreamSender("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:");
StreamTracker 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.expectEnd().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 StreamSenderTest method testIncompleteStreamClosureWithNoWritesAbortsTransfer.
@Test
void testIncompleteStreamClosureWithNoWritesAbortsTransfer() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.remoteFlow().withLinkCredit(1).queue();
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());
StreamSender sender = connection.openStreamSender("test-queue");
StreamSenderMessage message = sender.beginMessage();
// Populate all Header values
Header header = new Header();
header.setDurable(true);
header.setPriority((byte) 1);
header.setDeliveryCount(1);
message.header(header);
OutputStreamOptions options = new OutputStreamOptions().bodyLength(8192).completeSendOnClose(false);
OutputStream stream = message.body(options);
HeaderMatcher headerMatcher = new HeaderMatcher(true);
headerMatcher.withDurable(true);
headerMatcher.withPriority((byte) 1);
headerMatcher.withDeliveryCount(1);
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.setHeadersMatcher(headerMatcher);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectDetach().respond();
peer.expectEnd().respond();
peer.expectClose().respond();
// This should abort the transfer as we might have triggered output upon create when the
// preamble was written.
stream.close();
assertTrue(message.aborted());
// Should have no affect.
message.abort();
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 StreamSenderTest method testAutoFlushAfterSingleWriteExceedsConfiguredBufferLimit.
@Test
void testAutoFlushAfterSingleWriteExceedsConfiguredBufferLimit() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.remoteFlow().withLinkCredit(1).queue();
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());
StreamSender sender = connection.openStreamSender("test-queue", new StreamSenderOptions().writeBufferSize(512));
StreamSenderMessage tracker = sender.beginMessage();
final byte[] payload = new byte[512];
Arrays.fill(payload, (byte) 16);
// Populate all Header values
Header header = new Header();
header.setDurable(true);
header.setPriority((byte) 1);
header.setTimeToLive(65535);
header.setFirstAcquirer(true);
header.setDeliveryCount(2);
tracker.header(header);
OutputStreamOptions options = new OutputStreamOptions();
OutputStream stream = tracker.body(options);
HeaderMatcher headerMatcher = new HeaderMatcher(true);
headerMatcher.withDurable(true);
headerMatcher.withPriority((byte) 1);
headerMatcher.withTtl(65535);
headerMatcher.withFirstAcquirer(true);
headerMatcher.withDeliveryCount(2);
EncodedDataMatcher dataMatcher = new EncodedDataMatcher(payload);
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.setHeadersMatcher(headerMatcher);
payloadMatcher.setMessageContentMatcher(dataMatcher);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withPayload(payloadMatcher).withMore(true);
// Stream won't output until some body bytes are written.
stream.write(payload);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withNullPayload().withMore(false).accept();
peer.expectDetach().respond();
peer.expectEnd().respond();
peer.expectClose().respond();
stream.close();
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 StreamSenderTest method testWriteToCreditLimitFramesOfMessagePayload.
@Test
void testWriteToCreditLimitFramesOfMessagePayload() throws Exception {
final int WRITE_COUNT = 10;
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofSender().respond();
peer.remoteFlow().withIncomingWindow(WRITE_COUNT).withNextIncomingId(0).withLinkCredit(WRITE_COUNT).queue();
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());
StreamSender sender = connection.openStreamSender("test-queue");
StreamSenderMessage tracker = sender.beginMessage();
OutputStream stream = tracker.body();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
final byte[][] payloads = new byte[WRITE_COUNT][256];
for (int i = 0; i < WRITE_COUNT; ++i) {
payloads[i] = new byte[256];
Arrays.fill(payloads[i], (byte) (i + 1));
}
for (int i = 0; i < WRITE_COUNT; ++i) {
EncodedDataMatcher dataMatcher = new EncodedDataMatcher(payloads[i]);
TransferPayloadCompositeMatcher payloadMatcher = new TransferPayloadCompositeMatcher();
payloadMatcher.setMessageContentMatcher(dataMatcher);
peer.expectTransfer().withPayload(payloadMatcher).withMore(true);
}
for (int i = 0; i < WRITE_COUNT; ++i) {
stream.write(payloads[i]);
stream.flush();
}
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectTransfer().withNullPayload().withMore(false).accept();
peer.expectDetach().respond();
peer.expectEnd().respond();
peer.expectClose().respond();
// grant one more credit for the complete to arrive.
peer.remoteFlow().withIncomingWindow(1).withNextIncomingId(WRITE_COUNT).withLinkCredit(1).now();
stream.close();
sender.closeAsync().get();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations