use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.
the class StreamReceiverTest method doTestCreateReceiverAndCloseOrDetachWithErrorAsync.
private void doTestCreateReceiverAndCloseOrDetachWithErrorAsync(boolean close) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofReceiver().respond();
peer.expectFlow();
peer.expectDetach().withError("amqp-resource-deleted", "an error message").withClosed(close).respond();
peer.expectEnd().respond();
peer.expectClose().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());
StreamReceiver receiver = connection.openStreamReceiver("test-queue");
receiver.openFuture().get(10, TimeUnit.SECONDS);
if (close) {
receiver.closeAsync(ErrorCondition.create("amqp-resource-deleted", "an error message", null)).get();
} else {
receiver.detachAsync(ErrorCondition.create("amqp-resource-deleted", "an error message", null)).get();
}
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 StreamReceiverTest method testStreamDeliveryUsesUnsettledDeliveryOnOpen.
@Test
public void testStreamDeliveryUsesUnsettledDeliveryOnOpen() 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(false).withMessageFormat(0).withPayload(payload).queue();
peer.remoteDisposition().withRole(Role.SENDER.getValue()).withFirst(0).withSettled(true).withState(Accepted.getInstance()).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 StreamReceiverOptions options = new StreamReceiverOptions().autoAccept(false);
final StreamReceiver receiver = connection.openStreamReceiver("test-queue", options);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
final StreamDelivery delivery = receiver.receive();
Wait.assertTrue("Should eventually be remotely settled", delivery::remoteSettled);
Wait.assertTrue(() -> {
return delivery.remoteState() == DeliveryState.accepted();
});
peer.expectDetach().respond();
peer.expectEnd().respond();
peer.expectClose().respond();
receiver.close();
connection.close();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.
the class StreamReceiverTest method testDrainCompletesWhenReceiverHasNoCredit.
@Test
public void testDrainCompletesWhenReceiverHasNoCredit() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().withRole(Role.RECEIVER.getValue()).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());
StreamReceiver receiver = connection.openStreamReceiver("test-queue", new StreamReceiverOptions().creditWindow(0));
receiver.openFuture().get(5, TimeUnit.SECONDS);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
Future<StreamReceiver> draining = receiver.drain();
draining.get(5, TimeUnit.SECONDS);
// Close things down
peer.expectClose().respond();
connection.closeAsync().get(5, TimeUnit.SECONDS);
peer.waitForScriptToComplete(1, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.
the class StreamReceiverTest method testStreamDeliveryHandlesInvalidApplicationPropertiesEncoding.
@Test
public void testStreamDeliveryHandlesInvalidApplicationPropertiesEncoding() throws Exception {
final byte[] payload = createInvalidApplicationPropertiesEncoding();
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 StreamReceiverOptions options = new StreamReceiverOptions().autoAccept(false);
final StreamReceiver receiver = connection.openStreamReceiver("test-queue", options);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectDisposition().withState().rejected("decode-error", "failed reading message header");
final StreamDelivery delivery = receiver.receive();
final StreamReceiverMessage message = delivery.message();
assertThrows(ClientException.class, () -> message.applicationProperties());
assertThrows(ClientException.class, () -> message.body());
delivery.reject("decode-error", "failed reading message header");
peer.expectDetach().respond();
peer.expectEnd().respond();
peer.expectClose().respond();
receiver.close();
connection.close();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Connection in project qpid-protonj2 by apache.
the class StreamReceiverTest method testReadApplicationPropertiesStreamReceiverMessage.
@Test
public void testReadApplicationPropertiesStreamReceiverMessage() throws Exception {
final Map<String, Object> propertiesMap = new HashMap<>();
final ApplicationProperties appProperties = new ApplicationProperties(propertiesMap);
propertiesMap.put("property1", UnsignedInteger.MAX_VALUE);
propertiesMap.put("property2", UnsignedInteger.ONE);
propertiesMap.put("property3", UnsignedInteger.ZERO);
final byte[] payload = createEncodedMessage(appProperties);
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.expectDisposition().withFirst(0).withState().accepted().withSettled(true);
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);
assertTrue(delivery.completed());
assertFalse(delivery.aborted());
StreamReceiverMessage message = delivery.message();
assertNotNull(message);
assertTrue(message.hasProperties());
assertFalse(message.hasFooters());
assertFalse(message.hasAnnotations());
assertFalse(message.hasProperty("property"));
assertEquals(UnsignedInteger.MAX_VALUE, message.property("property1"));
assertEquals(UnsignedInteger.ONE, message.property("property2"));
assertEquals(UnsignedInteger.ZERO, message.property("property3"));
message.forEachProperty((key, value) -> {
assertTrue(propertiesMap.containsKey(key));
assertEquals(value, propertiesMap.get(key));
});
peer.expectDetach().respond();
peer.expectEnd().respond();
peer.expectClose().respond();
receiver.closeAsync().get();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations