From 19ef0b3a978f927da69c756a2baedeba6e6f4073 Mon Sep 17 00:00:00 2001 From: Geng Zhang Date: Wed, 17 Apr 2019 21:21:43 +0800 Subject: [PATCH 1/7] Integrate with SOFARegistry. --- dubbo-all/pom.xml | 16 + dubbo-config/dubbo-config-spring/pom.xml | 1 - dubbo-dependencies-bom/pom.xml | 7 +- dubbo-registry/dubbo-registry-sofa/pom.xml | 157 ++++++++++ .../dubbo/registry/sofa/SofaRegistry.java | 294 ++++++++++++++++++ .../registry/sofa/SofaRegistryConstants.java | 44 +++ .../registry/sofa/SofaRegistryFactory.java | 43 +++ .../org.apache.dubbo.registry.RegistryFactory | 1 + .../dubbo/registry/sofa/HelloService.java | 25 ++ .../dubbo/registry/sofa/HelloServiceImpl.java | 45 +++ .../dubbo/registry/sofa/SofaRegistryTest.java | 149 +++++++++ .../src/test/resources/log4j.properties | 7 + dubbo-registry/pom.xml | 1 + dubbo-rpc/dubbo-rpc-thrift/pom.xml | 5 + .../rpc/protocol/thrift/ThriftCodec.java | 3 +- 15 files changed, 794 insertions(+), 4 deletions(-) create mode 100644 dubbo-registry/dubbo-registry-sofa/pom.xml create mode 100644 dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistry.java create mode 100644 dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistryConstants.java create mode 100644 dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistryFactory.java create mode 100644 dubbo-registry/dubbo-registry-sofa/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory create mode 100644 dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/HelloService.java create mode 100644 dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/HelloServiceImpl.java create mode 100644 dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/SofaRegistryTest.java create mode 100644 dubbo-registry/dubbo-registry-sofa/src/test/resources/log4j.properties diff --git a/dubbo-all/pom.xml b/dubbo-all/pom.xml index e0e2366bd44b..f1ed0943300c 100644 --- a/dubbo-all/pom.xml +++ b/dubbo-all/pom.xml @@ -254,6 +254,20 @@ compile true + + org.apache.dubbo + dubbo-registry-nacos + ${project.version} + compile + true + + + org.apache.dubbo + dubbo-registry-sofa + ${project.version} + compile + true + org.apache.dubbo dubbo-monitor-api @@ -530,6 +544,8 @@ org.apache.dubbo:dubbo-registry-redis org.apache.dubbo:dubbo-registry-consul org.apache.dubbo:dubbo-registry-etcd3 + org.apache.dubbo:dubbo-registry-nacos + org.apache.dubbo:dubbo-registry-sofa org.apache.dubbo:dubbo-monitor-api org.apache.dubbo:dubbo-monitor-default org.apache.dubbo:dubbo-config-api diff --git a/dubbo-config/dubbo-config-spring/pom.xml b/dubbo-config/dubbo-config-spring/pom.xml index 04a8223bcb78..5ec896d5b31d 100644 --- a/dubbo-config/dubbo-config-spring/pom.xml +++ b/dubbo-config/dubbo-config-spring/pom.xml @@ -120,7 +120,6 @@ junit junit - 4.12 test diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index 0329e73ba601..769a9dd645f7 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -140,7 +140,7 @@ 3.2.5 1.5.19 4.3.16.RELEASE - + 4.12 2.0.1 2.8.5 1.2.0 @@ -513,6 +513,11 @@ + + junit + junit + ${junit_version} + org.apache.curator curator-test diff --git a/dubbo-registry/dubbo-registry-sofa/pom.xml b/dubbo-registry/dubbo-registry-sofa/pom.xml new file mode 100644 index 000000000000..6b30198004f0 --- /dev/null +++ b/dubbo-registry/dubbo-registry-sofa/pom.xml @@ -0,0 +1,157 @@ + + + + org.apache.dubbo + dubbo-registry + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-registry-sofa + ${project.artifactId} + The SOFARegistry module of Dubbo project + + + 5.2.0 + 2.26 + 2.1 + + + + + + org.apache.dubbo + dubbo-registry-api + ${project.version} + true + + + + org.apache.dubbo + dubbo-common + ${project.version} + true + + + + com.alipay.sofa + registry-client-all + ${sofa.registry.version} + + + com.alipay.sofa + sofa-common-tools + + + + + + + org.apache.dubbo + dubbo-config-api + ${project.version} + test + + + + + com.alipay.sofa + registry-test + ${sofa.registry.version} + test + + + log4j-over-slf4j + org.slf4j + + + log4j-jcl + org.apache.logging.log4j + + + log4j-core + org.apache.logging.log4j + + + log4j-api + org.apache.logging.log4j + + + + + org.jboss.resteasy + resteasy-jaxrs + test + + + org.jboss.resteasy + resteasy-netty4 + test + + + org.glassfish.jersey.media + jersey-media-json-jackson + ${jersey.version} + test + + + org.glassfish.jersey.media + jersey-media-jaxb + ${jersey.version} + test + + + javax.ws.rs + javax.ws.rs-api + ${javax.ws.rs.version} + + + + org.apache.dubbo + dubbo-rpc-dubbo + ${project.version} + test + + + org.apache.dubbo + dubbo-remoting-netty4 + ${project.version} + test + + + org.apache.dubbo + dubbo-serialization-hessian2 + ${project.version} + test + + + ch.qos.logback + logback-classic + test + + + + junit + junit + test + + + + \ No newline at end of file diff --git a/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistry.java b/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistry.java new file mode 100644 index 000000000000..bcd6a9e8983c --- /dev/null +++ b/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistry.java @@ -0,0 +1,294 @@ +/* + * 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.registry.sofa; + +import com.alipay.sofa.registry.client.api.RegistryClient; +import com.alipay.sofa.registry.client.api.RegistryClientConfig; +import com.alipay.sofa.registry.client.api.Subscriber; +import com.alipay.sofa.registry.client.api.model.RegistryType; +import com.alipay.sofa.registry.client.api.model.UserData; +import com.alipay.sofa.registry.client.api.registration.PublisherRegistration; +import com.alipay.sofa.registry.client.api.registration.SubscriberRegistration; +import com.alipay.sofa.registry.client.provider.DefaultRegistryClient; +import com.alipay.sofa.registry.client.provider.DefaultRegistryClientConfigBuilder; +import com.alipay.sofa.registry.core.model.ScopeEnum; +import org.apache.dubbo.common.Constants; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.common.utils.ConfigUtils; +import org.apache.dubbo.common.utils.StringUtils; +import org.apache.dubbo.registry.NotifyListener; +import org.apache.dubbo.registry.support.FailbackRegistry; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import static org.apache.dubbo.registry.sofa.SofaRegistryConstants.ADDRESS_WAIT_TIME_KEY; +import static org.apache.dubbo.registry.sofa.SofaRegistryConstants.DEFAULT_GROUP; +import static org.apache.dubbo.registry.sofa.SofaRegistryConstants.LOCAL_DATA_CENTER; +import static org.apache.dubbo.registry.sofa.SofaRegistryConstants.LOCAL_REGION; + +/** + * The Sofa registry. + * + * @author GengZhang + * @since 2.7.2 + */ +public class SofaRegistry extends FailbackRegistry { + + private static final Logger LOGGER = LoggerFactory.getLogger(SofaRegistry.class); + + /** + * Cache subscriber by dataId + */ + private final Map subscribers = new ConcurrentHashMap<>(); + + /** + * Direct registry client + */ + private RegistryClient registryClient; + /** + * wait address from registry + */ + private int waitAddressTimeout; + + /** + * Instantiates a new Sofa registry. + * + * @param url the url + */ + public SofaRegistry(URL url) { + super(url); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Build sofa registry by url:" + url); + } + this.registryClient = buildClient(url); + this.waitAddressTimeout = Integer.parseInt(ConfigUtils.getProperty(ADDRESS_WAIT_TIME_KEY, "5000")); + } + + /** + * Build client registry client. + * + * @param url the url + * @return the registry client + */ + protected RegistryClient buildClient(URL url) { + RegistryClientConfig config = DefaultRegistryClientConfigBuilder.start() + .setDataCenter(LOCAL_DATA_CENTER) + .setZone(LOCAL_REGION) + .setRegistryEndpoint(url.getHost()) + .setRegistryEndpointPort(url.getPort()).build(); + + DefaultRegistryClient registryClient = new DefaultRegistryClient(config); + registryClient.init(); + return registryClient; + } + + @Override + public boolean isAvailable() { + return true; + } + + @Override + public void doRegister(URL url) { + if (!url.getParameter(Constants.REGISTER_KEY, true) + || Constants.CONSUMER_PROTOCOL.equals(url.getProtocol())) { + return; + } + + String serviceName = buildServiceName(url); + String serviceData = url.toFullString(); + + PublisherRegistration dsrRegistration; + dsrRegistration = new PublisherRegistration(serviceName); + addAttributesForPub(dsrRegistration); + + registryClient.register(dsrRegistration, serviceData); + } + + /** + * Add attributes for pub. + * + * @param dsrRegistration the dsr registration + */ + protected void addAttributesForPub(PublisherRegistration dsrRegistration) { + dsrRegistration.setGroup(DEFAULT_GROUP); + } + + @Override + public void doUnregister(URL url) { + if (!url.getParameter(Constants.REGISTER_KEY, true) + || Constants.CONSUMER_PROTOCOL.equals(url.getProtocol())) { + return; + } + String serviceName = buildServiceName(url); + registryClient.unregister(serviceName, DEFAULT_GROUP, RegistryType.PUBLISHER); + } + + @Override + public void doSubscribe(URL url, final NotifyListener listener) { + if (!url.getParameter(Constants.SUBSCRIBE_KEY, true) + || Constants.PROVIDER_PROTOCOL.equals(url.getProtocol())) { + return; + } + + String serviceName = buildServiceName(url); + // com.alipay.test.TestService:1.0:group@dubbo + Subscriber listSubscriber = subscribers.get(serviceName); + + if (listSubscriber != null) { + LOGGER.warn("Service name [" + serviceName + "] have bean registered in SOFARegistry."); + + CountDownLatch countDownLatch = new CountDownLatch(1); + handleRegistryData(listSubscriber.peekData(), listener, countDownLatch); + waitAddress(serviceName, countDownLatch); + return; + } + + final CountDownLatch latch = new CountDownLatch(1); + SubscriberRegistration subscriberRegistration = new SubscriberRegistration(serviceName, + (dataId, data) -> { + //record change + printAddressData(dataId, data); + handleRegistryData(data, listener, latch); + }); + + addAttributesForSub(subscriberRegistration); + listSubscriber = registryClient.register(subscriberRegistration); + + subscribers.put(serviceName, listSubscriber); + + waitAddress(serviceName, latch); + } + + private void waitAddress(String serviceName, CountDownLatch countDownLatch) { + try { + if (!countDownLatch.await(waitAddressTimeout, TimeUnit.MILLISECONDS)) { + LOGGER.warn("Subscribe data failed by dataId " + serviceName); + } + } catch (Exception e) { + LOGGER.error("Error when wait Address!", e); + } + } + + @Override + public void doUnsubscribe(URL url, NotifyListener listener) { + if (!url.getParameter(Constants.SUBSCRIBE_KEY, true) + || Constants.PROVIDER_PROTOCOL.equals(url.getProtocol())) { + return; + } + String serviceName = buildServiceName(url); + + registryClient.unregister(serviceName, DEFAULT_GROUP, RegistryType.SUBSCRIBER); + } + + private void handleRegistryData(UserData data, NotifyListener notifyListener, + CountDownLatch latch) { + try { + List urls = new ArrayList<>(); + if (null != data) { + + List datas = flatUserData(data); + for (String serviceUrl : datas) { + URL url = URL.valueOf(serviceUrl); + String serverApplication = url.getParameter(Constants.APPLICATION_KEY); + if (StringUtils.isNotEmpty(serverApplication)) { + url = url.addParameter("dstApp", serverApplication); + } + urls.add(url); + } + } + notifyListener.notify(urls); + } finally { + latch.countDown(); + } + } + + private String buildServiceName(URL url) { + // return url.getServiceKey(); + StringBuilder buf = new StringBuilder(); + buf.append(url.getServiceInterface()); + String version = url.getParameter(Constants.VERSION_KEY); + if (StringUtils.isNotEmpty(version)) { + buf.append(":").append(version); + } + String group = url.getParameter(Constants.GROUP_KEY); + if (StringUtils.isNotEmpty(group)) { + buf.append(":").append(group); + } + buf.append("@dubbo"); + return buf.toString(); + } + + /** + * Print address data. + * + * @param dataId the data id + * @param userData the user data + */ + protected void printAddressData(String dataId, UserData userData) { + + List datas; + if (userData == null) { + datas = new ArrayList<>(0); + } else { + datas = flatUserData(userData); + } + + StringBuilder sb = new StringBuilder(); + for (String provider : datas) { + sb.append(" >>> ").append(provider).append("\n"); + } + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Receive updated RPC service addresses: service[" + dataId + + "]\n .Available target addresses size [" + datas.size() + "]\n" + + sb.toString()); + } + } + + /** + * Add attributes for sub. + * + * @param dsrRegistration the dsr registration + */ + protected void addAttributesForSub(SubscriberRegistration dsrRegistration) { + dsrRegistration.setGroup(DEFAULT_GROUP); + dsrRegistration.setScopeEnum(ScopeEnum.global); + } + + /** + * Flat user data list. + * + * @param userData the user data + * @return the list + */ + protected List flatUserData(UserData userData) { + List result = new ArrayList<>(); + Map> zoneData = userData.getZoneData(); + + for (Map.Entry> entry : zoneData.entrySet()) { + result.addAll(entry.getValue()); + } + + return result; + } +} diff --git a/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistryConstants.java b/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistryConstants.java new file mode 100644 index 000000000000..6b6b7a1108d5 --- /dev/null +++ b/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistryConstants.java @@ -0,0 +1,44 @@ +/* + * 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.registry.sofa; + +/** + * @author GengZhang + * @since 2.7.2 + */ +public class SofaRegistryConstants { + + /** + * Default data center + */ + public static final String LOCAL_DATA_CENTER = "DefaultDataCenter"; + + /** + * Default region + */ + public static final String LOCAL_REGION = "DEFAULT_ZONE"; + + /** + * Default group + */ + public static final String DEFAULT_GROUP = "SOFA"; + + /** + * parameter for address.wait.time of rpc reference + */ + public static final String ADDRESS_WAIT_TIME_KEY = "rpc.reference.address.wait.time"; +} diff --git a/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistryFactory.java b/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistryFactory.java new file mode 100644 index 000000000000..cef7d0166d13 --- /dev/null +++ b/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistryFactory.java @@ -0,0 +1,43 @@ +/* + * 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.registry.sofa; + +import org.apache.dubbo.common.URL; +import org.apache.dubbo.registry.Registry; +import org.apache.dubbo.registry.support.AbstractRegistryFactory; + +/** + * + * @author Geng Zhang + * @since 2.7.2 + */ +public class SofaRegistryFactory extends AbstractRegistryFactory { + + @Override + protected Registry createRegistry(URL url) { + initEnvironment(url); + return new SofaRegistry(url); + } + + /** + * For extension, such as load zone/accessKey/secretKey/... + * + * @param url URL + */ + protected void initEnvironment(URL url) { + } +} diff --git a/dubbo-registry/dubbo-registry-sofa/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory b/dubbo-registry/dubbo-registry-sofa/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory new file mode 100644 index 000000000000..dff4cbb8c528 --- /dev/null +++ b/dubbo-registry/dubbo-registry-sofa/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.RegistryFactory @@ -0,0 +1 @@ +sofa=org.apache.dubbo.registry.sofa.SofaRegistryFactory \ No newline at end of file diff --git a/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/HelloService.java b/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/HelloService.java new file mode 100644 index 000000000000..8ffe38a9420c --- /dev/null +++ b/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/HelloService.java @@ -0,0 +1,25 @@ +/* + * 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.registry.sofa; + +/** + * @author GengZhang + */ +public interface HelloService { + + String sayHello(String name); +} diff --git a/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/HelloServiceImpl.java b/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/HelloServiceImpl.java new file mode 100644 index 000000000000..af0880ebf076 --- /dev/null +++ b/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/HelloServiceImpl.java @@ -0,0 +1,45 @@ +/* + * 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.registry.sofa; + +import com.alipay.sofa.registry.server.test.TestRegistryMain; + +/** + * @author GengZhang + */ +public class HelloServiceImpl implements HelloService { + + private final String result; + + public HelloServiceImpl(String result) { + this.result = result; + } + + @Override + public String sayHello(String name) { + return result != null ? result : "hello, " + name + "!"; + } + + public static void main(String[] args) { + TestRegistryMain registryMain = new TestRegistryMain(); + try { + registryMain.startRegistry(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/SofaRegistryTest.java b/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/SofaRegistryTest.java new file mode 100644 index 000000000000..9066e5dfc946 --- /dev/null +++ b/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/SofaRegistryTest.java @@ -0,0 +1,149 @@ +/* + * 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.registry.sofa; + +import com.alipay.sofa.registry.server.test.TestRegistryMain; +import org.apache.dubbo.common.logger.Logger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ProtocolConfig; +import org.apache.dubbo.config.ReferenceConfig; +import org.apache.dubbo.config.RegistryConfig; +import org.apache.dubbo.config.ServiceConfig; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * @author GengZhang + */ +public class SofaRegistryTest { + + public static final Logger LOGGER = LoggerFactory.getLogger(SofaRegistryTest.class); + + private static TestRegistryMain registryMain; + + private static ApplicationConfig applicationConfig = new ApplicationConfig("test-sofa-registry"); + + private static ProtocolConfig protocolConfig1; + + private static ProtocolConfig protocolConfig2; + + private static RegistryConfig registryConfig; + + @BeforeClass + public static void beforeClass() { + + protocolConfig1 = new ProtocolConfig(); + protocolConfig1.setName("dubbo"); + protocolConfig1.setPort(20890); + + protocolConfig2 = new ProtocolConfig(); + protocolConfig2.setName("dubbo"); + protocolConfig2.setPort(20891); + + registryConfig = new RegistryConfig(); + registryConfig.setAddress("sofa://127.0.0.1:9603"); + registryConfig.setProtocol("sofa"); + + registryMain = new TestRegistryMain(); + try { + registryMain.startRegistry(); + } catch (Exception e) { + LOGGER.error("start test sofa registry error!", e); + } + } + + @Test + public void testPubAndSub() throws InterruptedException { + + ServiceConfig serviceConfig1 = new ServiceConfig<>(); + serviceConfig1.setInterface(HelloService.class); + serviceConfig1.setRef(new HelloServiceImpl("rrr11")); + serviceConfig1.setProtocol(protocolConfig1); + serviceConfig1.setRegistry(registryConfig); + serviceConfig1.setGroup("g1"); + serviceConfig1.setApplication(applicationConfig); + serviceConfig1.export(); + + ServiceConfig serviceConfig2 = new ServiceConfig<>(); + serviceConfig2.setInterface(HelloService.class); + serviceConfig2.setRef(new HelloServiceImpl("rrr22")); + serviceConfig2.setProtocol(protocolConfig1); + serviceConfig2.setRegistry(registryConfig); + serviceConfig2.setGroup("g2"); + serviceConfig2.setApplication(applicationConfig); + serviceConfig2.setRegister(false); + serviceConfig2.export(); + + Thread.sleep(1000); + + // do refer + ReferenceConfig referenceConfig1 = new ReferenceConfig<>(); + referenceConfig1.setInterface(HelloService.class); + referenceConfig1.setProtocol("dubbo"); + referenceConfig1.setInjvm(false); + referenceConfig1.setGroup("g1"); + referenceConfig1.setRegistry(registryConfig); + referenceConfig1.setApplication(applicationConfig); + HelloService service = referenceConfig1.get(); + Assert.assertEquals("rrr11", service.sayHello("xxx")); + + // do refer duplicated + ReferenceConfig referenceConfig2 = new ReferenceConfig<>(); + referenceConfig2.setInterface(HelloService.class); + referenceConfig2.setProtocol("dubbo"); + referenceConfig2.setInjvm(false); + referenceConfig2.setGroup("g1"); + referenceConfig2.setRegistry(registryConfig); + referenceConfig2.setApplication(applicationConfig); + HelloService service2 = referenceConfig2.get(); + Assert.assertEquals("rrr11", service2.sayHello("xxx")); + + // export on service + ServiceConfig serviceConfig3 = new ServiceConfig<>(); + serviceConfig3.setInterface(HelloService.class); + serviceConfig3.setRef(new HelloServiceImpl("rrr12")); + serviceConfig3.setProtocol(protocolConfig2); + serviceConfig3.setRegistry(registryConfig); + serviceConfig3.setGroup("g1"); + serviceConfig3.setApplication(applicationConfig); + serviceConfig3.export(); + Assert.assertTrue(service2.sayHello("xxx").startsWith("rrr1")); + + // unrefer + referenceConfig1.destroy(); + Assert.assertTrue(service2.sayHello("xxx").startsWith("rrr1")); + + // unexport on service + serviceConfig1.unexport(); + Thread.sleep(2000); + Assert.assertTrue(service2.sayHello("xxx").startsWith("rrr1")); + } + + @AfterClass + public static void afterClass() { + try { + registryMain.stopRegistry(); + protocolConfig1.destroy(); + } catch (Exception e) { + LOGGER.error("Stop test sofa registry error!", e); + } + } + +} \ No newline at end of file diff --git a/dubbo-registry/dubbo-registry-sofa/src/test/resources/log4j.properties b/dubbo-registry/dubbo-registry-sofa/src/test/resources/log4j.properties new file mode 100644 index 000000000000..15a0900f0d25 --- /dev/null +++ b/dubbo-registry/dubbo-registry-sofa/src/test/resources/log4j.properties @@ -0,0 +1,7 @@ +###set log levels### +log4j.rootLogger=info, stdout +###output to the console### +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n \ No newline at end of file diff --git a/dubbo-registry/pom.xml b/dubbo-registry/pom.xml index c9c3441ca251..962148b354a9 100644 --- a/dubbo-registry/pom.xml +++ b/dubbo-registry/pom.xml @@ -37,5 +37,6 @@ dubbo-registry-consul dubbo-registry-etcd3 dubbo-registry-nacos + dubbo-registry-sofa diff --git a/dubbo-rpc/dubbo-rpc-thrift/pom.xml b/dubbo-rpc/dubbo-rpc-thrift/pom.xml index d6e20ed95e2a..d4de52447de4 100644 --- a/dubbo-rpc/dubbo-rpc-thrift/pom.xml +++ b/dubbo-rpc/dubbo-rpc-thrift/pom.xml @@ -69,5 +69,10 @@ ${project.parent.version} test + + org.slf4j + slf4j-api + test + \ No newline at end of file diff --git a/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodec.java b/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodec.java index 58058f4f64f7..72d5468e103c 100644 --- a/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodec.java +++ b/dubbo-rpc/dubbo-rpc-thrift/src/main/java/org/apache/dubbo/rpc/protocol/thrift/ThriftCodec.java @@ -19,6 +19,7 @@ import org.apache.dubbo.common.Constants; import org.apache.dubbo.common.extension.ExtensionLoader; import org.apache.dubbo.common.utils.ClassHelper; +import org.apache.dubbo.common.utils.StringUtils; import org.apache.dubbo.remoting.Channel; import org.apache.dubbo.remoting.Codec2; import org.apache.dubbo.remoting.buffer.ChannelBuffer; @@ -29,8 +30,6 @@ import org.apache.dubbo.rpc.RpcInvocation; import org.apache.dubbo.rpc.RpcResult; import org.apache.dubbo.rpc.protocol.thrift.io.RandomAccessByteArrayOutputStream; - -import org.apache.commons.lang.StringUtils; import org.apache.thrift.TApplicationException; import org.apache.thrift.TBase; import org.apache.thrift.TException; From 8c3975e0ab332528f9df57b39ff3c6dac11304c2 Mon Sep 17 00:00:00 2001 From: Geng Zhang Date: Thu, 18 Apr 2019 10:24:31 +0800 Subject: [PATCH 2/7] Change variable name. --- .../dubbo/registry/sofa/SofaRegistry.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistry.java b/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistry.java index bcd6a9e8983c..0f5c4b60c60d 100644 --- a/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistry.java +++ b/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistry.java @@ -118,20 +118,19 @@ public void doRegister(URL url) { String serviceName = buildServiceName(url); String serviceData = url.toFullString(); - PublisherRegistration dsrRegistration; - dsrRegistration = new PublisherRegistration(serviceName); - addAttributesForPub(dsrRegistration); + PublisherRegistration registration = new PublisherRegistration(serviceName); + addAttributesForPub(registration); - registryClient.register(dsrRegistration, serviceData); + registryClient.register(registration, serviceData); } /** * Add attributes for pub. * - * @param dsrRegistration the dsr registration + * @param publisherRegistration the publisher registration */ - protected void addAttributesForPub(PublisherRegistration dsrRegistration) { - dsrRegistration.setGroup(DEFAULT_GROUP); + protected void addAttributesForPub(PublisherRegistration publisherRegistration) { + publisherRegistration.setGroup(DEFAULT_GROUP); } @Override @@ -235,7 +234,7 @@ private String buildServiceName(URL url) { if (StringUtils.isNotEmpty(group)) { buf.append(":").append(group); } - buf.append("@dubbo"); + buf.append("@").append(Constants.DUBBO); return buf.toString(); } @@ -268,11 +267,11 @@ protected void printAddressData(String dataId, UserData userData) { /** * Add attributes for sub. * - * @param dsrRegistration the dsr registration + * @param subscriberRegistration the subscriber registration */ - protected void addAttributesForSub(SubscriberRegistration dsrRegistration) { - dsrRegistration.setGroup(DEFAULT_GROUP); - dsrRegistration.setScopeEnum(ScopeEnum.global); + protected void addAttributesForSub(SubscriberRegistration subscriberRegistration) { + subscriberRegistration.setGroup(DEFAULT_GROUP); + subscriberRegistration.setScopeEnum(ScopeEnum.global); } /** From 08fa5b649ed2dc5745e9ef8178745c58eb639e75 Mon Sep 17 00:00:00 2001 From: Geng Zhang Date: Fri, 26 Apr 2019 14:22:15 +0800 Subject: [PATCH 3/7] Fix as review. --- dubbo-all/pom.xml | 8 ------ dubbo-bom/pom.xml | 5 ++++ dubbo-dependencies-bom/pom.xml | 27 ++++++++++++++++++- dubbo-distribution/pom.xml | 5 ++++ .../dubbo/registry/sofa/SofaRegistry.java | 1 - .../registry/sofa/SofaRegistryConstants.java | 1 - .../dubbo/registry/sofa/HelloService.java | 1 - .../dubbo/registry/sofa/HelloServiceImpl.java | 1 - .../dubbo/registry/sofa/SofaRegistryTest.java | 1 - 9 files changed, 36 insertions(+), 14 deletions(-) diff --git a/dubbo-all/pom.xml b/dubbo-all/pom.xml index f1ed0943300c..08621e41394d 100644 --- a/dubbo-all/pom.xml +++ b/dubbo-all/pom.xml @@ -254,13 +254,6 @@ compile true - - org.apache.dubbo - dubbo-registry-nacos - ${project.version} - compile - true - org.apache.dubbo dubbo-registry-sofa @@ -544,7 +537,6 @@ org.apache.dubbo:dubbo-registry-redis org.apache.dubbo:dubbo-registry-consul org.apache.dubbo:dubbo-registry-etcd3 - org.apache.dubbo:dubbo-registry-nacos org.apache.dubbo:dubbo-registry-sofa org.apache.dubbo:dubbo-monitor-api org.apache.dubbo:dubbo-monitor-default diff --git a/dubbo-bom/pom.xml b/dubbo-bom/pom.xml index e894f8b0619e..148b49aebdcf 100644 --- a/dubbo-bom/pom.xml +++ b/dubbo-bom/pom.xml @@ -252,6 +252,11 @@ dubbo-registry-consul ${project.version} + + org.apache.dubbo + dubbo-registry-sofa + ${project.version} + org.apache.dubbo dubbo-monitor-api diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index 769a9dd645f7..d8a80c90cd93 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -142,6 +142,10 @@ 4.3.16.RELEASE 4.12 2.0.1 + 1.4.6 + 3.3.6 + 1.0.12 + 1.5.2 2.8.5 1.2.0 2.0 @@ -450,7 +454,6 @@ ${commons_lang3_version} - javax.xml.bind @@ -511,6 +514,28 @@ metrics-rest ${metrics_version} + + + + com.alipay.sofa + bolt + ${sofa_bolt_version} + + + com.alipay.sofa + hessian + ${sofa_hessian_version} + + + com.alipay.sofa.common + sofa-common-tools + ${sofa_common_version} + + + com.alipay.sofa.lookout + lookout-api + ${sofa_lookout_version} + diff --git a/dubbo-distribution/pom.xml b/dubbo-distribution/pom.xml index 50fd85532cca..e92363db722c 100644 --- a/dubbo-distribution/pom.xml +++ b/dubbo-distribution/pom.xml @@ -180,6 +180,11 @@ dubbo-registry-redis ${project.version} + + org.apache.dubbo + dubbo-registry-sofa + ${project.version} + org.apache.dubbo dubbo-monitor-api diff --git a/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistry.java b/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistry.java index 0f5c4b60c60d..a514d7a2517f 100644 --- a/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistry.java +++ b/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistry.java @@ -50,7 +50,6 @@ /** * The Sofa registry. * - * @author GengZhang * @since 2.7.2 */ public class SofaRegistry extends FailbackRegistry { diff --git a/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistryConstants.java b/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistryConstants.java index 6b6b7a1108d5..f832e802f608 100644 --- a/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistryConstants.java +++ b/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistryConstants.java @@ -17,7 +17,6 @@ package org.apache.dubbo.registry.sofa; /** - * @author GengZhang * @since 2.7.2 */ public class SofaRegistryConstants { diff --git a/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/HelloService.java b/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/HelloService.java index 8ffe38a9420c..cc66a5ede586 100644 --- a/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/HelloService.java +++ b/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/HelloService.java @@ -17,7 +17,6 @@ package org.apache.dubbo.registry.sofa; /** - * @author GengZhang */ public interface HelloService { diff --git a/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/HelloServiceImpl.java b/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/HelloServiceImpl.java index af0880ebf076..a9fb0ca70759 100644 --- a/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/HelloServiceImpl.java +++ b/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/HelloServiceImpl.java @@ -19,7 +19,6 @@ import com.alipay.sofa.registry.server.test.TestRegistryMain; /** - * @author GengZhang */ public class HelloServiceImpl implements HelloService { diff --git a/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/SofaRegistryTest.java b/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/SofaRegistryTest.java index 9066e5dfc946..bf16a271fb07 100644 --- a/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/SofaRegistryTest.java +++ b/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/SofaRegistryTest.java @@ -30,7 +30,6 @@ import org.junit.Test; /** - * @author GengZhang */ public class SofaRegistryTest { From 10a9517ca6fb332bfa29e802998de5d8c2a6e996 Mon Sep 17 00:00:00 2001 From: Geng Zhang Date: Fri, 26 Apr 2019 14:29:06 +0800 Subject: [PATCH 4/7] Fix as review. --- dubbo-dependencies-bom/pom.xml | 24 ++++----------- dubbo-registry/dubbo-registry-sofa/pom.xml | 35 ---------------------- 2 files changed, 6 insertions(+), 53 deletions(-) diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index d8a80c90cd93..d9a1fc56af4d 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -142,10 +142,7 @@ 4.3.16.RELEASE 4.12 2.0.1 - 1.4.6 - 3.3.6 - 1.0.12 - 1.5.2 + 5.2.0 2.8.5 1.2.0 2.0 @@ -518,23 +515,14 @@ com.alipay.sofa - bolt - ${sofa_bolt_version} + registry-client-all + ${sofa_registry_version} com.alipay.sofa - hessian - ${sofa_hessian_version} - - - com.alipay.sofa.common - sofa-common-tools - ${sofa_common_version} - - - com.alipay.sofa.lookout - lookout-api - ${sofa_lookout_version} + registry-test + ${sofa_registry_version} + test diff --git a/dubbo-registry/dubbo-registry-sofa/pom.xml b/dubbo-registry/dubbo-registry-sofa/pom.xml index 6b30198004f0..53b48d85e934 100644 --- a/dubbo-registry/dubbo-registry-sofa/pom.xml +++ b/dubbo-registry/dubbo-registry-sofa/pom.xml @@ -28,12 +28,6 @@ ${project.artifactId} The SOFARegistry module of Dubbo project - - 5.2.0 - 2.26 - 2.1 - - @@ -53,7 +47,6 @@ com.alipay.sofa registry-client-all - ${sofa.registry.version} com.alipay.sofa @@ -74,7 +67,6 @@ com.alipay.sofa registry-test - ${sofa.registry.version} test @@ -95,33 +87,6 @@ - - org.jboss.resteasy - resteasy-jaxrs - test - - - org.jboss.resteasy - resteasy-netty4 - test - - - org.glassfish.jersey.media - jersey-media-json-jackson - ${jersey.version} - test - - - org.glassfish.jersey.media - jersey-media-jaxb - ${jersey.version} - test - - - javax.ws.rs - javax.ws.rs-api - ${javax.ws.rs.version} - org.apache.dubbo From 6cf25f5c6e7f85031f97da3c19c4ba755c6f5fc0 Mon Sep 17 00:00:00 2001 From: Geng Zhang Date: Fri, 26 Apr 2019 14:35:13 +0800 Subject: [PATCH 5/7] remove author info. --- .../org/apache/dubbo/registry/sofa/SofaRegistryFactory.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistryFactory.java b/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistryFactory.java index cef7d0166d13..18a7809ea587 100644 --- a/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistryFactory.java +++ b/dubbo-registry/dubbo-registry-sofa/src/main/java/org/apache/dubbo/registry/sofa/SofaRegistryFactory.java @@ -21,8 +21,6 @@ import org.apache.dubbo.registry.support.AbstractRegistryFactory; /** - * - * @author Geng Zhang * @since 2.7.2 */ public class SofaRegistryFactory extends AbstractRegistryFactory { From 16d1b2e8f9e65acdb8fcc63f1fb63b4c7ce61761 Mon Sep 17 00:00:00 2001 From: Geng Zhang Date: Fri, 26 Apr 2019 14:38:27 +0800 Subject: [PATCH 6/7] remove dependency. --- dubbo-rpc/dubbo-rpc-thrift/pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/dubbo-rpc/dubbo-rpc-thrift/pom.xml b/dubbo-rpc/dubbo-rpc-thrift/pom.xml index d4de52447de4..d6e20ed95e2a 100644 --- a/dubbo-rpc/dubbo-rpc-thrift/pom.xml +++ b/dubbo-rpc/dubbo-rpc-thrift/pom.xml @@ -69,10 +69,5 @@ ${project.parent.version} test - - org.slf4j - slf4j-api - test - \ No newline at end of file From 3e6157cef94552c565d4e064c60364ed03837e2e Mon Sep 17 00:00:00 2001 From: Geng Zhang Date: Sat, 27 Apr 2019 20:05:26 +0800 Subject: [PATCH 7/7] Use junit5. --- dubbo-config/dubbo-config-spring/pom.xml | 1 + dubbo-dependencies-bom/pom.xml | 7 +-- dubbo-registry/dubbo-registry-sofa/pom.xml | 55 +++++++++++++------ .../dubbo/registry/sofa/SofaRegistryTest.java | 38 ++++++------- 4 files changed, 58 insertions(+), 43 deletions(-) diff --git a/dubbo-config/dubbo-config-spring/pom.xml b/dubbo-config/dubbo-config-spring/pom.xml index 5ec896d5b31d..04a8223bcb78 100644 --- a/dubbo-config/dubbo-config-spring/pom.xml +++ b/dubbo-config/dubbo-config-spring/pom.xml @@ -120,6 +120,7 @@ junit junit + 4.12 test diff --git a/dubbo-dependencies-bom/pom.xml b/dubbo-dependencies-bom/pom.xml index d9a1fc56af4d..3af25741d219 100644 --- a/dubbo-dependencies-bom/pom.xml +++ b/dubbo-dependencies-bom/pom.xml @@ -140,7 +140,7 @@ 3.2.5 1.5.19 4.3.16.RELEASE - 4.12 + 2.0.1 5.2.0 2.8.5 @@ -526,11 +526,6 @@ - - junit - junit - ${junit_version} - org.apache.curator curator-test diff --git a/dubbo-registry/dubbo-registry-sofa/pom.xml b/dubbo-registry/dubbo-registry-sofa/pom.xml index 53b48d85e934..7a2415fc216b 100644 --- a/dubbo-registry/dubbo-registry-sofa/pom.xml +++ b/dubbo-registry/dubbo-registry-sofa/pom.xml @@ -28,8 +28,12 @@ ${project.artifactId} The SOFARegistry module of Dubbo project + + 2.1 + -Dnetwork_interface_denylist=docker0 + + - org.apache.dubbo dubbo-registry-api @@ -62,6 +66,29 @@ ${project.version} test + + org.apache.dubbo + dubbo-rpc-dubbo + ${project.version} + test + + + org.apache.dubbo + dubbo-remoting-netty4 + ${project.version} + test + + + org.apache.dubbo + dubbo-serialization-hessian2 + ${project.version} + test + + + ch.qos.logback + logback-classic + test + @@ -89,32 +116,24 @@ - org.apache.dubbo - dubbo-rpc-dubbo - ${project.version} + org.jboss.resteasy + resteasy-jaxrs test - org.apache.dubbo - dubbo-remoting-netty4 - ${project.version} + org.jboss.resteasy + resteasy-netty4 test - org.apache.dubbo - dubbo-serialization-hessian2 - ${project.version} + javax.ws.rs + javax.ws.rs-api + ${javax.ws.rs.version} test - ch.qos.logback - logback-classic - test - - - - junit - junit + javax.xml.bind + jaxb-api test diff --git a/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/SofaRegistryTest.java b/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/SofaRegistryTest.java index bf16a271fb07..4d67b7465e3c 100644 --- a/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/SofaRegistryTest.java +++ b/dubbo-registry/dubbo-registry-sofa/src/test/java/org/apache/dubbo/registry/sofa/SofaRegistryTest.java @@ -24,10 +24,10 @@ import org.apache.dubbo.config.ReferenceConfig; import org.apache.dubbo.config.RegistryConfig; import org.apache.dubbo.config.ServiceConfig; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; /** */ @@ -45,9 +45,9 @@ public class SofaRegistryTest { private static RegistryConfig registryConfig; - @BeforeClass + @BeforeAll public static void beforeClass() { - + protocolConfig1 = new ProtocolConfig(); protocolConfig1.setName("dubbo"); protocolConfig1.setPort(20890); @@ -59,7 +59,7 @@ public static void beforeClass() { registryConfig = new RegistryConfig(); registryConfig.setAddress("sofa://127.0.0.1:9603"); registryConfig.setProtocol("sofa"); - + registryMain = new TestRegistryMain(); try { registryMain.startRegistry(); @@ -79,7 +79,7 @@ public void testPubAndSub() throws InterruptedException { serviceConfig1.setGroup("g1"); serviceConfig1.setApplication(applicationConfig); serviceConfig1.export(); - + ServiceConfig serviceConfig2 = new ServiceConfig<>(); serviceConfig2.setInterface(HelloService.class); serviceConfig2.setRef(new HelloServiceImpl("rrr22")); @@ -90,8 +90,8 @@ public void testPubAndSub() throws InterruptedException { serviceConfig2.setRegister(false); serviceConfig2.export(); - Thread.sleep(1000); - + Thread.sleep(1000); + // do refer ReferenceConfig referenceConfig1 = new ReferenceConfig<>(); referenceConfig1.setInterface(HelloService.class); @@ -101,7 +101,7 @@ public void testPubAndSub() throws InterruptedException { referenceConfig1.setRegistry(registryConfig); referenceConfig1.setApplication(applicationConfig); HelloService service = referenceConfig1.get(); - Assert.assertEquals("rrr11", service.sayHello("xxx")); + Assertions.assertEquals("rrr11", service.sayHello("xxx")); // do refer duplicated ReferenceConfig referenceConfig2 = new ReferenceConfig<>(); @@ -112,9 +112,9 @@ public void testPubAndSub() throws InterruptedException { referenceConfig2.setRegistry(registryConfig); referenceConfig2.setApplication(applicationConfig); HelloService service2 = referenceConfig2.get(); - Assert.assertEquals("rrr11", service2.sayHello("xxx")); + Assertions.assertEquals("rrr11", service2.sayHello("xxx")); - // export on service + // export one service ServiceConfig serviceConfig3 = new ServiceConfig<>(); serviceConfig3.setInterface(HelloService.class); serviceConfig3.setRef(new HelloServiceImpl("rrr12")); @@ -123,19 +123,19 @@ public void testPubAndSub() throws InterruptedException { serviceConfig3.setGroup("g1"); serviceConfig3.setApplication(applicationConfig); serviceConfig3.export(); - Assert.assertTrue(service2.sayHello("xxx").startsWith("rrr1")); + Assertions.assertTrue(service2.sayHello("xxx").startsWith("rrr1")); // unrefer referenceConfig1.destroy(); - Assert.assertTrue(service2.sayHello("xxx").startsWith("rrr1")); - - // unexport on service + Assertions.assertTrue(service2.sayHello("xxx").startsWith("rrr1")); + + // unexport one service serviceConfig1.unexport(); Thread.sleep(2000); - Assert.assertTrue(service2.sayHello("xxx").startsWith("rrr1")); + Assertions.assertTrue(service2.sayHello("xxx").startsWith("rrr1")); } - @AfterClass + @AfterAll public static void afterClass() { try { registryMain.stopRegistry();