bitflicker64 commented on code in PR #3309:
URL: https://github.com/apache/hugegraph/pull/3309#discussion_r4248266101


##########
hugegraph-commons/hugegraph-rpc/src/test/java/org/apache/hugegraph/unit/RpcConfigTest.java:
##########
@@ -0,0 +1,246 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.unit;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.hugegraph.config.ConfigException;
+import org.apache.hugegraph.config.HugeConfig;
+import org.apache.hugegraph.config.RpcOptions;
+import org.apache.hugegraph.rpc.RpcClientProvider;
+import org.apache.hugegraph.rpc.RpcConsumerConfig;
+import org.apache.hugegraph.rpc.RpcProviderConfig;
+import org.apache.hugegraph.rpc.RpcServer;
+import org.apache.hugegraph.testutil.Assert;
+import org.apache.hugegraph.testutil.Whitebox;
+import org.apache.hugegraph.unit.ServerClientTest.HelloService;
+import org.apache.hugegraph.unit.ServerClientTest.HelloServiceImpl;
+import org.junit.Test;
+
+import com.alipay.sofa.rpc.config.ConsumerConfig;
+import com.alipay.sofa.rpc.config.ProviderConfig;
+
+public class RpcConfigTest extends BaseUnitTest {
+
+    private static final String HELLO = HelloService.class.getName();
+
+    @Test
+    public void testExcludeSelfUrl() {
+        Assert.assertEquals("127.0.0.1:8092,127.0.0.1:8093",
+                            
excludeSelfUrl("127.0.0.1:8091,127.0.0.1:8092;127.0.0.1:8093",
+                                           "127.0.0.1:8091"));
+        // Order is kept and duplicates are collapsed
+        Assert.assertEquals("b:2,a:1",
+                            excludeSelfUrl("b:2,a:1,b:2,self:0", "self:0"));
+        Assert.assertEquals("a:1", excludeSelfUrl("a:1", "self:0"));
+        Assert.assertEquals("", excludeSelfUrl("self:0,self:0", "self:0"));
+        Assert.assertEquals("", excludeSelfUrl("", "self:0"));
+    }
+
+    @Test
+    public void testClientDisabledWhenOnlySelfIsRemote() {
+        Map<String, Object> options = new HashMap<>();
+        options.put(RpcOptions.RPC_SERVER_HOST.name(), "127.0.0.1");
+        options.put(RpcOptions.RPC_SERVER_PORT.name(), "8091");
+        options.put(RpcOptions.RPC_REMOTE_URL.name(), "127.0.0.1:8091");
+        RpcClientProvider selfOnly = new RpcClientProvider(new 
HugeConfig(options));
+        Assert.assertFalse(selfOnly.enabled());
+        Assert.assertThrows(IllegalArgumentException.class, selfOnly::config, 
e -> {
+            Assert.assertContains("add an address other than self service", 
e.getMessage());
+        });
+        // Both are no-ops when the client is disabled
+        selfOnly.unreferAll();
+        selfOnly.destroy();
+
+        options.put(RpcOptions.RPC_REMOTE_URL.name(), 
"127.0.0.1:8091,127.0.0.1:8092");
+        RpcClientProvider withPeer = new RpcClientProvider(new 
HugeConfig(options));
+        try {
+            Assert.assertTrue(withPeer.enabled());
+            Assert.assertEquals("127.0.0.1:8092",
+                                Whitebox.getInternalState(withPeer.config(), 
"remoteUrls"));

Review Comment:
   Changed in 7aa5b789e: the test now checks `getDirectUrl()` on the consumer 
config that `RpcConsumerConfig` builds for SOFA, rather than reading the 
private `remoteUrls` field. That method is private, so it still goes through 
the module's `Whitebox` helper, the same way the other tests in this class do, 
but it asserts the value the client actually uses. `RpcConfigTest` passed alone 
twice (6/0) and the rpc `UnitTestSuite` 31/0. An injected wrong expectation 
fails at line 77.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to