You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2021/09/02 16:03:12 UTC

[qpid-protonj2] branch main updated: PROTON-2428 Don't enforce container id in client options

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 ca17c00  PROTON-2428 Don't enforce container id in client options
ca17c00 is described below

commit ca17c00bda6bd504ee12052275c8e8dbcd53dd76
Author: Timothy Bish <ta...@gmail.com>
AuthorDate: Thu Sep 2 12:02:31 2021 -0400

    PROTON-2428 Don't enforce container id in client options
    
    Use the normal generated value when not set by user who might be setting
    future type or other options added down the road.
---
 .../qpid/protonj2/client/impl/ClientInstance.java  |  1 -
 .../qpid/protonj2/client/impl/ClientTest.java      | 14 +++++--------
 .../qpid/protonj2/client/impl/ConnectionTest.java  | 23 ++++++++++++++++++++++
 3 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientInstance.java b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientInstance.java
index 3597296..acd6ff9 100644
--- a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientInstance.java
+++ b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientInstance.java
@@ -72,7 +72,6 @@ public final class ClientInstance implements Client {
      */
     public static ClientInstance create(ClientOptions options) {
         Objects.requireNonNull(options, "Client options must be non-null");
-        Objects.requireNonNull(options.id(), "User supplied container Id must be non-null");
 
         return new ClientInstance(new ClientOptions(options));
     }
diff --git a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ClientTest.java b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ClientTest.java
index 2b54bb0..d1627cf 100644
--- a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ClientTest.java
+++ b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ClientTest.java
@@ -42,21 +42,17 @@ import org.junit.jupiter.api.Timeout;
 @Timeout(20)
 public class ClientTest extends ImperativeClientTestCase {
 
-    /**
-     * Tests that when using the ClientOptions you need to configure a
-     * container id as that is mandatory and the only reason one would
-     * be supplying ClientOptions instances.
-     */
     @Test
-    public void testCreateWithNoContainerIdFails() {
+    public void testCreateWithNoContainerIdIsAllowed() {
         ClientOptions options = new ClientOptions();
         assertNull(options.id());
 
         try {
-            Client.create(options);
-            fail("Should enforce user supplied container Id");
+            Client instance = Client.create(options);
+
+            assertNull(instance.containerId());
         } catch (NullPointerException npe) {
-            // Expected
+            fail("Should not enforce user supplied container Id");
         }
     }
 
diff --git a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ConnectionTest.java b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ConnectionTest.java
index 340df50..4d21679 100644
--- a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ConnectionTest.java
+++ b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ConnectionTest.java
@@ -236,6 +236,29 @@ public class ConnectionTest extends ImperativeClientTestCase {
     }
 
     @Test
+    public void testCreateConnectionWithUnconfiguredContainerId() throws Exception {
+        try (ProtonTestServer peer = new ProtonTestServer(testServerOptions())) {
+            peer.expectSASLAnonymousConnect();
+            peer.expectOpen().withContainerId(Matchers.any(String.class)).respond();
+            peer.expectClose().respond();
+            peer.start();
+
+            URI remoteURI = peer.getServerURI();
+
+            LOG.info("Connect test started, peer listening on: {}", remoteURI);
+
+            ClientOptions options = new ClientOptions();
+            Client container = Client.create(options);
+            Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort(), connectionOptions());
+
+            connection.openFuture().get(10, TimeUnit.SECONDS);
+            connection.closeAsync().get(10, TimeUnit.SECONDS);
+
+            peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
+        }
+    }
+
+    @Test
     public void testCreateConnectionStringWithDefaultTcpPort() throws Exception {
         try (ProtonTestServer peer = new ProtonTestServer(testServerOptions())) {
             peer.expectSASLAnonymousConnect();

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org