This is an automated email from the ASF dual-hosted git repository. tabish pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git
The following commit(s) were added to refs/heads/main by this push: new 80792ce Adds additional tests for reconnect recovering sessions 80792ce is described below commit 80792ce4f8b974c8d8110dd876fb14ca3c33f2eb Author: Timothy Bish <tabish...@gmail.com> AuthorDate: Tue Apr 27 17:44:05 2021 -0400 Adds additional tests for reconnect recovering sessions Adds tests that demonstrate various cases of connection recovery handling where the response for a session resource was not received before connection drops and in some cases a similar outcome happens on connection attempt to an second host. --- .../protonj2/client/impl/ReconnectSessionTest.java | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ReconnectSessionTest.java b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ReconnectSessionTest.java index a4a2521..31577b0 100644 --- a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ReconnectSessionTest.java +++ b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ReconnectSessionTest.java @@ -16,11 +16,14 @@ */ package org.apache.qpid.protonj2.client.impl; +import static org.junit.jupiter.api.Assertions.assertNull; + import java.net.URI; import org.apache.qpid.protonj2.client.Client; import org.apache.qpid.protonj2.client.Connection; import org.apache.qpid.protonj2.client.ConnectionOptions; +import org.apache.qpid.protonj2.client.Receiver; import org.apache.qpid.protonj2.client.Session; import org.apache.qpid.protonj2.client.test.ImperativeClientTestCase; import org.apache.qpid.protonj2.test.driver.ProtonTestServer; @@ -74,4 +77,109 @@ class ReconnectSessionTest extends ImperativeClientTestCase { finalPeer.waitForScriptToComplete(); } } + + @Test + public void testSessionCreationRecoversAfterDropWithNoBeginResponse() throws Exception { + try (ProtonTestServer firstPeer = new ProtonTestServer(); + ProtonTestServer finalPeer = new ProtonTestServer()) { + + firstPeer.expectSASLAnonymousConnect(); + firstPeer.expectOpen().respond(); + firstPeer.expectBegin(); + firstPeer.dropAfterLastHandler(20); + firstPeer.start(); + + finalPeer.expectSASLAnonymousConnect(); + finalPeer.expectOpen().respond(); + finalPeer.expectBegin().respond(); + finalPeer.expectAttach().ofReceiver().respond(); + finalPeer.expectFlow(); + finalPeer.expectClose().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(); + + firstPeer.waitForScriptToComplete(); + + Receiver receiver = session.openFuture().get().openReceiver("queue").openFuture().get(); + + assertNull(receiver.tryReceive()); + + connection.close(); + + finalPeer.waitForScriptToComplete(1000); + } + } + + @Test + public void testMultipleSessionCreationRecoversAfterDropWithNoBeginResponse() throws Exception { + try (ProtonTestServer firstPeer = new ProtonTestServer(); + ProtonTestServer intermediatePeer = new ProtonTestServer(); + ProtonTestServer finalPeer = new ProtonTestServer()) { + + firstPeer.expectSASLAnonymousConnect(); + firstPeer.expectOpen().respond(); + firstPeer.expectBegin().respond(); + firstPeer.expectBegin(); + firstPeer.dropAfterLastHandler(20); + firstPeer.start(); + + intermediatePeer.expectSASLAnonymousConnect(); + intermediatePeer.expectOpen().respond(); + intermediatePeer.expectBegin().respond(); + intermediatePeer.expectBegin(); + intermediatePeer.dropAfterLastHandler(); + intermediatePeer.start(); + + finalPeer.expectSASLAnonymousConnect(); + finalPeer.expectOpen().respond(); + finalPeer.expectBegin().respond(); + finalPeer.expectBegin().respond(); + finalPeer.expectAttach().ofReceiver().respond(); + finalPeer.expectFlow(); + finalPeer.expectAttach().ofReceiver().respond(); + finalPeer.expectFlow(); + finalPeer.expectClose().respond(); + finalPeer.start(); + + final URI primaryURI = firstPeer.getServerURI(); + final URI intermediateURI = intermediatePeer.getServerURI(); + final URI backupURI = finalPeer.getServerURI(); + + ConnectionOptions options = new ConnectionOptions(); + options.reconnectOptions().reconnectEnabled(true); + options.reconnectOptions().addReconnectLocation(intermediateURI.getHost(), intermediateURI.getPort()); + options.reconnectOptions().addReconnectLocation(backupURI.getHost(), backupURI.getPort()); + + Client container = Client.create(); + Connection connection = container.connect(primaryURI.getHost(), primaryURI.getPort(), options); + Session session1 = connection.openSession(); + Session session2 = connection.openSession(); + + firstPeer.waitForScriptToComplete(); + + // Await both being open before doing work to make the outcome predictable + session1.openFuture().get(); + session2.openFuture().get(); + + Receiver receiver1 = session1.openReceiver("queue").openFuture().get(); + Receiver receiver2 = session2.openReceiver("queue").openFuture().get(); + + assertNull(receiver1.tryReceive()); + assertNull(receiver2.tryReceive()); + + connection.close(); + + finalPeer.waitForScriptToComplete(1000); + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org