use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class ReceiverTest method tryReadReceiverTarget.
private void tryReadReceiverTarget(boolean attachResponse) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().withRole(Role.RECEIVER.getValue());
peer.expectFlow();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Test started, peer listening on: {}", remoteURI);
Client container = Client.create();
ConnectionOptions options = new ConnectionOptions().openTimeout(100);
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), options);
connection.openFuture().get();
Session session = connection.openSession();
session.openFuture().get();
Receiver receiver = session.openReceiver("test-receiver");
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
if (attachResponse) {
peer.expectDetach().respond();
peer.respondToLastAttach().later(10);
} else {
peer.expectDetach();
}
if (attachResponse) {
assertNotNull(receiver.target(), "Remote should have responded with a Target value");
} else {
try {
receiver.target();
fail("Should failed to get remote source due to no attach response");
} catch (ClientException ex) {
LOG.debug("Caught expected exception from blocking call", ex);
}
}
try {
receiver.closeAsync().get();
} catch (ExecutionException ex) {
LOG.debug("Caught unexpected exception from close call", ex);
fail("Should not fail to close when connection not closed and detach sent");
}
peer.expectClose().respond();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class ReceiverTest method testDrainFutureSignalsFailureWhenSessionDrainTimeoutExceeded.
@Test
public void testDrainFutureSignalsFailureWhenSessionDrainTimeoutExceeded() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofReceiver().respond();
peer.expectFlow();
peer.expectFlow().withDrain(true);
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());
SessionOptions sessionOptions = new SessionOptions().drainTimeout(20);
Session session = connection.openSession(sessionOptions);
Receiver receiver = session.openReceiver("test-queue").openFuture().get();
try {
receiver.drain().get();
fail("Drain call should fail timeout exceeded.");
} catch (ExecutionException cliEx) {
LOG.debug("Receiver threw error on drain call", cliEx);
assertTrue(cliEx.getCause() instanceof ClientOperationTimedOutException);
}
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class ReceiverTest method testDeliveryRefusesRawStreamAfterMessage.
@Test
public void testDeliveryRefusesRawStreamAfterMessage() 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().withLinkCredit(10);
peer.remoteTransfer().withHandle(0).withDeliveryId(0).withDeliveryTag(new byte[] { 1 }).withMore(false).withSettled(true).withMessageFormat(0).withPayload(payload).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());
Session session = connection.openSession();
Receiver receiver = session.openReceiver("test-queue");
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
peer.expectDetach().respond();
peer.expectClose().respond();
Delivery delivery = receiver.receive(5, TimeUnit.SECONDS);
assertNotNull(delivery);
Message<String> message = delivery.message();
assertNotNull(message);
try {
delivery.rawInputStream();
fail("Should not be able to use the inputstream once message is requested");
} catch (ClientIllegalStateException cliEx) {
// Expected
}
receiver.closeAsync();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class ReceiverTest method testReceiverDrainAllOutstanding.
@Test
public void testReceiverDrainAllOutstanding() 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());
connection.openFuture().get(5, TimeUnit.SECONDS);
Session session = connection.openSession();
session.openFuture().get(5, TimeUnit.SECONDS);
Receiver receiver = session.openReceiver("test-queue", new ReceiverOptions().creditWindow(0));
receiver.openFuture().get(5, TimeUnit.SECONDS);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
// Add some credit, verify not draining
int credit = 7;
Matcher<Boolean> drainMatcher = anyOf(equalTo(false), nullValue());
peer.expectFlow().withDrain(drainMatcher).withLinkCredit(credit).withDeliveryCount(0);
receiver.addCredit(credit);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
// Drain all the credit
peer.expectFlow().withDrain(true).withLinkCredit(credit).withDeliveryCount(0).respond().withDrain(true).withLinkCredit(0).withDeliveryCount(credit);
Future<? extends Receiver> 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.Session in project qpid-protonj2 by apache.
the class ReceiverTest method testDrainAdditionalDrainCallThrowsWhenReceiverStillDraining.
@Test
public void testDrainAdditionalDrainCallThrowsWhenReceiverStillDraining() throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectAttach().ofReceiver().respond();
peer.expectFlow();
peer.expectFlow().withDrain(true);
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();
Receiver receiver = session.openReceiver("test-queue").openFuture().get();
receiver.drain();
try {
receiver.drain().get();
fail("Drain call should fail timeout exceeded.");
} catch (ExecutionException cliEx) {
LOG.debug("Receiver threw error on drain call", cliEx);
assertTrue(cliEx.getCause() instanceof ClientIllegalStateException);
}
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations