use of org.apache.qpid.protonj2.test.driver.ProtonTestServer in project qpid-protonj2 by apache.
the class StreamReceiverTest method testStreamDeliveryReceivedWhileTransferIsIncomplete.
@Test
public void testStreamDeliveryReceivedWhileTransferIsIncomplete() throws Exception {
final byte[] payload = createEncodedMessage(new AmqpValue<>("Hello World"));
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().withRole(Role.RECEIVER.getValue()).respond();
peer.expectFlow();
peer.remoteTransfer().withHandle(0).withDeliveryId(0).withDeliveryTag(new byte[] { 1 }).withMore(true).withMessageFormat(0).withPayload(payload).queue();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Test started, peer listening on: {}", remoteURI);
final Client container = Client.create();
final Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
final StreamReceiver receiver = connection.openStreamReceiver("test-queue");
final StreamDelivery delivery = receiver.receive();
assertNotNull(delivery);
assertFalse(delivery.completed());
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectDisposition().withSettled(true);
peer.remoteTransfer().withHandle(0).withDeliveryId(0).withNullDeliveryTag().withMore(false).withMessageFormat(0).withPayload(payload).now();
Wait.assertTrue("Should eventually be marked as completed", delivery::completed);
peer.expectDetach().respond();
peer.expectEnd().respond();
peer.expectClose().respond();
receiver.closeAsync().get();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of org.apache.qpid.protonj2.test.driver.ProtonTestServer in project qpid-protonj2 by apache.
the class StreamReceiverTest method doTestStreamReceiverSessionCapacity.
private void doTestStreamReceiverSessionCapacity(int maxFrameSize, int readBufferSize, int expectedSessionWindow) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().withMaxFrameSize(maxFrameSize).respond();
peer.expectBegin().withIncomingWindow(expectedSessionWindow).respond();
peer.expectAttach().ofReceiver().respond();
peer.expectFlow().withIncomingWindow(expectedSessionWindow);
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();
ConnectionOptions connectionOptions = new ConnectionOptions().maxFrameSize(maxFrameSize);
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), connectionOptions);
StreamReceiverOptions streamOptions = new StreamReceiverOptions().readBufferSize(readBufferSize);
StreamReceiver receiver = connection.openStreamReceiver("test-queue", streamOptions);
receiver.openFuture().get();
receiver.closeAsync().get();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of org.apache.qpid.protonj2.test.driver.ProtonTestServer in project qpid-protonj2 by apache.
the class StreamReceiverTest method testStreamDeliveryRawInputStreamBlockedReadBytesAborted.
@Test
public void testStreamDeliveryRawInputStreamBlockedReadBytesAborted() throws Exception {
final byte[] payload = createEncodedMessage(new AmqpValue<>("Hello World"));
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().withRole(Role.RECEIVER.getValue()).respond();
peer.expectFlow();
peer.remoteTransfer().withHandle(0).withDeliveryId(0).withDeliveryTag(new byte[] { 1 }).withMore(true).withMessageFormat(0).withPayload(payload).queue();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Test started, peer listening on: {}", remoteURI);
final Client container = Client.create();
final Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
final StreamReceiver receiver = connection.openStreamReceiver("test-queue");
final StreamDelivery delivery = receiver.receive();
assertNotNull(delivery);
assertFalse(delivery.completed());
assertFalse(delivery.aborted());
final InputStream stream = delivery.rawInputStream();
assertNotNull(stream);
assertEquals(payload.length, stream.available());
final byte[] deliveryBytes = new byte[payload.length * 2];
peer.remoteTransfer().withHandle(0).withDeliveryId(0).withDeliveryTag(new byte[] { 1 }).withMore(false).withAborted(true).withMessageFormat(0).later(50);
try {
stream.read(deliveryBytes);
fail("Delivery should have been aborted while waiting for more data.");
} catch (IOException ioe) {
assertTrue(ioe.getCause() instanceof ClientDeliveryAbortedException);
}
stream.close();
peer.expectDetach().respond();
peer.expectEnd().respond();
peer.expectClose().respond();
receiver.closeAsync().get();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of org.apache.qpid.protonj2.test.driver.ProtonTestServer in project qpid-protonj2 by apache.
the class StreamReceiverTest method doTestReceiveFailsWhenLinkRemotelyClose.
private void doTestReceiveFailsWhenLinkRemotelyClose(boolean timed) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().withRole(Role.RECEIVER.getValue()).respond();
peer.expectFlow();
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());
StreamReceiver receiver = connection.openStreamReceiver("test-queue");
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectDetach();
peer.expectEnd().respond();
peer.expectClose().respond();
peer.remoteDetach().later(50);
if (timed) {
assertThrows(ClientLinkRemotelyClosedException.class, () -> receiver.receive(1, TimeUnit.MINUTES));
} else {
assertThrows(ClientLinkRemotelyClosedException.class, () -> receiver.receive());
}
receiver.closeAsync();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of org.apache.qpid.protonj2.test.driver.ProtonTestServer in project qpid-protonj2 by apache.
the class StreamReceiverTest method testReadBytesFromBodyInputStreamWithinTransactedSession.
@Test
public void testReadBytesFromBodyInputStreamWithinTransactedSession() throws Exception {
final byte[] body = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
final byte[] payload = createEncodedMessage(new Data(body));
final byte[] txnId = new byte[] { 0, 1, 2, 3 };
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().withRole(Role.RECEIVER.getValue()).respond();
peer.expectFlow();
peer.remoteTransfer().withHandle(0).withDeliveryId(0).withDeliveryTag(new byte[] { 1 }).withMore(false).withMessageFormat(0).withPayload(payload).queue();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Test started, peer listening on: {}", remoteURI);
final Client container = Client.create();
final Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
final StreamReceiver receiver = connection.openStreamReceiver("test-queue");
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectCoordinatorAttach().respond();
peer.remoteFlow().withLinkCredit(2).queue();
peer.expectDeclare().accept(txnId);
peer.expectDisposition().withSettled(true).withState().transactional().withTxnId(txnId).withAccepted();
peer.expectDischarge().withFail(false).withTxnId(txnId).accept();
receiver.session().beginTransaction();
final StreamDelivery delivery = receiver.receive();
assertNotNull(delivery);
assertTrue(delivery.completed());
assertFalse(delivery.aborted());
StreamReceiverMessage message = delivery.message();
assertNotNull(message);
InputStream bodyStream = message.body();
assertNotNull(bodyStream);
assertNull(message.header());
assertNull(message.annotations());
assertNull(message.properties());
assertNull(delivery.annotations());
final byte[] receivedBody = new byte[body.length];
for (int i = 0; i < body.length; ++i) {
receivedBody[i] = (byte) bodyStream.read();
}
assertArrayEquals(body, receivedBody);
assertEquals(-1, bodyStream.read());
receiver.session().commitTransaction();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectDetach().respond();
peer.expectEnd().respond();
peer.expectClose().respond();
receiver.closeAsync().get();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations