You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2023/03/27 09:22:37 UTC

[dubbo] branch 3.2 updated: Fix if isolated service not implemented (#11938)

This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.2
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.2 by this push:
     new 5a2114d140 Fix if isolated service not implemented (#11938)
5a2114d140 is described below

commit 5a2114d1406882c1d2859bcc692fd22190a957e0
Author: Albumen Kevin <jh...@gmail.com>
AuthorDate: Mon Mar 27 17:22:10 2023 +0800

    Fix if isolated service not implemented (#11938)
    
    * Fix if isolated service not implemented
    
    * Add uts
    
    * Fix  license
---
 ...=> DefaultIsolationExecutorSupportFactory.java} | 22 +++-----------
 .../executor/IsolationExecutorSupportFactory.java  |  8 ++---
 ...bo.rpc.executor.IsolationExecutorSupportFactory |  1 +
 .../IsolationExecutorSupportFactoryTest.java       | 34 ++++++++++++++++++++++
 .../dubbo/rpc/executor/Mock1ExecutorSupport.java   | 26 +++++++++++++++++
 .../Mock1IsolationExecutorSupportFactory.java}     | 22 +++-----------
 .../dubbo/rpc/executor/Mock2ExecutorSupport.java   | 26 +++++++++++++++++
 .../Mock2IsolationExecutorSupportFactory.java}     | 22 +++-----------
 ...bo.rpc.executor.IsolationExecutorSupportFactory |  2 ++
 9 files changed, 103 insertions(+), 60 deletions(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/executor/IsolationExecutorSupportFactory.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/executor/DefaultIsolationExecutorSupportFactory.java
similarity index 50%
copy from dubbo-common/src/main/java/org/apache/dubbo/rpc/executor/IsolationExecutorSupportFactory.java
copy to dubbo-common/src/main/java/org/apache/dubbo/rpc/executor/DefaultIsolationExecutorSupportFactory.java
index b610e9ac93..0cdfd26f16 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/executor/IsolationExecutorSupportFactory.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/executor/DefaultIsolationExecutorSupportFactory.java
@@ -17,24 +17,10 @@
 package org.apache.dubbo.rpc.executor;
 
 import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.Adaptive;
-import org.apache.dubbo.common.extension.ExtensionLoader;
-import org.apache.dubbo.common.extension.SPI;
-import org.apache.dubbo.rpc.model.ApplicationModel;
 
-import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
-
-@SPI
-public interface IsolationExecutorSupportFactory {
-
-    @Adaptive(PROTOCOL_KEY)
-    ExecutorSupport createIsolationExecutorSupport(URL url);
-
-    static ExecutorSupport getIsolationExecutorSupport(URL url) {
-        ApplicationModel applicationModel = url.getOrDefaultApplicationModel();
-        ExtensionLoader<IsolationExecutorSupportFactory> extensionLoader = applicationModel.getExtensionLoader(IsolationExecutorSupportFactory.class);
-        IsolationExecutorSupportFactory factory = extensionLoader.getAdaptiveExtension();
-        return factory.createIsolationExecutorSupport(url);
+public class DefaultIsolationExecutorSupportFactory implements IsolationExecutorSupportFactory {
+    @Override
+    public ExecutorSupport createIsolationExecutorSupport(URL url) {
+        return new DefaultExecutorSupport(url);
     }
-
 }
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/executor/IsolationExecutorSupportFactory.java b/dubbo-common/src/main/java/org/apache/dubbo/rpc/executor/IsolationExecutorSupportFactory.java
index b610e9ac93..b3f4a551d8 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/executor/IsolationExecutorSupportFactory.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/rpc/executor/IsolationExecutorSupportFactory.java
@@ -17,23 +17,19 @@
 package org.apache.dubbo.rpc.executor;
 
 import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.Adaptive;
 import org.apache.dubbo.common.extension.ExtensionLoader;
 import org.apache.dubbo.common.extension.SPI;
 import org.apache.dubbo.rpc.model.ApplicationModel;
 
-import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
-
-@SPI
+@SPI("default")
 public interface IsolationExecutorSupportFactory {
 
-    @Adaptive(PROTOCOL_KEY)
     ExecutorSupport createIsolationExecutorSupport(URL url);
 
     static ExecutorSupport getIsolationExecutorSupport(URL url) {
         ApplicationModel applicationModel = url.getOrDefaultApplicationModel();
         ExtensionLoader<IsolationExecutorSupportFactory> extensionLoader = applicationModel.getExtensionLoader(IsolationExecutorSupportFactory.class);
-        IsolationExecutorSupportFactory factory = extensionLoader.getAdaptiveExtension();
+        IsolationExecutorSupportFactory factory = extensionLoader.getOrDefaultExtension(url.getProtocol());
         return factory.createIsolationExecutorSupport(url);
     }
 
diff --git a/dubbo-common/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.executor.IsolationExecutorSupportFactory b/dubbo-common/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.executor.IsolationExecutorSupportFactory
new file mode 100644
index 0000000000..8cf24fbe2d
--- /dev/null
+++ b/dubbo-common/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.executor.IsolationExecutorSupportFactory
@@ -0,0 +1 @@
+default=org.apache.dubbo.rpc.executor.DefaultIsolationExecutorSupportFactory
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/rpc/executor/IsolationExecutorSupportFactoryTest.java b/dubbo-common/src/test/java/org/apache/dubbo/rpc/executor/IsolationExecutorSupportFactoryTest.java
new file mode 100644
index 0000000000..a0608064ed
--- /dev/null
+++ b/dubbo-common/src/test/java/org/apache/dubbo/rpc/executor/IsolationExecutorSupportFactoryTest.java
@@ -0,0 +1,34 @@
+/*
+ * 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.dubbo.rpc.executor;
+
+import org.apache.dubbo.common.URL;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class IsolationExecutorSupportFactoryTest {
+    @Test
+    void test() {
+        Assertions.assertInstanceOf(DefaultExecutorSupport.class, IsolationExecutorSupportFactory.getIsolationExecutorSupport(URL.valueOf("dubbo://")));
+        Assertions.assertInstanceOf(DefaultExecutorSupport.class, IsolationExecutorSupportFactory.getIsolationExecutorSupport(URL.valueOf("empty://")));
+        Assertions.assertInstanceOf(DefaultExecutorSupport.class, IsolationExecutorSupportFactory.getIsolationExecutorSupport(URL.valueOf("exchange://")));
+        Assertions.assertInstanceOf(Mock1ExecutorSupport.class, IsolationExecutorSupportFactory.getIsolationExecutorSupport(URL.valueOf("mock1://")));
+        Assertions.assertInstanceOf(Mock2ExecutorSupport.class, IsolationExecutorSupportFactory.getIsolationExecutorSupport(URL.valueOf("mock2://")));
+        Assertions.assertInstanceOf(DefaultExecutorSupport.class, IsolationExecutorSupportFactory.getIsolationExecutorSupport(URL.valueOf("mock3://")));
+    }
+}
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/rpc/executor/Mock1ExecutorSupport.java b/dubbo-common/src/test/java/org/apache/dubbo/rpc/executor/Mock1ExecutorSupport.java
new file mode 100644
index 0000000000..7e0182dce1
--- /dev/null
+++ b/dubbo-common/src/test/java/org/apache/dubbo/rpc/executor/Mock1ExecutorSupport.java
@@ -0,0 +1,26 @@
+/*
+ * 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.dubbo.rpc.executor;
+
+import java.util.concurrent.Executor;
+
+public class Mock1ExecutorSupport implements ExecutorSupport {
+    @Override
+    public Executor getExecutor(Object data) {
+        return null;
+    }
+}
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/executor/IsolationExecutorSupportFactory.java b/dubbo-common/src/test/java/org/apache/dubbo/rpc/executor/Mock1IsolationExecutorSupportFactory.java
similarity index 50%
copy from dubbo-common/src/main/java/org/apache/dubbo/rpc/executor/IsolationExecutorSupportFactory.java
copy to dubbo-common/src/test/java/org/apache/dubbo/rpc/executor/Mock1IsolationExecutorSupportFactory.java
index b610e9ac93..015fe5e4fb 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/executor/IsolationExecutorSupportFactory.java
+++ b/dubbo-common/src/test/java/org/apache/dubbo/rpc/executor/Mock1IsolationExecutorSupportFactory.java
@@ -17,24 +17,10 @@
 package org.apache.dubbo.rpc.executor;
 
 import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.Adaptive;
-import org.apache.dubbo.common.extension.ExtensionLoader;
-import org.apache.dubbo.common.extension.SPI;
-import org.apache.dubbo.rpc.model.ApplicationModel;
 
-import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
-
-@SPI
-public interface IsolationExecutorSupportFactory {
-
-    @Adaptive(PROTOCOL_KEY)
-    ExecutorSupport createIsolationExecutorSupport(URL url);
-
-    static ExecutorSupport getIsolationExecutorSupport(URL url) {
-        ApplicationModel applicationModel = url.getOrDefaultApplicationModel();
-        ExtensionLoader<IsolationExecutorSupportFactory> extensionLoader = applicationModel.getExtensionLoader(IsolationExecutorSupportFactory.class);
-        IsolationExecutorSupportFactory factory = extensionLoader.getAdaptiveExtension();
-        return factory.createIsolationExecutorSupport(url);
+public class Mock1IsolationExecutorSupportFactory implements IsolationExecutorSupportFactory {
+    @Override
+    public ExecutorSupport createIsolationExecutorSupport(URL url) {
+        return new Mock1ExecutorSupport();
     }
-
 }
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/rpc/executor/Mock2ExecutorSupport.java b/dubbo-common/src/test/java/org/apache/dubbo/rpc/executor/Mock2ExecutorSupport.java
new file mode 100644
index 0000000000..93e130de60
--- /dev/null
+++ b/dubbo-common/src/test/java/org/apache/dubbo/rpc/executor/Mock2ExecutorSupport.java
@@ -0,0 +1,26 @@
+/*
+ * 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.dubbo.rpc.executor;
+
+import java.util.concurrent.Executor;
+
+public class Mock2ExecutorSupport implements ExecutorSupport {
+    @Override
+    public Executor getExecutor(Object data) {
+        return null;
+    }
+}
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/rpc/executor/IsolationExecutorSupportFactory.java b/dubbo-common/src/test/java/org/apache/dubbo/rpc/executor/Mock2IsolationExecutorSupportFactory.java
similarity index 50%
copy from dubbo-common/src/main/java/org/apache/dubbo/rpc/executor/IsolationExecutorSupportFactory.java
copy to dubbo-common/src/test/java/org/apache/dubbo/rpc/executor/Mock2IsolationExecutorSupportFactory.java
index b610e9ac93..f416813641 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/rpc/executor/IsolationExecutorSupportFactory.java
+++ b/dubbo-common/src/test/java/org/apache/dubbo/rpc/executor/Mock2IsolationExecutorSupportFactory.java
@@ -17,24 +17,10 @@
 package org.apache.dubbo.rpc.executor;
 
 import org.apache.dubbo.common.URL;
-import org.apache.dubbo.common.extension.Adaptive;
-import org.apache.dubbo.common.extension.ExtensionLoader;
-import org.apache.dubbo.common.extension.SPI;
-import org.apache.dubbo.rpc.model.ApplicationModel;
 
-import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
-
-@SPI
-public interface IsolationExecutorSupportFactory {
-
-    @Adaptive(PROTOCOL_KEY)
-    ExecutorSupport createIsolationExecutorSupport(URL url);
-
-    static ExecutorSupport getIsolationExecutorSupport(URL url) {
-        ApplicationModel applicationModel = url.getOrDefaultApplicationModel();
-        ExtensionLoader<IsolationExecutorSupportFactory> extensionLoader = applicationModel.getExtensionLoader(IsolationExecutorSupportFactory.class);
-        IsolationExecutorSupportFactory factory = extensionLoader.getAdaptiveExtension();
-        return factory.createIsolationExecutorSupport(url);
+public class Mock2IsolationExecutorSupportFactory implements IsolationExecutorSupportFactory {
+    @Override
+    public ExecutorSupport createIsolationExecutorSupport(URL url) {
+        return new Mock2ExecutorSupport();
     }
-
 }
diff --git a/dubbo-common/src/test/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.executor.IsolationExecutorSupportFactory b/dubbo-common/src/test/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.executor.IsolationExecutorSupportFactory
new file mode 100644
index 0000000000..e743289f83
--- /dev/null
+++ b/dubbo-common/src/test/resources/META-INF/dubbo/internal/org.apache.dubbo.rpc.executor.IsolationExecutorSupportFactory
@@ -0,0 +1,2 @@
+mock1=org.apache.dubbo.rpc.executor.Mock1IsolationExecutorSupportFactory
+mock2=org.apache.dubbo.rpc.executor.Mock2IsolationExecutorSupportFactory