use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class ReconnectTransactionTest method testDeclareTransactionAfterConnectionDropsAndReconnects.
@Test
public void testDeclareTransactionAfterConnectionDropsAndReconnects() throws Exception {
final byte[] txnId = new byte[] { 0, 1, 2, 3 };
try (ProtonTestServer firstPeer = new ProtonTestServer();
ProtonTestServer finalPeer = new ProtonTestServer()) {
firstPeer.expectSASLAnonymousConnect();
firstPeer.expectOpen().respond();
firstPeer.expectBegin().respond();
firstPeer.dropAfterLastHandler();
firstPeer.start();
finalPeer.expectSASLAnonymousConnect();
finalPeer.expectOpen().respond();
finalPeer.expectBegin().respond();
finalPeer.start();
final URI primaryURI = firstPeer.getServerURI();
final URI backupURI = finalPeer.getServerURI();
ConnectionOptions options = new ConnectionOptions();
options.reconnectOptions().reconnectEnabled(true);
options.reconnectOptions().addReconnectLocation(backupURI.getHost(), backupURI.getPort());
Client container = Client.create();
Connection connection = container.connect(primaryURI.getHost(), primaryURI.getPort(), options);
Session session = connection.openSession().openFuture().get();
firstPeer.waitForScriptToComplete();
finalPeer.waitForScriptToComplete();
finalPeer.expectCoordinatorAttach().respond();
finalPeer.remoteFlow().withLinkCredit(2).queue();
finalPeer.expectDeclare().accept(txnId);
finalPeer.expectClose().respond();
try {
session.beginTransaction();
} catch (ClientException cliEx) {
LOG.info("Caught unexpected error from test", cliEx);
fail("Should not have failed to declare transaction");
}
connection.closeAsync().get();
finalPeer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class ReconnectSenderTest method testOpenedSenderRecoveredAfterConnectionDropped.
@Test
public void testOpenedSenderRecoveredAfterConnectionDropped() throws Exception {
try (ProtonTestServer firstPeer = new ProtonTestServer();
ProtonTestServer finalPeer = new ProtonTestServer()) {
firstPeer.expectSASLAnonymousConnect();
firstPeer.expectOpen().respond();
firstPeer.expectBegin().respond();
firstPeer.expectAttach().ofSender().withTarget().withAddress("test").and().respond();
firstPeer.dropAfterLastHandler(5);
firstPeer.start();
finalPeer.expectSASLAnonymousConnect();
finalPeer.expectOpen().respond();
finalPeer.expectBegin().respond();
finalPeer.expectAttach().ofSender().withTarget().withAddress("test").and().respond();
finalPeer.start();
final URI primaryURI = firstPeer.getServerURI();
final URI backupURI = finalPeer.getServerURI();
ConnectionOptions options = new ConnectionOptions();
options.reconnectOptions().reconnectEnabled(true);
options.reconnectOptions().addReconnectLocation(backupURI.getHost(), backupURI.getPort());
Client container = Client.create();
Connection connection = container.connect(primaryURI.getHost(), primaryURI.getPort(), options);
Session session = connection.openSession();
Sender sender = session.openSender("test");
firstPeer.waitForScriptToComplete();
finalPeer.waitForScriptToComplete();
finalPeer.expectDetach().withClosed(true).respond();
finalPeer.expectEnd().respond();
finalPeer.expectClose().respond();
sender.close();
session.close();
connection.close();
finalPeer.waitForScriptToComplete();
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class ReconnectSenderTest method testAwaitSettlementOnSendFiredBeforeConnectionDrops.
@Test
public void testAwaitSettlementOnSendFiredBeforeConnectionDrops() throws Exception {
try (ProtonTestServer firstPeer = new ProtonTestServer();
ProtonTestServer finalPeer = new ProtonTestServer()) {
firstPeer.expectSASLAnonymousConnect();
firstPeer.expectOpen().respond();
firstPeer.expectBegin().respond();
firstPeer.expectAttach().ofSender().withTarget().withAddress("test").and().respond();
firstPeer.remoteFlow().withLinkCredit(1).queue();
firstPeer.expectTransfer().withNonNullPayload();
firstPeer.dropAfterLastHandler(15);
firstPeer.start();
finalPeer.expectSASLAnonymousConnect();
finalPeer.expectOpen().respond();
finalPeer.expectBegin().respond();
finalPeer.expectAttach().ofSender().withTarget().withAddress("test").and().respond();
finalPeer.start();
final URI primaryURI = firstPeer.getServerURI();
final URI backupURI = finalPeer.getServerURI();
ConnectionOptions options = new ConnectionOptions();
options.reconnectOptions().reconnectEnabled(true);
options.reconnectOptions().addReconnectLocation(backupURI.getHost(), backupURI.getPort());
Client container = Client.create();
Connection connection = container.connect(primaryURI.getHost(), primaryURI.getPort(), options);
Session session = connection.openSession();
Sender sender = session.openSender("test");
Tracker tracker = sender.send(Message.create("Hello"));
firstPeer.waitForScriptToComplete();
finalPeer.waitForScriptToComplete();
finalPeer.expectDetach().withClosed(true).respond();
finalPeer.expectEnd().respond();
finalPeer.expectClose().respond();
try {
tracker.awaitSettlement(120, TimeUnit.SECONDS);
fail("Should not be able to successfully await settlement");
} catch (ClientConnectionRemotelyClosedException crce) {
}
assertFalse(tracker.remoteSettled());
assertNull(tracker.remoteState());
sender.close();
session.close();
connection.close();
finalPeer.waitForScriptToComplete();
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class ReconnectSenderTest method testSendBlockedOnCreditGetsSentAfterReconnectAndCreditGranted.
@Test
public void testSendBlockedOnCreditGetsSentAfterReconnectAndCreditGranted() throws Exception {
try (ProtonTestServer firstPeer = new ProtonTestServer();
ProtonTestServer finalPeer = new ProtonTestServer()) {
firstPeer.expectSASLAnonymousConnect();
firstPeer.expectOpen().respond();
firstPeer.expectBegin().respond();
firstPeer.expectAttach().ofSender().withTarget().withAddress("test").and().respond();
firstPeer.dropAfterLastHandler(15);
firstPeer.start();
finalPeer.expectSASLAnonymousConnect();
finalPeer.expectOpen().respond();
finalPeer.expectBegin().respond();
finalPeer.expectAttach().ofSender().withTarget().withAddress("test").and().respond();
finalPeer.start();
final URI primaryURI = firstPeer.getServerURI();
final URI backupURI = finalPeer.getServerURI();
ConnectionOptions options = new ConnectionOptions();
options.reconnectOptions().reconnectEnabled(true);
options.reconnectOptions().addReconnectLocation(backupURI.getHost(), backupURI.getPort());
Client container = Client.create();
Connection connection = container.connect(primaryURI.getHost(), primaryURI.getPort(), options);
Session session = connection.openSession();
Sender sender = session.openSender("test");
final AtomicReference<Tracker> tracker = new AtomicReference<>();
final AtomicReference<Exception> sendError = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
ForkJoinPool.commonPool().execute(() -> {
try {
tracker.set(sender.send(Message.create("Hello")));
} catch (ClientException e) {
sendError.set(e);
} finally {
latch.countDown();
}
});
firstPeer.waitForScriptToComplete();
finalPeer.waitForScriptToComplete();
finalPeer.expectTransfer().withNonNullPayload().respond().withSettled(true).withState().accepted();
finalPeer.expectDetach().withClosed(true).respond();
finalPeer.expectEnd().respond();
finalPeer.expectClose().respond();
// Grant credit now and await expected message send.
finalPeer.remoteFlow().withDeliveryCount(0).withLinkCredit(10).withIncomingWindow(10).withOutgoingWindow(10).withNextIncomingId(0).withNextOutgoingId(1).now();
assertTrue(latch.await(10, TimeUnit.SECONDS), "Should have sent blocked message");
assertNull(sendError.get());
assertNotNull(tracker.get());
Tracker send = tracker.get();
assertSame(tracker.get(), send.awaitSettlement(10, TimeUnit.SECONDS));
assertTrue(send.remoteSettled());
assertEquals(DeliveryState.accepted(), send.remoteState());
sender.close();
session.close();
connection.close();
finalPeer.waitForScriptToComplete();
}
}
use of com.swiftmq.amqp.v100.client.Session in project qpid-protonj2 by apache.
the class ReconnectReceiverTest method testDispositionFromDeliveryReceivedBeforeDisconnectIsNoOp.
@Test
public void testDispositionFromDeliveryReceivedBeforeDisconnectIsNoOp() throws Exception {
final byte[] payload = createEncodedMessage(new AmqpValue<>("Hello World"));
try (ProtonTestServer firstPeer = new ProtonTestServer();
ProtonTestServer finalPeer = new ProtonTestServer()) {
firstPeer.expectSASLAnonymousConnect();
firstPeer.expectOpen().respond();
firstPeer.expectBegin().respond();
firstPeer.expectAttach().withRole(Role.RECEIVER.getValue()).respond();
firstPeer.expectFlow().withLinkCredit(10);
firstPeer.remoteTransfer().withHandle(0).withDeliveryId(0).withDeliveryTag(new byte[] { 1 }).withMore(false).withSettled(true).withMessageFormat(0).withPayload(payload).queue();
firstPeer.dropAfterLastHandler(100);
firstPeer.start();
finalPeer.expectSASLAnonymousConnect();
finalPeer.expectOpen().respond();
finalPeer.expectBegin().respond();
finalPeer.expectAttach().withRole(Role.RECEIVER.getValue()).respond();
finalPeer.expectFlow().withLinkCredit(9);
finalPeer.start();
final URI primaryURI = firstPeer.getServerURI();
final URI backupURI = finalPeer.getServerURI();
ConnectionOptions options = new ConnectionOptions();
options.reconnectOptions().reconnectEnabled(true);
options.reconnectOptions().addReconnectLocation(backupURI.getHost(), backupURI.getPort());
Client container = Client.create();
Connection connection = container.connect(primaryURI.getHost(), primaryURI.getPort(), options);
Session session = connection.openSession();
ReceiverOptions rcvOpts = new ReceiverOptions().autoAccept(false);
Receiver receiver = session.openReceiver("test-queue", rcvOpts);
Delivery delivery = receiver.receive(10, TimeUnit.SECONDS);
firstPeer.waitForScriptToComplete(5, TimeUnit.SECONDS);
finalPeer.waitForScriptToComplete();
finalPeer.expectDetach().respond();
finalPeer.expectEnd().respond();
finalPeer.expectClose().respond();
assertNotNull(delivery);
delivery.accept();
receiver.close();
session.close();
connection.close();
assertNotNull(delivery);
}
}
Aggregations