repo stringclasses 1k
values | file_url stringlengths 96 373 | file_path stringlengths 11 294 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 6
values | commit_sha stringclasses 1k
values | retrieved_at stringdate 2026-01-04 14:45:56 2026-01-04 18:30:23 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmService.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmService.java | /*
* 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.config.integration.multiple.injvm;
/**
* This interface is used to check if the exported injvm protocol works well or not.
*/
public interface MultipleRegistryCenterInjvmService {
/**
* The simple method for testing.
*/
String hello(String name);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmServiceListener.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmServiceListener.java | /*
* 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.config.integration.multiple.injvm;
import org.apache.dubbo.config.ServiceListener;
import org.apache.dubbo.config.integration.AbstractRegistryCenterServiceListener;
/**
* This implementation of {@link ServiceListener} is to record exported services with injvm protocol in multiple registry center.
*/
public class MultipleRegistryCenterInjvmServiceListener extends AbstractRegistryCenterServiceListener {
/**
* {@inheritDoc}
*/
@Override
protected Class<?> getInterface() {
return MultipleRegistryCenterInjvmService.class;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmServiceImpl.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/injvm/MultipleRegistryCenterInjvmServiceImpl.java | /*
* 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.config.integration.multiple.injvm;
/**
* The simple implementation for {@link MultipleRegistryCenterInjvmService}
*/
public class MultipleRegistryCenterInjvmServiceImpl implements MultipleRegistryCenterInjvmService {
/**
* {@inheritDoc}
*/
@Override
public String hello(String name) {
return "Hello " + name;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryServiceImpl.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryServiceImpl.java | /*
* 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.config.integration.multiple.servicediscoveryregistry;
/**
* The simple implementation for {@link MultipleRegistryCenterServiceDiscoveryRegistryService}
*/
public class MultipleRegistryCenterServiceDiscoveryRegistryServiceImpl
implements MultipleRegistryCenterServiceDiscoveryRegistryService {
/**
* {@inheritDoc}
*/
@Override
public String hello(String name) {
return "Hello " + name;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.java | /*
* 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.config.integration.multiple.servicediscoveryregistry;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.ExtensionLoader;
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.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.integration.IntegrationTest;
import org.apache.dubbo.registry.RegistryServiceListener;
import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegation;
import org.apache.dubbo.test.check.registrycenter.config.ZookeeperConfig;
import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.dubbo.config.integration.Constants.MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY;
/**
* The testcases are only for checking the process of exporting provider using service-discovery-registry protocol.
*/
class MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest implements IntegrationTest {
private static final Logger logger =
LoggerFactory.getLogger(MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.class);
/**
* Define the provider application name.
*/
public static String PROVIDER_APPLICATION_NAME =
"multiple-registry-center-provider-for-service-discovery-registry-protocol";
/**
* Define the protocol's name.
*/
private static String PROTOCOL_NAME = CommonConstants.DUBBO;
/**
* Define the protocol's port.
*/
private static int PROTOCOL_PORT = 20880;
/**
* Define the {@link ServiceConfig} instance.
*/
private ServiceConfig<MultipleRegistryCenterServiceDiscoveryRegistryService> serviceConfig;
/**
* Define a {@link RegistryServiceListener} instance.
*/
private MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener registryServiceListener;
/**
* The localhost.
*/
private static String HOST = "127.0.0.1";
/**
* The port of register center.
*/
private Set<Integer> ports = new HashSet<>(2);
@BeforeEach
public void setUp() throws Exception {
logger.info(getClass().getSimpleName() + " testcase is beginning...");
DubboBootstrap.reset();
// initialize service config
serviceConfig = new ServiceConfig<>();
serviceConfig.setInterface(MultipleRegistryCenterServiceDiscoveryRegistryService.class);
serviceConfig.setRef(new MultipleRegistryCenterServiceDiscoveryRegistryServiceImpl());
serviceConfig.setAsync(false);
RegistryConfig registryConfig1 = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress1());
Map<String, String> parameters1 = new HashMap<>();
parameters1.put("registry.listeners", MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY);
registryConfig1.updateParameters(parameters1);
DubboBootstrap.getInstance().registry(registryConfig1);
ports.add(ZookeeperConfig.DEFAULT_CLIENT_PORT_1);
RegistryConfig registryConfig2 = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress2());
Map<String, String> parameters2 = new HashMap<>();
parameters2.put("registry.listeners", MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY);
registryConfig2.updateParameters(parameters2);
DubboBootstrap.getInstance().registry(registryConfig2);
ports.add(ZookeeperConfig.DEFAULT_CLIENT_PORT_2);
DubboBootstrap.getInstance()
.application(new ApplicationConfig(PROVIDER_APPLICATION_NAME))
.protocol(new ProtocolConfig(PROTOCOL_NAME, PROTOCOL_PORT))
.service(serviceConfig);
// ---------------initialize--------------- //
registryServiceListener = (MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener)
ExtensionLoader.getExtensionLoader(RegistryServiceListener.class)
.getExtension(MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY);
// RegistryServiceListener is not null
Assertions.assertNotNull(registryServiceListener);
registryServiceListener.getStorage().clear();
}
/**
* Define a {@link RegistryServiceListener} for helping check.<p>
* There are some checkpoints need to verify as follow:
* <ul>
* <li>ServiceConfig is exported or not</li>
* <li>ServiceDiscoveryRegistryStorage is empty or not</li>
* </ul>
*/
private void beforeExport() {
// ---------------checkpoints--------------- //
// ServiceConfig isn't exported
Assertions.assertFalse(serviceConfig.isExported());
// ServiceDiscoveryRegistryStorage is empty
Assertions.assertEquals(registryServiceListener.getStorage().size(), 0);
}
/**
* {@inheritDoc}
*/
@Test
@Override
public void integrate() {
beforeExport();
DubboBootstrap.getInstance().start();
afterExport();
ReferenceConfig<MultipleRegistryCenterServiceDiscoveryRegistryService> referenceConfig =
new ReferenceConfig<>();
referenceConfig.setInterface(MultipleRegistryCenterServiceDiscoveryRegistryService.class);
referenceConfig.get().hello("Dubbo in multiple registry center");
afterInvoke();
}
/**
* There are some checkpoints need to check after exported as follow:
* <ul>
* <li>ServiceDiscoveryRegistry is right or not</li>
* <li>All register center has been registered and subscribed</li>
* </ul>
*/
private void afterExport() {
// ServiceDiscoveryRegistry is not null
Assertions.assertEquals(registryServiceListener.getStorage().size(), 2);
// All register center has been registered and subscribed
for (int port : ports) {
Assertions.assertTrue(registryServiceListener.getStorage().contains(HOST, port));
ServiceDiscoveryRegistryInfoWrapper serviceDiscoveryRegistryInfoWrapper =
registryServiceListener.getStorage().get(HOST, port);
// check if it's registered
Assertions.assertTrue(serviceDiscoveryRegistryInfoWrapper.isRegistered());
// check if it's subscribed
Assertions.assertFalse(serviceDiscoveryRegistryInfoWrapper.isSubscribed());
MetadataServiceDelegation metadataService = DubboBootstrap.getInstance()
.getApplicationModel()
.getBeanFactory()
.getBean(MetadataServiceDelegation.class);
// check if the count of exported urls is right or not
Assertions.assertEquals(metadataService.getExportedURLs().size(), 1);
// check the exported url is right or not.
Assertions.assertTrue(metadataService
.getExportedURLs()
.first()
.contains(MultipleRegistryCenterServiceDiscoveryRegistryService.class.getName()));
// check the count of metadatainfo is right or not.
Assertions.assertEquals(2, metadataService.getMetadataInfos().size());
}
}
/**
* There are some checkpoints need to check after invoked as follow:
*/
private void afterInvoke() {}
@AfterEach
public void tearDown() throws IOException {
DubboBootstrap.reset();
serviceConfig = null;
// TODO: we need to check whether this scenario is normal
// TODO: the Exporter and ServiceDiscoveryRegistry are same in multiple registry center
/*
for (int port: ports) {
Assertions.assertTrue(registryServiceListener.getStorage().contains(HOST, port));
ServiceDiscoveryRegistryInfoWrapper serviceDiscoveryRegistryInfoWrapper = registryServiceListener.getStorage().get(HOST, port);
// check if it's registered
Assertions.assertFalse(serviceDiscoveryRegistryInfoWrapper.isRegistered());
// check if it's subscribed
Assertions.assertFalse(serviceDiscoveryRegistryInfoWrapper.isSubscribed());
}
*/
registryServiceListener.getStorage().clear();
registryServiceListener = null;
logger.info(getClass().getSimpleName() + " testcase is ending...");
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/ServiceDiscoveryRegistryStorage.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/ServiceDiscoveryRegistryStorage.java | /*
* 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.config.integration.multiple.servicediscoveryregistry;
import org.apache.dubbo.config.integration.multiple.AbstractStorage;
/**
* The storage to store {@link ServiceDiscoveryRegistryInfoWrapper} instances in multiple registry center.
*/
public class ServiceDiscoveryRegistryStorage extends AbstractStorage<ServiceDiscoveryRegistryInfoWrapper> {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener.java | /*
* 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.config.integration.multiple.servicediscoveryregistry;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.RegistryServiceListener;
import org.apache.dubbo.registry.client.ServiceDiscoveryRegistry;
import static org.apache.dubbo.config.integration.Constants.MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY;
@Activate(value = MULTIPLE_CONFIG_CENTER_SERVICE_DISCOVERY_REGISTRY)
public class MultipleRegistryCenterServiceDiscoveryRegistryRegistryServiceListener implements RegistryServiceListener {
private ServiceDiscoveryRegistryStorage storage = new ServiceDiscoveryRegistryStorage();
/**
* Create an {@link ServiceDiscoveryRegistryInfoWrapper} instance.
*/
private ServiceDiscoveryRegistryInfoWrapper createServiceDiscoveryRegistryInfoWrapper(
ServiceDiscoveryRegistry serviceDiscoveryRegistry) {
URL url = serviceDiscoveryRegistry.getUrl();
String host = url.getHost();
int port = url.getPort();
ServiceDiscoveryRegistryInfoWrapper serviceDiscoveryRegistryInfoWrapper =
new ServiceDiscoveryRegistryInfoWrapper();
serviceDiscoveryRegistryInfoWrapper.setHost(host);
serviceDiscoveryRegistryInfoWrapper.setPort(port);
serviceDiscoveryRegistryInfoWrapper.setServiceDiscoveryRegistry(serviceDiscoveryRegistry);
serviceDiscoveryRegistryInfoWrapper.setRegistered(true);
return serviceDiscoveryRegistryInfoWrapper;
}
/**
* Checks if the registry is checked application
*/
private boolean isCheckedApplication(Registry registry) {
return registry.getUrl()
.getApplication()
.equals(MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest.PROVIDER_APPLICATION_NAME);
}
public void onRegister(URL url, Registry registry) {
if (registry instanceof ServiceDiscoveryRegistry && isCheckedApplication(registry)) {
ServiceDiscoveryRegistry serviceDiscoveryRegistry = (ServiceDiscoveryRegistry) registry;
String host = serviceDiscoveryRegistry.getUrl().getHost();
int port = serviceDiscoveryRegistry.getUrl().getPort();
if (!storage.contains(host, port)) {
storage.put(host, port, createServiceDiscoveryRegistryInfoWrapper(serviceDiscoveryRegistry));
}
storage.get(host, port).setRegistered(true);
}
}
public void onUnregister(URL url, Registry registry) {
if (registry instanceof ServiceDiscoveryRegistry && isCheckedApplication(registry)) {
String host = registry.getUrl().getHost();
int port = registry.getUrl().getPort();
storage.get(host, port).setRegistered(false);
}
}
public void onSubscribe(URL url, Registry registry) {
if (registry instanceof ServiceDiscoveryRegistry && isCheckedApplication(registry)) {
ServiceDiscoveryRegistry serviceDiscoveryRegistry = (ServiceDiscoveryRegistry) registry;
String host = serviceDiscoveryRegistry.getUrl().getHost();
int port = serviceDiscoveryRegistry.getUrl().getPort();
if (!storage.contains(host, port)) {
storage.put(host, port, createServiceDiscoveryRegistryInfoWrapper(serviceDiscoveryRegistry));
}
storage.get(host, port).setSubscribed(true);
}
}
public void onUnsubscribe(URL url, Registry registry) {
if (registry instanceof ServiceDiscoveryRegistry && isCheckedApplication(registry)) {
String host = registry.getUrl().getHost();
int port = registry.getUrl().getPort();
storage.get(host, port).setSubscribed(false);
}
}
/**
* Return the stored {@link ServiceDiscoveryRegistryInfoWrapper} instances.
*/
public ServiceDiscoveryRegistryStorage getStorage() {
return storage;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/ServiceDiscoveryRegistryInfoWrapper.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/ServiceDiscoveryRegistryInfoWrapper.java | /*
* 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.config.integration.multiple.servicediscoveryregistry;
import org.apache.dubbo.registry.client.ServiceDiscoveryRegistry;
import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegation;
/**
* The instance to wrap {@link org.apache.dubbo.registry.client.ServiceDiscoveryRegistry}
*/
public class ServiceDiscoveryRegistryInfoWrapper {
private ServiceDiscoveryRegistry serviceDiscoveryRegistry;
private MetadataServiceDelegation inMemoryWritableMetadataService;
private boolean registered;
private boolean subscribed;
private String host;
private int port;
public ServiceDiscoveryRegistry getServiceDiscoveryRegistry() {
return serviceDiscoveryRegistry;
}
public void setServiceDiscoveryRegistry(ServiceDiscoveryRegistry serviceDiscoveryRegistry) {
this.serviceDiscoveryRegistry = serviceDiscoveryRegistry;
}
public boolean isRegistered() {
return registered;
}
public void setRegistered(boolean registered) {
this.registered = registered;
}
public boolean isSubscribed() {
return subscribed;
}
public void setSubscribed(boolean subscribed) {
this.subscribed = subscribed;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryService.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/servicediscoveryregistry/MultipleRegistryCenterServiceDiscoveryRegistryService.java | /*
* 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.config.integration.multiple.servicediscoveryregistry;
/**
* This interface is used to check if the exported service-discovery-registry protocol works well or not.
*/
public interface MultipleRegistryCenterServiceDiscoveryRegistryService {
/**
* The simple method for testing.
*/
String hello(String name);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataExporterListener.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataExporterListener.java | /*
* 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.config.integration.multiple.exportmetadata;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.config.integration.AbstractRegistryCenterExporterListener;
import org.apache.dubbo.metadata.MetadataService;
@Activate(group = CommonConstants.PROVIDER, order = 1000)
public class MultipleRegistryCenterExportMetadataExporterListener extends AbstractRegistryCenterExporterListener {
/**
* Returns the interface of exported service.
*/
@Override
protected Class<?> getInterface() {
return MetadataService.class;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataServiceImpl.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataServiceImpl.java | /*
* 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.config.integration.multiple.exportmetadata;
/**
* The simple implementation for {@link MultipleRegistryCenterExportMetadataService}
*/
public class MultipleRegistryCenterExportMetadataServiceImpl implements MultipleRegistryCenterExportMetadataService {
/**
* {@inheritDoc}
*/
@Override
public String hello(String name) {
return "Hello " + name;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataServiceListener.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataServiceListener.java | /*
* 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.config.integration.multiple.exportmetadata;
import org.apache.dubbo.config.ServiceListener;
import org.apache.dubbo.config.integration.AbstractRegistryCenterServiceListener;
import org.apache.dubbo.metadata.MetadataService;
/**
* This implementation of {@link ServiceListener} is to record exported metadata services in multiple registry center.
*/
public class MultipleRegistryCenterExportMetadataServiceListener extends AbstractRegistryCenterServiceListener {
/**
* {@inheritDoc}
*/
@Override
protected Class<?> getInterface() {
return MetadataService.class;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataService.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataService.java | /*
* 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.config.integration.multiple.exportmetadata;
/**
* This interface is used to check if the exported metadata service works well or not in multiple registry center.
*/
public interface MultipleRegistryCenterExportMetadataService {
/**
* The simple method for testing.
*/
String hello(String name);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataIntegrationTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/multiple/exportmetadata/MultipleRegistryCenterExportMetadataIntegrationTest.java | /*
* 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.config.integration.multiple.exportmetadata;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.ServiceListener;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.integration.IntegrationTest;
import org.apache.dubbo.metadata.MetadataService;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.ExporterListener;
import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig;
import java.io.IOException;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.dubbo.rpc.Constants.SCOPE_LOCAL;
/**
* The testcases are only for checking the process of exporting metadata service.
*/
class MultipleRegistryCenterExportMetadataIntegrationTest implements IntegrationTest {
private static final Logger logger =
LoggerFactory.getLogger(MultipleRegistryCenterExportMetadataIntegrationTest.class);
/**
* Define the provider application name.
*/
private static String PROVIDER_APPLICATION_NAME = "multiple-registry-center-export-metadata";
/**
* The name for getting the specified instance, which is loaded using SPI.
*/
private static String SPI_NAME = "multipleConfigCenterExportMetadata";
/**
* Define the protocol's name.
*/
private static String PROTOCOL_NAME = "injvm";
/**
* Define the {@link ServiceConfig} instance.
*/
private ServiceConfig<MultipleRegistryCenterExportMetadataService> serviceConfig;
/**
* The listener to record exported services
*/
private MultipleRegistryCenterExportMetadataServiceListener serviceListener;
/**
* The listener to record exported exporters.
*/
private MultipleRegistryCenterExportMetadataExporterListener exporterListener;
@BeforeEach
public void setUp() throws Exception {
logger.info(getClass().getSimpleName() + " testcase is beginning...");
DubboBootstrap.reset();
// initialize service config
serviceConfig = new ServiceConfig<>();
serviceConfig.setInterface(MultipleRegistryCenterExportMetadataService.class);
serviceConfig.setRef(new MultipleRegistryCenterExportMetadataServiceImpl());
serviceConfig.setAsync(false);
serviceConfig.setScope(SCOPE_LOCAL);
// initialize bootstrap
DubboBootstrap.getInstance()
.application(new ApplicationConfig(PROVIDER_APPLICATION_NAME))
.protocol(new ProtocolConfig(PROTOCOL_NAME))
.service(serviceConfig)
.registry(new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress1()))
.registry(new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress2()));
}
/**
* Define {@link ServiceListener}, {@link ExporterListener} and {@link Filter} for helping check.
* <p>Use SPI to load them before exporting.
* <p>After that, there are some checkpoints need to verify as follow:
* <ul>
* <li>There is nothing in ServiceListener or not</li>
* <li>There is nothing in ExporterListener or not</li>
* <li>ServiceConfig is exported or not</li>
* </ul>
*/
private void beforeExport() {
// ---------------initialize--------------- //
serviceListener = (MultipleRegistryCenterExportMetadataServiceListener)
ExtensionLoader.getExtensionLoader(ServiceListener.class).getExtension(SPI_NAME);
exporterListener = (MultipleRegistryCenterExportMetadataExporterListener)
ExtensionLoader.getExtensionLoader(ExporterListener.class).getExtension(SPI_NAME);
// ---------------checkpoints--------------- //
// There is nothing in ServiceListener
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
// There is nothing in ExporterListener
Assertions.assertTrue(exporterListener.getExportedExporters().isEmpty());
// ServiceConfig isn't exported
Assertions.assertFalse(serviceConfig.isExported());
}
/**
* {@inheritDoc}
*/
@Test
@Override
public void integrate() {
beforeExport();
DubboBootstrap.getInstance().start();
afterExport();
}
/**
* There are some checkpoints need to check after exported as follow:
* <ul>
* <li>The metadata service is only one or not</li>
* <li>The exported service is MetadataService or not</li>
* <li>The MetadataService is exported or not</li>
* <li>The exported exporters are right or not</li>
* </ul>
*/
private void afterExport() {
// The metadata service is only one
Assertions.assertEquals(serviceListener.getExportedServices().size(), 1);
// The exported service is MetadataService
Assertions.assertEquals(
serviceListener.getExportedServices().get(0).getInterfaceClass(), MetadataService.class);
// The MetadataService is exported
Assertions.assertTrue(serviceListener.getExportedServices().get(0).isExported());
// FIXME there may be something wrong with the whole process of
// registering service-discovery-registry.
// So, all testcases may need to be modified.
// There are two exported exporters
// 1. Metadata Service exporter with Injvm protocol
// 2. MultipleRegistryCenterExportMetadataService exporter with Injvm protocol
Assertions.assertEquals(exporterListener.getExportedExporters().size(), 2);
List<Exporter<?>> injvmExporters = exporterListener.getExportedExporters();
// Make sure there two injvmExporters
Assertions.assertEquals(2, injvmExporters.size());
}
@AfterEach
public void tearDown() throws IOException {
DubboBootstrap.reset();
serviceConfig = null;
// The exported service has been unexported
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
serviceListener = null;
logger.info(getClass().getSimpleName() + " testcase is ending...");
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterExportedServiceListener.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterExportedServiceListener.java | /*
* 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.config.integration.single;
import org.apache.dubbo.config.ServiceListener;
import org.apache.dubbo.config.integration.AbstractRegistryCenterServiceListener;
/**
* This implementation of {@link ServiceListener} is to record exported services in single registry center.
*/
public class SingleRegistryCenterExportedServiceListener extends AbstractRegistryCenterServiceListener {
/**
* {@inheritDoc}
*/
@Override
protected Class<?> getInterface() {
return SingleRegistryCenterIntegrationService.class;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/package-info.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/package-info.java | /*
* 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.
*/
/**
* There are two scenario in integration testcases.<p>
* The one is single registry center, the other is multiple registry centers.<p>
* The purpose of all of testcases in this package is to test for single registry center.
*/
package org.apache.dubbo.config.integration.single;
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterIntegrationServiceImpl.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterIntegrationServiceImpl.java | /*
* 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.config.integration.single;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The implementation for {@link SingleRegistryCenterIntegrationService}
*/
public class SingleRegistryCenterIntegrationServiceImpl implements SingleRegistryCenterIntegrationService {
private static final Logger logger = LoggerFactory.getLogger(SingleRegistryCenterIntegrationServiceImpl.class);
@Override
public String hello(String name) {
String value = "Hello " + name;
logger.info(value);
return value;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterIntegrationService.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterIntegrationService.java | /*
* 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.config.integration.single;
/**
* This interface for integration testcases in single registry center.
*/
public interface SingleRegistryCenterIntegrationService {
String hello(String name);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterDubboProtocolIntegrationTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/SingleRegistryCenterDubboProtocolIntegrationTest.java | /*
* 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.config.integration.single;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.ExtensionLoader;
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.apache.dubbo.config.ServiceListener;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.integration.IntegrationTest;
import org.apache.dubbo.metadata.MetadataInfo;
import org.apache.dubbo.metadata.MetadataService;
import org.apache.dubbo.registry.ListenerRegistryWrapper;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.client.ServiceDiscoveryRegistry;
import org.apache.dubbo.registry.client.ServiceDiscoveryRegistryDirectory;
import org.apache.dubbo.registry.client.metadata.MetadataServiceDelegation;
import org.apache.dubbo.registry.client.migration.MigrationInvoker;
import org.apache.dubbo.registry.support.RegistryManager;
import org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery;
import org.apache.dubbo.rpc.cluster.Directory;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig;
import java.io.IOException;
import java.util.Collection;
import java.util.Set;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.dubbo.common.constants.RegistryConstants.CONSUMERS_CATEGORY;
import static org.apache.dubbo.rpc.Constants.SCOPE_REMOTE;
/**
* This abstraction class will implement some methods as base for single registry center.
*/
@DisabledForJreRange(min = JRE.JAVA_16)
class SingleRegistryCenterDubboProtocolIntegrationTest implements IntegrationTest {
private static final Logger logger =
LoggerFactory.getLogger(SingleRegistryCenterDubboProtocolIntegrationTest.class);
/**
* Define the provider application name.
*/
private static String PROVIDER_APPLICATION_NAME = "single-registry-center-provider-for-dubbo-protocol";
/**
* Define the protocol's name.
*/
private static String PROTOCOL_NAME = CommonConstants.DUBBO;
/**
* Define the protocol's port.
*/
private static int PROTOCOL_PORT = 20800;
/**
* Define the {@link ServiceConfig} instance.
*/
private ServiceConfig<SingleRegistryCenterIntegrationServiceImpl> serviceConfig;
/**
* Define the {@link ReferenceConfig} instance.
*/
private ReferenceConfig<SingleRegistryCenterIntegrationService> referenceConfig;
/**
* Define the {@link RegistryConfig} instance.
*/
private RegistryConfig registryConfig;
/**
* The service instance of {@link SingleRegistryCenterIntegrationService}
*/
private SingleRegistryCenterIntegrationService singleRegistryCenterIntegrationService;
/**
* Define the {@link SingleRegistryCenterExportedServiceListener} instance to obtain the exported services.
*/
private SingleRegistryCenterExportedServiceListener singleRegistryCenterExportedServiceListener;
@BeforeEach
public void setUp() throws Exception {
logger.info(getClass().getSimpleName() + " testcase is beginning...");
DubboBootstrap.reset();
// initialize ServiceConfig
serviceConfig = new ServiceConfig<>();
serviceConfig.setInterface(SingleRegistryCenterIntegrationService.class);
serviceConfig.setRef(new SingleRegistryCenterIntegrationServiceImpl());
serviceConfig.setAsync(false);
DubboBootstrap.getInstance()
.application(new ApplicationConfig(PROVIDER_APPLICATION_NAME))
.protocol(new ProtocolConfig(PROTOCOL_NAME, PROTOCOL_PORT))
.service(serviceConfig);
registryConfig = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress());
DubboBootstrap.getInstance().registry(registryConfig);
}
@Test
@Override
public void integrate() {
this.beforeExport();
// export provider
DubboBootstrap.getInstance().start();
this.afterExport();
// initialize consumer
this.initConsumer();
this.beforeRefer();
singleRegistryCenterIntegrationService = referenceConfig.get();
this.afterRefer();
}
/**
* There are some checkpoints needed to check as follow :
* <ul>
* <li>ServiceConfig is exported or not</li>
* <li>ServiceConfig's exportedUrl has values or not</li>
* <li>DubboBootstrap is initialized or not</li>
* <li>DubboBootstrap is started or not</li>
* <li>DubboBootstrap is shutdown or not</li>
* <li>The ServiceListener is loaded by SPI or not</li>
* </ul>
*/
private void beforeExport() {
// ServiceConfig is exported or not
Assertions.assertFalse(serviceConfig.isExported());
// ServiceConfig's exportedUrl has values or not
Assertions.assertEquals(0, serviceConfig.getExportedUrls().size());
// DubboBootstrap is pending or not
Assertions.assertTrue(DubboBootstrap.getInstance().isPending());
// DubboBootstrap is initialized or not
Assertions.assertFalse(DubboBootstrap.getInstance().isInitialized());
// DubboBootstrap is started or not
Assertions.assertFalse(DubboBootstrap.getInstance().isStarted());
// DubboBootstrap is stopped or not
Assertions.assertFalse(DubboBootstrap.getInstance().isStopped());
// The ServiceListener is loaded by SPI or not
Assertions.assertNull(singleRegistryCenterExportedServiceListener);
}
/**
* There are some checkpoints needed to check as follow :
* <ul>
* <li>DubboBootstrap is initialized or not</li>
* <li>DubboBootstrap is started or not</li>
* <li>DubboBootstrap is shutdown or not</li>
* <li>Service has been exported or not</li>
* <li>There is exported urls or not</li>
* <li>Protocol name is right or not</li>
* <li>Protocol port is right or not</li>
* <li>ServiceDiscoveryRegistry's protocol is right or not</li>
* <li>Registered service in registry center is right or not</li>
* <li>MetadataInfo has reported or not</li>
* <li>MetadataInfo has reported or not has service or not</li>
* <li>MetadataInfo's application name is right or not</li>
* <li>MetadataInfo's service exists or not</li>
* <li>The name of MetadataInfo's service is right or not</li>
* <li>The group of MetadataInfo's service is right or not</li>
* <li>The version of MetadataInfo's service is right or not</li>
* <li>The protocol of MetadataInfo's service is right or not</li>
* <li>The serviceKey of MetadataInfo's service is right or not</li>
* <li>The matchKey of MetadataInfo's service is right or not</li>
* <li>The exported service are right or not</li>
* </ul>
*/
private void afterExport() {
// DubboBootstrap is initialized or not
Assertions.assertTrue(DubboBootstrap.getInstance().isInitialized());
// DubboBootstrap is pending or not
Assertions.assertFalse(DubboBootstrap.getInstance().isPending());
// DubboBootstrap is started or not
Assertions.assertTrue(DubboBootstrap.getInstance().isCompletion());
// DubboBootstrap is running
Assertions.assertTrue(DubboBootstrap.getInstance().isRunning());
// DubboBootstrap is shutdown or not
Assertions.assertFalse(DubboBootstrap.getInstance().isStopped());
// Service has been exported or not
Assertions.assertTrue(this.serviceConfig.isExported());
// There is exported urls or not
Assertions.assertEquals(1, this.serviceConfig.getExportedUrls().size());
URL exportedUrl = this.serviceConfig.getExportedUrls().get(0);
// Protocol name is right or not
Assertions.assertEquals(exportedUrl.getProtocol(), PROTOCOL_NAME);
// Protocol port is right or not
Assertions.assertEquals(exportedUrl.getPort(), PROTOCOL_PORT);
// Application name is right or not
Assertions.assertEquals(exportedUrl.getApplication(), PROVIDER_APPLICATION_NAME);
// obtain ServiceDiscoveryRegistry instance
ServiceDiscoveryRegistry serviceDiscoveryRegistry = this.getServiceDiscoveryRegistry();
// ServiceDiscoveryRegistry instance cannot be null
Assertions.assertNotNull(serviceDiscoveryRegistry);
// ServiceDiscoveryRegistry's protocol is right or not
Assertions.assertTrue(serviceDiscoveryRegistry.getServiceDiscovery() instanceof ZookeeperServiceDiscovery);
// Convert to ZookeeperServiceDiscovery instance
ZookeeperServiceDiscovery zookeeperServiceDiscovery =
(ZookeeperServiceDiscovery) serviceDiscoveryRegistry.getServiceDiscovery();
// Gets registered service by ZookeeperServiceDiscovery
Set<String> services = zookeeperServiceDiscovery.getServices();
// check service exists
Assertions.assertTrue(!services.isEmpty());
// Registered service in registry center is right or not
Assertions.assertTrue(services.contains(PROVIDER_APPLICATION_NAME));
// obtain InMemoryWritableMetadataService instance
MetadataServiceDelegation inMemoryWritableMetadataService = (MetadataServiceDelegation)
serviceConfig.getScopeModel().getBeanFactory().getBean(MetadataService.class);
// Exported url is right or not in InMemoryWritableMetadataService
Assertions.assertEquals(
1, inMemoryWritableMetadataService.getExportedURLs().size());
// MetadataInfo exists or not in InMemoryWritableMetadataService
Assertions.assertFalse(
inMemoryWritableMetadataService.getMetadataInfos().isEmpty());
// MetadataInfo has reported or not has service or not
Assertions.assertFalse(inMemoryWritableMetadataService
.getMetadataInfos()
.get(0)
.getServices()
.isEmpty());
// MetadataInfo has reported or not has service or not
Assertions.assertEquals(
1,
inMemoryWritableMetadataService
.getMetadataInfos()
.get(0)
.getServices()
.size());
// obtain the service's key
String key = SingleRegistryCenterIntegrationService.class.getName() + ":" + PROTOCOL_NAME;
MetadataInfo.ServiceInfo serviceInfo = inMemoryWritableMetadataService
.getMetadataInfos()
.get(0)
.getServices()
.get(key);
// MetadataInfo's service exists or not
Assertions.assertNotNull(serviceInfo);
// The name of MetadataInfo's service is right or not
Assertions.assertEquals(serviceInfo.getName(), SingleRegistryCenterIntegrationService.class.getName());
// The group of MetadataInfo's service is right or not
Assertions.assertNull(serviceInfo.getGroup());
// The version of MetadataInfo's service is right or not
Assertions.assertNull(serviceInfo.getVersion());
// The protocol of MetadataInfo's service is right or not
Assertions.assertEquals(serviceInfo.getProtocol(), PROTOCOL_NAME);
// The serviceKey of MetadataInfo's service is right or not
Assertions.assertEquals(serviceInfo.getServiceKey(), SingleRegistryCenterIntegrationService.class.getName());
// The matchKey of MetadataInfo's service is right or not
Assertions.assertEquals(serviceInfo.getMatchKey(), key);
// The exported services are right or not
// 1. The exported service must contain SingleRegistryCenterIntegrationService
// 2. The exported service's interface must be SingleRegistryCenterIntegrationService.class
// 3. All exported services must be exported
singleRegistryCenterExportedServiceListener = (SingleRegistryCenterExportedServiceListener)
ExtensionLoader.getExtensionLoader(ServiceListener.class).getExtension("exported");
Assertions.assertNotNull(singleRegistryCenterExportedServiceListener);
Assertions.assertEquals(
1,
singleRegistryCenterExportedServiceListener
.getExportedServices()
.size());
Assertions.assertEquals(
SingleRegistryCenterIntegrationService.class,
singleRegistryCenterExportedServiceListener
.getExportedServices()
.get(0)
.getInterfaceClass());
ServiceConfig singleRegistryCenterServiceConfig = singleRegistryCenterExportedServiceListener
.getExportedServices()
.get(0);
Assertions.assertNotNull(singleRegistryCenterServiceConfig);
Assertions.assertTrue(singleRegistryCenterServiceConfig.isExported());
}
/**
* Returns {@link ServiceDiscoveryRegistry} instance.
* <p>
* FIXME It's not a good way to obtain {@link ServiceDiscoveryRegistry} using Reflection.
*/
private ServiceDiscoveryRegistry getServiceDiscoveryRegistry() {
Collection<Registry> registries =
RegistryManager.getInstance(ApplicationModel.defaultModel()).getRegistries();
for (Registry registry : registries) {
if (registry instanceof ServiceDiscoveryRegistry) {
return (ServiceDiscoveryRegistry) registry;
}
}
return null;
}
/**
* Initialize the consumer.
*/
private void initConsumer() {
referenceConfig = new ReferenceConfig<>();
referenceConfig.setInterface(SingleRegistryCenterIntegrationService.class);
DubboBootstrap.getInstance().reference(referenceConfig);
referenceConfig.setRegistry(registryConfig);
referenceConfig.setScope(SCOPE_REMOTE);
referenceConfig.setGeneric("false");
referenceConfig.setProtocol(PROTOCOL_NAME);
}
/**
* There are some checkpoints needed to check before referring as follow :
* <ul>
* <li>ReferenceConfig has integrated into DubboBootstrap or not</li>
* </ul>
*/
private void beforeRefer() {
// ReferenceConfig has integrated into DubboBootstrap or not
Assertions.assertEquals(
referenceConfig.getScopeModel(),
DubboBootstrap.getInstance().getApplicationModel().getDefaultModule());
}
/**
* There are some checkpoints needed to check after referred as follow :
* <ul>
* <li>SingleRegistryCenterIntegrationService instance can't be null</li>
* <li>RPC works well or not</li>
* <li>Invoker is right or not</li>
* <li>Directory is null or not</li>
* <li>Registered interface is right or not</li>
* <li>Directory is available or not</li>
* <li>Directory is destroyed or not</li>
* <li>Directory has received notification or not</li>
* <li>ServiceDiscoveryRegistryDirectory should register or not</li>
* <li>ServiceDiscoveryRegistryDirectory's registered consumer url is right or not</li>
* <li>ServiceDiscoveryRegistryDirectory's registry is right or not</li>
* <li>Directory's invokers are right or not</li>
* </ul>
*/
private void afterRefer() {
// SingleRegistryCenterIntegrationService instance can't be null
Assertions.assertNotNull(singleRegistryCenterIntegrationService);
// Invoker is right or not
Assertions.assertNotNull(referenceConfig.getInvoker());
Assertions.assertTrue(referenceConfig.getInvoker() instanceof MigrationInvoker);
// RPC works well or not
Assertions.assertEquals("Hello Reference", singleRegistryCenterIntegrationService.hello("Reference"));
// get ServiceDiscoveryRegistryDirectory instance
Directory directory = ((MigrationInvoker) referenceConfig.getInvoker()).getDirectory();
// Directory is null or not
Assertions.assertNotNull(directory);
// Check Directory's type
Assertions.assertTrue(directory instanceof ServiceDiscoveryRegistryDirectory);
// Registered interface is right or not
Assertions.assertEquals(directory.getInterface(), SingleRegistryCenterIntegrationService.class);
// Directory is available or not
Assertions.assertTrue(directory.isAvailable());
// Directory is destroyed or not
Assertions.assertFalse(directory.isDestroyed());
// Directory has received notification or not
Assertions.assertTrue(directory.isNotificationReceived());
ServiceDiscoveryRegistryDirectory serviceDiscoveryRegistryDirectory =
(ServiceDiscoveryRegistryDirectory) directory;
// ServiceDiscoveryRegistryDirectory should register or not
Assertions.assertTrue(serviceDiscoveryRegistryDirectory.isShouldRegister());
// ServiceDiscoveryRegistryDirectory's registered consumer url is right or not
Assertions.assertEquals(
CONSUMERS_CATEGORY,
serviceDiscoveryRegistryDirectory.getRegisteredConsumerUrl().getCategory());
// ServiceDiscoveryRegistryDirectory's registry is right or not
Assertions.assertTrue(serviceDiscoveryRegistryDirectory.getRegistry() instanceof ListenerRegistryWrapper);
// Directory's invokers are right or not
Assertions.assertEquals(
1, serviceDiscoveryRegistryDirectory.getAllInvokers().size());
Assertions.assertEquals(
serviceDiscoveryRegistryDirectory.getInvokers(), serviceDiscoveryRegistryDirectory.getAllInvokers());
}
@AfterEach
public void tearDown() throws IOException {
DubboBootstrap.reset();
PROVIDER_APPLICATION_NAME = null;
PROTOCOL_NAME = null;
PROTOCOL_PORT = 0;
serviceConfig = null;
referenceConfig = null;
// The exported service has been unexported
Assertions.assertTrue(singleRegistryCenterExportedServiceListener
.getExportedServices()
.isEmpty());
singleRegistryCenterExportedServiceListener = null;
logger.info(getClass().getSimpleName() + " testcase is ending...");
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderExporterListener.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderExporterListener.java | /*
* 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.config.integration.single.exportprovider;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.config.integration.AbstractRegistryCenterExporterListener;
@Activate(group = CommonConstants.PROVIDER, order = 1000)
public class SingleRegistryCenterExportProviderExporterListener extends AbstractRegistryCenterExporterListener {
/**
* Returns the interface of exported service.
*/
@Override
protected Class<?> getInterface() {
return SingleRegistryCenterExportProviderService.class;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderService.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderService.java | /*
* 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.config.integration.single.exportprovider;
/**
* This interface is used to check if the exported provider works well or not.
*/
public interface SingleRegistryCenterExportProviderService {
/**
* The simple method for testing.
*/
String hello(String name);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderFilter.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderFilter.java | /*
* 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.config.integration.single.exportprovider;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;
@Activate(group = CommonConstants.PROVIDER, order = 10000)
public class SingleRegistryCenterExportProviderFilter implements Filter, Filter.Listener {
/**
* The filter is called or not
*/
private boolean called = false;
/**
* There has error after invoked
*/
private boolean error = false;
/**
* The returned result
*/
private String response;
/**
* Always call invoker.invoke() in the implementation to hand over the request to the next filter node.
*
* @param invoker
* @param invocation
*/
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
called = true;
return invoker.invoke(invocation);
}
@Override
public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
response = String.valueOf(appResponse.getValue());
}
@Override
public void onError(Throwable t, Invoker<?> invoker, Invocation invocation) {
error = true;
}
/**
* Returns if the filter has called.
*/
public boolean hasCalled() {
return called;
}
/**
* Returns if there exists error.
*/
public boolean hasError() {
return error;
}
/**
* Returns the response.
*/
public String getResponse() {
return response;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderIntegrationTest.java | /*
* 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.config.integration.single.exportprovider;
import org.apache.dubbo.common.config.configcenter.ConfigItem;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.ExtensionLoader;
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.apache.dubbo.config.ServiceListener;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.integration.IntegrationTest;
import org.apache.dubbo.metadata.ServiceNameMapping;
import org.apache.dubbo.metadata.report.MetadataReportInstance;
import org.apache.dubbo.registry.integration.RegistryProtocolListener;
import org.apache.dubbo.rpc.ExporterListener;
import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.dubbo.common.constants.CommonConstants.REGISTRY_PROTOCOL_LISTENER_KEY;
import static org.apache.dubbo.config.integration.Constants.SINGLE_CONFIG_CENTER_EXPORT_PROVIDER;
import static org.apache.dubbo.rpc.Constants.SCOPE_LOCAL;
/**
* The testcases are only for checking the core process of exporting provider.
*/
class SingleRegistryCenterExportProviderIntegrationTest implements IntegrationTest {
private static final Logger logger =
LoggerFactory.getLogger(SingleRegistryCenterExportProviderIntegrationTest.class);
/**
* Define the provider application name.
*/
private static String PROVIDER_APPLICATION_NAME = "single-registry-center-for-export-provider";
/**
* Define the protocol's name.
*/
private static String PROTOCOL_NAME = CommonConstants.DUBBO;
/**
* Define the protocol's port.
*/
private static int PROTOCOL_PORT = 20800;
/**
* Define the {@link ServiceConfig} instance.
*/
private ServiceConfig<SingleRegistryCenterExportProviderService> serviceConfig;
/**
* Define a {@link RegistryProtocolListener} instance.
*/
private SingleRegistryCenterExportProviderRegistryProtocolListener registryProtocolListener;
/**
* Define a {@link ExporterListener} instance.
*/
private SingleRegistryCenterExportProviderExporterListener exporterListener;
/**
* Define a {@link Filter} instance.
*/
private SingleRegistryCenterExportProviderFilter filter;
/**
* Define a {@link ServiceListener} instance.
*/
private SingleRegistryCenterExportProviderServiceListener serviceListener;
@BeforeEach
public void setUp() throws Exception {
logger.info(getClass().getSimpleName() + " testcase is beginning...");
DubboBootstrap.reset();
// initialize service config
serviceConfig = new ServiceConfig<>();
serviceConfig.setInterface(SingleRegistryCenterExportProviderService.class);
serviceConfig.setRef(new SingleRegistryCenterExportProviderServiceImpl());
serviceConfig.setAsync(false);
// initialize bootstrap
DubboBootstrap.getInstance()
.application(new ApplicationConfig(PROVIDER_APPLICATION_NAME))
.protocol(new ProtocolConfig(PROTOCOL_NAME, PROTOCOL_PORT))
.service(serviceConfig);
RegistryConfig registryConfig = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress());
Map<String, String> parameters = new HashMap<>();
parameters.put(REGISTRY_PROTOCOL_LISTENER_KEY, "singleConfigCenterExportProvider");
registryConfig.updateParameters(parameters);
DubboBootstrap.getInstance().registry(registryConfig);
}
/**
* There are some checkpoints need to verify as follow:
* <ul>
* <li>ServiceConfig is exported or not</li>
* <li>SingleRegistryCenterExportProviderRegistryProtocolListener is null or not</li>
* <li>There is nothing in ServiceListener or not</li>
* <li>There is nothing in ExporterListener or not</li>
* </ul>
*/
private void beforeExport() {
registryProtocolListener = (SingleRegistryCenterExportProviderRegistryProtocolListener)
ExtensionLoader.getExtensionLoader(RegistryProtocolListener.class)
.getExtension(SINGLE_CONFIG_CENTER_EXPORT_PROVIDER);
exporterListener = (SingleRegistryCenterExportProviderExporterListener)
ExtensionLoader.getExtensionLoader(ExporterListener.class)
.getExtension(SINGLE_CONFIG_CENTER_EXPORT_PROVIDER);
filter = (SingleRegistryCenterExportProviderFilter)
ExtensionLoader.getExtensionLoader(Filter.class).getExtension(SINGLE_CONFIG_CENTER_EXPORT_PROVIDER);
serviceListener = (SingleRegistryCenterExportProviderServiceListener)
ExtensionLoader.getExtensionLoader(ServiceListener.class)
.getExtension(SINGLE_CONFIG_CENTER_EXPORT_PROVIDER);
// ---------------checkpoints--------------- //
// ServiceConfig isn't exported
Assertions.assertFalse(serviceConfig.isExported());
// registryProtocolListener is just initialized by SPI
// so, all of fields are the default value.
Assertions.assertNotNull(registryProtocolListener);
Assertions.assertFalse(registryProtocolListener.isExported());
// There is nothing in ServiceListener
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
// There is nothing in ExporterListener
Assertions.assertTrue(exporterListener.getExportedExporters().isEmpty());
}
/**
* {@inheritDoc}
*/
@Test
@Override
public void integrate() {
beforeExport();
DubboBootstrap.getInstance().start();
afterExport();
ReferenceConfig<SingleRegistryCenterExportProviderService> referenceConfig = new ReferenceConfig<>();
referenceConfig.setInterface(SingleRegistryCenterExportProviderService.class);
referenceConfig.setScope(SCOPE_LOCAL);
referenceConfig.get().hello(PROVIDER_APPLICATION_NAME);
afterInvoke();
}
/**
* There are some checkpoints need to check after exported as follow:
* <ul>
* <li>the exporter is exported or not</li>
* <li>The exported exporter are three</li>
* <li>The exported service is SingleRegistryCenterExportProviderService or not</li>
* <li>The SingleRegistryCenterExportProviderService is exported or not</li>
* <li>The exported exporter contains SingleRegistryCenterExportProviderFilter or not</li>
* <li>The metadata mapping info is right or not</li>
* </ul>
*/
private void afterExport() {
// The exporter is exported
Assertions.assertTrue(registryProtocolListener.isExported());
// The exported service is only one
Assertions.assertEquals(serviceListener.getExportedServices().size(), 1);
// The exported service is SingleRegistryCenterExportProviderService
Assertions.assertEquals(
serviceListener.getExportedServices().get(0).getInterfaceClass(),
SingleRegistryCenterExportProviderService.class);
// The SingleRegistryCenterExportProviderService is exported
Assertions.assertTrue(serviceListener.getExportedServices().get(0).isExported());
// The exported exporter are three
// 1. InjvmExporter
// 2. DubboExporter with service-discovery-registry protocol
// 3. DubboExporter with registry protocol
Assertions.assertEquals(exporterListener.getExportedExporters().size(), 4);
// The exported exporter contains SingleRegistryCenterExportProviderFilter
Assertions.assertTrue(exporterListener.getFilters().contains(filter));
// The consumer can be notified and get provider's metadata through metadata mapping info.
// So, the metadata mapping is necessary to check after exported service (or provider)
// The best way to verify this issue is to check if the exported service (or provider)
// has been registered in the path of /dubbo/mapping/****
// What are the parameters?
// registryKey: the registryKey is the default cluster, CommonConstants.DEFAULT_KEY
// key: The exported interface's name
// group: the group is "mapping", ServiceNameMapping.DEFAULT_MAPPING_GROUP
ConfigItem configItem = ApplicationModel.defaultModel()
.getBeanFactory()
.getBean(MetadataReportInstance.class)
.getMetadataReport(CommonConstants.DEFAULT_KEY)
.getConfigItem(serviceConfig.getInterface(), ServiceNameMapping.DEFAULT_MAPPING_GROUP);
// Check if the exported service (provider) is registered
Assertions.assertNotNull(configItem);
// Check if registered service (provider)'s name is right
Assertions.assertEquals(PROVIDER_APPLICATION_NAME, configItem.getContent());
// Check if registered service (provider)'s version exists
Assertions.assertNotNull(configItem.getTicket());
}
/**
* There are some checkpoints need to check after invoked as follow:
* <ul>
* <li>The SingleRegistryCenterExportProviderFilter has called or not</li>
* <li>The SingleRegistryCenterExportProviderFilter exists error after invoked</li>
* <li>The SingleRegistryCenterExportProviderFilter's response is right or not</li>
* </ul>
*/
private void afterInvoke() {
// The SingleRegistryCenterExportProviderFilter has called
Assertions.assertTrue(filter.hasCalled());
// The SingleRegistryCenterExportProviderFilter doesn't exist error
Assertions.assertFalse(filter.hasError());
// Check the SingleRegistryCenterExportProviderFilter's response
Assertions.assertEquals("Hello " + PROVIDER_APPLICATION_NAME, filter.getResponse());
}
@AfterEach
public void tearDown() throws IOException {
DubboBootstrap.reset();
serviceConfig = null;
// The exported service has been unexported
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
logger.info(getClass().getSimpleName() + " testcase is ending...");
registryProtocolListener = null;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderServiceImpl.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderServiceImpl.java | /*
* 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.config.integration.single.exportprovider;
/**
* The implementation of {@link SingleRegistryCenterExportProviderService}
*/
public class SingleRegistryCenterExportProviderServiceImpl implements SingleRegistryCenterExportProviderService {
/**
* {@inheritDoc}
*/
@Override
public String hello(String name) {
return "Hello " + name;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderServiceListener.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderServiceListener.java | /*
* 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.config.integration.single.exportprovider;
import org.apache.dubbo.config.ServiceListener;
import org.apache.dubbo.config.integration.AbstractRegistryCenterServiceListener;
/**
* This implementation of {@link ServiceListener} is to record exported services with injvm protocol in single registry center.
*/
public class SingleRegistryCenterExportProviderServiceListener extends AbstractRegistryCenterServiceListener {
/**
* {@inheritDoc}
*/
@Override
protected Class<?> getInterface() {
return SingleRegistryCenterExportProviderService.class;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderRegistryProtocolListener.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportprovider/SingleRegistryCenterExportProviderRegistryProtocolListener.java | /*
* 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.config.integration.single.exportprovider;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.registry.integration.InterfaceCompatibleRegistryProtocol;
import org.apache.dubbo.registry.integration.RegistryProtocol;
import org.apache.dubbo.registry.integration.RegistryProtocolListener;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.cluster.ClusterInvoker;
import static org.apache.dubbo.config.integration.Constants.SINGLE_CONFIG_CENTER_EXPORT_PROVIDER;
/**
* The {@link RegistryProtocolListener} for {@link SingleRegistryCenterExportProviderService}
*/
@Activate(order = 100, value = SINGLE_CONFIG_CENTER_EXPORT_PROVIDER)
public class SingleRegistryCenterExportProviderRegistryProtocolListener implements RegistryProtocolListener {
private boolean exported = false;
/**
* {@inheritDoc}
*/
@Override
public void onExport(RegistryProtocol registryProtocol, Exporter<?> exporter) {
if (registryProtocol instanceof InterfaceCompatibleRegistryProtocol
&& exporter != null
&& exporter.getInvoker() != null
&& exporter.getInvoker().getInterface().equals(SingleRegistryCenterExportProviderService.class)) {
this.exported = true;
}
}
/**
* {@inheritDoc}
*/
@Override
public void onRefer(RegistryProtocol registryProtocol, ClusterInvoker<?> invoker, URL url, URL registryURL) {}
/**
* {@inheritDoc}
*/
@Override
public void onDestroy() {}
/**
* Returns if this exporter is exported.
*/
public boolean isExported() {
return exported;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmFilter.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmFilter.java | /*
* 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.config.integration.single.injvm;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;
@Activate(group = CommonConstants.PROVIDER, order = 10000)
public class SingleRegistryCenterInjvmFilter implements Filter, Filter.Listener {
/**
* The filter is called or not
*/
private boolean called = false;
/**
* There has error after invoked
*/
private boolean error = false;
/**
* The returned result
*/
private String response;
/**
* Always call invoker.invoke() in the implementation to hand over the request to the next filter node.
*
* @param invoker
* @param invocation
*/
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
called = true;
return invoker.invoke(invocation);
}
@Override
public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {
response = String.valueOf(appResponse.getValue());
}
@Override
public void onError(Throwable t, Invoker<?> invoker, Invocation invocation) {
error = true;
}
/**
* Returns if the filter has called.
*/
public boolean hasCalled() {
return called;
}
/**
* Returns if there exists error.
*/
public boolean hasError() {
return error;
}
/**
* Returns the response.
*/
public String getResponse() {
return response;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmIntegrationTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmIntegrationTest.java | /*
* 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.config.integration.single.injvm;
import org.apache.dubbo.common.extension.ExtensionLoader;
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.apache.dubbo.config.ServiceListener;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.integration.IntegrationTest;
import org.apache.dubbo.rpc.ExporterListener;
import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig;
import java.io.IOException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.dubbo.rpc.Constants.SCOPE_LOCAL;
/**
* The testcases are only for checking the process of exporting provider using injvm protocol.
*/
class SingleRegistryCenterInjvmIntegrationTest implements IntegrationTest {
private static final Logger logger = LoggerFactory.getLogger(SingleRegistryCenterInjvmIntegrationTest.class);
/**
* Define the provider application name.
*/
private static String PROVIDER_APPLICATION_NAME = "single-registry-center-provider-for-injvm-protocol";
/**
* The name for getting the specified instance, which is loaded using SPI.
*/
private static String SPI_NAME = "singleConfigCenterInjvm";
/**
* Define the {@link ServiceConfig} instance.
*/
private ServiceConfig<SingleRegistryCenterInjvmService> serviceConfig;
/**
* The listener to record exported services
*/
private SingleRegistryCenterInjvmServiceListener serviceListener;
/**
* The listener to record exported exporters.
*/
private SingleRegistryCenterInjvmExporterListener exporterListener;
/**
* The filter for checking filter chain.
*/
private SingleRegistryCenterInjvmFilter filter;
@BeforeEach
public void setUp() throws Exception {
logger.info(getClass().getSimpleName() + " testcase is beginning...");
DubboBootstrap.reset();
// initialize service config
serviceConfig = new ServiceConfig<>();
serviceConfig.setInterface(SingleRegistryCenterInjvmService.class);
serviceConfig.setRef(new SingleRegistryCenterInjvmServiceImpl());
serviceConfig.setAsync(false);
serviceConfig.setScope(SCOPE_LOCAL);
// initialize bootstrap
DubboBootstrap.getInstance()
.application(new ApplicationConfig(PROVIDER_APPLICATION_NAME))
.protocol(new ProtocolConfig("injvm"))
.service(serviceConfig);
RegistryConfig registryConfig = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress());
DubboBootstrap.getInstance().registry(registryConfig);
}
/**
* Define {@link ServiceListener}, {@link ExporterListener} and {@link Filter} for helping check.
* <p>Use SPI to load them before exporting.
* <p>After that, there are some checkpoints need to verify as follow:
* <ul>
* <li>There is nothing in ServiceListener or not</li>
* <li>There is nothing in ExporterListener or not</li>
* <li>ServiceConfig is exported or not</li>
* </ul>
*/
private void beforeExport() {
// ---------------initialize--------------- //
serviceListener = (SingleRegistryCenterInjvmServiceListener)
ExtensionLoader.getExtensionLoader(ServiceListener.class).getExtension(SPI_NAME);
exporterListener = (SingleRegistryCenterInjvmExporterListener)
ExtensionLoader.getExtensionLoader(ExporterListener.class).getExtension(SPI_NAME);
filter = (SingleRegistryCenterInjvmFilter)
ExtensionLoader.getExtensionLoader(Filter.class).getExtension(SPI_NAME);
// ---------------checkpoints--------------- //
// There is nothing in ServiceListener
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
// There is nothing in ExporterListener
Assertions.assertTrue(exporterListener.getExportedExporters().isEmpty());
// ServiceConfig isn't exported
Assertions.assertFalse(serviceConfig.isExported());
}
/**
* {@inheritDoc}
*/
@Test
@Override
public void integrate() {
beforeExport();
DubboBootstrap.getInstance().start();
afterExport();
ReferenceConfig<SingleRegistryCenterInjvmService> referenceConfig = new ReferenceConfig<>();
referenceConfig.setInterface(SingleRegistryCenterInjvmService.class);
referenceConfig.setScope(SCOPE_LOCAL);
referenceConfig.get().hello("Dubbo");
afterInvoke();
}
/**
* There are some checkpoints need to check after exported as follow:
* <ul>
* <li>The exported service is only one or not</li>
* <li>The exported service is SingleRegistryCenterInjvmService or not</li>
* <li>The SingleRegistryCenterInjvmService is exported or not</li>
* <li>The exported exporter is only one or not</li>
* <li>The exported exporter contains SingleRegistryCenterInjvmFilter or not</li>
* </ul>
*/
private void afterExport() {
// The exported service is only one
Assertions.assertEquals(serviceListener.getExportedServices().size(), 1);
// The exported service is SingleRegistryCenterInjvmService
Assertions.assertEquals(
serviceListener.getExportedServices().get(0).getInterfaceClass(),
SingleRegistryCenterInjvmService.class);
// The SingleRegistryCenterInjvmService is exported
Assertions.assertTrue(serviceListener.getExportedServices().get(0).isExported());
// The exported exporter is only one
Assertions.assertEquals(exporterListener.getExportedExporters().size(), 3);
// The exported exporter contains SingleRegistryCenterInjvmFilter
Assertions.assertTrue(exporterListener.getFilters().contains(filter));
}
/**
* There are some checkpoints need to check after invoked as follow:
* <ul>
* <li>The SingleRegistryCenterInjvmFilter has called or not</li>
* <li>The SingleRegistryCenterInjvmFilter exists error after invoked</li>
* <li>The SingleRegistryCenterInjvmFilter's response is right or not</li>
* </ul>
*/
private void afterInvoke() {
// The SingleRegistryCenterInjvmFilter has called
Assertions.assertTrue(filter.hasCalled());
// The SingleRegistryCenterInjvmFilter doesn't exist error
Assertions.assertFalse(filter.hasError());
// Check the SingleRegistryCenterInjvmFilter's response
Assertions.assertEquals("Hello Dubbo", filter.getResponse());
}
@AfterEach
public void tearDown() throws IOException {
DubboBootstrap.reset();
serviceConfig = null;
// The exported service has been unexported
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
serviceListener = null;
logger.info(getClass().getSimpleName() + " testcase is ending...");
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmServiceImpl.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmServiceImpl.java | /*
* 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.config.integration.single.injvm;
/**
* The simple implementation for {@link SingleRegistryCenterInjvmService}
*/
public class SingleRegistryCenterInjvmServiceImpl implements SingleRegistryCenterInjvmService {
/**
* {@inheritDoc}
*/
@Override
public String hello(String name) {
return "Hello " + name;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmService.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmService.java | /*
* 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.config.integration.single.injvm;
/**
* This interface is used to check if the exported injvm protocol works well or not.
*/
public interface SingleRegistryCenterInjvmService {
/**
* The simple method for testing.
*/
String hello(String name);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmExporterListener.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmExporterListener.java | /*
* 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.config.integration.single.injvm;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.config.integration.AbstractRegistryCenterExporterListener;
@Activate(group = CommonConstants.PROVIDER, order = 1000)
public class SingleRegistryCenterInjvmExporterListener extends AbstractRegistryCenterExporterListener {
/**
* Returns the interface of exported service.
*/
@Override
protected Class<?> getInterface() {
return SingleRegistryCenterInjvmService.class;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmServiceListener.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/injvm/SingleRegistryCenterInjvmServiceListener.java | /*
* 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.config.integration.single.injvm;
import org.apache.dubbo.config.ServiceListener;
import org.apache.dubbo.config.integration.AbstractRegistryCenterServiceListener;
/**
* This implementation of {@link ServiceListener} is to record exported services with injvm protocol in single registry center.
*/
public class SingleRegistryCenterInjvmServiceListener extends AbstractRegistryCenterServiceListener {
/**
* {@inheritDoc}
*/
@Override
protected Class<?> getInterface() {
return SingleRegistryCenterInjvmService.class;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceListener.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceListener.java | /*
* 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.config.integration.single.exportmetadata;
import org.apache.dubbo.config.ServiceListener;
import org.apache.dubbo.config.integration.AbstractRegistryCenterServiceListener;
import org.apache.dubbo.metadata.MetadataService;
/**
* This implementation of {@link ServiceListener} is to record exported metadata services in single registry center.
*/
public class SingleRegistryCenterExportMetadataServiceListener extends AbstractRegistryCenterServiceListener {
/**
* {@inheritDoc}
*/
@Override
protected Class<?> getInterface() {
return MetadataService.class;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataExporterListener.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataExporterListener.java | /*
* 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.config.integration.single.exportmetadata;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.config.integration.AbstractRegistryCenterExporterListener;
import org.apache.dubbo.metadata.MetadataService;
@Activate(group = CommonConstants.PROVIDER, order = 1000)
public class SingleRegistryCenterExportMetadataExporterListener extends AbstractRegistryCenterExporterListener {
/**
* Returns the interface of exported service.
*/
@Override
protected Class<?> getInterface() {
return MetadataService.class;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceImpl.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataServiceImpl.java | /*
* 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.config.integration.single.exportmetadata;
/**
* The simple implementation for {@link SingleRegistryCenterExportMetadataService}
*/
public class SingleRegistryCenterExportMetadataServiceImpl implements SingleRegistryCenterExportMetadataService {
/**
* {@inheritDoc}
*/
@Override
public String hello(String name) {
return "Hello " + name;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataService.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataService.java | /*
* 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.config.integration.single.exportmetadata;
/**
* This interface is used to check if the exported metadata service works well or not.
*/
public interface SingleRegistryCenterExportMetadataService {
/**
* The simple method for testing.
*/
String hello(String name);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataIntegrationTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/integration/single/exportmetadata/SingleRegistryCenterExportMetadataIntegrationTest.java | /*
* 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.config.integration.single.exportmetadata;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.ServiceListener;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.integration.IntegrationTest;
import org.apache.dubbo.metadata.MetadataService;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.ExporterListener;
import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig;
import java.io.IOException;
import java.util.List;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.dubbo.rpc.Constants.SCOPE_LOCAL;
/**
* The testcases are only for checking the process of exporting metadata service.
*/
class SingleRegistryCenterExportMetadataIntegrationTest implements IntegrationTest {
private static final Logger logger =
LoggerFactory.getLogger(SingleRegistryCenterExportMetadataIntegrationTest.class);
/**
* Define the provider application name.
*/
private static String PROVIDER_APPLICATION_NAME = "single-registry-center-export-metadata";
/**
* The name for getting the specified instance, which is loaded using SPI.
*/
private static String SPI_NAME = "singleConfigCenterExportMetadata";
/**
* Define the protocol's name.
*/
private static String PROTOCOL_NAME = "injvm";
/**
* Define the {@link ServiceConfig} instance.
*/
private ServiceConfig<SingleRegistryCenterExportMetadataService> serviceConfig;
/**
* The listener to record exported services
*/
private SingleRegistryCenterExportMetadataServiceListener serviceListener;
/**
* The listener to record exported exporters.
*/
private SingleRegistryCenterExportMetadataExporterListener exporterListener;
@BeforeEach
public void setUp() throws Exception {
logger.info(getClass().getSimpleName() + " testcase is beginning...");
DubboBootstrap.reset();
// initialize service config
serviceConfig = new ServiceConfig<>();
serviceConfig.setInterface(SingleRegistryCenterExportMetadataService.class);
serviceConfig.setRef(new SingleRegistryCenterExportMetadataServiceImpl());
serviceConfig.setAsync(false);
serviceConfig.setScope(SCOPE_LOCAL);
// initialize bootstrap
DubboBootstrap.getInstance()
.application(new ApplicationConfig(PROVIDER_APPLICATION_NAME))
.protocol(new ProtocolConfig(PROTOCOL_NAME))
.service(serviceConfig);
RegistryConfig registryConfig = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress());
DubboBootstrap.getInstance().registry(registryConfig);
}
/**
* Define {@link ServiceListener}, {@link ExporterListener} and {@link Filter} for helping check.
* <p>Use SPI to load them before exporting.
* <p>After that, there are some checkpoints need to verify as follow:
* <ul>
* <li>There is nothing in ServiceListener or not</li>
* <li>There is nothing in ExporterListener or not</li>
* <li>ServiceConfig is exported or not</li>
* </ul>
*/
private void beforeExport() {
// ---------------initialize--------------- //
serviceListener = (SingleRegistryCenterExportMetadataServiceListener)
ExtensionLoader.getExtensionLoader(ServiceListener.class).getExtension(SPI_NAME);
exporterListener = (SingleRegistryCenterExportMetadataExporterListener)
ExtensionLoader.getExtensionLoader(ExporterListener.class).getExtension(SPI_NAME);
// ---------------checkpoints--------------- //
// There is nothing in ServiceListener
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
// There is nothing in ExporterListener
Assertions.assertTrue(exporterListener.getExportedExporters().isEmpty());
// ServiceConfig isn't exported
Assertions.assertFalse(serviceConfig.isExported());
}
/**
* {@inheritDoc}
*/
@Test
@Override
public void integrate() {
beforeExport();
DubboBootstrap.getInstance().start();
afterExport();
}
/**
* There are some checkpoints need to check after exported as follow:
* <ul>
* <li>The metadata service is only one or not</li>
* <li>The exported service is MetadataService or not</li>
* <li>The MetadataService is exported or not</li>
* <li>The exported exporters are right or not</li>
* </ul>
*/
private void afterExport() {
// The metadata service is only one
Assertions.assertEquals(serviceListener.getExportedServices().size(), 1);
// The exported service is MetadataService
Assertions.assertEquals(
serviceListener.getExportedServices().get(0).getInterfaceClass(), MetadataService.class);
// The MetadataService is exported
Assertions.assertTrue(serviceListener.getExportedServices().get(0).isExported());
// There are two exported exporters
// 1. Metadata Service exporter with Injvm protocol
// 2. SingleRegistryCenterExportMetadataService exporter with Injvm protocol
Assertions.assertEquals(exporterListener.getExportedExporters().size(), 2);
List<Exporter<?>> injvmExporters = exporterListener.getExportedExporters();
// Make sure there are 2 injvmExporters
Assertions.assertEquals(2, injvmExporters.size());
}
@AfterEach
public void tearDown() throws IOException {
DubboBootstrap.reset();
serviceConfig = null;
// The exported service has been unexported
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
serviceListener = null;
logger.info(getClass().getSimpleName() + " testcase is ending...");
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/metadata/MetadataServiceURLParamsMetadataCustomizerTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/metadata/MetadataServiceURLParamsMetadataCustomizerTest.java | /*
* 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.config.metadata;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.JsonUtils;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.api.DemoService;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.provider.impl.DemoServiceImpl;
import org.apache.dubbo.registry.client.DefaultServiceInstance;
import org.apache.dubbo.rpc.model.ApplicationModel;
import java.io.IOException;
import java.util.Map;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_METADATA_STORAGE_TYPE;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PORT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.registry.client.metadata.ServiceInstanceMetadataUtils.METADATA_SERVICE_URL_PARAMS_PROPERTY_NAME;
class MetadataServiceURLParamsMetadataCustomizerTest {
public DefaultServiceInstance instance;
private URL metadataServiceURL = URL.valueOf(
"dubbo://10.225.12.124:2002/org.apache.dubbo.metadata.MetadataService"
+ "?application=MetadataServiceURLParamsMetadataCustomizerTest&group=MetadataServiceURLParamsMetadataCustomizerTest"
+ "&interface=org.apache.dubbo.metadata.MetadataService&side=provider×tamp=1637573430740&version=1.0.0");
public static DefaultServiceInstance createInstance() {
return new DefaultServiceInstance("A", "127.0.0.1", 20880, ApplicationModel.defaultModel());
}
@BeforeEach
public void init() {
instance = createInstance();
}
@AfterEach
public void tearDown() throws IOException {
Mockito.framework().clearInlineMocks();
}
@Test
void test() throws InterruptedException {
DubboBootstrap providerBootstrap = DubboBootstrap.newInstance();
ServiceConfig<DemoService> serviceConfig = new ServiceConfig<>();
serviceConfig.setInterface(DemoService.class);
serviceConfig.setRef(new DemoServiceImpl());
serviceConfig.setDelay(1000);
ApplicationConfig applicationConfig = new ApplicationConfig("MetadataServiceURLParamsMetadataCustomizerTest");
applicationConfig.setMetadataType(DEFAULT_METADATA_STORAGE_TYPE);
providerBootstrap
.application(applicationConfig)
.registry(new RegistryConfig("N/A"))
.protocol(new ProtocolConfig("dubbo", 2002))
.service(serviceConfig);
// will start exporter.export()
providerBootstrap.start();
ApplicationModel applicationModel = providerBootstrap.getApplicationModel();
MetadataServiceURLParamsMetadataCustomizer customizer = new MetadataServiceURLParamsMetadataCustomizer();
Thread.sleep(5000); // wait for service delay export
customizer.customize(instance, applicationModel);
String val = instance.getMetadata().get(METADATA_SERVICE_URL_PARAMS_PROPERTY_NAME);
Assertions.assertNotNull(val);
Map<String, String> map = JsonUtils.toJavaObject(val, Map.class);
Assertions.assertEquals(map.get(PORT_KEY), String.valueOf(metadataServiceURL.getPort()));
Assertions.assertEquals(map.get(PROTOCOL_KEY), metadataServiceURL.getProtocol());
Assertions.assertEquals(map.get(VERSION_KEY), metadataServiceURL.getVersion());
Assertions.assertFalse(map.containsKey(TIMESTAMP_KEY));
Assertions.assertFalse(map.containsKey(GROUP_KEY));
Assertions.assertFalse(map.containsKey(APPLICATION_KEY));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/cache/CacheTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/cache/CacheTest.java | /*
* 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.config.cache;
import org.apache.dubbo.cache.Cache;
import org.apache.dubbo.cache.CacheFactory;
import org.apache.dubbo.cache.support.threadlocal.ThreadLocalCache;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.url.component.ServiceConfigURL;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.MethodConfig;
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.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.RpcInvocation;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class CacheTest {
@BeforeEach
public void setUp() {
DubboBootstrap.reset();
}
@AfterEach
public void tearDown() {
// ApplicationModel.defaultModel().getConfigManager().clear();
}
private void testCache(String type) throws Exception {
ApplicationConfig applicationConfig = new ApplicationConfig("cache-test");
RegistryConfig registryConfig = new RegistryConfig("N/A");
ProtocolConfig protocolConfig = new ProtocolConfig("injvm");
ServiceConfig<CacheService> service = new ServiceConfig<CacheService>();
service.setApplication(applicationConfig);
service.setRegistry(registryConfig);
service.setProtocol(protocolConfig);
service.setInterface(CacheService.class.getName());
service.setRef(new CacheServiceImpl());
service.export();
try {
ReferenceConfig<CacheService> reference = new ReferenceConfig<CacheService>();
reference.setApplication(applicationConfig);
reference.setInterface(CacheService.class);
reference.setUrl("injvm://127.0.0.1?scope=remote&cache=true");
MethodConfig method = new MethodConfig();
method.setName("findCache");
method.setCache(type);
reference.setMethods(Arrays.asList(method));
CacheService cacheService = reference.get();
try {
// verify cache, same result is returned for multiple invocations (in fact, the return value increases
// on every invocation on the server side)
String fix = null;
cacheService.findCache("0");
for (int i = 0; i < 3; i++) {
String result = cacheService.findCache("0");
assertTrue(fix == null || fix.equals(result));
fix = result;
Thread.sleep(100);
}
if ("lru".equals(type)) {
// default cache.size is 1000 for LRU, should have cache expired if invoke more than 1001 times
for (int n = 0; n < 1001; n++) {
String pre = null;
cacheService.findCache(String.valueOf(n));
for (int i = 0; i < 10; i++) {
String result = cacheService.findCache(String.valueOf(n));
assertTrue(pre == null || pre.equals(result));
pre = result;
}
}
// verify if the first cache item is expired in LRU cache
String result = cacheService.findCache("0");
assertFalse(fix == null || fix.equals(result));
}
} finally {
reference.destroy();
}
} finally {
service.unexport();
}
}
@Test
void testCacheLru() throws Exception {
testCache("lru");
}
@Test
void testCacheThreadlocal() throws Exception {
testCache("threadlocal");
}
@Test
void testCacheProvider() {
CacheFactory cacheFactory =
ExtensionLoader.getExtensionLoader(CacheFactory.class).getAdaptiveExtension();
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("findCache.cache", "threadlocal");
URL url = new ServiceConfigURL(
"dubbo", "127.0.0.1", 29582, "org.apache.dubbo.config.cache.CacheService", parameters);
Invocation invocation = new RpcInvocation(
"findCache",
CacheService.class.getName(),
"",
new Class[] {String.class},
new String[] {"0"},
null,
null,
null);
Cache cache = cacheFactory.getCache(url, invocation);
assertTrue(cache instanceof ThreadLocalCache);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/cache/CacheServiceImpl.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/cache/CacheServiceImpl.java | /*
* 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.config.cache;
import java.util.concurrent.atomic.AtomicInteger;
/**
* ValidationServiceImpl
*/
public class CacheServiceImpl implements CacheService {
private final AtomicInteger i = new AtomicInteger();
public String findCache(String id) {
return "request: " + id + ", response: " + i.getAndIncrement();
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/cache/CacheService.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/cache/CacheService.java | /*
* 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.config.cache;
/**
* ValidationService
*/
public interface CacheService {
String findCache(String id);
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployerTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/deploy/DefaultApplicationDeployerTest.java | /*
* 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.config.deploy;
import org.apache.dubbo.common.utils.Assert;
import org.apache.dubbo.config.MetricsConfig;
import org.apache.dubbo.metrics.utils.MetricsSupportUtil;
import org.junit.jupiter.api.Test;
import static org.apache.dubbo.common.constants.MetricsConstants.PROTOCOL_PROMETHEUS;
class DefaultApplicationDeployerTest {
@Test
void isSupportPrometheus() {
boolean supportPrometheus = MetricsSupportUtil.isSupportPrometheus();
Assert.assertTrue(supportPrometheus, "MetricsSupportUtil.isSupportPrometheus() should return true");
}
@Test
void isImportPrometheus() {
MetricsConfig metricsConfig = new MetricsConfig();
metricsConfig.setProtocol("prometheus");
boolean importPrometheus =
PROTOCOL_PROMETHEUS.equals(metricsConfig.getProtocol()) && !MetricsSupportUtil.isSupportPrometheus();
Assert.assertTrue(!importPrometheus, " should return false");
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockExchanger.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockExchanger.java | /*
* 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.config.mock;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.remoting.RemotingException;
import org.apache.dubbo.remoting.exchange.ExchangeClient;
import org.apache.dubbo.remoting.exchange.ExchangeHandler;
import org.apache.dubbo.remoting.exchange.ExchangeServer;
import org.apache.dubbo.remoting.exchange.Exchanger;
public class MockExchanger implements Exchanger {
@Override
public ExchangeServer bind(URL url, ExchangeHandler handler) throws RemotingException {
return null;
}
@Override
public ExchangeClient connect(URL url, ExchangeHandler handler) throws RemotingException {
return null;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockServiceDiscovery.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockServiceDiscovery.java | /*
* 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.config.mock;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.registry.client.AbstractServiceDiscovery;
import org.apache.dubbo.registry.client.ServiceInstance;
import org.apache.dubbo.rpc.model.ApplicationModel;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class MockServiceDiscovery extends AbstractServiceDiscovery {
private URL registryURL;
public MockServiceDiscovery(ApplicationModel applicationModel, URL registryURL) {
super(applicationModel, registryURL);
}
public MockServiceDiscovery(String serviceName, URL registryURL) {
super(serviceName, registryURL);
}
@Override
public void doDestroy() throws Exception {}
@Override
public void doRegister(ServiceInstance serviceInstance) throws RuntimeException {
this.serviceInstance = serviceInstance;
}
@Override
protected void doUpdate(ServiceInstance oldServiceInstance, ServiceInstance newServiceInstance)
throws RuntimeException {
this.serviceInstance = newServiceInstance;
}
@Override
public void doUnregister(ServiceInstance serviceInstance) throws RuntimeException {
this.serviceInstance = null;
}
@Override
public Set<String> getServices() {
return new HashSet<>();
}
@Override
public List<ServiceInstance> getInstances(String serviceName) throws NullPointerException {
return Collections.emptyList();
}
@Override
public URL getUrl() {
return registryURL;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockRegistryFactory2.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockRegistryFactory2.java | /*
* 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.config.mock;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.RegistryFactory;
public class MockRegistryFactory2 implements RegistryFactory {
public static Registry registry;
@Override
public Registry getRegistry(URL url) {
return registry;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockServiceListener.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockServiceListener.java | /*
* 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.config.mock;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.ServiceListener;
import org.apache.dubbo.metadata.MetadataService;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class MockServiceListener implements ServiceListener {
private Map<String, ServiceConfig> exportedServices = new ConcurrentHashMap<>();
@Override
public void exported(ServiceConfig sc) {
// Ignore MetadataService
if (sc.getInterfaceClass() == MetadataService.class) {
return;
}
exportedServices.put(sc.getUniqueServiceName(), sc);
}
@Override
public void unexported(ServiceConfig sc) {}
public Map<String, ServiceConfig> getExportedServices() {
return exportedServices;
}
public void clearExportedServices() {
exportedServices.clear();
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockProtocol2.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockProtocol2.java | /*
* 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.config.mock;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.RpcException;
public class MockProtocol2 implements Protocol {
public static Protocol delegate;
@Override
public int getDefaultPort() {
return delegate.getDefaultPort();
}
@Override
public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException {
return delegate.export(invoker);
}
@Override
public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
return delegate.refer(type, url);
}
@Override
public void destroy() {
delegate.destroy();
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockThreadPool.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockThreadPool.java | /*
* 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.config.mock;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.threadpool.ThreadPool;
import java.util.concurrent.Executor;
public class MockThreadPool implements ThreadPool {
@Override
public Executor getExecutor(URL url) {
return null;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockRegistry.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockRegistry.java | /*
* 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.config.mock;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.url.component.ServiceConfigURL;
import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.Registry;
import java.util.ArrayList;
import java.util.List;
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY;
/**
* TODO Comment of MockRegistry
*/
public class MockRegistry implements Registry {
static URL subscribedUrl = new ServiceConfigURL("null", "0.0.0.0", 0);
public static URL getSubscribedUrl() {
return subscribedUrl;
}
/*
* @see org.apache.dubbo.common.Node#getUrl()
*/
public URL getUrl() {
return null;
}
/*
* @see org.apache.dubbo.common.Node#isAvailable()
*/
@Override
public boolean isAvailable() {
return true;
}
/*
* @see org.apache.dubbo.common.Node#destroy()
*/
@Override
public void destroy() {}
/*
* @see org.apache.dubbo.registry.RegistryService#register(org.apache.dubbo.common.URL)
*/
@Override
public void register(URL url) {}
/*
* @see org.apache.dubbo.registry.RegistryService#unregister(org.apache.dubbo.common.URL)
*/
@Override
public void unregister(URL url) {}
/*
* @see org.apache.dubbo.registry.RegistryService#subscribe(org.apache.dubbo.common.URL, org.apache.dubbo.registry.NotifyListener)
*/
@Override
public void subscribe(URL url, NotifyListener listener) {
this.subscribedUrl = url;
List<URL> urls = new ArrayList<URL>();
urls.add(url.setProtocol("mockprotocol").removeParameter(CATEGORY_KEY).addParameter(METHODS_KEY, "sayHello"));
listener.notify(urls);
}
/*
* @see org.apache.dubbo.registry.RegistryService#unsubscribe(org.apache.dubbo.common.URL, org.apache.dubbo.registry.NotifyListener)
*/
@Override
public void unsubscribe(URL url, NotifyListener listener) {}
/*
* @see org.apache.dubbo.registry.RegistryService#lookup(org.apache.dubbo.common.URL)
*/
@Override
public List<URL> lookup(URL url) {
return null;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockProtocol.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockProtocol.java | /*
* 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.config.mock;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;
import org.mockito.Mockito;
public class MockProtocol implements Protocol {
/* (non-Javadoc)
* @see org.apache.dubbo.rpc.Protocol#getDefaultPort()
*/
@Override
public int getDefaultPort() {
return 0;
}
/* (non-Javadoc)
* @see org.apache.dubbo.rpc.Protocol#export(org.apache.dubbo.rpc.Invoker)
*/
@Override
public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException {
return Mockito.mock(Exporter.class);
}
/* (non-Javadoc)
* @see org.apache.dubbo.rpc.Protocol#refer(java.lang.Class, org.apache.dubbo.common.URL)
*/
@Override
public <T> Invoker<T> refer(Class<T> type, URL url) throws RpcException {
final URL u = url;
return new Invoker<T>() {
@Override
public Class<T> getInterface() {
return null;
}
public URL getUrl() {
return u;
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public Result invoke(Invocation invocation) throws RpcException {
return null;
}
@Override
public void destroy() {}
};
}
/* (non-Javadoc)
* @see org.apache.dubbo.rpc.Protocol#destroy()
*/
@Override
public void destroy() {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/GreetingLocal1.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/GreetingLocal1.java | /*
* 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.config.mock;
public class GreetingLocal1 {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockProxyFactory.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockProxyFactory.java | /*
* 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.config.mock;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.ProxyFactory;
import org.apache.dubbo.rpc.RpcException;
public class MockProxyFactory implements ProxyFactory {
@Override
public <T> T getProxy(Invoker<T> invoker) throws RpcException {
return null;
}
@Override
public <T> T getProxy(Invoker<T> invoker, boolean generic) throws RpcException {
return null;
}
@Override
public <T> Invoker<T> getInvoker(T proxy, Class<T> type, URL url) throws RpcException {
return null;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockCluster.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockCluster.java | /*
* 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.config.mock;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.cluster.Cluster;
import org.apache.dubbo.rpc.cluster.Directory;
public class MockCluster implements Cluster {
@Override
public <T> Invoker<T> join(Directory<T> directory, boolean buildFilterChain) throws RpcException {
return null;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockExporterListener.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockExporterListener.java | /*
* 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.config.mock;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.ExporterListener;
import org.apache.dubbo.rpc.RpcException;
public class MockExporterListener implements ExporterListener {
@Override
public void exported(Exporter<?> exporter) throws RpcException {}
@Override
public void unexported(Exporter<?> exporter) {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockFilter.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockFilter.java | /*
* 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.config.mock;
import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;
public class MockFilter implements Filter {
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
return null;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockTransporter.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockTransporter.java | /*
* 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.config.mock;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.remoting.ChannelHandler;
import org.apache.dubbo.remoting.Client;
import org.apache.dubbo.remoting.RemotingException;
import org.apache.dubbo.remoting.RemotingServer;
import org.apache.dubbo.remoting.Transporter;
import org.mockito.Mockito;
public class MockTransporter implements Transporter {
private RemotingServer server = Mockito.mock(RemotingServer.class);
private Client client = Mockito.mock(Client.class);
@Override
public RemotingServer bind(URL url, ChannelHandler handler) throws RemotingException {
return server;
}
@Override
public Client connect(URL url, ChannelHandler handler) throws RemotingException {
return client;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockTelnetHandler.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockTelnetHandler.java | /*
* 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.config.mock;
import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.remoting.RemotingException;
import org.apache.dubbo.remoting.telnet.TelnetHandler;
public class MockTelnetHandler implements TelnetHandler {
@Override
public String telnet(Channel channel, String message) throws RemotingException {
return null;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockInvokerListener.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockInvokerListener.java | /*
* 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.config.mock;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.InvokerListener;
import org.apache.dubbo.rpc.RpcException;
public class MockInvokerListener implements InvokerListener {
@Override
public void referred(Invoker<?> invoker) throws RpcException {}
@Override
public void destroyed(Invoker<?> invoker) {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockLoadBalance.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockLoadBalance.java | /*
* 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.config.mock;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.cluster.LoadBalance;
import java.util.List;
public class MockLoadBalance implements LoadBalance {
@Override
public <T> Invoker<T> select(List<Invoker<T>> invokers, URL url, Invocation invocation) throws RpcException {
return null;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockDispatcher.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockDispatcher.java | /*
* 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.config.mock;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.remoting.ChannelHandler;
import org.apache.dubbo.remoting.Dispatcher;
public class MockDispatcher implements Dispatcher {
@Override
public ChannelHandler dispatch(ChannelHandler handler, URL url) {
return null;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockCodec.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockCodec.java | /*
* 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.config.mock;
import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.remoting.Codec;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class MockCodec implements Codec {
@Override
public void encode(Channel channel, OutputStream output, Object message) throws IOException {}
@Override
public Object decode(Channel channel, InputStream input) throws IOException {
return null;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/TestProxyFactory.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/TestProxyFactory.java | /*
* 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.config.mock;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.proxy.jdk.JdkProxyFactory;
public class TestProxyFactory extends JdkProxyFactory {
public static int count = 0;
@Override
public <T> Invoker<T> getInvoker(T proxy, Class<T> type, URL url) throws RpcException {
count++;
return super.getInvoker(proxy, type, url);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/GreetingLocal2.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/GreetingLocal2.java | /*
* 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.config.mock;
import org.apache.dubbo.config.api.Greeting;
public class GreetingLocal2 implements Greeting {
@Override
public String hello() {
return "local";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockStatusChecker.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockStatusChecker.java | /*
* 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.config.mock;
import org.apache.dubbo.common.status.Status;
import org.apache.dubbo.common.status.StatusChecker;
public class MockStatusChecker implements StatusChecker {
@Override
public Status check() {
return null;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockRegistryFactory.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/MockRegistryFactory.java | /*
* 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.config.mock;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.RegistryFactory;
/**
* TODO Comment of MockRegistryFactory
*/
public class MockRegistryFactory implements RegistryFactory {
/*
* @see org.apache.dubbo.registry.RegistryFactory#getRegistry(org.apache.dubbo.common.URL)
*/
@Override
public Registry getRegistry(URL url) {
return new MockRegistry();
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/GreetingLocal3.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/mock/GreetingLocal3.java | /*
* 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.config.mock;
import org.apache.dubbo.config.api.Greeting;
public class GreetingLocal3 implements Greeting {
private Greeting greeting;
public GreetingLocal3(Greeting greeting) {
this.greeting = greeting;
}
@Override
public String hello() {
return null;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/DubboBootstrapTest.java | /*
* 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.config.bootstrap;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.deploy.ApplicationDeployListener;
import org.apache.dubbo.common.url.component.ServiceConfigURL;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.ReflectUtils;
import org.apache.dubbo.common.utils.SystemPropertyConfigUtils;
import org.apache.dubbo.config.AbstractInterfaceConfig;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.MetadataReportConfig;
import org.apache.dubbo.config.MonitorConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.SysProps;
import org.apache.dubbo.config.api.DemoService;
import org.apache.dubbo.config.deploy.DefaultApplicationDeployer;
import org.apache.dubbo.config.metadata.ConfigurableMetadataServiceExporter;
import org.apache.dubbo.config.metadata.ExporterDeployListener;
import org.apache.dubbo.config.nested.TripleConfig;
import org.apache.dubbo.config.provider.impl.DemoServiceImpl;
import org.apache.dubbo.config.utils.ConfigValidationUtils;
import org.apache.dubbo.metadata.MetadataService;
import org.apache.dubbo.metadata.report.MetadataReport;
import org.apache.dubbo.metadata.report.MetadataReportInstance;
import org.apache.dubbo.monitor.MonitorService;
import org.apache.dubbo.registry.RegistryService;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol;
import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.stream.Collectors;
import com.google.common.collect.Maps;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import static org.apache.dubbo.common.constants.CommonConstants.CONFIG_NAMESPACE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_MONITOR_ADDRESS;
import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE;
import static org.apache.dubbo.common.constants.CommonConstants.SHUTDOWN_WAIT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SHUTDOWN_WAIT_SECONDS_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_CLUSTER_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_KEY;
import static org.apache.dubbo.metadata.MetadataConstants.REPORT_CONSUMER_URL_KEY;
import static org.hamcrest.CoreMatchers.anything;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.is;
/**
* {@link DubboBootstrap} Test
*
* @since 2.7.5
*/
class DubboBootstrapTest {
private static File dubboProperties;
private static String zkServerAddress;
@BeforeAll
public static void setUp(@TempDir Path folder) {
DubboBootstrap.reset();
zkServerAddress = System.getProperty("zookeeper.connection.address.1");
dubboProperties = folder.resolve(CommonConstants.DubboProperty.DUBBO_PROPERTIES_KEY)
.toFile();
SystemPropertyConfigUtils.setSystemProperty(
CommonConstants.DubboProperty.DUBBO_PROPERTIES_KEY, dubboProperties.getAbsolutePath());
}
@AfterAll
public static void tearDown() {
SystemPropertyConfigUtils.clearSystemProperty(CommonConstants.DubboProperty.DUBBO_PROPERTIES_KEY);
}
@BeforeEach
public void beforeEach() {
DubboBootstrap.reset();
SysProps.clear();
SysProps.setProperty("dubbo.metrics.enabled", "false");
SysProps.setProperty("dubbo.metrics.protocol", "disabled");
}
@AfterEach
public void afterEach() throws IOException {
DubboBootstrap.reset();
ApplicationModel.reset();
SysProps.clear();
}
@Test
void checkApplication() {
SysProps.setProperty("dubbo.application.name", "demo");
ApplicationConfig applicationConfig = new ApplicationConfig();
applicationConfig.refresh();
Assertions.assertEquals("demo", applicationConfig.getName());
}
@Test
void compatibleApplicationShutdown() {
try {
System.clearProperty(SHUTDOWN_WAIT_KEY);
System.clearProperty(SHUTDOWN_WAIT_SECONDS_KEY);
writeDubboProperties(SHUTDOWN_WAIT_KEY, "100");
ApplicationModel.defaultModel()
.modelEnvironment()
.getPropertiesConfiguration()
.refresh();
ConfigValidationUtils.validateApplicationConfig(new ApplicationConfig("demo"));
Assertions.assertEquals("100", System.getProperty(SHUTDOWN_WAIT_KEY));
System.clearProperty(SHUTDOWN_WAIT_KEY);
writeDubboProperties(SHUTDOWN_WAIT_SECONDS_KEY, "1000");
ApplicationModel.defaultModel()
.modelEnvironment()
.getPropertiesConfiguration()
.refresh();
ConfigValidationUtils.validateApplicationConfig(new ApplicationConfig("demo"));
Assertions.assertEquals("1000", System.getProperty(SHUTDOWN_WAIT_SECONDS_KEY));
} finally {
System.clearProperty("dubbo.application.name");
System.clearProperty(SHUTDOWN_WAIT_KEY);
System.clearProperty(SHUTDOWN_WAIT_SECONDS_KEY);
}
}
@Test
void testLoadRegistries() {
ServiceConfig serviceConfig = new ServiceConfig();
serviceConfig.setInterface(DemoService.class);
serviceConfig.setRef(new DemoServiceImpl());
serviceConfig.setApplication(new ApplicationConfig("testLoadRegistries"));
String registryId = "nacosRegistry";
String namespace1 = "test";
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setId(registryId);
registryConfig.setAddress("nacos://addr1:8848");
Map<String, String> registryParamMap = Maps.newHashMap();
registryParamMap.put(CONFIG_NAMESPACE_KEY, namespace1);
registryConfig.setParameters(registryParamMap);
String namespace2 = "test2";
RegistryConfig registryConfig2 = new RegistryConfig();
registryConfig2.setAddress("polaris://addr1:9999");
Map<String, String> registryParamMap2 = Maps.newHashMap();
registryParamMap2.put(CONFIG_NAMESPACE_KEY, namespace2);
registryConfig2.setParameters(registryParamMap2);
serviceConfig.setRegistries(Arrays.asList(registryConfig, registryConfig2));
// load configs from props
DubboBootstrap.getInstance().initialize();
serviceConfig.refresh();
// ApplicationModel.defaultModel().getEnvironment().setDynamicConfiguration(new
// CompositeDynamicConfiguration());
List<URL> urls = ConfigValidationUtils.loadRegistries(serviceConfig, true);
Assertions.assertEquals(4, urls.size());
Map<String, List<URL>> urlsMap =
urls.stream().collect(Collectors.groupingBy(url -> url.getParameter(REGISTRY_KEY)));
Assertions.assertEquals(2, urlsMap.get("nacos").size());
for (URL url : urlsMap.get("nacos")) {
Assertions.assertTrue(url.getProtocol().contains("registry"));
Assertions.assertEquals("addr1:8848", url.getAddress());
Assertions.assertEquals(RegistryService.class.getName(), url.getPath());
Assertions.assertEquals(registryId + ":" + namespace1, url.getParameter(REGISTRY_CLUSTER_KEY));
Assertions.assertTrue(url.getParameters().containsKey("timestamp"));
Assertions.assertTrue(url.getParameters().containsKey("pid"));
Assertions.assertTrue(url.getParameters().containsKey("registry"));
Assertions.assertTrue(url.getParameters().containsKey("dubbo"));
}
Assertions.assertEquals(2, urlsMap.get("polaris").size());
for (URL url : urlsMap.get("polaris")) {
Assertions.assertTrue(url.getProtocol().contains("registry"));
Assertions.assertEquals("addr1:9999", url.getAddress());
Assertions.assertEquals(RegistryService.class.getName(), url.getPath());
Assertions.assertEquals(DEFAULT_KEY + ":" + namespace2, url.getParameter(REGISTRY_CLUSTER_KEY));
Assertions.assertTrue(url.getParameters().containsKey("timestamp"));
Assertions.assertTrue(url.getParameters().containsKey("pid"));
Assertions.assertTrue(url.getParameters().containsKey("registry"));
Assertions.assertTrue(url.getParameters().containsKey("dubbo"));
}
}
@Test
void testRegistryWithMetadataReport() {
ServiceConfig serviceConfig = new ServiceConfig();
serviceConfig.setInterface(DemoService.class);
serviceConfig.setRef(new DemoServiceImpl());
List<RegistryConfig> registryConfigs = new ArrayList<>();
List<MetadataReportConfig> metadataReportConfigs = new ArrayList<>();
String registryId = "nacosRegistry";
String namespace1 = "test";
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setId(registryId);
registryConfig.setAddress(zkServerAddress);
Map<String, String> registryParamMap = Maps.newHashMap();
registryParamMap.put(CONFIG_NAMESPACE_KEY, namespace1);
registryConfig.setParameters(registryParamMap);
registryConfigs.add(registryConfig);
MetadataReportConfig metadataReportConfig = new MetadataReportConfig();
metadataReportConfig.setRegistry(registryId);
metadataReportConfig.setAddress(registryConfig.getAddress());
Map<String, String> metadataParamMap = Maps.newHashMap();
metadataParamMap.put(CONFIG_NAMESPACE_KEY, namespace1);
metadataParamMap.put(REPORT_CONSUMER_URL_KEY, Boolean.TRUE.toString());
metadataReportConfig.setParameters(metadataParamMap);
metadataReportConfig.setReportMetadata(true);
metadataReportConfigs.add(metadataReportConfig);
String namespace2 = "test2";
RegistryConfig registryConfig2 = new RegistryConfig();
registryConfig2.setAddress(zkServerAddress);
Map<String, String> registryParamMap2 = Maps.newHashMap();
registryParamMap2.put(CONFIG_NAMESPACE_KEY, namespace2);
registryConfig2.setParameters(registryParamMap2);
registryConfigs.add(registryConfig2);
MetadataReportConfig metadataReportConfig2 = new MetadataReportConfig();
metadataReportConfig2.setAddress(registryConfig2.getAddress());
Map<String, String> metadataParamMap2 = Maps.newHashMap();
metadataParamMap2.put(CONFIG_NAMESPACE_KEY, namespace2);
metadataParamMap2.put(REPORT_CONSUMER_URL_KEY, Boolean.TRUE.toString());
metadataReportConfig2.setParameters(metadataParamMap2);
metadataReportConfig2.setReportMetadata(true);
metadataReportConfigs.add(metadataReportConfig2);
serviceConfig.setRegistries(registryConfigs);
DubboBootstrap.getInstance()
.application(new ApplicationConfig("testRegistryWithMetadataReport"))
.registries(registryConfigs)
.metadataReports(metadataReportConfigs)
.service(serviceConfig)
.protocol(new ProtocolConfig(CommonConstants.DUBBO_PROTOCOL, -1))
.start();
ApplicationModel applicationModel = DubboBootstrap.getInstance().getApplicationModel();
MetadataReportInstance metadataReportInstance =
applicationModel.getBeanFactory().getBean(MetadataReportInstance.class);
Map<String, MetadataReport> metadataReports = metadataReportInstance.getMetadataReports(true);
Assertions.assertEquals(2, metadataReports.size());
List<URL> urls = ConfigValidationUtils.loadRegistries(serviceConfig, true);
Assertions.assertEquals(4, urls.size());
for (URL url : urls) {
Assertions.assertTrue(metadataReports.containsKey(url.getParameter(REGISTRY_CLUSTER_KEY)));
}
}
@Test
void testLoadUserMonitor_address_only() {
// -Ddubbo.monitor.address=monitor-addr:12080
SysProps.setProperty(DUBBO_MONITOR_ADDRESS, "monitor-addr:12080");
URL url = ConfigValidationUtils.loadMonitor(
getTestInterfaceConfig(new MonitorConfig()), new ServiceConfigURL("dubbo", "addr1", 9090));
Assertions.assertEquals("monitor-addr:12080", url.getAddress());
Assertions.assertEquals(MonitorService.class.getName(), url.getParameter("interface"));
Assertions.assertNotNull(url.getParameter("dubbo"));
Assertions.assertNotNull(url.getParameter("pid"));
Assertions.assertNotNull(url.getParameter("timestamp"));
}
@Test
void testLoadUserMonitor_registry() {
// dubbo.monitor.protocol=registry
MonitorConfig monitorConfig = new MonitorConfig();
monitorConfig.setProtocol("registry");
URL url = ConfigValidationUtils.loadMonitor(
getTestInterfaceConfig(monitorConfig),
URL.valueOf(ZookeeperRegistryCenterConfig.getConnectionAddress()));
Assertions.assertEquals("dubbo", url.getProtocol());
Assertions.assertEquals("registry", url.getParameter("protocol"));
}
@Test
void testLoadUserMonitor_service_discovery() {
// dubbo.monitor.protocol=service-discovery-registry
MonitorConfig monitorConfig = new MonitorConfig();
monitorConfig.setProtocol("service-discovery-registry");
URL url = ConfigValidationUtils.loadMonitor(
getTestInterfaceConfig(monitorConfig),
URL.valueOf(ZookeeperRegistryCenterConfig.getConnectionAddress()));
Assertions.assertEquals("dubbo", url.getProtocol());
Assertions.assertEquals("service-discovery-registry", url.getParameter("protocol"));
}
@Test
void testLoadUserMonitor_no_monitor() {
URL url = ConfigValidationUtils.loadMonitor(
getTestInterfaceConfig(null), URL.valueOf(ZookeeperRegistryCenterConfig.getConnectionAddress()));
Assertions.assertNull(url);
}
@Test
void testLoadUserMonitor_user() {
// dubbo.monitor.protocol=user
MonitorConfig monitorConfig = new MonitorConfig();
monitorConfig.setProtocol("user");
URL url = ConfigValidationUtils.loadMonitor(
getTestInterfaceConfig(monitorConfig),
URL.valueOf(ZookeeperRegistryCenterConfig.getConnectionAddress()));
Assertions.assertEquals("user", url.getProtocol());
}
@Test
void testLoadUserMonitor_user_address() {
// dubbo.monitor.address=user://1.2.3.4:5678?k=v
MonitorConfig monitorConfig = new MonitorConfig();
monitorConfig.setAddress("user://1.2.3.4:5678?param1=value1");
URL url = ConfigValidationUtils.loadMonitor(
getTestInterfaceConfig(monitorConfig),
URL.valueOf(ZookeeperRegistryCenterConfig.getConnectionAddress()));
Assertions.assertEquals("user", url.getProtocol());
Assertions.assertEquals("1.2.3.4:5678", url.getAddress());
Assertions.assertEquals("value1", url.getParameter("param1"));
}
private InterfaceConfig getTestInterfaceConfig(MonitorConfig monitorConfig) {
InterfaceConfig interfaceConfig = new InterfaceConfig();
interfaceConfig.setApplication(new ApplicationConfig("testLoadMonitor"));
if (monitorConfig != null) {
interfaceConfig.setMonitor(monitorConfig);
}
return interfaceConfig;
}
@Test
void testBootstrapStart() {
ServiceConfig<DemoService> service = new ServiceConfig<>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap
.application(new ApplicationConfig("bootstrap-test"))
.registry(new RegistryConfig(zkServerAddress))
.protocol(new ProtocolConfig(CommonConstants.DUBBO_PROTOCOL, -1))
.service(service)
.start();
Assertions.assertTrue(bootstrap.isInitialized());
Assertions.assertTrue(bootstrap.isCompletion());
Assertions.assertFalse(bootstrap.isStopped());
ApplicationModel applicationModel = bootstrap.getApplicationModel();
DefaultApplicationDeployer applicationDeployer = getApplicationDeployer(applicationModel);
Assertions.assertNotNull(ReflectUtils.getFieldValue(applicationDeployer, "asyncMetadataFuture"));
Assertions.assertTrue(applicationModel
.getDefaultModule()
.getServiceRepository()
.getExportedServices()
.size()
> 0);
}
private DefaultApplicationDeployer getApplicationDeployer(ApplicationModel applicationModel) {
return (DefaultApplicationDeployer) DefaultApplicationDeployer.get(applicationModel);
}
@Test
void testLocalMetadataServiceExporter() {
ServiceConfig<DemoService> service = new ServiceConfig<>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
int availablePort = NetUtils.getAvailablePort();
ApplicationConfig applicationConfig = new ApplicationConfig("bootstrap-test");
applicationConfig.setMetadataServicePort(availablePort);
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap
.application(applicationConfig)
.registry(new RegistryConfig(zkServerAddress))
.protocol(new ProtocolConfig(CommonConstants.DUBBO_PROTOCOL, -1))
.service(service)
.start();
assertMetadataService(bootstrap, availablePort, true);
}
@Test
void testRemoteMetadataServiceExporter() {
ServiceConfig<DemoService> service = new ServiceConfig<>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
int availablePort = NetUtils.getAvailablePort();
ApplicationConfig applicationConfig = new ApplicationConfig("bootstrap-test");
applicationConfig.setMetadataServicePort(availablePort);
applicationConfig.setMetadataType(REMOTE_METADATA_STORAGE_TYPE);
RegistryConfig registryConfig = new RegistryConfig(zkServerAddress);
registryConfig.setUseAsMetadataCenter(false);
registryConfig.setUseAsConfigCenter(false);
DubboBootstrap.getInstance()
.application(applicationConfig)
.registry(registryConfig)
.protocol(new ProtocolConfig(CommonConstants.DUBBO_PROTOCOL, -1))
.service(service)
.metadataReport(new MetadataReportConfig(zkServerAddress))
.start();
assertMetadataService(DubboBootstrap.getInstance(), availablePort, false);
}
@Test
void testRemoteMetadataServiceExporterCheckMetadataType() {
Assertions.assertThrowsExactly(IllegalStateException.class, () -> {
ServiceConfig<DemoService> service = new ServiceConfig<>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
int availablePort = NetUtils.getAvailablePort();
ApplicationConfig applicationConfig = new ApplicationConfig("bootstrap-test");
applicationConfig.setMetadataServicePort(availablePort);
applicationConfig.setMetadataType(REMOTE_METADATA_STORAGE_TYPE);
RegistryConfig registryConfig = new RegistryConfig(zkServerAddress);
registryConfig.setUseAsMetadataCenter(false);
registryConfig.setUseAsConfigCenter(false);
DubboBootstrap.getInstance()
.application(applicationConfig)
.registry(registryConfig)
.protocol(new ProtocolConfig(CommonConstants.DUBBO_PROTOCOL, -1))
.service(service)
.start();
});
}
@Test
void testDefaultTriple() {
ServiceConfig<DemoService> service = new ServiceConfig<>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
TripleConfig triple = new TripleConfig();
triple.setMaxBodySize(50);
triple.setMaxResponseBodySize(100);
ProtocolConfig protocolConfig = new ProtocolConfig(CommonConstants.DUBBO_PROTOCOL, -1);
protocolConfig.setTriple(triple);
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap
.application(new ApplicationConfig("bootstrap-test"))
.registry(new RegistryConfig(zkServerAddress))
.protocol(protocolConfig)
.service(service)
.start();
TripleConfig tripleConfig = bootstrap
.getConfigManager()
.getProtocol(protocolConfig.getName())
.flatMap(protocol -> Optional.of(protocol.getTriple()))
.orElse(null);
// check custom value
Assertions.assertEquals(50, tripleConfig.getMaxBodySizeOrDefault());
Assertions.assertEquals(100, tripleConfig.getMaxResponseBodySizeOrDefault());
// check default value
Assertions.assertEquals(1 << 23, tripleConfig.getMaxChunkSizeOrDefault());
Assertions.assertEquals(8192, tripleConfig.getMaxHeaderSizeOrDefault());
Assertions.assertEquals(4096, tripleConfig.getMaxInitialLineLengthOrDefault());
Assertions.assertEquals(16384, tripleConfig.getInitialBufferSizeOrDefault());
Assertions.assertEquals(4096, tripleConfig.getHeaderTableSizeOrDefault());
Assertions.assertFalse(tripleConfig.getEnablePushOrDefault());
Assertions.assertEquals(Integer.MAX_VALUE, tripleConfig.getMaxConcurrentStreamsOrDefault());
Assertions.assertEquals(1 << 23, tripleConfig.getInitialWindowSizeOrDefault());
Assertions.assertEquals(1 << 16, tripleConfig.getConnectionInitialWindowSizeOrDefault());
Assertions.assertEquals(1 << 23, tripleConfig.getMaxFrameSizeOrDefault());
Assertions.assertEquals(1 << 15, tripleConfig.getMaxHeaderListSizeOrDefault());
}
private ExporterDeployListener getListener(ApplicationModel model) {
return (ExporterDeployListener)
model.getExtensionLoader(ApplicationDeployListener.class).getExtension("exporter");
}
private void assertMetadataService(DubboBootstrap bootstrap, int availablePort, boolean metadataExported) {
ExporterDeployListener listener = getListener(bootstrap.getApplicationModel());
ConfigurableMetadataServiceExporter metadataServiceExporter = listener.getMetadataServiceExporter();
Assertions.assertEquals(metadataExported, metadataServiceExporter.isExported());
DubboProtocol protocol = DubboProtocol.getDubboProtocol(bootstrap.getApplicationModel());
Map<String, Exporter<?>> exporters = protocol.getExporterMap();
if (metadataExported) {
Assertions.assertEquals(2, exporters.size());
ServiceConfig<MetadataService> serviceConfig = new ServiceConfig<>();
serviceConfig.setRegistry(new RegistryConfig("N/A"));
serviceConfig.setInterface(MetadataService.class);
serviceConfig.setGroup(
ApplicationModel.defaultModel().getCurrentConfig().getName());
serviceConfig.setVersion(MetadataService.VERSION);
assertThat(exporters, hasEntry(is(serviceConfig.getUniqueServiceName() + ":" + availablePort), anything()));
} else {
Assertions.assertEquals(1, exporters.size());
}
}
private void writeDubboProperties(String key, String value) {
OutputStream os = null;
try {
os = new BufferedOutputStream(new FileOutputStream(dubboProperties));
Properties properties = new Properties();
properties.put(key, value);
properties.store(os, "");
os.close();
} catch (IOException e) {
if (os != null) {
try {
os.close();
} catch (IOException ioe) {
// ignore
}
}
}
}
public static class InterfaceConfig extends AbstractInterfaceConfig {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/MultiInstanceTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/MultiInstanceTest.java | /*
* 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.config.bootstrap;
import org.apache.dubbo.common.deploy.ApplicationDeployer;
import org.apache.dubbo.common.deploy.DeployListener;
import org.apache.dubbo.common.deploy.DeployState;
import org.apache.dubbo.common.deploy.ModuleDeployer;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ConfigKeys;
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.apache.dubbo.config.SysProps;
import org.apache.dubbo.config.api.DemoService;
import org.apache.dubbo.config.api.Greeting;
import org.apache.dubbo.config.context.ConfigMode;
import org.apache.dubbo.config.mock.GreetingLocal2;
import org.apache.dubbo.config.provider.impl.DemoServiceImpl;
import org.apache.dubbo.registry.client.migration.MigrationInvoker;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.FrameworkModel;
import org.apache.dubbo.rpc.model.FrameworkServiceRepository;
import org.apache.dubbo.rpc.model.ModuleModel;
import org.apache.dubbo.rpc.model.ServiceDescriptor;
import org.apache.dubbo.test.check.DubboTestChecker;
import org.apache.dubbo.test.check.registrycenter.config.ZookeeperRegistryCenterConfig;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.apache.dubbo.remoting.Constants.EVENT_LOOP_BOSS_POOL_NAME;
@Disabled
class MultiInstanceTest {
private static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(MultiInstanceTest.class);
private RegistryConfig registryConfig;
private static DubboTestChecker testChecker;
private static String testClassName;
@BeforeEach
public void beforeAll() {
FrameworkModel.destroyAll();
registryConfig = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress1());
// pre-check threads
// precheckUnclosedThreads();
}
@AfterEach
public void afterAll() throws Exception {
FrameworkModel.destroyAll();
// check threads
// checkUnclosedThreads();
}
private static Map<Thread, StackTraceElement[]> precheckUnclosedThreads() throws IOException {
// create a special DubboTestChecker
if (testChecker == null) {
testChecker = new DubboTestChecker();
testChecker.init(null);
testClassName = MultiInstanceTest.class.getName();
}
return testChecker.checkUnclosedThreads(testClassName, 0);
}
private static void checkUnclosedThreads() {
Map<Thread, StackTraceElement[]> unclosedThreadMap = testChecker.checkUnclosedThreads(testClassName, 3000);
if (unclosedThreadMap.size() > 0) {
String str = getStackTraceString(unclosedThreadMap);
Assertions.fail("Found unclosed threads: " + unclosedThreadMap.size() + "\n" + str);
}
}
private static String getStackTraceString(Map<Thread, StackTraceElement[]> unclosedThreadMap) {
StringBuilder sb = new StringBuilder();
for (Thread thread : unclosedThreadMap.keySet()) {
sb.append(DubboTestChecker.getFullStacktrace(thread, unclosedThreadMap.get(thread)));
sb.append("\n");
}
return sb.toString();
}
@BeforeEach
public void setup() {
FrameworkModel.destroyAll();
}
@AfterEach
public void afterEach() {
SysProps.clear();
DubboBootstrap.reset();
}
@Test
void testIsolatedApplications() {
DubboBootstrap dubboBootstrap1 = DubboBootstrap.newInstance(new FrameworkModel());
DubboBootstrap dubboBootstrap2 = DubboBootstrap.newInstance(new FrameworkModel());
try {
ApplicationModel applicationModel1 = dubboBootstrap1.getApplicationModel();
ApplicationModel applicationModel2 = dubboBootstrap2.getApplicationModel();
Assertions.assertNotSame(applicationModel1, applicationModel2);
Assertions.assertNotSame(applicationModel1.getFrameworkModel(), applicationModel2.getFrameworkModel());
Assertions.assertNotSame(dubboBootstrap1.getConfigManager(), dubboBootstrap2.getConfigManager());
// bootstrap1: provider app
configProviderApp(dubboBootstrap1).start();
// bootstrap2: consumer app
configConsumerApp(dubboBootstrap2).start();
testConsumer(dubboBootstrap2);
DemoService demoServiceFromProvider = dubboBootstrap1.getCache().get(DemoService.class);
Assertions.assertNull(demoServiceFromProvider);
} finally {
dubboBootstrap2.destroy();
dubboBootstrap1.destroy();
}
}
@Test
void testDefaultProviderApplication() {
DubboBootstrap dubboBootstrap = DubboBootstrap.getInstance();
try {
configProviderApp(dubboBootstrap).start();
} finally {
dubboBootstrap.destroy();
DubboBootstrap.reset();
}
}
@Test
void testDefaultConsumerApplication() {
SysProps.setProperty("dubbo.consumer.check", "false");
DubboBootstrap dubboBootstrap = DubboBootstrap.getInstance();
try {
configConsumerApp(dubboBootstrap).start();
testConsumer(dubboBootstrap);
} catch (Exception e) {
Assertions.assertTrue(e.toString().contains("No provider available"), StringUtils.toString(e));
} finally {
dubboBootstrap.destroy();
DubboBootstrap.reset();
SysProps.clear();
}
}
@Test
void testDefaultMixedApplication() {
DubboBootstrap dubboBootstrap = DubboBootstrap.getInstance();
try {
dubboBootstrap.application("mixed-app");
configProviderApp(dubboBootstrap);
configConsumerApp(dubboBootstrap);
dubboBootstrap.start();
testConsumer(dubboBootstrap);
} finally {
dubboBootstrap.destroy();
DubboBootstrap.reset();
}
}
@Test
void testSharedApplications() {
FrameworkModel frameworkModel = new FrameworkModel();
DubboBootstrap dubboBootstrap1 = DubboBootstrap.newInstance(frameworkModel);
DubboBootstrap dubboBootstrap2 = DubboBootstrap.newInstance(frameworkModel);
try {
ApplicationModel applicationModel1 = dubboBootstrap1.getApplicationModel();
ApplicationModel applicationModel2 = dubboBootstrap2.getApplicationModel();
Assertions.assertNotSame(applicationModel1, applicationModel2);
Assertions.assertSame(applicationModel1.getFrameworkModel(), applicationModel2.getFrameworkModel());
Assertions.assertNotSame(dubboBootstrap1.getConfigManager(), dubboBootstrap2.getConfigManager());
configProviderApp(dubboBootstrap1).start();
configConsumerApp(dubboBootstrap2).start();
testConsumer(dubboBootstrap2);
} finally {
dubboBootstrap1.destroy();
dubboBootstrap2.destroy();
}
}
@Test
void testMultiModuleApplication() throws InterruptedException {
// SysProps.setProperty(METADATA_PUBLISH_DELAY_KEY, "100");
String version1 = "1.0";
String version2 = "2.0";
String version3 = "3.0";
DubboBootstrap providerBootstrap = null;
DubboBootstrap consumerBootstrap = null;
try {
// provider app
providerBootstrap = DubboBootstrap.newInstance();
ServiceConfig serviceConfig1 = new ServiceConfig();
serviceConfig1.setInterface(DemoService.class);
serviceConfig1.setRef(new DemoServiceImpl());
serviceConfig1.setVersion(version1);
ServiceConfig serviceConfig2 = new ServiceConfig();
serviceConfig2.setInterface(DemoService.class);
serviceConfig2.setRef(new DemoServiceImpl());
serviceConfig2.setVersion(version2);
ServiceConfig serviceConfig3 = new ServiceConfig();
serviceConfig3.setInterface(DemoService.class);
serviceConfig3.setRef(new DemoServiceImpl());
serviceConfig3.setVersion(version3);
providerBootstrap
.application("provider-app")
.registry(registryConfig)
.protocol(new ProtocolConfig("dubbo", -1))
.service(serviceConfig1)
.newModule()
.service(serviceConfig2)
.endModule()
.newModule()
.service(serviceConfig3)
.endModule();
ApplicationModel applicationModel = providerBootstrap.getApplicationModel();
List<ModuleModel> moduleModels = applicationModel.getModuleModels();
Assertions.assertEquals(4, moduleModels.size());
Assertions.assertSame(moduleModels.get(0), applicationModel.getInternalModule());
Assertions.assertSame(moduleModels.get(1), applicationModel.getDefaultModule());
Assertions.assertSame(applicationModel.getDefaultModule(), serviceConfig1.getScopeModel());
Assertions.assertSame(moduleModels.get(2), serviceConfig2.getScopeModel());
Assertions.assertSame(moduleModels.get(3), serviceConfig3.getScopeModel());
Assertions.assertNotSame(applicationModel.getDefaultModule(), applicationModel.getInternalModule());
providerBootstrap.start();
// Thread.sleep(200);
// consumer app
consumerBootstrap = DubboBootstrap.newInstance();
consumerBootstrap
.application("consumer-app")
.registry(registryConfig)
.reference(builder -> builder.interfaceClass(DemoService.class)
.version(version1)
.injvm(false))
.newModule()
.reference(builder -> builder.interfaceClass(DemoService.class)
.version(version2)
.injvm(false))
.endModule();
consumerBootstrap.start();
DemoService referProxy1 = consumerBootstrap.getCache().get(DemoService.class.getName() + ":" + version1);
Assertions.assertEquals("say:dubbo", referProxy1.sayName("dubbo"));
DemoService referProxy2 = consumerBootstrap.getCache().get(DemoService.class.getName() + ":" + version2);
Assertions.assertEquals("say:dubbo", referProxy2.sayName("dubbo"));
Assertions.assertNotEquals(referProxy1, referProxy2);
} finally {
if (providerBootstrap != null) {
providerBootstrap.destroy();
}
if (consumerBootstrap != null) {
consumerBootstrap.destroy();
}
}
}
@Test
void testMultiProviderApplicationsStopOneByOne() {
FrameworkModel.destroyAll();
String version1 = "1.0";
String version2 = "2.0";
DubboBootstrap providerBootstrap1 = null;
DubboBootstrap providerBootstrap2 = null;
try {
// save threads before provider app 1
Map<Thread, StackTraceElement[]> stackTraces0 = Thread.getAllStackTraces();
// start provider app 1
ServiceConfig serviceConfig1 = new ServiceConfig();
serviceConfig1.setInterface(DemoService.class);
serviceConfig1.setRef(new DemoServiceImpl());
serviceConfig1.setVersion(version1);
ProtocolConfig protocolConfig1 = new ProtocolConfig("dubbo", NetUtils.getAvailablePort());
providerBootstrap1 = DubboBootstrap.getInstance();
providerBootstrap1
.application("provider1")
.registry(new RegistryConfig(registryConfig.getAddress()))
.service(serviceConfig1)
.protocol(protocolConfig1)
.start();
// save threads of provider app 1
Map<Thread, StackTraceElement[]> lastAllThreadStackTraces = Thread.getAllStackTraces();
Map<Thread, StackTraceElement[]> stackTraces1 = findNewThreads(lastAllThreadStackTraces, stackTraces0);
Assertions.assertTrue(stackTraces1.size() > 0, "Get threads of provider app 1 failed");
// start zk server 2
RegistryConfig registryConfig2 = new RegistryConfig(ZookeeperRegistryCenterConfig.getConnectionAddress2());
// start provider app 2 use a difference zk server 2
ServiceConfig serviceConfig2 = new ServiceConfig();
serviceConfig2.setInterface(DemoService.class);
serviceConfig2.setRef(new DemoServiceImpl());
serviceConfig2.setVersion(version2);
ProtocolConfig protocolConfig2 = new ProtocolConfig("dubbo", NetUtils.getAvailablePort());
providerBootstrap2 = DubboBootstrap.newInstance();
providerBootstrap2
.application("provider2")
.registry(registryConfig2)
.service(serviceConfig2)
.protocol(protocolConfig2)
.start();
// save threads of provider app 2
Map<Thread, StackTraceElement[]> stackTraces2 = findNewThreads(Thread.getAllStackTraces(), stackTraces0);
Assertions.assertTrue(stackTraces2.size() > 0, "Get threads of provider app 2 failed");
// stop provider app 1 and check threads
providerBootstrap1.stop();
// TODO Remove ignore thread prefix of NettyServerBoss if supporting close protocol server only used by one
// application
// see org.apache.dubbo.config.deploy.DefaultApplicationDeployer.postDestroy
// NettyServer will close when all applications are shutdown, but not close if any application of the
// framework is alive, just ignore it currently
checkUnclosedThreadsOfApp(stackTraces1, "Found unclosed threads of app 1: ", new String[] {
EVENT_LOOP_BOSS_POOL_NAME, "Dubbo-global-shared-handler", "Dubbo-framework"
});
// stop provider app 2 and check threads
providerBootstrap2.stop();
// shutdown register center after dubbo application to avoid unregister services blocking
checkUnclosedThreadsOfApp(stackTraces2, "Found unclosed threads of app 2: ", null);
} finally {
if (providerBootstrap1 != null) {
providerBootstrap1.stop();
}
if (providerBootstrap2 != null) {
providerBootstrap2.stop();
}
}
}
private Map<Thread, StackTraceElement[]> findNewThreads(
Map<Thread, StackTraceElement[]> newAllThreadMap, Map<Thread, StackTraceElement[]> prevThreadMap) {
Map<Thread, StackTraceElement[]> deltaThreadMap = new HashMap<>(newAllThreadMap);
deltaThreadMap.keySet().removeAll(prevThreadMap.keySet());
// expect deltaThreadMap not contains any elements of prevThreadMap
Assertions.assertFalse(deltaThreadMap.keySet().stream()
.filter(thread -> prevThreadMap.containsKey(thread))
.findAny()
.isPresent());
return deltaThreadMap;
}
private void checkUnclosedThreadsOfApp(
Map<Thread, StackTraceElement[]> stackTraces1, String msg, String[] ignoredThreadPrefixes) {
int waitTimeMs = 5000;
try {
Thread.sleep(waitTimeMs);
} catch (InterruptedException e) {
}
HashMap<Thread, StackTraceElement[]> unclosedThreadMap1 = new HashMap<>(stackTraces1);
unclosedThreadMap1.keySet().removeIf(thread -> !thread.isAlive());
if (ignoredThreadPrefixes != null && ignoredThreadPrefixes.length > 0) {
unclosedThreadMap1.keySet().removeIf(thread -> isIgnoredThread(thread.getName(), ignoredThreadPrefixes));
}
if (unclosedThreadMap1.size() > 0) {
String str = getStackTraceString(unclosedThreadMap1);
Assertions.fail(msg + unclosedThreadMap1.size() + "\n" + str);
}
}
private boolean isIgnoredThread(String name, String[] ignoredThreadPrefixes) {
if (ignoredThreadPrefixes != null && ignoredThreadPrefixes.length > 0) {
for (String prefix : ignoredThreadPrefixes) {
if (name.startsWith(prefix)) {
return true;
}
}
}
return false;
}
@Test
void testMultiModuleDeployAndReload() throws Exception {
String version1 = "1.0";
String version2 = "2.0";
String version3 = "3.0";
String serviceKey1 = DemoService.class.getName() + ":" + version1;
String serviceKey2 = DemoService.class.getName() + ":" + version2;
String serviceKey3 = DemoService.class.getName() + ":" + version3;
DubboBootstrap providerBootstrap = null;
DubboBootstrap consumerBootstrap = null;
try {
// provider app
providerBootstrap = DubboBootstrap.newInstance();
ServiceConfig serviceConfig1 = new ServiceConfig();
serviceConfig1.setInterface(DemoService.class);
serviceConfig1.setRef(new DemoServiceImpl());
serviceConfig1.setVersion(version1);
// provider module 1
providerBootstrap
.application("provider-app")
.registry(registryConfig)
.protocol(new ProtocolConfig("dubbo", -1))
.service(builder -> builder.interfaceClass(Greeting.class).ref(new GreetingLocal2()))
.newModule()
.service(serviceConfig1)
.endModule();
ApplicationModel applicationModel = providerBootstrap.getApplicationModel();
List<ModuleModel> moduleModels = applicationModel.getModuleModels();
Assertions.assertEquals(3, moduleModels.size());
Assertions.assertSame(moduleModels.get(0), applicationModel.getInternalModule());
Assertions.assertSame(moduleModels.get(1), applicationModel.getDefaultModule());
Assertions.assertSame(moduleModels.get(2), serviceConfig1.getScopeModel());
ModuleDeployer moduleDeployer1 = serviceConfig1.getScopeModel().getDeployer();
moduleDeployer1.start().get();
Assertions.assertTrue(moduleDeployer1.isCompletion());
ModuleDeployer internalModuleDeployer =
applicationModel.getInternalModule().getDeployer();
Assertions.assertTrue(internalModuleDeployer.isCompletion());
FrameworkServiceRepository frameworkServiceRepository =
applicationModel.getFrameworkModel().getServiceRepository();
Assertions.assertNotNull(frameworkServiceRepository.lookupExportedServiceWithoutGroup(serviceKey1));
Assertions.assertNull(frameworkServiceRepository.lookupExportedServiceWithoutGroup(serviceKey2));
Assertions.assertNull(frameworkServiceRepository.lookupExportedServiceWithoutGroup(serviceKey3));
// consumer module 1
consumerBootstrap = DubboBootstrap.newInstance();
consumerBootstrap
.application("consumer-app")
.registry(registryConfig)
.reference(builder -> builder.interfaceClass(DemoService.class)
.version(version1)
.injvm(false));
consumerBootstrap.start();
DemoService referProxy1 = consumerBootstrap.getCache().get(serviceKey1);
String result1 = referProxy1.sayName("dubbo");
Assertions.assertEquals("say:dubbo", result1);
// destroy provider module 1
serviceConfig1.getScopeModel().destroy();
// provider module 2
ServiceConfig serviceConfig2 = new ServiceConfig();
serviceConfig2.setInterface(DemoService.class);
serviceConfig2.setRef(new DemoServiceImpl());
serviceConfig2.setVersion(version2);
providerBootstrap.newModule().service(serviceConfig2).endModule();
// start provider module 2 and wait
serviceConfig2.getScopeModel().getDeployer().start().get();
Assertions.assertNull(frameworkServiceRepository.lookupExportedServiceWithoutGroup(serviceKey1));
Assertions.assertNotNull(frameworkServiceRepository.lookupExportedServiceWithoutGroup(serviceKey2));
Assertions.assertNull(frameworkServiceRepository.lookupExportedServiceWithoutGroup(serviceKey3));
// consumer module2
ModuleModel consumerModule2 = consumerBootstrap
.newModule()
.reference(builder -> builder.interfaceClass(DemoService.class)
.version(version2)
.injvm(false))
.getModuleModel();
ModuleDeployer moduleDeployer2 = consumerModule2.getDeployer();
moduleDeployer2.start().get();
DemoService referProxy2 = moduleDeployer2.getReferenceCache().get(serviceKey2);
String result2 = referProxy2.sayName("dubbo2");
Assertions.assertEquals("say:dubbo2", result2);
// destroy provider module 2
serviceConfig2.getScopeModel().destroy();
// provider module 3
ServiceConfig serviceConfig3 = new ServiceConfig();
serviceConfig3.setInterface(DemoService.class);
serviceConfig3.setRef(new DemoServiceImpl());
serviceConfig3.setVersion(version3);
providerBootstrap.newModule().service(serviceConfig3).endModule();
serviceConfig3.getScopeModel().getDeployer().start().get();
Assertions.assertNull(frameworkServiceRepository.lookupExportedServiceWithoutGroup(serviceKey1));
Assertions.assertNull(frameworkServiceRepository.lookupExportedServiceWithoutGroup(serviceKey2));
Assertions.assertNotNull(frameworkServiceRepository.lookupExportedServiceWithoutGroup(serviceKey3));
// consumer module3
ModuleModel consumerModule3 = consumerBootstrap
.newModule()
.reference(builder -> builder.interfaceClass(DemoService.class)
.version(version3)
.injvm(false))
.getModuleModel();
consumerBootstrap.start();
DemoService referProxy3 =
consumerModule3.getDeployer().getReferenceCache().get(serviceKey3);
String result3 = referProxy3.sayName("dubbo3");
Assertions.assertEquals("say:dubbo3", result3);
} finally {
if (providerBootstrap != null) {
providerBootstrap.destroy();
}
if (consumerBootstrap != null) {
consumerBootstrap.destroy();
}
}
}
@Test
void testBothStartByModuleAndByApplication() throws Exception {
String version1 = "1.0";
String version2 = "2.0";
String version3 = "3.0";
String serviceKey1 = DemoService.class.getName() + ":" + version1;
String serviceKey2 = DemoService.class.getName() + ":" + version2;
String serviceKey3 = DemoService.class.getName() + ":" + version3;
// provider app
DubboBootstrap providerBootstrap = null;
try {
providerBootstrap = DubboBootstrap.newInstance();
ServiceConfig serviceConfig1 = new ServiceConfig();
serviceConfig1.setInterface(DemoService.class);
serviceConfig1.setRef(new DemoServiceImpl());
serviceConfig1.setVersion(version1);
// provider module 1
providerBootstrap
.application("provider-app")
.registry(registryConfig)
.protocol(new ProtocolConfig("dubbo", -1))
.service(builder -> builder.interfaceClass(Greeting.class).ref(new GreetingLocal2()))
.newModule()
.service(serviceConfig1)
.endModule();
// 1. start module1 and wait
ModuleDeployer moduleDeployer1 = serviceConfig1.getScopeModel().getDeployer();
moduleDeployer1.start().get();
Assertions.assertEquals(DeployState.COMPLETION, moduleDeployer1.getState());
ApplicationModel applicationModel = providerBootstrap.getApplicationModel();
ApplicationDeployer applicationDeployer = applicationModel.getDeployer();
Assertions.assertEquals(DeployState.STARTING, applicationDeployer.getState());
ModuleModel defaultModule = applicationModel.getDefaultModule();
Assertions.assertEquals(
DeployState.PENDING, defaultModule.getDeployer().getState());
// 2. start application after module1 is started
providerBootstrap.start();
Assertions.assertEquals(DeployState.COMPLETION, applicationDeployer.getState());
Assertions.assertEquals(
DeployState.COMPLETION, defaultModule.getDeployer().getState());
// 3. add module2 and re-start application
ServiceConfig serviceConfig2 = new ServiceConfig();
serviceConfig2.setInterface(DemoService.class);
serviceConfig2.setRef(new DemoServiceImpl());
serviceConfig2.setVersion(version2);
ModuleModel moduleModel2 =
providerBootstrap.newModule().service(serviceConfig2).getModuleModel();
providerBootstrap.start();
Assertions.assertEquals(DeployState.COMPLETION, applicationDeployer.getState());
Assertions.assertEquals(
DeployState.COMPLETION, moduleModel2.getDeployer().getState());
// 4. add module3 and start module3
ServiceConfig serviceConfig3 = new ServiceConfig();
serviceConfig3.setInterface(DemoService.class);
serviceConfig3.setRef(new DemoServiceImpl());
serviceConfig3.setVersion(version3);
ModuleModel moduleModel3 =
providerBootstrap.newModule().service(serviceConfig3).getModuleModel();
moduleModel3.getDeployer().start().get();
Assertions.assertEquals(DeployState.COMPLETION, applicationDeployer.getState());
Assertions.assertEquals(
DeployState.COMPLETION, moduleModel3.getDeployer().getState());
} finally {
if (providerBootstrap != null) {
providerBootstrap.stop();
}
}
}
@Test
void testBothStartModuleAndApplicationNoWait() throws Exception {
String version1 = "1.0";
String version2 = "2.0";
String version3 = "3.0";
String serviceKey1 = DemoService.class.getName() + ":" + version1;
String serviceKey2 = DemoService.class.getName() + ":" + version2;
String serviceKey3 = DemoService.class.getName() + ":" + version3;
// provider app
DubboBootstrap providerBootstrap = null;
try {
providerBootstrap = DubboBootstrap.newInstance();
ServiceConfig serviceConfig1 = new ServiceConfig();
serviceConfig1.setInterface(DemoService.class);
serviceConfig1.setRef(new DemoServiceImpl());
serviceConfig1.setVersion(version1);
// provider module 1
providerBootstrap
.application("provider-app")
.registry(registryConfig)
.protocol(new ProtocolConfig("dubbo", -1))
.service(builder -> builder.interfaceClass(Greeting.class).ref(new GreetingLocal2()))
.newModule()
.service(serviceConfig1)
.endModule();
ApplicationModel applicationModel = providerBootstrap.getApplicationModel();
// 1. start module1 but no wait
ModuleDeployer moduleDeployer1 = serviceConfig1.getScopeModel().getDeployer();
moduleDeployer1.start();
Assertions.assertTrue(moduleDeployer1.isRunning());
ApplicationDeployer applicationDeployer = applicationModel.getDeployer();
Assertions.assertEquals(DeployState.STARTING, applicationDeployer.getState());
ModuleModel defaultModule = applicationModel.getDefaultModule();
Assertions.assertEquals(
DeployState.PENDING, defaultModule.getDeployer().getState());
// 2. start application after module1 is starting
providerBootstrap.start();
Assertions.assertEquals(DeployState.COMPLETION, applicationDeployer.getState());
Assertions.assertEquals(DeployState.COMPLETION, moduleDeployer1.getState());
Assertions.assertEquals(
DeployState.COMPLETION, defaultModule.getDeployer().getState());
} finally {
if (providerBootstrap != null) {
providerBootstrap.stop();
}
}
}
@Test
void testOldApiDeploy() throws Exception {
try {
SysProps.setProperty(ConfigKeys.DUBBO_CONFIG_MODE, ConfigMode.OVERRIDE.name());
// provider app
ApplicationModel providerApplicationModel = ApplicationModel.defaultModel();
ServiceConfig<DemoService> serviceConfig = new ServiceConfig<>();
serviceConfig.setScopeModel(providerApplicationModel.getDefaultModule());
serviceConfig.setRef(new DemoServiceImpl());
serviceConfig.setInterface(DemoService.class);
serviceConfig.setApplication(new ApplicationConfig("provider-app"));
serviceConfig.setRegistry(new RegistryConfig(registryConfig.getAddress()));
// add service
// serviceConfig.getScopeModel().getConfigManager().addService(serviceConfig);
// detect deploy events
DeployEventHandler serviceDeployEventHandler = new DeployEventHandler(serviceConfig.getScopeModel());
serviceConfig.getScopeModel().getDeployer().addDeployListener(serviceDeployEventHandler);
// before starting
Map<DeployState, Long> serviceDeployEventMap = serviceDeployEventHandler.deployEventMap;
Assertions.assertFalse(serviceDeployEventMap.containsKey(DeployState.STARTING));
Assertions.assertFalse(serviceDeployEventMap.containsKey(DeployState.STARTED));
Assertions.assertFalse(serviceDeployEventMap.containsKey(DeployState.COMPLETION));
// export service and start module
serviceConfig.export();
// expect internal module is started
Assertions.assertTrue(
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | true |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ApplicationBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ApplicationBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.MonitorConfig;
import org.apache.dubbo.config.RegistryConfig;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class ApplicationBuilderTest {
@Test
void name() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.name("app");
Assertions.assertEquals("app", builder.build().getName());
}
@Test
void version() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.version("version");
Assertions.assertEquals("version", builder.build().getVersion());
}
@Test
void owner() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.owner("owner");
Assertions.assertEquals("owner", builder.build().getOwner());
}
@Test
void organization() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.organization("organization");
Assertions.assertEquals("organization", builder.build().getOrganization());
}
@Test
void architecture() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.architecture("architecture");
Assertions.assertEquals("architecture", builder.build().getArchitecture());
}
@Test
void environment() {
ApplicationBuilder builder = new ApplicationBuilder();
Assertions.assertEquals("product", builder.build().getEnvironment());
builder.environment("develop");
Assertions.assertEquals("develop", builder.build().getEnvironment());
builder.environment("test");
Assertions.assertEquals("test", builder.build().getEnvironment());
builder.environment("product");
Assertions.assertEquals("product", builder.build().getEnvironment());
}
@Test
void compiler() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.compiler("compiler");
Assertions.assertEquals("compiler", builder.build().getCompiler());
}
@Test
void logger() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.logger("log4j2");
Assertions.assertEquals("log4j2", builder.build().getLogger());
}
@Test
void addRegistry() {
RegistryConfig registry = new RegistryConfig();
ApplicationBuilder builder = new ApplicationBuilder();
builder.addRegistry(registry);
Assertions.assertNotNull(builder.build().getRegistry());
Assertions.assertEquals(1, builder.build().getRegistries().size());
Assertions.assertSame(registry, builder.build().getRegistry());
}
@Test
void addRegistries() {
RegistryConfig registry = new RegistryConfig();
ApplicationBuilder builder = new ApplicationBuilder();
builder.addRegistries(Collections.singletonList(registry));
Assertions.assertNotNull(builder.build().getRegistry());
Assertions.assertEquals(1, builder.build().getRegistries().size());
Assertions.assertSame(registry, builder.build().getRegistry());
}
@Test
void registryIds() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.registryIds("registryIds");
Assertions.assertEquals("registryIds", builder.build().getRegistryIds());
}
@Test
void monitor() {
MonitorConfig monitor = new MonitorConfig("monitor-addr");
ApplicationBuilder builder = new ApplicationBuilder();
builder.monitor(monitor);
Assertions.assertSame(monitor, builder.build().getMonitor());
Assertions.assertEquals("monitor-addr", builder.build().getMonitor().getAddress());
}
@Test
void monitor1() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.monitor("monitor-addr");
Assertions.assertEquals("monitor-addr", builder.build().getMonitor().getAddress());
}
@Test
void isDefault() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.isDefault(true);
Assertions.assertTrue(builder.build().isDefault());
builder.isDefault(false);
Assertions.assertFalse(builder.build().isDefault());
builder.isDefault(null);
Assertions.assertNull(builder.build().isDefault());
}
@Test
void dumpDirectory() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.dumpDirectory("dumpDirectory");
Assertions.assertEquals("dumpDirectory", builder.build().getDumpDirectory());
}
@Test
void qosEnable() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.qosEnable(true);
Assertions.assertTrue(builder.build().getQosEnable());
builder.qosEnable(false);
Assertions.assertFalse(builder.build().getQosEnable());
builder.qosEnable(null);
Assertions.assertNull(builder.build().getQosEnable());
}
@Test
void qosPort() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.qosPort(8080);
Assertions.assertEquals(8080, builder.build().getQosPort());
}
@Test
void qosAcceptForeignIp() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.qosAcceptForeignIp(true);
Assertions.assertTrue(builder.build().getQosAcceptForeignIp());
builder.qosAcceptForeignIp(false);
Assertions.assertFalse(builder.build().getQosAcceptForeignIp());
builder.qosAcceptForeignIp(null);
Assertions.assertNull(builder.build().getQosAcceptForeignIp());
}
@Test
void shutwait() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.shutwait("shutwait");
Assertions.assertEquals("shutwait", builder.build().getShutwait());
}
@Test
void appendParameter() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.appendParameter("default.num", "one").appendParameter("num", "ONE");
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void appendParameters() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one");
source.put("num", "ONE");
ApplicationBuilder builder = new ApplicationBuilder();
builder.appendParameters(source);
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void metadataServicePort() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.metadataServicePort(12345);
Assertions.assertEquals(12345, builder.build().getMetadataServicePort());
}
@Test
void livenessProbe() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.livenessProbe("TestProbe");
Assertions.assertEquals("TestProbe", builder.build().getLivenessProbe());
}
@Test
void readinessProbe() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.readinessProbe("TestProbe");
Assertions.assertEquals("TestProbe", builder.build().getReadinessProbe());
}
@Test
void startupProbe() {
ApplicationBuilder builder = new ApplicationBuilder();
builder.startupProbe("TestProbe");
Assertions.assertEquals("TestProbe", builder.build().getStartupProbe());
}
@Test
void build() {
MonitorConfig monitor = new MonitorConfig("monitor-addr");
RegistryConfig registry = new RegistryConfig();
ApplicationBuilder builder = new ApplicationBuilder();
builder.id("id")
.name("name")
.version("version")
.owner("owner")
.organization("organization")
.architecture("architecture")
.environment("develop")
.compiler("compiler")
.logger("log4j2")
.monitor(monitor)
.isDefault(false)
.dumpDirectory("dumpDirectory")
.qosEnable(true)
.qosPort(8080)
.qosAcceptForeignIp(false)
.shutwait("shutwait")
.registryIds("registryIds")
.addRegistry(registry)
.appendParameter("default.num", "one")
.metadataServicePort(12345)
.livenessProbe("liveness")
.readinessProbe("readiness")
.startupProbe("startup");
ApplicationConfig config = builder.build();
ApplicationConfig config2 = builder.build();
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals("name", config.getName());
Assertions.assertEquals("version", config.getVersion());
Assertions.assertEquals("owner", config.getOwner());
Assertions.assertEquals("organization", config.getOrganization());
Assertions.assertEquals("architecture", config.getArchitecture());
Assertions.assertEquals("develop", config.getEnvironment());
Assertions.assertEquals("compiler", config.getCompiler());
Assertions.assertEquals("log4j2", config.getLogger());
Assertions.assertSame(monitor, config.getMonitor());
Assertions.assertFalse(config.isDefault());
Assertions.assertEquals("dumpDirectory", config.getDumpDirectory());
Assertions.assertTrue(config.getQosEnable());
Assertions.assertEquals(8080, config.getQosPort());
Assertions.assertFalse(config.getQosAcceptForeignIp());
Assertions.assertEquals("shutwait", config.getShutwait());
Assertions.assertEquals("registryIds", config.getRegistryIds());
Assertions.assertSame(registry, config.getRegistry());
Assertions.assertTrue(config.getParameters().containsKey("default.num"));
Assertions.assertEquals("one", config.getParameters().get("default.num"));
Assertions.assertEquals(12345, config.getMetadataServicePort());
Assertions.assertEquals("liveness", config.getLivenessProbe());
Assertions.assertEquals("readiness", config.getReadinessProbe());
Assertions.assertEquals("startup", config.getStartupProbe());
Assertions.assertNotSame(config, config2);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/AbstractInterfaceBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/AbstractInterfaceBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.AbstractInterfaceConfig;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ConfigCenterConfig;
import org.apache.dubbo.config.MetadataReportConfig;
import org.apache.dubbo.config.ModuleConfig;
import org.apache.dubbo.config.MonitorConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import java.util.Collections;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class AbstractInterfaceBuilderTest {
@BeforeEach
void beforeEach() {
DubboBootstrap.reset();
}
@Test
void local() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.local("GreetingMock");
Assertions.assertEquals("GreetingMock", builder.build().getLocal());
}
@Test
void local1() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.local((Boolean) null);
Assertions.assertNull(builder.build().getLocal());
builder.local(false);
Assertions.assertEquals("false", builder.build().getLocal());
builder.local(true);
Assertions.assertEquals("true", builder.build().getLocal());
}
@Test
void stub() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.stub("GreetingMock");
Assertions.assertEquals("GreetingMock", builder.build().getStub());
}
@Test
void stub1() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.stub((Boolean) null);
Assertions.assertNull(builder.build().getLocal());
builder.stub(false);
Assertions.assertEquals("false", builder.build().getStub());
builder.stub(true);
Assertions.assertEquals("true", builder.build().getStub());
}
@Test
void monitor() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.monitor("123");
MonitorConfig monitorConfig = new MonitorConfig("123");
Assertions.assertEquals(monitorConfig, builder.build().getMonitor());
}
@Test
void monitor1() {
MonitorConfig monitorConfig = new MonitorConfig("123");
InterfaceBuilder builder = new InterfaceBuilder();
builder.monitor(monitorConfig);
Assertions.assertEquals(monitorConfig, builder.build().getMonitor());
}
@Test
void proxy() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.proxy("mockproxyfactory");
Assertions.assertEquals("mockproxyfactory", builder.build().getProxy());
}
@Test
void cluster() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.cluster("mockcluster");
Assertions.assertEquals("mockcluster", builder.build().getCluster());
}
@Test
void filter() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.filter("mockfilter");
Assertions.assertEquals("mockfilter", builder.build().getFilter());
}
@Test
void listener() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.listener("mockinvokerlistener");
Assertions.assertEquals("mockinvokerlistener", builder.build().getListener());
}
@Test
void owner() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.owner("owner");
Assertions.assertEquals("owner", builder.build().getOwner());
}
@Test
void connections() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.connections(1);
Assertions.assertEquals(1, builder.build().getConnections().intValue());
}
@Test
void layer() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.layer("layer");
Assertions.assertEquals("layer", builder.build().getLayer());
}
@Test
void application() {
ApplicationConfig applicationConfig = new ApplicationConfig("AbtractInterfaceBuilderTest");
InterfaceBuilder builder = new InterfaceBuilder();
builder.application(applicationConfig);
Assertions.assertEquals(applicationConfig, builder.build().getApplication());
}
@Test
void module() {
ModuleConfig moduleConfig = new ModuleConfig();
InterfaceBuilder builder = new InterfaceBuilder();
builder.module(moduleConfig);
Assertions.assertEquals(moduleConfig, builder.build().getModule());
}
@Test
void addRegistries() {
RegistryConfig registryConfig = new RegistryConfig();
InterfaceBuilder builder = new InterfaceBuilder();
builder.addRegistries(Collections.singletonList(registryConfig));
Assertions.assertEquals(1, builder.build().getRegistries().size());
Assertions.assertSame(registryConfig, builder.build().getRegistries().get(0));
Assertions.assertSame(registryConfig, builder.build().getRegistry());
}
@Test
void addRegistry() {
RegistryConfig registryConfig = new RegistryConfig();
InterfaceBuilder builder = new InterfaceBuilder();
builder.addRegistry(registryConfig);
Assertions.assertEquals(1, builder.build().getRegistries().size());
Assertions.assertSame(registryConfig, builder.build().getRegistries().get(0));
Assertions.assertSame(registryConfig, builder.build().getRegistry());
}
@Test
void registryIds() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.registryIds("registryIds");
Assertions.assertEquals("registryIds", builder.build().getRegistryIds());
}
@Test
void onconnect() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.onconnect("onconnect");
Assertions.assertEquals("onconnect", builder.build().getOnconnect());
}
@Test
void ondisconnect() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.ondisconnect("ondisconnect");
Assertions.assertEquals("ondisconnect", builder.build().getOndisconnect());
}
@Test
void metadataReportConfig() {
MetadataReportConfig metadataReportConfig = new MetadataReportConfig();
InterfaceBuilder builder = new InterfaceBuilder();
builder.metadataReportConfig(metadataReportConfig);
Assertions.assertEquals(metadataReportConfig, builder.build().getMetadataReportConfig());
}
@Test
void configCenter() {
ConfigCenterConfig configCenterConfig = new ConfigCenterConfig();
InterfaceBuilder builder = new InterfaceBuilder();
builder.configCenter(configCenterConfig);
Assertions.assertEquals(configCenterConfig, builder.build().getConfigCenter());
}
@Test
void callbacks() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.callbacks(2);
Assertions.assertEquals(2, builder.build().getCallbacks().intValue());
}
@Test
void scope() {
InterfaceBuilder builder = new InterfaceBuilder();
builder.scope("scope");
Assertions.assertEquals("scope", builder.build().getScope());
}
@Test
void build() {
MonitorConfig monitorConfig = new MonitorConfig("123");
ApplicationConfig applicationConfig = new ApplicationConfig();
applicationConfig.setName("appName");
ModuleConfig moduleConfig = new ModuleConfig();
RegistryConfig registryConfig = new RegistryConfig();
MetadataReportConfig metadataReportConfig = new MetadataReportConfig();
ConfigCenterConfig configCenterConfig = new ConfigCenterConfig();
InterfaceBuilder builder = new InterfaceBuilder();
builder.id("id")
.local(true)
.stub(false)
.monitor("123")
.proxy("mockproxyfactory")
.cluster("mockcluster")
.filter("mockfilter")
.listener("mockinvokerlistener")
.owner("owner")
.connections(1)
.layer("layer")
.application(applicationConfig)
.module(moduleConfig)
.addRegistry(registryConfig)
.registryIds("registryIds")
.onconnect("onconnet")
.ondisconnect("ondisconnect")
.metadataReportConfig(metadataReportConfig)
.configCenter(configCenterConfig)
.callbacks(2)
.scope("scope");
InterfaceConfig config = builder.build();
InterfaceConfig config2 = builder.build();
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals("true", config.getLocal());
Assertions.assertEquals("false", config.getStub());
Assertions.assertEquals(monitorConfig, config.getMonitor());
Assertions.assertEquals("mockproxyfactory", config.getProxy());
Assertions.assertEquals("mockcluster", config.getCluster());
Assertions.assertEquals("mockfilter", config.getFilter());
Assertions.assertEquals("mockinvokerlistener", config.getListener());
Assertions.assertEquals("owner", config.getOwner());
Assertions.assertEquals(1, config.getConnections().intValue());
Assertions.assertEquals("layer", config.getLayer());
Assertions.assertEquals(applicationConfig, config.getApplication());
Assertions.assertEquals(moduleConfig, config.getModule());
Assertions.assertEquals(registryConfig, config.getRegistry());
Assertions.assertEquals("registryIds", config.getRegistryIds());
Assertions.assertEquals("onconnet", config.getOnconnect());
Assertions.assertEquals("ondisconnect", config.getOndisconnect());
Assertions.assertEquals(metadataReportConfig, config.getMetadataReportConfig());
Assertions.assertEquals(configCenterConfig, config.getConfigCenter());
Assertions.assertEquals(2, config.getCallbacks().intValue());
Assertions.assertEquals("scope", config.getScope());
Assertions.assertNotSame(config, config2);
}
private static class InterfaceBuilder extends AbstractInterfaceBuilder<InterfaceConfig, InterfaceBuilder> {
public InterfaceConfig build() {
InterfaceConfig config = new InterfaceConfig();
super.build(config);
return config;
}
@Override
protected InterfaceBuilder getThis() {
return this;
}
}
private static class InterfaceConfig extends AbstractInterfaceConfig {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/AbstractMethodBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/AbstractMethodBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.AbstractMethodConfig;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class AbstractMethodBuilderTest {
@Test
void timeout() {
MethodBuilder builder = new MethodBuilder();
builder.timeout(10);
Assertions.assertEquals(10, builder.build().getTimeout());
}
@Test
void retries() {
MethodBuilder builder = new MethodBuilder();
builder.retries(3);
Assertions.assertEquals(3, builder.build().getRetries());
}
@Test
void actives() {
MethodBuilder builder = new MethodBuilder();
builder.actives(3);
Assertions.assertEquals(3, builder.build().getActives());
}
@Test
void loadbalance() {
MethodBuilder builder = new MethodBuilder();
builder.loadbalance("mockloadbalance");
Assertions.assertEquals("mockloadbalance", builder.build().getLoadbalance());
}
@Test
void async() {
MethodBuilder builder = new MethodBuilder();
builder.async(true);
Assertions.assertTrue(builder.build().isAsync());
}
@Test
void sent() {
MethodBuilder builder = new MethodBuilder();
builder.sent(true);
Assertions.assertTrue(builder.build().getSent());
}
@Test
void mock() {
MethodBuilder builder = new MethodBuilder();
builder.mock("mock");
Assertions.assertEquals("mock", builder.build().getMock());
builder.mock("return null");
Assertions.assertEquals("return null", builder.build().getMock());
}
@Test
void mock1() {
MethodBuilder builder = new MethodBuilder();
builder.mock(true);
Assertions.assertEquals("true", builder.build().getMock());
builder.mock(false);
Assertions.assertEquals("false", builder.build().getMock());
}
@Test
void merger() {
MethodBuilder builder = new MethodBuilder();
builder.merger("merger");
Assertions.assertEquals("merger", builder.build().getMerger());
}
@Test
void cache() {
MethodBuilder builder = new MethodBuilder();
builder.cache("cache");
Assertions.assertEquals("cache", builder.build().getCache());
}
@Test
void validation() {
MethodBuilder builder = new MethodBuilder();
builder.validation("validation");
Assertions.assertEquals("validation", builder.build().getValidation());
}
@Test
void appendParameter() {
MethodBuilder builder = new MethodBuilder();
builder.appendParameter("default.num", "one").appendParameter("num", "ONE");
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void appendParameters() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one");
source.put("num", "ONE");
MethodBuilder builder = new MethodBuilder();
builder.appendParameters(source);
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void forks() {
MethodBuilder builder = new MethodBuilder();
builder.forks(5);
Assertions.assertEquals(5, builder.build().getForks());
}
@Test
void build() {
MethodBuilder builder = new MethodBuilder();
builder.id("id")
.timeout(1)
.retries(2)
.actives(3)
.loadbalance("mockloadbalance")
.async(true)
.sent(false)
.mock("mock")
.merger("merger")
.cache("cache")
.validation("validation")
.appendParameter("default.num", "one");
MethodConfig config = builder.build();
MethodConfig config2 = builder.build();
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals(1, config.getTimeout());
Assertions.assertEquals(2, config.getRetries());
Assertions.assertEquals(3, config.getActives());
Assertions.assertEquals("mockloadbalance", config.getLoadbalance());
Assertions.assertTrue(config.isAsync());
Assertions.assertFalse(config.getSent());
Assertions.assertEquals("mock", config.getMock());
Assertions.assertEquals("merger", config.getMerger());
Assertions.assertEquals("cache", config.getCache());
Assertions.assertEquals("validation", config.getValidation());
Assertions.assertTrue(config.getParameters().containsKey("default.num"));
Assertions.assertEquals("one", config.getParameters().get("default.num"));
Assertions.assertNotSame(config, config2);
}
private static class MethodBuilder extends AbstractMethodBuilder<MethodConfig, MethodBuilder> {
public MethodConfig build() {
MethodConfig parameterConfig = new MethodConfig();
super.build(parameterConfig);
return parameterConfig;
}
@Override
protected MethodBuilder getThis() {
return this;
}
}
private static class MethodConfig extends AbstractMethodConfig {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/MethodBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/MethodBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.ArgumentConfig;
import org.apache.dubbo.config.MethodConfig;
import java.util.Collections;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class MethodBuilderTest {
@Test
void name() {
MethodBuilder builder = MethodBuilder.newBuilder();
builder.name("name");
Assertions.assertEquals("name", builder.build().getName());
}
@Test
void stat() {
MethodBuilder builder = MethodBuilder.newBuilder();
builder.stat(1);
Assertions.assertEquals(1, builder.build().getStat());
}
@Test
void retry() {
MethodBuilder builder = MethodBuilder.newBuilder();
builder.retry(true);
Assertions.assertTrue(builder.build().isRetry());
}
@Test
void reliable() {
MethodBuilder builder = MethodBuilder.newBuilder();
builder.reliable(true);
Assertions.assertTrue(builder.build().isReliable());
}
@Test
void executes() {
MethodBuilder builder = MethodBuilder.newBuilder();
builder.executes(1);
Assertions.assertEquals(1, builder.build().getExecutes());
}
@Test
void deprecated() {
MethodBuilder builder = MethodBuilder.newBuilder();
builder.deprecated(true);
Assertions.assertTrue(builder.build().getDeprecated());
}
@Test
void sticky() {
MethodBuilder builder = MethodBuilder.newBuilder();
builder.sticky(true);
Assertions.assertTrue(builder.build().getSticky());
}
@Test
void isReturn() {
MethodBuilder builder = MethodBuilder.newBuilder();
builder.isReturn(true);
Assertions.assertTrue(builder.build().isReturn());
}
@Test
void oninvoke() {
MethodBuilder builder = MethodBuilder.newBuilder();
builder.oninvoke("on-invoke-object");
Assertions.assertEquals("on-invoke-object", builder.build().getOninvoke());
}
@Test
void oninvokeMethod() {
MethodBuilder builder = MethodBuilder.newBuilder();
builder.oninvokeMethod("on-invoke-method");
Assertions.assertEquals("on-invoke-method", builder.build().getOninvokeMethod());
}
@Test
void onreturn() {
MethodBuilder builder = MethodBuilder.newBuilder();
builder.onreturn("on-return-object");
Assertions.assertEquals("on-return-object", builder.build().getOnreturn());
}
@Test
void onreturnMethod() {
MethodBuilder builder = MethodBuilder.newBuilder();
builder.onreturnMethod("on-return-method");
Assertions.assertEquals("on-return-method", builder.build().getOnreturnMethod());
}
@Test
void onthrow() {
MethodBuilder builder = MethodBuilder.newBuilder();
builder.onthrow("on-throw-object");
Assertions.assertEquals("on-throw-object", builder.build().getOnthrow());
}
@Test
void onthrowMethod() {
MethodBuilder builder = MethodBuilder.newBuilder();
builder.onthrowMethod("on-throw-method");
Assertions.assertEquals("on-throw-method", builder.build().getOnthrowMethod());
}
@Test
void addArguments() {
ArgumentConfig argument = new ArgumentConfig();
MethodBuilder builder = MethodBuilder.newBuilder();
builder.addArguments(Collections.singletonList(argument));
Assertions.assertTrue(builder.build().getArguments().contains(argument));
Assertions.assertEquals(1, builder.build().getArguments().size());
}
@Test
void addArgument() {
ArgumentConfig argument = new ArgumentConfig();
MethodBuilder builder = MethodBuilder.newBuilder();
builder.addArgument(argument);
Assertions.assertTrue(builder.build().getArguments().contains(argument));
Assertions.assertEquals(1, builder.build().getArguments().size());
}
@Test
void service() {
MethodBuilder builder = MethodBuilder.newBuilder();
builder.service("service");
Assertions.assertEquals("service", builder.build().getService());
}
@Test
void serviceId() {
MethodBuilder builder = MethodBuilder.newBuilder();
builder.serviceId("serviceId");
Assertions.assertEquals("serviceId", builder.build().getServiceId());
}
@Test
void build() {
ArgumentConfig argument = new ArgumentConfig();
MethodBuilder builder = MethodBuilder.newBuilder();
builder.name("name")
.stat(1)
.retry(true)
.reliable(false)
.executes(2)
.deprecated(true)
.sticky(false)
.isReturn(true)
.oninvoke("on-invoke-object")
.oninvokeMethod("on-invoke-method")
.service("service")
.onreturn("on-return-object")
.onreturnMethod("on-return-method")
.serviceId("serviceId")
.onthrow("on-throw-object")
.onthrowMethod("on-throw-method")
.addArgument(argument);
MethodConfig config = builder.build();
MethodConfig config2 = builder.build();
Assertions.assertTrue(config.isRetry());
Assertions.assertFalse(config.isReliable());
Assertions.assertTrue(config.getDeprecated());
Assertions.assertFalse(config.getSticky());
Assertions.assertTrue(config.isReturn());
Assertions.assertEquals(1, config.getStat());
Assertions.assertEquals(2, config.getExecutes());
Assertions.assertEquals("on-invoke-object", config.getOninvoke());
Assertions.assertEquals("on-invoke-method", config.getOninvokeMethod());
Assertions.assertEquals("on-return-object", config.getOnreturn());
Assertions.assertEquals("on-return-method", config.getOnreturnMethod());
Assertions.assertEquals("on-throw-object", config.getOnthrow());
Assertions.assertEquals("on-throw-method", config.getOnthrowMethod());
Assertions.assertEquals("name", config.getName());
Assertions.assertEquals("service", config.getService());
Assertions.assertEquals("serviceId", config.getServiceId());
Assertions.assertNotSame(config, config2);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/RegistryBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/RegistryBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.RegistryConfig;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class RegistryBuilderTest {
@Test
void address() {
RegistryBuilder builder = new RegistryBuilder();
builder.address("address");
Assertions.assertEquals("address", builder.build().getAddress());
}
@Test
void username() {
RegistryBuilder builder = new RegistryBuilder();
builder.username("username");
Assertions.assertEquals("username", builder.build().getUsername());
}
@Test
void password() {
RegistryBuilder builder = new RegistryBuilder();
builder.password("password");
Assertions.assertEquals("password", builder.build().getPassword());
}
@Test
void port() {
RegistryBuilder builder = new RegistryBuilder();
builder.port(8080);
Assertions.assertEquals(8080, builder.build().getPort());
}
@Test
void protocol() {
RegistryBuilder builder = new RegistryBuilder();
builder.protocol("protocol");
Assertions.assertEquals("protocol", builder.build().getProtocol());
}
@Test
void transporter() {
RegistryBuilder builder = new RegistryBuilder();
builder.transporter("transporter");
Assertions.assertEquals("transporter", builder.build().getTransporter());
}
@Test
void transport() {
RegistryBuilder builder = new RegistryBuilder();
builder.transport("transport");
Assertions.assertEquals("transport", builder.build().getTransport());
}
@Test
void server() {
RegistryBuilder builder = new RegistryBuilder();
builder.server("server");
Assertions.assertEquals("server", builder.build().getServer());
}
@Test
void client() {
RegistryBuilder builder = new RegistryBuilder();
builder.client("client");
Assertions.assertEquals("client", builder.build().getClient());
}
@Test
void cluster() {
RegistryBuilder builder = new RegistryBuilder();
builder.cluster("cluster");
Assertions.assertEquals("cluster", builder.build().getCluster());
}
@Test
void group() {
RegistryBuilder builder = new RegistryBuilder();
builder.group("group");
Assertions.assertEquals("group", builder.build().getGroup());
}
@Test
void version() {
RegistryBuilder builder = new RegistryBuilder();
builder.version("version");
Assertions.assertEquals("version", builder.build().getVersion());
}
@Test
void timeout() {
RegistryBuilder builder = new RegistryBuilder();
builder.timeout(1000);
Assertions.assertEquals(1000, builder.build().getTimeout());
}
@Test
void session() {
RegistryBuilder builder = new RegistryBuilder();
builder.session(2000);
Assertions.assertEquals(2000, builder.build().getSession());
}
@Test
void file() {
RegistryBuilder builder = new RegistryBuilder();
builder.file("file");
Assertions.assertEquals("file", builder.build().getFile());
}
@Test
void testWait() {
RegistryBuilder builder = new RegistryBuilder();
builder.wait(Integer.valueOf(1000));
Assertions.assertEquals(1000, builder.build().getWait());
}
@Test
void isCheck() {
RegistryBuilder builder = new RegistryBuilder();
builder.isCheck(true);
Assertions.assertTrue(builder.build().isCheck());
}
@Test
void isDynamic() {
RegistryBuilder builder = new RegistryBuilder();
builder.isDynamic(true);
Assertions.assertTrue(builder.build().isDynamic());
}
@Test
void register() {
RegistryBuilder builder = new RegistryBuilder();
builder.register(true);
Assertions.assertTrue(builder.build().isRegister());
}
@Test
void subscribe() {
RegistryBuilder builder = new RegistryBuilder();
builder.subscribe(true);
Assertions.assertTrue(builder.build().isSubscribe());
}
@Test
void appendParameter() {
RegistryBuilder builder = new RegistryBuilder();
builder.appendParameter("default.num", "one").appendParameter("num", "ONE");
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void appendParameters() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one");
source.put("num", "ONE");
RegistryBuilder builder = new RegistryBuilder();
builder.appendParameters(source);
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void isDefault() {
RegistryBuilder builder = new RegistryBuilder();
builder.isDefault(true);
Assertions.assertTrue(builder.build().isDefault());
}
@Test
void simplified() {
RegistryBuilder builder = new RegistryBuilder();
builder.simplified(true);
Assertions.assertTrue(builder.build().getSimplified());
}
@Test
void extraKeys() {
RegistryBuilder builder = new RegistryBuilder();
builder.extraKeys("extraKeys");
Assertions.assertEquals("extraKeys", builder.build().getExtraKeys());
}
@Test
void build() {
RegistryBuilder builder = new RegistryBuilder();
builder.address("address")
.username("username")
.password("password")
.port(8080)
.protocol("protocol")
.transporter("transporter")
.server("server")
.client("client")
.cluster("cluster")
.group("group")
.version("version")
.timeout(1000)
.session(2000)
.file("file")
.wait(Integer.valueOf(10))
.isCheck(true)
.isDynamic(false)
.register(true)
.subscribe(false)
.isDefault(true)
.simplified(false)
.extraKeys("A")
.parameter("default.num", "one")
.id("id");
RegistryConfig config = builder.build();
RegistryConfig config2 = builder.build();
Assertions.assertEquals(8080, config.getPort());
Assertions.assertEquals(1000, config.getTimeout());
Assertions.assertEquals(2000, config.getSession());
Assertions.assertEquals(10, config.getWait());
Assertions.assertTrue(config.isCheck());
Assertions.assertFalse(config.isDynamic());
Assertions.assertTrue(config.isRegister());
Assertions.assertFalse(config.isSubscribe());
Assertions.assertTrue(config.isDefault());
Assertions.assertFalse(config.getSimplified());
Assertions.assertEquals("address", config.getAddress());
Assertions.assertEquals("username", config.getUsername());
Assertions.assertEquals("password", config.getPassword());
Assertions.assertEquals("protocol", config.getProtocol());
Assertions.assertEquals("transporter", config.getTransporter());
Assertions.assertEquals("server", config.getServer());
Assertions.assertEquals("client", config.getClient());
Assertions.assertEquals("cluster", config.getCluster());
Assertions.assertEquals("group", config.getGroup());
Assertions.assertEquals("version", config.getVersion());
Assertions.assertEquals("file", config.getFile());
Assertions.assertEquals("A", config.getExtraKeys());
Assertions.assertTrue(config.getParameters().containsKey("default.num"));
Assertions.assertEquals("one", config.getParameters().get("default.num"));
Assertions.assertEquals("id", config.getId());
Assertions.assertNotSame(config, config2);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/AbstractServiceBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/AbstractServiceBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.AbstractServiceConfig;
import org.apache.dubbo.config.ProtocolConfig;
import java.util.Collections;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class AbstractServiceBuilderTest {
@Test
void version() {
ServiceBuilder builder = new ServiceBuilder();
builder.version("version");
Assertions.assertEquals("version", builder.build().getVersion());
}
@Test
void group() {
ServiceBuilder builder = new ServiceBuilder();
builder.group("group");
Assertions.assertEquals("group", builder.build().getGroup());
}
@Test
void deprecated() {
ServiceBuilder builder = new ServiceBuilder();
builder.deprecated(true);
Assertions.assertTrue(builder.build().isDeprecated());
builder.deprecated(false);
Assertions.assertFalse(builder.build().isDeprecated());
}
@Test
void delay() {
ServiceBuilder builder = new ServiceBuilder();
builder.delay(1000);
Assertions.assertEquals(1000, builder.build().getDelay());
}
@Test
void export() {
ServiceBuilder builder = new ServiceBuilder();
builder.export(true);
Assertions.assertTrue(builder.build().getExport());
builder.export(false);
Assertions.assertFalse(builder.build().getExport());
}
@Test
void weight() {
ServiceBuilder builder = new ServiceBuilder();
builder.weight(500);
Assertions.assertEquals(500, builder.build().getWeight());
}
@Test
void document() {
ServiceBuilder builder = new ServiceBuilder();
builder.document("http://dubbo.apache.org");
Assertions.assertEquals("http://dubbo.apache.org", builder.build().getDocument());
}
@Test
void dynamic() {
ServiceBuilder builder = new ServiceBuilder();
builder.dynamic(true);
Assertions.assertTrue(builder.build().isDynamic());
builder.dynamic(false);
Assertions.assertFalse(builder.build().isDynamic());
}
@Test
void token() {
ServiceBuilder builder = new ServiceBuilder();
builder.token("token");
Assertions.assertEquals("token", builder.build().getToken());
}
@Test
void token1() {
ServiceBuilder builder = new ServiceBuilder();
builder.token(true);
Assertions.assertEquals("true", builder.build().getToken());
builder.token(false);
Assertions.assertEquals("false", builder.build().getToken());
builder.token((Boolean) null);
Assertions.assertNull(builder.build().getToken());
}
@Test
void accesslog() {
ServiceBuilder builder = new ServiceBuilder();
builder.accesslog("accesslog");
Assertions.assertEquals("accesslog", builder.build().getAccesslog());
}
@Test
void accesslog1() {
ServiceBuilder builder = new ServiceBuilder();
builder.accesslog(true);
Assertions.assertEquals("true", builder.build().getAccesslog());
builder.accesslog(false);
Assertions.assertEquals("false", builder.build().getAccesslog());
builder.accesslog((Boolean) null);
Assertions.assertNull(builder.build().getAccesslog());
}
@Test
void addProtocols() {
ProtocolConfig protocol = new ProtocolConfig();
ServiceBuilder builder = new ServiceBuilder();
Assertions.assertNull(builder.build().getProtocols());
builder.addProtocols(Collections.singletonList(protocol));
Assertions.assertNotNull(builder.build().getProtocols());
Assertions.assertEquals(1, builder.build().getProtocols().size());
}
@Test
void addProtocol() {
ProtocolConfig protocol = new ProtocolConfig();
ServiceBuilder builder = new ServiceBuilder();
Assertions.assertNull(builder.build().getProtocols());
builder.addProtocol(protocol);
Assertions.assertNotNull(builder.build().getProtocols());
Assertions.assertEquals(1, builder.build().getProtocols().size());
Assertions.assertEquals(protocol, builder.build().getProtocol());
}
@Test
void protocolIds() {
ServiceBuilder builder = new ServiceBuilder();
builder.protocolIds("protocolIds");
Assertions.assertEquals("protocolIds", builder.build().getProtocolIds());
}
@Test
void tag() {
ServiceBuilder builder = new ServiceBuilder();
builder.tag("tag");
Assertions.assertEquals("tag", builder.build().getTag());
}
@Test
void executes() {
ServiceBuilder builder = new ServiceBuilder();
builder.executes(10);
Assertions.assertEquals(10, builder.build().getExecutes());
}
@Test
void register() {
ServiceBuilder builder = new ServiceBuilder();
builder.register(true);
Assertions.assertTrue(builder.build().isRegister());
builder.register(false);
Assertions.assertFalse(builder.build().isRegister());
}
@Test
void warmup() {
ServiceBuilder builder = new ServiceBuilder();
builder.warmup(100);
Assertions.assertEquals(100, builder.build().getWarmup());
}
@Test
void serialization() {
ServiceBuilder builder = new ServiceBuilder();
builder.serialization("serialization");
Assertions.assertEquals("serialization", builder.build().getSerialization());
}
@Test
void build() {
ProtocolConfig protocol = new ProtocolConfig();
ServiceBuilder builder = new ServiceBuilder();
builder.version("version")
.group("group")
.deprecated(true)
.delay(1000)
.export(false)
.weight(1)
.document("document")
.dynamic(true)
.token("token")
.accesslog("accesslog")
.addProtocol(protocol)
.protocolIds("protocolIds")
.tag("tag")
.executes(100)
.register(false)
.warmup(200)
.serialization("serialization")
.id("id");
ServiceConfig config = builder.build();
ServiceConfig config2 = builder.build();
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals("version", config.getVersion());
Assertions.assertEquals("group", config.getGroup());
Assertions.assertEquals("document", config.getDocument());
Assertions.assertEquals("token", config.getToken());
Assertions.assertEquals("accesslog", config.getAccesslog());
Assertions.assertEquals("protocolIds", config.getProtocolIds());
Assertions.assertEquals("tag", config.getTag());
Assertions.assertEquals("serialization", config.getSerialization());
Assertions.assertTrue(config.isDeprecated());
Assertions.assertFalse(config.getExport());
Assertions.assertTrue(config.isDynamic());
Assertions.assertFalse(config.isRegister());
Assertions.assertEquals(1000, config.getDelay());
Assertions.assertEquals(1, config.getWeight());
Assertions.assertEquals(100, config.getExecutes());
Assertions.assertEquals(200, config.getWarmup());
Assertions.assertNotSame(config, config2);
}
private static class ServiceBuilder extends AbstractServiceBuilder<ServiceConfig, ServiceBuilder> {
public ServiceConfig build() {
ServiceConfig parameterConfig = new ServiceConfig();
super.build(parameterConfig);
return parameterConfig;
}
@Override
protected ServiceBuilder getThis() {
return this;
}
}
private static class ServiceConfig extends AbstractServiceConfig {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ProviderBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ProviderBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.ProviderConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class ProviderBuilderTest {
@Test
void setHost() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.host("host");
Assertions.assertEquals("host", builder.build().getHost());
}
@Test
void port() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.port(8080);
Assertions.assertEquals(8080, builder.build().getPort());
}
@Test
void contextPath() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.contextPath("contextpath");
Assertions.assertEquals("contextpath", builder.build().getContextpath());
}
@Test
void threadPool() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.threadPool("mockthreadpool");
Assertions.assertEquals("mockthreadpool", builder.build().getThreadpool());
}
@Test
void threads() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.threads(20);
Assertions.assertEquals(20, builder.build().getThreads());
}
@Test
void ioThreads() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.ioThreads(25);
Assertions.assertEquals(25, builder.build().getIothreads());
}
@Test
void queues() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.queues(30);
Assertions.assertEquals(30, builder.build().getQueues());
}
@Test
void accepts() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.accepts(35);
Assertions.assertEquals(35, builder.build().getAccepts());
}
@Test
void codec() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.codec("mockcodec");
Assertions.assertEquals("mockcodec", builder.build().getCodec());
}
@Test
void charset() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.charset("utf-8");
Assertions.assertEquals("utf-8", builder.build().getCharset());
}
@Test
void payload() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.payload(40);
Assertions.assertEquals(40, builder.build().getPayload());
}
@Test
void buffer() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.buffer(1024);
Assertions.assertEquals(1024, builder.build().getBuffer());
}
@Test
void transporter() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.transporter("mocktransporter");
Assertions.assertEquals("mocktransporter", builder.build().getTransporter());
}
@Test
void exchanger() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.exchanger("mockexchanger");
Assertions.assertEquals("mockexchanger", builder.build().getExchanger());
}
@Test
void dispatcher() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.dispatcher("mockdispatcher");
Assertions.assertEquals("mockdispatcher", builder.build().getDispatcher());
}
@Test
void networker() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.networker("networker");
Assertions.assertEquals("networker", builder.build().getNetworker());
}
@Test
void server() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.server("server");
Assertions.assertEquals("server", builder.build().getServer());
}
@Test
void client() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.client("client");
Assertions.assertEquals("client", builder.build().getClient());
}
@Test
void telnet() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.telnet("mocktelnethandler");
Assertions.assertEquals("mocktelnethandler", builder.build().getTelnet());
}
@Test
void prompt() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.prompt("prompt");
Assertions.assertEquals("prompt", builder.build().getPrompt());
}
@Test
void status() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.status("mockstatuschecker");
Assertions.assertEquals("mockstatuschecker", builder.build().getStatus());
}
@Test
void Wait() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.wait(Integer.valueOf(1000));
Assertions.assertEquals(1000, builder.build().getWait());
}
@Test
void isDefault() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.isDefault(true);
Assertions.assertTrue(builder.build().isDefault());
}
@Test
void build() {
ProviderBuilder builder = ProviderBuilder.newBuilder();
builder.host("host")
.port(8080)
.contextPath("contextpath")
.threadPool("mockthreadpool")
.threads(2)
.ioThreads(3)
.queues(4)
.accepts(5)
.codec("mockcodec")
.charset("utf-8")
.payload(6)
.buffer(1024)
.transporter("mocktransporter")
.exchanger("mockexchanger")
.dispatcher("mockdispatcher")
.networker("networker")
.server("server")
.client("client")
.telnet("mocktelnethandler")
.prompt("prompt")
.status("mockstatuschecker")
.wait(Integer.valueOf(1000))
.isDefault(true)
.id("id");
ProviderConfig config = builder.build();
ProviderConfig config2 = builder.build();
Assertions.assertEquals(8080, config.getPort());
Assertions.assertEquals(2, config.getThreads());
Assertions.assertEquals(3, config.getIothreads());
Assertions.assertEquals(4, config.getQueues());
Assertions.assertEquals(5, config.getAccepts());
Assertions.assertEquals(6, config.getPayload());
Assertions.assertEquals(1024, config.getBuffer());
Assertions.assertEquals(1000, config.getWait());
Assertions.assertEquals("host", config.getHost());
Assertions.assertEquals("contextpath", config.getContextpath());
Assertions.assertEquals("mockthreadpool", config.getThreadpool());
Assertions.assertEquals("mockcodec", config.getCodec());
Assertions.assertEquals("utf-8", config.getCharset());
Assertions.assertEquals("mocktransporter", config.getTransporter());
Assertions.assertEquals("mockexchanger", config.getExchanger());
Assertions.assertEquals("mockdispatcher", config.getDispatcher());
Assertions.assertEquals("networker", config.getNetworker());
Assertions.assertEquals("server", config.getServer());
Assertions.assertEquals("client", config.getClient());
Assertions.assertEquals("mocktelnethandler", config.getTelnet());
Assertions.assertEquals("prompt", config.getPrompt());
Assertions.assertEquals("mockstatuschecker", config.getStatus());
Assertions.assertTrue(config.isDefault());
Assertions.assertEquals("id", config.getId());
Assertions.assertNotSame(config, config2);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/AbstractBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/AbstractBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.AbstractConfig;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class AbstractBuilderTest {
@Test
void id() {
Builder builder = new Builder();
builder.id("id");
Assertions.assertEquals("id", builder.build().getId());
}
@Test
void appendParameter() {
Map<String, String> source = null;
Map<String, String> parameters = new HashMap<>();
parameters.put("default.num", "one");
parameters.put("num", "ONE");
source = AbstractBuilder.appendParameters(source, parameters);
Assertions.assertTrue(source.containsKey("default.num"));
Assertions.assertEquals("ONE", source.get("num"));
}
@Test
void appendParameter2() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one1");
source.put("num", "ONE1");
Map<String, String> parameters = new HashMap<>();
parameters.put("default.num", "one");
parameters.put("num", "ONE");
source = AbstractBuilder.appendParameters(source, parameters);
Assertions.assertTrue(source.containsKey("default.num"));
Assertions.assertEquals("ONE", source.get("num"));
}
@Test
void appendParameters() {
Map<String, String> source = null;
source = AbstractBuilder.appendParameter(source, "default.num", "one");
source = AbstractBuilder.appendParameter(source, "num", "ONE");
Assertions.assertTrue(source.containsKey("default.num"));
Assertions.assertEquals("ONE", source.get("num"));
}
@Test
void appendParameters2() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one1");
source.put("num", "ONE1");
source = AbstractBuilder.appendParameter(source, "default.num", "one");
source = AbstractBuilder.appendParameter(source, "num", "ONE");
Assertions.assertTrue(source.containsKey("default.num"));
Assertions.assertEquals("ONE", source.get("num"));
}
@Test
void build() {
Builder builder = new Builder();
builder.id("id");
Config config = builder.build();
Config config2 = builder.build();
Assertions.assertEquals("id", config.getId());
Assertions.assertNotSame(config, config2);
}
private static class Builder extends AbstractBuilder<Config, Builder> {
public Config build() {
Config parameterConfig = new Config();
super.build(parameterConfig);
return parameterConfig;
}
@Override
protected Builder getThis() {
return this;
}
}
private static class Config extends AbstractConfig {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/AbstractReferenceBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/AbstractReferenceBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.AbstractReferenceConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.apache.dubbo.common.constants.CommonConstants.GENERIC_SERIALIZATION_BEAN;
class AbstractReferenceBuilderTest {
@Test
void check() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.check(true);
Assertions.assertTrue(builder.build().isCheck());
builder.check(false);
Assertions.assertFalse(builder.build().isCheck());
}
@Test
void init() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.init(true);
Assertions.assertTrue(builder.build().isInit());
builder.init(false);
Assertions.assertFalse(builder.build().isInit());
}
@Test
void generic() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.generic(true);
Assertions.assertTrue(builder.build().isGeneric());
builder.generic(false);
Assertions.assertFalse(builder.build().isGeneric());
}
@Test
void generic1() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.generic(GENERIC_SERIALIZATION_BEAN);
Assertions.assertEquals(GENERIC_SERIALIZATION_BEAN, builder.build().getGeneric());
}
@Test
void injvm() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.injvm(true);
Assertions.assertTrue(builder.build().isInjvm());
builder.injvm(false);
Assertions.assertFalse(builder.build().isInjvm());
}
@Test
void lazy() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.lazy(true);
Assertions.assertTrue(builder.build().getLazy());
builder.lazy(false);
Assertions.assertFalse(builder.build().getLazy());
}
@Test
void reconnect() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.reconnect("reconnect");
Assertions.assertEquals("reconnect", builder.build().getReconnect());
}
@Test
void sticky() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.sticky(true);
Assertions.assertTrue(builder.build().getSticky());
builder.sticky(false);
Assertions.assertFalse(builder.build().getSticky());
}
@Test
void version() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.version("version");
Assertions.assertEquals("version", builder.build().getVersion());
}
@Test
void group() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.group("group");
Assertions.assertEquals("group", builder.build().getGroup());
}
@Test
void build() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.check(true)
.init(false)
.generic(true)
.injvm(false)
.lazy(true)
.reconnect("reconnect")
.sticky(false)
.version("version")
.group("group")
.id("id");
ReferenceConfig config = builder.build();
ReferenceConfig config2 = builder.build();
Assertions.assertEquals("id", config.getId());
Assertions.assertTrue(config.isCheck());
Assertions.assertFalse(config.isInit());
Assertions.assertTrue(config.isGeneric());
Assertions.assertFalse(config.isInjvm());
Assertions.assertTrue(config.getLazy());
Assertions.assertFalse(config.getSticky());
Assertions.assertEquals("reconnect", config.getReconnect());
Assertions.assertEquals("version", config.getVersion());
Assertions.assertEquals("group", config.getGroup());
Assertions.assertNotSame(config, config2);
}
private static class ReferenceBuilder extends AbstractReferenceBuilder<ReferenceConfig, ReferenceBuilder> {
public ReferenceConfig build() {
ReferenceConfig parameterConfig = new ReferenceConfig();
super.build(parameterConfig);
return parameterConfig;
}
@Override
protected ReferenceBuilder getThis() {
return this;
}
}
private static class ReferenceConfig extends AbstractReferenceConfig {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/TripleBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/TripleBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.nested.TripleConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class TripleBuilderTest {
@Test
void maxBodySize() {
TripleBuilder builder = TripleBuilder.newBuilder();
builder.maxBodySize(10240);
Assertions.assertEquals(10240, builder.build().getMaxBodySize());
}
@Test
void maxResponseBodySize() {
TripleBuilder builder = TripleBuilder.newBuilder();
builder.maxResponseBodySize(8192);
Assertions.assertEquals(8192, builder.build().getMaxResponseBodySize());
}
@Test
void maxChunkSize() {
TripleBuilder builder = TripleBuilder.newBuilder();
builder.maxChunkSize(2048);
Assertions.assertEquals(2048, builder.build().getMaxChunkSize());
}
@Test
void maxHeaderSize() {
TripleBuilder builder = TripleBuilder.newBuilder();
builder.maxHeaderSize(40960);
Assertions.assertEquals(40960, builder.build().getMaxHeaderSize());
}
@Test
void maxInitialLineLength() {
TripleBuilder builder = TripleBuilder.newBuilder();
builder.maxInitialLineLength(Integer.MAX_VALUE);
Assertions.assertEquals(Integer.MAX_VALUE, builder.build().getMaxInitialLineLength());
}
@Test
void initialBufferSize() {
TripleBuilder builder = TripleBuilder.newBuilder();
builder.initialBufferSize(3000);
Assertions.assertEquals(3000, builder.build().getInitialBufferSize());
}
@Test
void headerTableSize() {
TripleBuilder builder = TripleBuilder.newBuilder();
builder.headerTableSize(1000);
Assertions.assertEquals(1000, builder.build().getHeaderTableSize());
}
@Test
void enablePush() {
TripleBuilder builder = TripleBuilder.newBuilder();
builder.enablePush(false);
Assertions.assertFalse(builder.build().getEnablePush());
}
@Test
void maxConcurrentStreams() {
TripleBuilder builder = TripleBuilder.newBuilder();
builder.maxConcurrentStreams(3000);
Assertions.assertEquals(3000, builder.build().getMaxConcurrentStreams());
}
@Test
void initialWindowSize() {
TripleBuilder builder = TripleBuilder.newBuilder();
builder.initialWindowSize(10240);
Assertions.assertEquals(10240, builder.build().getInitialWindowSize());
}
@Test
void connectionInitialWindowSize() {
TripleBuilder builder = TripleBuilder.newBuilder();
builder.connectionInitialWindowSize(8192);
Assertions.assertEquals(8192, builder.build().getConnectionInitialWindowSize());
}
@Test
void maxFrameSize() {
TripleBuilder builder = TripleBuilder.newBuilder();
builder.maxFrameSize(4096);
Assertions.assertEquals(4096, builder.build().getMaxFrameSize());
}
@Test
void maxHeaderListSize() {
TripleBuilder builder = TripleBuilder.newBuilder();
builder.maxHeaderListSize(2000);
Assertions.assertEquals(2000, builder.build().getMaxHeaderListSize());
}
@Test
void build() {
TripleBuilder builder = TripleBuilder.newBuilder();
builder.maxBodySize(2048)
.maxResponseBodySize(3072)
.maxChunkSize(10240)
.maxHeaderSize(400)
.maxInitialLineLength(100)
.initialBufferSize(8192)
.headerTableSize(300)
.enablePush(true)
.maxConcurrentStreams(Integer.MAX_VALUE)
.initialWindowSize(4096)
.connectionInitialWindowSize(8192)
.maxFrameSize(1024)
.maxHeaderListSize(500);
TripleConfig config = builder.build();
TripleConfig config2 = builder.build();
Assertions.assertEquals(2048, config.getMaxBodySize());
Assertions.assertEquals(3072, config.getMaxResponseBodySize());
Assertions.assertEquals(10240, config.getMaxChunkSize());
Assertions.assertEquals(400, config.getMaxHeaderSize());
Assertions.assertEquals(100, config.getMaxInitialLineLength());
Assertions.assertEquals(8192, config.getInitialBufferSize());
Assertions.assertEquals(300, config.getHeaderTableSize());
Assertions.assertTrue(config.getEnablePush());
Assertions.assertEquals(Integer.MAX_VALUE, config.getMaxConcurrentStreams());
Assertions.assertEquals(4096, config.getInitialWindowSize());
Assertions.assertEquals(1024, config.getMaxFrameSize());
Assertions.assertEquals(500, config.getMaxHeaderListSize());
Assertions.assertNotSame(config, config2);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ArgumentBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ArgumentBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.ArgumentConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class ArgumentBuilderTest {
@Test
void index() {
ArgumentBuilder builder = ArgumentBuilder.newBuilder();
builder.index(1);
Assertions.assertEquals(1, builder.build().getIndex());
}
@Test
void type() {
ArgumentBuilder builder = ArgumentBuilder.newBuilder();
builder.type("int");
Assertions.assertEquals("int", builder.build().getType());
}
@Test
void callback() {
ArgumentBuilder builder = ArgumentBuilder.newBuilder();
builder.callback(true);
Assertions.assertTrue(builder.build().isCallback());
builder.callback(false);
Assertions.assertFalse(builder.build().isCallback());
}
@Test
void build() {
ArgumentBuilder builder = ArgumentBuilder.newBuilder();
builder.index(1).type("int").callback(true);
ArgumentConfig argument1 = builder.build();
ArgumentConfig argument2 = builder.build();
Assertions.assertTrue(argument1.isCallback());
Assertions.assertEquals("int", argument1.getType());
Assertions.assertEquals(1, argument1.getIndex());
Assertions.assertNotSame(argument1, argument2);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/MetricsBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/MetricsBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.MetricsConfig;
import org.apache.dubbo.config.nested.AggregationConfig;
import org.apache.dubbo.config.nested.HistogramConfig;
import org.apache.dubbo.config.nested.PrometheusConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class MetricsBuilderTest {
@Test
void protocol() {
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.protocol("test");
Assertions.assertEquals("test", builder.build().getProtocol());
}
@Test
void enableJvm() {
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.enableJvm(true);
Assertions.assertTrue(builder.build().getEnableJvm());
}
@Test
void enableThreadPool() {
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.enableThreadPool(false);
Assertions.assertFalse(builder.build().getEnableThreadpool());
}
@Test
void enableRegistry() {
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.enableRegistry(true);
Assertions.assertTrue(builder.build().getEnableRegistry());
}
@Test
void enableMetadata() {
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.enableMetadata(true);
Assertions.assertTrue(builder.build().getEnableMetadata());
}
@Test
void exportMetricsService() {
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.exportMetricsService(false);
Assertions.assertFalse(builder.build().getExportMetricsService());
}
@Test
void enableMetricsInit() {
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.enableMetricsInit(true);
Assertions.assertTrue(builder.build().getEnableMetricsInit());
}
@Test
void enableCollectorSync() {
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.enableCollectorSync(true);
Assertions.assertTrue(builder.build().getEnableCollectorSync());
}
@Test
void collectorSyncPeriod() {
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.collectorSyncPeriod(10);
Assertions.assertEquals(10, builder.build().getCollectorSyncPeriod());
}
@Test
void exportServiceProtocol() {
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.exportServiceProtocol("tri");
Assertions.assertEquals("tri", builder.build().getExportServiceProtocol());
}
@Test
void exportServicePort() {
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.exportServicePort(2999);
Assertions.assertEquals(2999, builder.build().getExportServicePort());
}
@Test
void useGlobalRegistry() {
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.useGlobalRegistry(true);
Assertions.assertTrue(builder.build().getUseGlobalRegistry());
}
@Test
void enableRpc() {
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.enableRpc(false);
Assertions.assertFalse(builder.build().getEnableRpc());
}
@Test
void rpcLevel() {
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.rpcLevel("SERVICE");
Assertions.assertEquals("SERVICE", builder.build().getRpcLevel());
}
@Test
void aggregation() {
AggregationConfig aggregation = new AggregationConfig();
aggregation.setEnabled(true);
aggregation.setEnableQps(false);
aggregation.setBucketNum(100);
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.aggregation(aggregation);
Assertions.assertSame(aggregation, builder.build().getAggregation());
Assertions.assertTrue(builder.build().getAggregation().getEnabled());
Assertions.assertFalse(builder.build().getAggregation().getEnableQps());
Assertions.assertEquals(100, builder.build().getAggregation().getBucketNum());
}
@Test
void histogram() {
HistogramConfig histogram = new HistogramConfig();
histogram.setEnabled(true);
histogram.setMaxExpectedMs(1000);
histogram.setBucketsMs(new Integer[] {100, 200, 300, 400, 500});
histogram.setPercentiles(new double[] {0.5, 0.9, 0.95, 0.99});
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.histogram(histogram);
Assertions.assertSame(histogram, builder.build().getHistogram());
Assertions.assertTrue(builder.build().getHistogram().getEnabled());
Assertions.assertEquals(1000, builder.build().getHistogram().getMaxExpectedMs());
Assertions.assertArrayEquals(
new Integer[] {100, 200, 300, 400, 500},
builder.build().getHistogram().getBucketsMs());
Assertions.assertArrayEquals(
new double[] {0.5, 0.9, 0.95, 0.99},
builder.build().getHistogram().getPercentiles());
}
@Test
void prometheus() {
PrometheusConfig.Exporter exporter = new PrometheusConfig.Exporter();
exporter.setEnabled(true);
exporter.setEnableHttpServiceDiscovery(true);
exporter.setHttpServiceDiscoveryUrl("localhost:8080");
PrometheusConfig.Pushgateway pushGateway = new PrometheusConfig.Pushgateway();
pushGateway.setEnabled(true);
pushGateway.setBaseUrl("localhost:9091");
pushGateway.setUsername("username");
pushGateway.setPassword("password");
pushGateway.setJob("job");
pushGateway.setPushInterval(30);
PrometheusConfig prometheus = new PrometheusConfig();
prometheus.setExporter(exporter);
prometheus.setPushgateway(pushGateway);
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.prometheus(prometheus);
Assertions.assertSame(prometheus, builder.build().getPrometheus());
Assertions.assertSame(exporter, builder.build().getPrometheus().getExporter());
Assertions.assertSame(pushGateway, builder.build().getPrometheus().getPushgateway());
Assertions.assertTrue(builder.build().getPrometheus().getExporter().getEnabled());
Assertions.assertTrue(builder.build().getPrometheus().getExporter().getEnableHttpServiceDiscovery());
Assertions.assertEquals(
"localhost:8080", builder.build().getPrometheus().getExporter().getHttpServiceDiscoveryUrl());
Assertions.assertTrue(builder.build().getPrometheus().getPushgateway().getEnabled());
Assertions.assertEquals(
"localhost:9091",
builder.build().getPrometheus().getPushgateway().getBaseUrl());
Assertions.assertEquals(
"username", builder.build().getPrometheus().getPushgateway().getUsername());
Assertions.assertEquals(
"password", builder.build().getPrometheus().getPushgateway().getPassword());
Assertions.assertEquals(
"job", builder.build().getPrometheus().getPushgateway().getJob());
Assertions.assertEquals(
30, builder.build().getPrometheus().getPushgateway().getPushInterval());
}
@Test
void build() {
PrometheusConfig.Exporter exporter = new PrometheusConfig.Exporter();
exporter.setEnabled(true);
exporter.setEnableHttpServiceDiscovery(true);
exporter.setHttpServiceDiscoveryUrl("localhost:8080");
PrometheusConfig.Pushgateway pushGateway = new PrometheusConfig.Pushgateway();
pushGateway.setEnabled(true);
pushGateway.setBaseUrl("localhost:9091");
pushGateway.setUsername("username");
pushGateway.setPassword("password");
pushGateway.setJob("job");
pushGateway.setPushInterval(30);
PrometheusConfig prometheus = new PrometheusConfig();
prometheus.setExporter(exporter);
prometheus.setPushgateway(pushGateway);
HistogramConfig histogram = new HistogramConfig();
histogram.setEnabled(true);
histogram.setMaxExpectedMs(1000);
histogram.setBucketsMs(new Integer[] {100, 200, 300, 400, 500});
histogram.setPercentiles(new double[] {0.5, 0.9, 0.95, 0.99});
AggregationConfig aggregation = new AggregationConfig();
aggregation.setEnabled(true);
aggregation.setEnableQps(false);
aggregation.setBucketNum(100);
MetricsBuilder builder = MetricsBuilder.newBuilder();
builder.protocol("test")
.enableJvm(true)
.enableThreadPool(true)
.enableRegistry(false)
.enableMetadata(false)
.exportMetricsService(true)
.enableMetricsInit(false)
.enableCollectorSync(true)
.collectorSyncPeriod(10)
.prometheus(prometheus)
.histogram(histogram)
.aggregation(aggregation)
.exportServiceProtocol("tri")
.exportServicePort(10010)
.useGlobalRegistry(true)
.enableRpc(true)
.rpcLevel("METHOD");
MetricsConfig config = builder.build();
MetricsConfig config2 = builder.build();
Assertions.assertEquals("test", config.getProtocol());
Assertions.assertTrue(config.getEnableJvm());
Assertions.assertTrue(config.getEnableThreadpool());
Assertions.assertFalse(config.getEnableRegistry());
Assertions.assertFalse(config.getEnableMetadata());
Assertions.assertTrue(config.getExportMetricsService());
Assertions.assertFalse(config.getEnableMetricsInit());
Assertions.assertTrue(config.getEnableCollectorSync());
Assertions.assertEquals(10, config.getCollectorSyncPeriod());
Assertions.assertSame(prometheus, config.getPrometheus());
Assertions.assertSame(exporter, config.getPrometheus().getExporter());
Assertions.assertSame(pushGateway, config.getPrometheus().getPushgateway());
Assertions.assertTrue(config.getPrometheus().getExporter().getEnabled());
Assertions.assertTrue(config.getPrometheus().getExporter().getEnableHttpServiceDiscovery());
Assertions.assertEquals(
"localhost:8080", config.getPrometheus().getExporter().getHttpServiceDiscoveryUrl());
Assertions.assertTrue(config.getPrometheus().getPushgateway().getEnabled());
Assertions.assertEquals(
"localhost:9091", config.getPrometheus().getPushgateway().getBaseUrl());
Assertions.assertEquals(
"username", config.getPrometheus().getPushgateway().getUsername());
Assertions.assertEquals(
"password", config.getPrometheus().getPushgateway().getPassword());
Assertions.assertEquals("job", config.getPrometheus().getPushgateway().getJob());
Assertions.assertEquals(30, config.getPrometheus().getPushgateway().getPushInterval());
Assertions.assertSame(histogram, config.getHistogram());
Assertions.assertTrue(config.getHistogram().getEnabled());
Assertions.assertEquals(1000, config.getHistogram().getMaxExpectedMs());
Assertions.assertArrayEquals(
new Integer[] {100, 200, 300, 400, 500}, config.getHistogram().getBucketsMs());
Assertions.assertArrayEquals(
new double[] {0.5, 0.9, 0.95, 0.99}, config.getHistogram().getPercentiles());
Assertions.assertSame(aggregation, config.getAggregation());
Assertions.assertTrue(config.getAggregation().getEnabled());
Assertions.assertFalse(config.getAggregation().getEnableQps());
Assertions.assertEquals(100, config.getAggregation().getBucketNum());
Assertions.assertEquals("tri", config.getExportServiceProtocol());
Assertions.assertEquals(10010, config.getExportServicePort());
Assertions.assertTrue(config.getUseGlobalRegistry());
Assertions.assertTrue(config.getEnableRpc());
Assertions.assertEquals("METHOD", config.getRpcLevel());
Assertions.assertNotSame(config, config2);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ProtocolBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ProtocolBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.ProtocolConfig;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class ProtocolBuilderTest {
@Test
void name() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.name("name");
Assertions.assertEquals("name", builder.build().getName());
}
@Test
void host() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.host("host");
Assertions.assertEquals("host", builder.build().getHost());
}
@Test
void port() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.port(8080);
Assertions.assertEquals(8080, builder.build().getPort());
}
@Test
void contextpath() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.contextpath("contextpath");
Assertions.assertEquals("contextpath", builder.build().getContextpath());
}
@Test
void path() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.path("path");
Assertions.assertEquals("path", builder.build().getPath());
}
@Test
void threadpool() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.threadpool("mockthreadpool");
Assertions.assertEquals("mockthreadpool", builder.build().getThreadpool());
}
@Test
void corethreads() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.corethreads(10);
Assertions.assertEquals(10, builder.build().getCorethreads());
}
@Test
void threads() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.threads(20);
Assertions.assertEquals(20, builder.build().getThreads());
}
@Test
void iothreads() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.iothreads(25);
Assertions.assertEquals(25, builder.build().getIothreads());
}
@Test
void queues() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.queues(30);
Assertions.assertEquals(30, builder.build().getQueues());
}
@Test
void accepts() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.accepts(35);
Assertions.assertEquals(35, builder.build().getAccepts());
}
@Test
void codec() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.codec("mockcodec");
Assertions.assertEquals("mockcodec", builder.build().getCodec());
}
@Test
void serialization() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.serialization("serialization");
Assertions.assertEquals("serialization", builder.build().getSerialization());
}
@Test
void charset() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.charset("utf-8");
Assertions.assertEquals("utf-8", builder.build().getCharset());
}
@Test
void payload() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.payload(40);
Assertions.assertEquals(40, builder.build().getPayload());
}
@Test
void buffer() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.buffer(1024);
Assertions.assertEquals(1024, builder.build().getBuffer());
}
@Test
void heartbeat() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.heartbeat(1000);
Assertions.assertEquals(1000, builder.build().getHeartbeat());
}
@Test
void accesslog() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.accesslog("accesslog");
Assertions.assertEquals("accesslog", builder.build().getAccesslog());
}
@Test
void transporter() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.transporter("mocktransporter");
Assertions.assertEquals("mocktransporter", builder.build().getTransporter());
}
@Test
void exchanger() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.exchanger("mockexchanger");
Assertions.assertEquals("mockexchanger", builder.build().getExchanger());
}
@Test
void dispatcher() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.dispatcher("mockdispatcher");
Assertions.assertEquals("mockdispatcher", builder.build().getDispatcher());
}
@Test
void dispather() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.dispather("mockdispatcher");
Assertions.assertEquals("mockdispatcher", builder.build().getDispatcher());
}
@Test
void networker() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.networker("networker");
Assertions.assertEquals("networker", builder.build().getNetworker());
}
@Test
void server() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.server("server");
Assertions.assertEquals("server", builder.build().getServer());
}
@Test
void client() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.client("client");
Assertions.assertEquals("client", builder.build().getClient());
}
@Test
void telnet() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.telnet("mocktelnethandler");
Assertions.assertEquals("mocktelnethandler", builder.build().getTelnet());
}
@Test
void prompt() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.prompt("prompt");
Assertions.assertEquals("prompt", builder.build().getPrompt());
}
@Test
void status() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.status("mockstatuschecker");
Assertions.assertEquals("mockstatuschecker", builder.build().getStatus());
}
@Test
void register() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.register(true);
Assertions.assertTrue(builder.build().isRegister());
}
@Test
void keepAlive() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.keepAlive(true);
Assertions.assertTrue(builder.build().getKeepAlive());
}
@Test
void optimizer() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.optimizer("optimizer");
Assertions.assertEquals("optimizer", builder.build().getOptimizer());
}
@Test
void extension() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.extension("extension");
Assertions.assertEquals("extension", builder.build().getExtension());
}
@Test
void appendParameter() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.appendParameter("default.num", "one").appendParameter("num", "ONE");
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void appendParameters() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one");
source.put("num", "ONE");
ProtocolBuilder builder = new ProtocolBuilder();
builder.appendParameters(source);
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void isDefault() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.isDefault(true);
Assertions.assertTrue(builder.build().isDefault());
}
@Test
void build() {
ProtocolBuilder builder = new ProtocolBuilder();
builder.name("name")
.host("host")
.port(8080)
.contextpath("contextpath")
.threadpool("mockthreadpool")
.corethreads(1)
.threads(2)
.iothreads(3)
.queues(4)
.accepts(5)
.codec("mockcodec")
.serialization("serialization")
.charset("utf-8")
.payload(6)
.buffer(1024)
.heartbeat(1000)
.accesslog("accesslog")
.transporter("mocktransporter")
.exchanger("mockexchanger")
.dispatcher("mockdispatcher")
.networker("networker")
.server("server")
.client("client")
.telnet("mocktelnethandler")
.prompt("prompt")
.status("mockstatuschecker")
.register(true)
.keepAlive(false)
.optimizer("optimizer")
.extension("extension")
.isDefault(true)
.appendParameter("default.num", "one")
.id("id");
ProtocolConfig config = builder.build();
ProtocolConfig config2 = builder.build();
Assertions.assertEquals(8080, config.getPort());
Assertions.assertEquals(1, config.getCorethreads());
Assertions.assertEquals(2, config.getThreads());
Assertions.assertEquals(3, config.getIothreads());
Assertions.assertEquals(4, config.getQueues());
Assertions.assertEquals(5, config.getAccepts());
Assertions.assertEquals(6, config.getPayload());
Assertions.assertEquals(1024, config.getBuffer());
Assertions.assertEquals(1000, config.getHeartbeat());
Assertions.assertEquals("name", config.getName());
Assertions.assertEquals("host", config.getHost());
Assertions.assertEquals("contextpath", config.getContextpath());
Assertions.assertEquals("mockthreadpool", config.getThreadpool());
Assertions.assertEquals("mockcodec", config.getCodec());
Assertions.assertEquals("serialization", config.getSerialization());
Assertions.assertEquals("utf-8", config.getCharset());
Assertions.assertEquals("accesslog", config.getAccesslog());
Assertions.assertEquals("mocktransporter", config.getTransporter());
Assertions.assertEquals("mockexchanger", config.getExchanger());
Assertions.assertEquals("mockdispatcher", config.getDispatcher());
Assertions.assertEquals("networker", config.getNetworker());
Assertions.assertEquals("server", config.getServer());
Assertions.assertEquals("client", config.getClient());
Assertions.assertEquals("mocktelnethandler", config.getTelnet());
Assertions.assertEquals("prompt", config.getPrompt());
Assertions.assertEquals("mockstatuschecker", config.getStatus());
Assertions.assertEquals("optimizer", config.getOptimizer());
Assertions.assertEquals("extension", config.getExtension());
Assertions.assertTrue(config.isRegister());
Assertions.assertFalse(config.getKeepAlive());
Assertions.assertTrue(config.isDefault());
Assertions.assertTrue(config.getParameters().containsKey("default.num"));
Assertions.assertEquals("one", config.getParameters().get("default.num"));
Assertions.assertEquals("id", config.getId());
Assertions.assertNotSame(config, config2);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/MetadataReportBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/MetadataReportBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.MetadataReportConfig;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class MetadataReportBuilderTest {
@Test
void address() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.address("address");
Assertions.assertEquals("address", builder.build().getAddress());
}
@Test
void username() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.username("username");
Assertions.assertEquals("username", builder.build().getUsername());
}
@Test
void password() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.password("password");
Assertions.assertEquals("password", builder.build().getPassword());
}
@Test
void timeout() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.timeout(1000);
Assertions.assertEquals(1000, builder.build().getTimeout());
}
@Test
void group() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.group("group");
Assertions.assertEquals("group", builder.build().getGroup());
}
@Test
void appendParameter() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.appendParameter("default.num", "one").appendParameter("num", "ONE");
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void appendParameters() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one");
source.put("num", "ONE");
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.appendParameters(source);
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void retryTimes() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.retryTimes(1);
Assertions.assertEquals(1, builder.build().getRetryTimes());
}
@Test
void retryPeriod() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.retryPeriod(2);
Assertions.assertEquals(2, builder.build().getRetryPeriod());
}
@Test
void cycleReport() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.cycleReport(true);
Assertions.assertTrue(builder.build().getCycleReport());
builder.cycleReport(false);
Assertions.assertFalse(builder.build().getCycleReport());
builder.cycleReport(null);
Assertions.assertNull(builder.build().getCycleReport());
}
@Test
void syncReport() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.syncReport(true);
Assertions.assertTrue(builder.build().getSyncReport());
builder.syncReport(false);
Assertions.assertFalse(builder.build().getSyncReport());
builder.syncReport(null);
Assertions.assertNull(builder.build().getSyncReport());
}
@Test
void build() {
MetadataReportBuilder builder = new MetadataReportBuilder();
builder.address("address")
.username("username")
.password("password")
.timeout(1000)
.group("group")
.retryTimes(1)
.retryPeriod(2)
.cycleReport(true)
.syncReport(false)
.appendParameter("default.num", "one")
.id("id");
MetadataReportConfig config = builder.build();
MetadataReportConfig config2 = builder.build();
Assertions.assertTrue(config.getCycleReport());
Assertions.assertFalse(config.getSyncReport());
Assertions.assertEquals(1000, config.getTimeout());
Assertions.assertEquals(1, config.getRetryTimes());
Assertions.assertEquals(2, config.getRetryPeriod());
Assertions.assertEquals("address", config.getAddress());
Assertions.assertEquals("username", config.getUsername());
Assertions.assertEquals("password", config.getPassword());
Assertions.assertEquals("group", config.getGroup());
Assertions.assertTrue(config.getParameters().containsKey("default.num"));
Assertions.assertEquals("one", config.getParameters().get("default.num"));
Assertions.assertEquals("id", config.getId());
Assertions.assertNotSame(config, config2);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ModuleBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ModuleBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.ModuleConfig;
import org.apache.dubbo.config.MonitorConfig;
import org.apache.dubbo.config.RegistryConfig;
import java.util.Collections;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class ModuleBuilderTest {
@Test
void name() {
ModuleBuilder builder = ModuleBuilder.newBuilder();
builder.name("name");
Assertions.assertEquals("name", builder.build().getName());
}
@Test
void version() {
ModuleBuilder builder = ModuleBuilder.newBuilder();
builder.version("version");
Assertions.assertEquals("version", builder.build().getVersion());
}
@Test
void owner() {
ModuleBuilder builder = ModuleBuilder.newBuilder();
builder.owner("owner");
Assertions.assertEquals("owner", builder.build().getOwner());
}
@Test
void organization() {
ModuleBuilder builder = ModuleBuilder.newBuilder();
builder.organization("organization");
Assertions.assertEquals("organization", builder.build().getOrganization());
}
@Test
void addRegistries() {
RegistryConfig registry = new RegistryConfig();
ModuleBuilder builder = ModuleBuilder.newBuilder();
builder.addRegistries(Collections.singletonList(registry));
Assertions.assertTrue(builder.build().getRegistries().contains(registry));
Assertions.assertEquals(1, builder.build().getRegistries().size());
}
@Test
void addRegistry() {
RegistryConfig registry = new RegistryConfig();
ModuleBuilder builder = ModuleBuilder.newBuilder();
builder.addRegistry(registry);
Assertions.assertTrue(builder.build().getRegistries().contains(registry));
Assertions.assertEquals(1, builder.build().getRegistries().size());
}
@Test
void monitor() {
MonitorConfig monitor = new MonitorConfig();
ModuleBuilder builder = ModuleBuilder.newBuilder();
builder.monitor(monitor);
Assertions.assertSame(monitor, builder.build().getMonitor());
}
@Test
void isDefault() {
ModuleBuilder builder = ModuleBuilder.newBuilder();
builder.isDefault(true);
Assertions.assertTrue(builder.build().isDefault());
}
@Test
void build() {
RegistryConfig registry = new RegistryConfig();
MonitorConfig monitor = new MonitorConfig();
ModuleBuilder builder = ModuleBuilder.newBuilder();
builder.name("name")
.version("version")
.owner("owner")
.organization("organization")
.addRegistry(registry)
.monitor(monitor)
.isDefault(false);
ModuleConfig config = builder.build();
ModuleConfig config2 = builder.build();
Assertions.assertEquals("name", config.getName());
Assertions.assertEquals("version", config.getVersion());
Assertions.assertEquals("owner", config.getOwner());
Assertions.assertEquals("organization", config.getOrganization());
Assertions.assertTrue(builder.build().getRegistries().contains(registry));
Assertions.assertSame(monitor, builder.build().getMonitor());
Assertions.assertFalse(config.isDefault());
Assertions.assertNotSame(config, config2);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ServiceBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ServiceBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.MethodConfig;
import org.apache.dubbo.config.ProviderConfig;
import org.apache.dubbo.config.ServiceConfig;
import java.util.Collections;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.apache.dubbo.common.constants.CommonConstants.GENERIC_SERIALIZATION_BEAN;
import static org.apache.dubbo.common.constants.CommonConstants.GENERIC_SERIALIZATION_DEFAULT;
import static org.apache.dubbo.common.constants.CommonConstants.GENERIC_SERIALIZATION_NATIVE_JAVA;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
class ServiceBuilderTest {
@Test
void path() {
ServiceBuilder builder = new ServiceBuilder();
builder.path("path");
Assertions.assertEquals("path", builder.build().getPath());
}
@Test
void addMethod() {
MethodConfig method = new MethodConfig();
ServiceBuilder builder = new ServiceBuilder();
builder.addMethod(method);
Assertions.assertTrue(builder.build().getMethods().contains(method));
Assertions.assertEquals(1, builder.build().getMethods().size());
}
@Test
void addMethods() {
MethodConfig method = new MethodConfig();
ServiceBuilder builder = new ServiceBuilder();
builder.addMethods(Collections.singletonList(method));
Assertions.assertTrue(builder.build().getMethods().contains(method));
Assertions.assertEquals(1, builder.build().getMethods().size());
}
@Test
void provider() {
ProviderConfig provider = new ProviderConfig();
ServiceBuilder builder = new ServiceBuilder();
builder.provider(provider);
Assertions.assertSame(provider, builder.build().getProvider());
}
@Test
void providerIds() {
ServiceBuilder builder = new ServiceBuilder();
builder.providerIds("providerIds");
Assertions.assertEquals("providerIds", builder.build().getProviderIds());
}
@Test
void generic() throws Exception {
ServiceBuilder builder = new ServiceBuilder();
builder.generic(GENERIC_SERIALIZATION_DEFAULT);
assertThat(builder.build().getGeneric(), equalTo(GENERIC_SERIALIZATION_DEFAULT));
builder.generic(GENERIC_SERIALIZATION_NATIVE_JAVA);
assertThat(builder.build().getGeneric(), equalTo(GENERIC_SERIALIZATION_NATIVE_JAVA));
builder.generic(GENERIC_SERIALIZATION_BEAN);
assertThat(builder.build().getGeneric(), equalTo(GENERIC_SERIALIZATION_BEAN));
}
@Test
void generic1() throws Exception {
Assertions.assertThrows(IllegalArgumentException.class, () -> {
ServiceBuilder builder = new ServiceBuilder();
builder.generic("illegal").build();
});
}
//
// @Test
// public void Mock() throws Exception {
// Assertions.assertThrows(IllegalArgumentException.class, () -> {
// ServiceBuilder builder = new ServiceBuilder();
// builder.mock("true");
// });
// }
//
// @Test
// public void Mock1() throws Exception {
// Assertions.assertThrows(IllegalArgumentException.class, () -> {
// ServiceBuilder builder = new ServiceBuilder();
// builder.mock(true);
// });
// }
@Test
void build() {
MethodConfig method = new MethodConfig();
ProviderConfig provider = new ProviderConfig();
ServiceBuilder builder = new ServiceBuilder();
builder.path("path")
.addMethod(method)
.provider(provider)
.providerIds("providerIds")
.generic(GENERIC_SERIALIZATION_DEFAULT);
ServiceConfig config = builder.build();
ServiceConfig config2 = builder.build();
assertThat(config.getGeneric(), equalTo(GENERIC_SERIALIZATION_DEFAULT));
Assertions.assertEquals("path", config.getPath());
Assertions.assertEquals("providerIds", config.getProviderIds());
Assertions.assertSame(provider, config.getProvider());
Assertions.assertTrue(config.getMethods().contains(method));
Assertions.assertEquals(1, config.getMethods().size());
Assertions.assertNotSame(config, config2);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/MonitorBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/MonitorBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.MonitorConfig;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class MonitorBuilderTest {
@Test
void protocol() {
MonitorBuilder builder = MonitorBuilder.newBuilder();
builder.protocol("protocol");
Assertions.assertEquals("protocol", builder.build().getProtocol());
}
@Test
void address() {
MonitorBuilder builder = MonitorBuilder.newBuilder();
builder.address("address");
Assertions.assertEquals("address", builder.build().getAddress());
}
@Test
void username() {
MonitorBuilder builder = MonitorBuilder.newBuilder();
builder.username("username");
Assertions.assertEquals("username", builder.build().getUsername());
}
@Test
void password() {
MonitorBuilder builder = MonitorBuilder.newBuilder();
builder.password("password");
Assertions.assertEquals("password", builder.build().getPassword());
}
@Test
void group() {
MonitorBuilder builder = MonitorBuilder.newBuilder();
builder.group("group");
Assertions.assertEquals("group", builder.build().getGroup());
}
@Test
void version() {
MonitorBuilder builder = MonitorBuilder.newBuilder();
builder.version("version");
Assertions.assertEquals("version", builder.build().getVersion());
}
@Test
void interval() {
MonitorBuilder builder = MonitorBuilder.newBuilder();
builder.interval("interval");
Assertions.assertEquals("interval", builder.build().getInterval());
}
@Test
void isDefault() {
MonitorBuilder builder = MonitorBuilder.newBuilder();
builder.isDefault(true);
Assertions.assertTrue(builder.build().isDefault());
}
@Test
void appendParameter() {
MonitorBuilder builder = MonitorBuilder.newBuilder();
builder.appendParameter("default.num", "one").appendParameter("num", "ONE");
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void appendParameters() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one");
source.put("num", "ONE");
MonitorBuilder builder = MonitorBuilder.newBuilder();
builder.appendParameters(source);
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void build() {
MonitorBuilder builder = MonitorBuilder.newBuilder();
builder.protocol("protocol")
.address("address")
.group("group")
.interval("interval")
.isDefault(true)
.password("password")
.username("username")
.version("version")
.appendParameter("default.num", "one")
.id("id");
MonitorConfig config = builder.build();
MonitorConfig config2 = builder.build();
Assertions.assertEquals("protocol", config.getProtocol());
Assertions.assertEquals("address", config.getAddress());
Assertions.assertEquals("group", config.getGroup());
Assertions.assertEquals("interval", config.getInterval());
Assertions.assertEquals("password", config.getPassword());
Assertions.assertEquals("username", config.getUsername());
Assertions.assertEquals("version", config.getVersion());
Assertions.assertTrue(config.isDefault());
Assertions.assertTrue(config.getParameters().containsKey("default.num"));
Assertions.assertEquals("one", config.getParameters().get("default.num"));
Assertions.assertEquals("id", config.getId());
Assertions.assertNotSame(config, config2);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ReferenceBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ReferenceBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.ConsumerConfig;
import org.apache.dubbo.config.MethodConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.api.DemoService;
import java.util.Collections;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.apache.dubbo.common.utils.CollectionUtils.ofSet;
class ReferenceBuilderTest {
@Test
void interfaceName() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.interfaceName(DemoService.class.getName());
Assertions.assertEquals(
"org.apache.dubbo.config.api.DemoService", builder.build().getInterface());
}
@Test
void interfaceClass() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.interfaceClass(DemoService.class);
Assertions.assertEquals(DemoService.class, builder.build().getInterfaceClass());
}
@Test
void client() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.client("client");
Assertions.assertEquals("client", builder.build().getClient());
}
@Test
void url() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.url("url");
Assertions.assertEquals("url", builder.build().getUrl());
}
@Test
void addMethods() {
MethodConfig method = new MethodConfig();
ReferenceBuilder builder = new ReferenceBuilder();
builder.addMethods(Collections.singletonList(method));
Assertions.assertTrue(builder.build().getMethods().contains(method));
Assertions.assertEquals(1, builder.build().getMethods().size());
}
@Test
void addMethod() {
MethodConfig method = new MethodConfig();
ReferenceBuilder builder = new ReferenceBuilder();
builder.addMethod(method);
Assertions.assertTrue(builder.build().getMethods().contains(method));
Assertions.assertEquals(1, builder.build().getMethods().size());
}
@Test
void consumer() {
ConsumerConfig consumer = new ConsumerConfig();
ReferenceBuilder builder = new ReferenceBuilder();
builder.consumer(consumer);
Assertions.assertSame(consumer, builder.build().getConsumer());
}
@Test
void protocol() {
ReferenceBuilder builder = new ReferenceBuilder();
builder.protocol("protocol");
Assertions.assertEquals("protocol", builder.build().getProtocol());
}
@Test
void build() {
ConsumerConfig consumer = new ConsumerConfig();
MethodConfig method = new MethodConfig();
ReferenceBuilder<DemoService> builder = new ReferenceBuilder<>();
builder.id("id")
.interfaceClass(DemoService.class)
.protocol("protocol")
.client("client")
.url("url")
.consumer(consumer)
.addMethod(method)
// introduced since 2.7.8
.services("test-service", "test-service2");
ReferenceConfig config = builder.build();
ReferenceConfig config2 = builder.build();
Assertions.assertEquals("org.apache.dubbo.config.api.DemoService", config.getInterface());
Assertions.assertEquals(DemoService.class, config.getInterfaceClass());
Assertions.assertEquals("protocol", config.getProtocol());
Assertions.assertEquals("client", config.getClient());
Assertions.assertEquals("url", config.getUrl());
Assertions.assertEquals(consumer, config.getConsumer());
Assertions.assertEquals("test-service,test-service2", config.getServices());
Assertions.assertEquals(ofSet("test-service", "test-service2"), config.getSubscribedServices());
Assertions.assertTrue(config.getMethods().contains(method));
Assertions.assertEquals(1, config.getMethods().size());
Assertions.assertNotSame(config, config2);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ConfigCenterBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ConfigCenterBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.ConfigCenterConfig;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class ConfigCenterBuilderTest {
@Test
void protocol() {
ConfigCenterBuilder builder = ConfigCenterBuilder.newBuilder();
builder.protocol("protocol");
Assertions.assertEquals("protocol", builder.build().getProtocol());
}
@Test
void address() {
ConfigCenterBuilder builder = ConfigCenterBuilder.newBuilder();
builder.address("address");
Assertions.assertEquals("address", builder.build().getAddress());
}
@Test
void cluster() {
ConfigCenterBuilder builder = ConfigCenterBuilder.newBuilder();
builder.cluster("cluster");
Assertions.assertEquals("cluster", builder.build().getCluster());
}
@Test
void namespace() {
ConfigCenterBuilder builder = ConfigCenterBuilder.newBuilder();
builder.namespace("namespace");
Assertions.assertEquals("namespace", builder.build().getNamespace());
}
@Test
void group() {
ConfigCenterBuilder builder = ConfigCenterBuilder.newBuilder();
builder.group("group");
Assertions.assertEquals("group", builder.build().getGroup());
}
@Test
void username() {
ConfigCenterBuilder builder = ConfigCenterBuilder.newBuilder();
builder.username("username");
Assertions.assertEquals("username", builder.build().getUsername());
}
@Test
void password() {
ConfigCenterBuilder builder = ConfigCenterBuilder.newBuilder();
builder.password("password");
Assertions.assertEquals("password", builder.build().getPassword());
}
@Test
void timeout() {
ConfigCenterBuilder builder = ConfigCenterBuilder.newBuilder();
builder.timeout(1000L);
Assertions.assertEquals(1000L, builder.build().getTimeout());
}
@Test
void highestPriority() {
ConfigCenterBuilder builder = ConfigCenterBuilder.newBuilder();
builder.highestPriority(true);
Assertions.assertTrue(builder.build().isHighestPriority());
}
@Test
void check() {
ConfigCenterBuilder builder = ConfigCenterBuilder.newBuilder();
builder.check(true);
Assertions.assertTrue(builder.build().isCheck());
}
@Test
void configFile() {
ConfigCenterBuilder builder = ConfigCenterBuilder.newBuilder();
builder.configFile("configFile");
Assertions.assertEquals("configFile", builder.build().getConfigFile());
}
@Test
void appConfigFile() {
ConfigCenterBuilder builder = ConfigCenterBuilder.newBuilder();
builder.appConfigFile("appConfigFile");
Assertions.assertEquals("appConfigFile", builder.build().getAppConfigFile());
}
@Test
void appendParameter() {
ConfigCenterBuilder builder = ConfigCenterBuilder.newBuilder();
builder.appendParameter("default.num", "one").appendParameter("num", "ONE");
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void appendParameters() {
Map<String, String> source = new HashMap<>();
source.put("default.num", "one");
source.put("num", "ONE");
ConfigCenterBuilder builder = ConfigCenterBuilder.newBuilder();
builder.appendParameters(source);
Map<String, String> parameters = builder.build().getParameters();
Assertions.assertTrue(parameters.containsKey("default.num"));
Assertions.assertEquals("ONE", parameters.get("num"));
}
@Test
void build() {
ConfigCenterBuilder builder = ConfigCenterBuilder.newBuilder();
builder.check(true)
.protocol("protocol")
.address("address")
.appConfigFile("appConfigFile")
.cluster("cluster")
.configFile("configFile")
.group("group")
.highestPriority(false)
.namespace("namespace")
.password("password")
.timeout(1000L)
.username("usernama")
.appendParameter("default.num", "one")
.id("id");
ConfigCenterConfig config = builder.build();
ConfigCenterConfig config2 = builder.build();
Assertions.assertTrue(config.isCheck());
Assertions.assertFalse(config.isHighestPriority());
Assertions.assertEquals(1000L, config.getTimeout());
Assertions.assertEquals("protocol", config.getProtocol());
Assertions.assertEquals("address", config.getAddress());
Assertions.assertEquals("appConfigFile", config.getAppConfigFile());
Assertions.assertEquals("cluster", config.getCluster());
Assertions.assertEquals("configFile", config.getConfigFile());
Assertions.assertEquals("group", config.getGroup());
Assertions.assertEquals("namespace", config.getNamespace());
Assertions.assertEquals("password", config.getPassword());
Assertions.assertEquals("usernama", config.getUsername());
Assertions.assertTrue(config.getParameters().containsKey("default.num"));
Assertions.assertEquals("one", config.getParameters().get("default.num"));
Assertions.assertEquals("id", config.getId());
Assertions.assertNotSame(config, config2);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ConsumerBuilderTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/bootstrap/builders/ConsumerBuilderTest.java | /*
* 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.config.bootstrap.builders;
import org.apache.dubbo.config.ConsumerConfig;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class ConsumerBuilderTest {
@Test
void isDefault() {
ConsumerBuilder builder = ConsumerBuilder.newBuilder();
builder.isDefault(false);
Assertions.assertFalse(builder.build().isDefault());
}
@Test
void client() {
ConsumerBuilder builder = ConsumerBuilder.newBuilder();
builder.client("client");
Assertions.assertEquals("client", builder.build().getClient());
}
@Test
void threadPool() {
ConsumerBuilder builder = ConsumerBuilder.newBuilder();
builder.threadPool("threadPool");
Assertions.assertEquals("threadPool", builder.build().getThreadpool());
}
@Test
void coreThreads() {
ConsumerBuilder builder = ConsumerBuilder.newBuilder();
builder.coreThreads(10);
Assertions.assertEquals(10, builder.build().getCorethreads());
}
@Test
void threads() {
ConsumerBuilder builder = ConsumerBuilder.newBuilder();
builder.threads(100);
Assertions.assertEquals(100, builder.build().getThreads());
}
@Test
void queues() {
ConsumerBuilder builder = ConsumerBuilder.newBuilder();
builder.queues(200);
Assertions.assertEquals(200, builder.build().getQueues());
}
@Test
void shareConnections() {
ConsumerBuilder builder = ConsumerBuilder.newBuilder();
builder.shareConnections(300);
Assertions.assertEquals(300, builder.build().getShareconnections());
}
@Test
void build() {
ConsumerBuilder builder = ConsumerBuilder.newBuilder();
builder.isDefault(true)
.client("client")
.threadPool("threadPool")
.coreThreads(10)
.threads(100)
.queues(200)
.shareConnections(300)
.id("id");
ConsumerConfig config = builder.build();
ConsumerConfig config2 = builder.build();
Assertions.assertTrue(config.isDefault());
Assertions.assertEquals("client", config.getClient());
Assertions.assertEquals("threadPool", config.getThreadpool());
Assertions.assertEquals("id", config.getId());
Assertions.assertEquals(10, config.getCorethreads());
Assertions.assertEquals(100, config.getThreads());
Assertions.assertEquals(200, config.getQueues());
Assertions.assertEquals(300, config.getShareconnections());
Assertions.assertNotSame(config, config2);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/nested/PrometheusConfigTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/nested/PrometheusConfigTest.java | /*
* 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.config.nested;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
class PrometheusConfigTest {
@Test
void testExporter() {
PrometheusConfig prometheusConfig = new PrometheusConfig();
PrometheusConfig.Exporter exporter = new PrometheusConfig.Exporter();
exporter.setEnabled(true);
exporter.setEnableHttpServiceDiscovery(true);
exporter.setHttpServiceDiscoveryUrl("localhost:8080");
prometheusConfig.setExporter(exporter);
assertThat(prometheusConfig.getExporter().getEnabled(), equalTo(true));
assertThat(prometheusConfig.getExporter().getEnableHttpServiceDiscovery(), equalTo(true));
assertThat(prometheusConfig.getExporter().getHttpServiceDiscoveryUrl(), equalTo("localhost:8080"));
}
@Test
void testPushgateway() {
PrometheusConfig prometheusConfig = new PrometheusConfig();
PrometheusConfig.Pushgateway pushgateway = new PrometheusConfig.Pushgateway();
pushgateway.setEnabled(true);
pushgateway.setBaseUrl("localhost:9091");
pushgateway.setUsername("username");
pushgateway.setPassword("password");
pushgateway.setJob("job");
pushgateway.setPushInterval(30);
prometheusConfig.setPushgateway(pushgateway);
assertThat(prometheusConfig.getPushgateway().getEnabled(), equalTo(true));
assertThat(prometheusConfig.getPushgateway().getBaseUrl(), equalTo("localhost:9091"));
assertThat(prometheusConfig.getPushgateway().getUsername(), equalTo("username"));
assertThat(prometheusConfig.getPushgateway().getPassword(), equalTo("password"));
assertThat(prometheusConfig.getPushgateway().getJob(), equalTo("job"));
assertThat(prometheusConfig.getPushgateway().getPushInterval(), equalTo(30));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/nested/AggregationConfigTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/nested/AggregationConfigTest.java | /*
* 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.config.nested;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
class AggregationConfigTest {
@Test
void testEnabled() {
AggregationConfig aggregationConfig = new AggregationConfig();
aggregationConfig.setEnabled(true);
assertThat(aggregationConfig.getEnabled(), equalTo(true));
}
@Test
void testBucketNum() {
AggregationConfig aggregationConfig = new AggregationConfig();
aggregationConfig.setBucketNum(5);
assertThat(aggregationConfig.getBucketNum(), equalTo(5));
}
@Test
void testTimeWindowSeconds() {
AggregationConfig aggregationConfig = new AggregationConfig();
aggregationConfig.setTimeWindowSeconds(120);
assertThat(aggregationConfig.getTimeWindowSeconds(), equalTo(120));
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/url/RpcConfigGetSetProxy.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/url/RpcConfigGetSetProxy.java | /*
* 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.config.url;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.config.AbstractConfig;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class RpcConfigGetSetProxy {
private static final String RPC_CONFIG_BASECLASS = AbstractConfig.class.getName();
private static final Logger log = LoggerFactory.getLogger(RpcConfigGetSetProxy.class);
private Object proxiee = null;
private Class<?> proxieeClass = null;
private Boolean isOk = false;
public RpcConfigGetSetProxy(Object p) {
if (p == null) {
return;
}
if (!isKindOf(p.getClass(), RPC_CONFIG_BASECLASS)) {
return;
}
proxiee = p;
// proxieeClass = c;
proxieeClass = p.getClass();
isOk = true;
}
public static boolean isKindOf(Class<?> c, String type) {
// get the class def for obj and type
Class<?> tClass;
try {
tClass = Class.forName(type);
} catch (ClassNotFoundException e) {
return false;
}
// check against type and superclasses
while (c != null) {
if (c == tClass) return true;
c = c.getSuperclass();
}
return false;
}
public boolean isOk() {
return isOk;
}
public Object setValue(String key, Object value) {
if (!isOk()) {
return null;
}
Method m = findSetMethod(key, value, proxieeClass);
return invoke(m, value);
}
public Object getValue(String key) {
if (!isOk()) {
return null;
}
Method m = findGetMethod(key, proxieeClass);
return invoke(m, null);
}
private Object invoke(Method m, Object value) {
if (m == null) {
return null;
}
try {
if (value == null) {
return m.invoke(proxiee, (Object[]) null);
} else {
return m.invoke(proxiee, value);
}
} catch (IllegalArgumentException e) {
log.error("IllegalArgumentException", e);
return null;
} catch (IllegalAccessException e) {
log.error("IllegalAccessException", e);
return null;
} catch (InvocationTargetException e) {
log.error("InvocationTargetException", e);
return null;
}
}
private Method findGetMethod(String key, Class<?> clazz) {
Method m = findMethod(key, null, "get", clazz);
if (m != null) {
return m;
}
return findMethod(key, null, "is", clazz);
}
private Method findSetMethod(String key, Object value, Class<?> clazz) {
return findMethod(key, value, "set", clazz);
}
private Method getMethod(String methodName, Object value, Class<?> clazz) {
try {
if (value == null) {
return clazz.getMethod(methodName, (Class<?>[]) null);
} else {
return clazz.getMethod(methodName, value.getClass());
}
} catch (SecurityException e) {
log.error("SecurityException: " + e.getMessage());
return null;
} catch (NoSuchMethodException e) {
log.error("NoSuchMethodException: " + e.getMessage());
return null;
}
}
private Method findMethod(String key, Object value, String prefix, Class<?> clazz) {
if (key.length() < 2) {
return null;
}
key = key.substring(0, 1).toUpperCase() + key.substring(1);
String methodName = prefix + key;
return getMethod(methodName, value, clazz);
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/url/InvokerSideConfigUrlTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/url/InvokerSideConfigUrlTest.java | /*
* 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.config.url;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.config.ConsumerConfig;
import org.apache.dubbo.config.MethodConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.api.DemoService;
import org.apache.dubbo.config.mock.MockRegistry;
import java.util.Arrays;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.apache.dubbo.rpc.Constants.SCOPE_REMOTE;
@Disabled
class InvokerSideConfigUrlTest extends UrlTestBase {
private static final Logger log = LoggerFactory.getLogger(InvokerSideConfigUrlTest.class);
// ======================================================
// invoker related data preparing
// ======================================================
private RegistryConfig regConfForConsumer;
private RegistryConfig regConfForReference;
private MethodConfig methodConfForReference;
private ConsumerConfig consumerConf;
private ReferenceConfig<DemoService> refConf;
private Object appConfForConsumerTable[][] = {
{"", "", "", "", "", "", "", "", "", ""},
};
private Object appConfForReferenceTable[][] = {
{"", "", "", "", "", "", "", "", "", ""},
};
private Object regConfForConsumerTable[][] = {
// {"timeout", "registry.timeout", "int", 5000, 9000, "", "", "", "", ""},
// {"file", "registry.file", "string", "", "regConfForServiceTable.log", "", "", "", "", ""},
// {"wait", "registry.wait", "int", 0, 9000, "", "", "", "", ""},
// {"transport", "registry.transporter", "string", "netty", "mina", "", "", "", "", ""},
{"subscribe", "subscribe", "boolean", true, false, "", "", "", "", ""},
{"dynamic", "dynamic", "boolean", true, false, "", "", "", "", ""},
};
private Object regConfForReferenceTable[][] = {
{"timeout", "registry.timeout", "int", 5000, 9000, "", "", "", "", ""},
{"file", "registry.file", "string", "", "regConfForServiceTable.log", "", "", "", "", ""},
{"wait", "registry.wait", "int", 0, 9000, "", "", "", "", ""},
{"transport", "registry.transporter", "string", "netty", "mina", "", "", "", "", ""},
{"subscribe", "subscribe", "boolean", true, false, "", "", "", "", ""},
{"dynamic", "dynamic", "boolean", true, false, "", "", "", "", ""},
};
private Object methodConfForReferenceTable[][] = {
{"actives", "eatTiger.actives", "int", 0, 90, "", "", "", "", ""},
{"executes", "eatTiger.executes", "int", 0, 90, "", "", "", "", ""},
{"deprecated", "eatTiger.deprecated", "boolean", false, true, "", "", "", "", ""},
{"async", "eatTiger.async", "boolean", false, true, "", "", "", "", ""},
{"timeout", "eatTiger.timeout", "int", 0, 90, "", "", "", "", ""},
};
private Object refConfTable[][] = {
// {"version", "version", "string", "0.0.0", "1.2.3", "", "", "", "", ""},
// {"group", "group", "string", "", "HaominTest", "", "", "", "", ""},
// {"delay", "delay", "int", 0, 5, "", "", "", "", ""}, // not boolean
{"timeout", "timeout", "int", 5000, 3000, "", "", "", "", ""},
{"retries", "retries", "int", 2, 5, "", "", "", "", ""},
{"connections", "connections", "boolean", 100, 20, "", "", "", "", ""},
{"loadbalance", "loadbalance", "string", "random", "roundrobin", "leastactive", "", "", ""},
{"async", "async", "boolean", false, true, "", "", "", "", ""},
// excluded = true
// {"generic", "generic", "boolean", false, true, "", "", "", "", ""},
{"check", "check", "boolean", false, true, "", "", "", "", ""},
// {"local", "local", "string", "false", "HelloServiceLocal", "true", "", "", "", ""},
// {"local", "local", "string", "false", "true", "", "", "", "", ""},
// {"mock", "mock", "string", "false", "dubbo.test.HelloServiceMock", "true", "", "", "", ""},
{"mock", "mock", "string", "false", "false", "", "", "", "", ""},
{"proxy", "proxy", "boolean", "javassist", "jdk", "", "", "", "", ""},
{"client", "client", "string", "netty", "mina", "", "", "", "", ""},
{"client", "client", "string", "netty", "mina", "", "", "", "", ""},
{"owner", "owner", "string", "", "haomin,ludvik", "", "", "", "", ""},
{"actives", "actives", "int", 0, 30, "", "", "", "", ""},
{"cluster", "cluster", "string", "failover", "failfast", "failsafe", "failback", "forking", "", ""},
// excluded = true
// {"filter", "service.filter", "string", "default", "-generic", "", "", "", "", ""},
// excluded = true
// {"listener", "exporter.listener", "string", "default", "-deprecated", "", "", "", "", ""},
// {"", "", "", "", "", "", "", "", "", ""},
};
private Object consumerConfTable[][] = {
{"timeout", "timeout", "int", 5000, 8000, "", "", "", "", ""},
{"retries", "retries", "int", 2, 5, "", "", "", "", ""},
{"loadbalance", "loadbalance", "string", "random", "leastactive", "", "", "", "", ""},
{"async", "async", "boolean", false, true, "", "", "", "", ""},
{"connections", "connections", "int", 100, 5, "", "", "", "", ""},
// {"generic", "generic", "boolean", false, false, "", "", "", "", ""},
{"check", "check", "boolean", true, false, "", "", "", "", ""},
{"proxy", "proxy", "string", "javassist", "jdk", "javassist", "", "", "", ""},
{"owner", "owner", "string", "", "haomin", "", "", "", "", ""},
{"actives", "actives", "int", 0, 5, "", "", "", "", ""},
{"cluster", "cluster", "string", "failover", "forking", "", "", "", "", ""},
{"filter", "", "string", "", "", "", "", "", "", ""},
{"listener", "", "string", "", "", "", "", "", "", ""},
// {"", "", "", "", "", "", "", "", "", ""},
};
// ======================================================
// test Start
// ======================================================
@BeforeAll
public static void start() {
// RegistryController.startRegistryIfAbsence(1);
}
@BeforeEach
public void setUp() {
initServConf();
initRefConf();
// ApplicationModel.defaultModel().getConfigManager().clear();
}
@AfterEach()
public void teardown() {
// RegistryServer.reloadCache();
// ApplicationModel.defaultModel().getConfigManager().clear();
}
@Test
void consumerConfUrlTest() {
verifyInvokerUrlGeneration(consumerConf, consumerConfTable);
}
@Test
void refConfUrlTest() {
verifyInvokerUrlGeneration(refConf, refConfTable);
}
@Disabled(
"parameter on register center will not be merged any longer with query parameter request from the consumer")
@Test
void regConfForConsumerUrlTest() {
verifyInvokerUrlGeneration(regConfForConsumer, regConfForConsumerTable);
}
// ======================================================
// private helper
// ======================================================
private void initRefConf() {
regConfForConsumer = new RegistryConfig();
regConfForReference = new RegistryConfig();
methodConfForReference = new MethodConfig();
refConf = new ReferenceConfig<DemoService>();
consumerConf = new ConsumerConfig();
methodConfForReference.setName("sayName");
regConfForReference.setAddress("127.0.0.1:9090");
regConfForReference.setProtocol("mockregistry");
refConf.setInterface("org.apache.dubbo.config.api.DemoService");
refConf.setApplication(application);
// consumerConf.setApplication(appConfForConsumer);
refConf.setRegistry(regConfForReference);
consumerConf.setRegistry(regConfForConsumer);
refConf.setConsumer(consumerConf);
refConf.setMethods(Arrays.asList(new MethodConfig[] {methodConfForReference}));
refConf.setScope(SCOPE_REMOTE);
}
private <T> void verifyInvokerUrlGeneration(T config, Object[][] dataTable) {
servConf.export();
fillConfigs(config, dataTable, TESTVALUE1);
refConf.get();
String subScribedUrlStr = getSubscribedUrlString();
String configName = config.getClass().getName();
int column = TESTVALUE1;
assertUrlStringWithLocalTable(subScribedUrlStr, dataTable, configName, column);
try {
refConf.destroy();
} catch (Exception e) {
}
}
private String getSubscribedUrlString() {
return MockRegistry.getSubscribedUrl().toString();
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/url/ExporterSideConfigUrlTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/url/ExporterSideConfigUrlTest.java | /*
* 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.config.url;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.config.SysProps;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class ExporterSideConfigUrlTest extends UrlTestBase {
private static final Logger log = LoggerFactory.getLogger(ExporterSideConfigUrlTest.class);
// ======================================================
// tests start
// ======================================================
@BeforeAll
public static void start() {}
@BeforeEach
public void setUp() {
DubboBootstrap.reset();
SysProps.clear();
SysProps.setProperty("dubbo.metrics.enabled", "false");
SysProps.setProperty("dubbo.metrics.protocol", "disabled");
initServConf();
}
@AfterEach()
public void teardown() {
DubboBootstrap.reset();
SysProps.clear();
}
@Test
void exporterMethodConfigUrlTest() {
verifyExporterUrlGeneration(methodConfForService, methodConfForServiceTable);
}
@Test
void exporterServiceConfigUrlTest() {
verifyExporterUrlGeneration(servConf, servConfTable);
}
@Test
void exporterProviderConfigUrlTest() {
verifyExporterUrlGeneration(provConf, provConfTable);
}
@Test
void exporterRegistryConfigUrlTest() {
// verifyExporterUrlGeneration(regConfForService, regConfForServiceTable);
}
protected <T> void verifyExporterUrlGeneration(T config, Object[][] dataTable) {
// 1. fill corresponding config with data
////////////////////////////////////////////////////////////
fillConfigs(config, dataTable, TESTVALUE1);
// 2. export service and get url parameter string from db
////////////////////////////////////////////////////////////
servConf.export();
String paramStringFromDb = getProviderParamString();
try {
paramStringFromDb = URLDecoder.decode(paramStringFromDb, "UTF-8");
} catch (UnsupportedEncodingException e) {
// impossible
}
assertUrlStringWithLocalTable(
paramStringFromDb, dataTable, config.getClass().getName(), TESTVALUE1);
// 4. unexport service
////////////////////////////////////////////////////////////
servConf.unexport();
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/url/UrlTestBase.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/url/UrlTestBase.java | /*
* 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.config.url;
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.MethodConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.ProviderConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.api.DemoService;
import org.apache.dubbo.config.provider.impl.DemoServiceImpl;
import java.util.ArrayList;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.fail;
@SuppressWarnings("unused")
public class UrlTestBase {
// ======================================================
// data column definition
// ======================================================
protected static final int KEY = 0;
protected static final int URL_KEY = 1;
protected static final int TESTVALUE1 = 4;
private static final Logger log = LoggerFactory.getLogger(UrlTestBase.class);
private static final int TYPE = 2;
private static final int DEFAULT = 3;
private static final int TESTVALUE2 = 5;
private static final int TESTVALUE3 = 6;
private static final int TESTVALUE4 = 7;
private static final int TESTVALUE5 = 8;
private static final int TESTVALUE6 = 9;
private static final int TESTVALUE7 = 10;
protected ApplicationConfig application;
protected RegistryConfig regConfForProvider;
protected RegistryConfig regConfForService;
protected ProviderConfig provConf;
protected ProtocolConfig protoConfForProvider;
protected ProtocolConfig protoConfForService;
protected MethodConfig methodConfForService;
protected ServiceConfig<DemoService> servConf;
protected Object servConfTable[][] = {
{"proxy", "proxy", "string", "javassist", "jdk", "javassist", "", "", "", ""},
{"actives", "actives", "int", 0, 90, "", "", "", "", ""},
{"executes", "executes", "int", 0, 90, "", "", "", "", ""},
{"deprecated", "deprecated", "boolean", false, true, "", "", "", "", ""},
{"dynamic", "dynamic", "boolean", true, false, "", "", "", "", ""},
{"accesslog", "accesslog", "string", "", "haominTest", "", "", "", "", ""},
{
"document",
"document",
"string",
"",
"http://dubbo.apache.org/zh-cn/docs/user/quick-start.html?testquery=你好你好",
"",
"",
"",
"",
""
},
{"weight", "weight", "int", 0, 90, "", "", "", "", ""},
// {"filter", "service.filter", "string", "", "", "", "", "", "", ""},
// {"listener", "listener", "string", "", "", "", "", "", "", ""},
};
protected Object regConfForServiceTable[][] = {
// {"timeout", "registry.timeout", "int", 5000, 9000, "", "", "", "", ""},
// {"file", "registry.file", "string", "", "regConfForServiceTable.log", "", "", "", "", ""},
// {"wait", "registry.wait", "int", 0, 9000, "", "", "", "", ""},
// {"transport", "registry.transporter", "string", "netty", "mina", "", "", "", "", ""},
// {"subscribe", "subscribe", "boolean", true, false, "", "", "", "", ""},
{"dynamic", "dynamic", "boolean", true, false, "", "", "", "", ""},
};
protected Object provConfTable[][] = {
{"cluster", "cluster", "string", "string", "failover", "failfast", "failsafe", "", "", ""},
{"async", "async", "boolean", false, true, "", "", "", "", ""},
{"loadbalance", "loadbalance", "string", "random", "leastactive", "", "", "", "", ""},
{"connections", "connections", "int", 0, 60, "", "", "", "", ""},
{"retries", "retries", "int", 2, 60, "", "", "", "", ""},
{"timeout", "timeout", "int", 5000, 60, "", "", "", "", ""},
// change by fengting listener 没有缺省值
// {"listener", "exporter.listener", "string", "", "", "", "", "", "", ""},
// {"filter", "service.filter", "string", "", "", "", "", "", "", ""},
};
protected Object methodConfForServiceTable[][] = {
{"actives", "sayName.actives", "int", 0, 90, "", "", "", "", ""},
{"executes", "sayName.executes", "int", 0, 90, "", "", "", "", ""},
{"deprecated", "sayName.deprecated", "boolean", false, true, "", "", "", "", ""},
{"async", "sayName.async", "boolean", false, true, "", "", "", "", ""},
{"timeout", "sayName.timeout", "int", 0, 90, "", "", "", "", ""},
};
protected DemoService demoService = new DemoServiceImpl();
private Object appConfForProviderTable[][] = {
{"", "", "", "", "", "", "", "", "", ""},
};
private Object appConfForServiceTable[][] = {
{"", "", "", "", "", "", "", "", "", ""},
};
private Object regConfForProviderTable[][] = {
{"", "", "", "", "", "", "", "", "", ""},
};
private Object protoConfForProviderTable[][] = {
{"", "", "", "", "", "", "", "", "", ""},
};
private Object protoConfForServiceTable[][] = {
{"", "", "", "", "", "", "", "", "", ""},
};
// ======================================================
// data table manipulation utils
// ======================================================
protected String genParamString(Object urlKey, Object value) {
return (String) urlKey + "=" + value.toString();
}
protected <T> void fillConfigs(T conf, Object[][] table, int column) {
for (Object[] row : table) {
fillConfig(conf, row, column);
}
}
protected <T> void fillConfig(T conf, Object[] row, int column) {
RpcConfigGetSetProxy proxy = new RpcConfigGetSetProxy(conf);
proxy.setValue((String) row[KEY], row[column]);
}
@SuppressWarnings("deprecation")
protected void initServConf() {
regConfForProvider = new RegistryConfig();
regConfForService = new RegistryConfig();
provConf = new ProviderConfig();
protoConfForProvider = new ProtocolConfig("mockprotocol");
protoConfForService = new ProtocolConfig("mockprotocol");
methodConfForService = new MethodConfig();
servConf = new ServiceConfig<DemoService>();
// provConf.setApplication(appConfForProvider);
application = new ApplicationConfig();
application.setMetadataServicePort(20881);
servConf.setApplication(application);
provConf.setRegistry(regConfForProvider);
servConf.setRegistry(regConfForService);
provConf.setProtocols(new ArrayList<>(Arrays.asList(protoConfForProvider)));
servConf.setProtocols(new ArrayList<>(Arrays.asList(protoConfForService)));
servConf.setMethods(Arrays.asList(new MethodConfig[] {methodConfForService}));
servConf.setProvider(provConf);
servConf.setRef(demoService);
servConf.setInterface(DemoService.class);
methodConfForService.setName("sayName");
regConfForService.setAddress("127.0.0.1:9090");
regConfForService.setProtocol("mockregistry");
application.setName("ConfigTests");
}
protected String getProviderParamString() {
return servConf.getExportedUrls().get(0).toString();
}
/**
* @param paramStringFromDb
* @param dataTable
* @param configName
* @param column
*/
protected void assertUrlStringWithLocalTable(
String paramStringFromDb, Object[][] dataTable, String configName, int column) {
final String FAILLOG_HEADER = "The following config items are not found in URLONE: ";
log.warn("Verifying service url for " + configName + "... ");
log.warn("Consumer url string: " + paramStringFromDb);
String failLog = FAILLOG_HEADER;
for (Object[] row : dataTable) {
String targetString = genParamString(row[URL_KEY], row[column]);
log.warn("Checking " + (String) row[KEY] + "for" + targetString);
if (paramStringFromDb.contains(targetString)) {
log.warn((String) row[KEY] + " --> " + targetString + " OK!");
} else {
failLog += targetString + ", ";
}
}
if (!failLog.equals(FAILLOG_HEADER)) {
fail(failLog);
}
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/MockReferenceConfig.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/MockReferenceConfig.java | /*
* 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.config.utils;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.utils.service.FooService;
import java.util.concurrent.atomic.AtomicLong;
public class MockReferenceConfig extends ReferenceConfig<FooService> {
static AtomicLong counter = new AtomicLong();
FooService value;
boolean destroyMethodRun = false;
public static void setCounter(long c) {
counter.set(c);
}
public boolean isGetMethodRun() {
return value != null;
}
public boolean isDestroyMethodRun() {
return destroyMethodRun;
}
@Override
public synchronized FooService get(boolean check) {
if (value != null) return value;
counter.getAndIncrement();
value = super.get(check);
return value;
}
public long getCounter() {
return counter.get();
}
@Override
public synchronized void destroy() {
super.destroy();
destroyMethodRun = true;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/XxxMockReferenceConfig.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/XxxMockReferenceConfig.java | /*
* 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.config.utils;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.utils.service.XxxService;
import java.util.concurrent.atomic.AtomicLong;
public class XxxMockReferenceConfig extends ReferenceConfig<XxxService> {
static AtomicLong counter = new AtomicLong();
XxxService value;
boolean destroyMethodRun = false;
public static void setCounter(long c) {
counter.set(c);
}
public boolean isGetMethodRun() {
return value != null;
}
public boolean isDestroyMethodRun() {
return destroyMethodRun;
}
@Override
public synchronized XxxService get(boolean check) {
if (value != null) return value;
counter.getAndIncrement();
value = super.get(check);
return value;
}
public long getCounter() {
return counter.get();
}
@Override
public synchronized void destroy() {
super.destroy();
destroyMethodRun = true;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/ReferenceCacheTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/ReferenceCacheTest.java | /*
* 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.config.utils;
import org.apache.dubbo.common.config.ReferenceCache;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.SysProps;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.utils.service.FooService;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class ReferenceCacheTest {
@BeforeEach
public void setUp() throws Exception {
DubboBootstrap.reset();
SysProps.clear();
SysProps.setProperty("dubbo.metrics.enabled", "false");
SysProps.setProperty("dubbo.metrics.protocol", "disabled");
MockReferenceConfig.setCounter(0);
XxxMockReferenceConfig.setCounter(0);
SimpleReferenceCache.CACHE_HOLDER.clear();
}
@AfterEach
public void tearDown() {
DubboBootstrap.reset();
SysProps.clear();
SimpleReferenceCache.CACHE_HOLDER.clear();
}
@Test
void testGetCacheSameReference() throws Exception {
ReferenceCache cache = SimpleReferenceCache.getCache();
MockReferenceConfig config =
buildMockReferenceConfig("org.apache.dubbo.config.utils.service.FooService", "group1", "1.0.0");
assertEquals(0L, config.getCounter());
Object proxy = cache.get(config);
assertTrue(config.isGetMethodRun());
// singleton reference config by default
MockReferenceConfig configCopy =
buildMockReferenceConfig("org.apache.dubbo.config.utils.service.FooService", "group1", "1.0.0");
assertEquals(1L, configCopy.getCounter());
Object proxyOfCopyConfig = cache.get(configCopy);
assertFalse(configCopy.isGetMethodRun());
assertEquals(1L, config.getCounter());
assertEquals(1L, configCopy.getCounter());
assertEquals(proxy, proxyOfCopyConfig);
}
@Test
void testGetCacheDiffReference() throws Exception {
ReferenceCache cache = SimpleReferenceCache.getCache();
MockReferenceConfig config =
buildMockReferenceConfig("org.apache.dubbo.config.utils.service.FooService", "group1", "1.0.0");
assertEquals(0L, config.getCounter());
cache.get(config);
assertEquals(1L, config.getCounter());
assertTrue(config.isGetMethodRun());
cache.get(config);
assertEquals(1L, config.getCounter());
XxxMockReferenceConfig configCopy =
buildXxxMockReferenceConfig("org.apache.dubbo.config.utils.service.XxxService", "group1", "1.0.0");
assertEquals(0L, configCopy.getCounter());
cache.get(configCopy);
assertTrue(configCopy.isGetMethodRun());
assertEquals(1L, configCopy.getCounter());
}
@Test
void testGetCacheWithKey() throws Exception {
ReferenceCache cache = SimpleReferenceCache.getCache();
MockReferenceConfig config =
buildMockReferenceConfig("org.apache.dubbo.config.utils.service.FooService", "group1", "1.0.0");
FooService value = cache.get(config);
assertEquals(
value, cache.get("group1/org.apache.dubbo.config.utils.service.FooService:1.0.0", FooService.class));
}
@Test
void testGetCacheDiffName() throws Exception {
SimpleReferenceCache cache = SimpleReferenceCache.getCache();
MockReferenceConfig config =
buildMockReferenceConfig("org.apache.dubbo.config.utils.service.FooService", "group1", "1.0.0");
assertEquals(0L, config.getCounter());
cache.get(config);
assertTrue(config.isGetMethodRun());
assertEquals(1L, config.getCounter());
cache = SimpleReferenceCache.getCache("foo");
config = buildMockReferenceConfig("org.apache.dubbo.config.utils.service.FooService", "group1", "1.0.0");
assertEquals(1L, config.getCounter());
cache.get(config);
// still init for the same ReferenceConfig if the cache is different
assertTrue(config.isGetMethodRun());
assertEquals(2L, config.getCounter());
}
@Test
void testDestroy() throws Exception {
SimpleReferenceCache cache = SimpleReferenceCache.getCache();
MockReferenceConfig config =
buildMockReferenceConfig("org.apache.dubbo.config.utils.service.FooService", "group1", "1.0.0");
cache.get(config);
XxxMockReferenceConfig configCopy =
buildXxxMockReferenceConfig("org.apache.dubbo.config.utils.service.XxxService", "group1", "1.0.0");
cache.get(configCopy);
assertEquals(2, cache.getReferenceMap().size());
cache.destroy(config);
assertTrue(config.isDestroyMethodRun());
assertEquals(1, cache.getReferenceMap().size());
cache.destroy(configCopy);
assertTrue(configCopy.isDestroyMethodRun());
assertEquals(0, cache.getReferenceMap().size());
}
@Test
void testDestroyAll() throws Exception {
SimpleReferenceCache cache = SimpleReferenceCache.getCache();
MockReferenceConfig config =
buildMockReferenceConfig("org.apache.dubbo.config.utils.service.FooService", "group1", "1.0.0");
cache.get(config);
XxxMockReferenceConfig configCopy =
buildXxxMockReferenceConfig("org.apache.dubbo.config.utils.service.XxxService", "group1", "1.0.0");
cache.get(configCopy);
assertEquals(2, cache.getReferenceMap().size());
cache.destroyAll();
assertTrue(config.isDestroyMethodRun());
assertTrue(configCopy.isDestroyMethodRun());
assertEquals(0, cache.getReferenceMap().size());
}
private MockReferenceConfig buildMockReferenceConfig(String service, String group, String version) {
MockReferenceConfig config = new MockReferenceConfig();
config.setApplication(new ApplicationConfig("cache"));
config.setRegistry(new RegistryConfig("multicast://224.5.6.7:1234"));
config.setCheck(false);
config.setInterface(service);
config.setGroup(group);
config.setVersion(version);
return config;
}
private XxxMockReferenceConfig buildXxxMockReferenceConfig(String service, String group, String version) {
XxxMockReferenceConfig config = new XxxMockReferenceConfig();
config.setApplication(new ApplicationConfig("cache"));
config.setRegistry(new RegistryConfig("multicast://224.5.6.7:1234"));
config.setInterface(service);
config.setCheck(false);
config.setGroup(group);
config.setVersion(version);
return config;
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/TestPreferSerializationProvider.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/TestPreferSerializationProvider.java | /*
* 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.config.utils;
import org.apache.dubbo.common.serialization.PreferSerializationProvider;
public class TestPreferSerializationProvider implements PreferSerializationProvider {
@Override
public String getPreferSerialization() {
return "fastjson2,hessian2";
}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/ConfigValidationUtilsTest.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/ConfigValidationUtilsTest.java | /*
* 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.config.utils;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.config.AbstractInterfaceConfig;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.MetadataReportConfig;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
class ConfigValidationUtilsTest {
@Test
void testValidateMetadataConfig() {
MetadataReportConfig config = new MetadataReportConfig();
config.setAddress("protocol://ip:host");
try {
ConfigValidationUtils.validateMetadataConfig(config);
} catch (Exception e) {
Assertions.fail("valid config expected.");
}
config.setAddress("ip:host");
config.setProtocol("protocol");
try {
ConfigValidationUtils.validateMetadataConfig(config);
} catch (Exception e) {
Assertions.fail("valid config expected.");
}
config.setAddress("ip:host");
config.setProtocol(null);
Assertions.assertThrows(IllegalArgumentException.class, () -> {
ConfigValidationUtils.validateMetadataConfig(config);
});
}
@Test
void testValidateApplicationConfig() throws Exception {
try (MockedStatic<ConfigValidationUtils> mockedStatic = Mockito.mockStatic(ConfigValidationUtils.class); ) {
mockedStatic
.when(() -> ConfigValidationUtils.validateApplicationConfig(any()))
.thenCallRealMethod();
ApplicationConfig config = new ApplicationConfig();
Assertions.assertThrows(IllegalStateException.class, () -> {
ConfigValidationUtils.validateApplicationConfig(config);
});
config.setName("testName");
config.setOwner("testOwner");
config.setOrganization("testOrg");
config.setArchitecture("testArchitecture");
config.setEnvironment("test");
Map<String, String> map = new HashMap();
map.put("k1", "v1");
map.put("k2", "v2");
config.setParameters(map);
ConfigValidationUtils.validateApplicationConfig(config);
mockedStatic.verify(
() -> {
ConfigValidationUtils.checkName(any(), any());
},
times(4));
mockedStatic.verify(
() -> {
ConfigValidationUtils.checkMultiName(any(), any());
},
times(1));
mockedStatic.verify(
() -> {
ConfigValidationUtils.checkParameterName(any());
},
times(1));
}
}
@Test
void testCheckQosInApplicationConfig() throws Exception {
ConfigValidationUtils mock = Mockito.mock(ConfigValidationUtils.class);
ErrorTypeAwareLogger loggerMock = Mockito.mock(ErrorTypeAwareLogger.class);
injectField(mock.getClass().getDeclaredField("logger"), loggerMock);
ApplicationConfig config = new ApplicationConfig();
config.setName("testName");
config.setQosEnable(false);
mock.validateApplicationConfig(config);
verify(loggerMock, never()).warn(any(), any(Throwable.class));
config.setQosEnable(true);
mock.validateApplicationConfig(config);
verify(loggerMock).info(anyString());
}
private void injectField(Field field, Object newValue) throws Exception {
field.setAccessible(true);
field.set(null, newValue);
}
public static class InterfaceConfig extends AbstractInterfaceConfig {}
}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
apache/dubbo | https://github.com/apache/dubbo/blob/ac1621f9a0470054c0308c47f84c7668f6bc2868/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/service/XxxServiceImpl.java | dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/service/XxxServiceImpl.java | /*
* 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.config.utils.service;
public class XxxServiceImpl implements XxxService {}
| java | Apache-2.0 | ac1621f9a0470054c0308c47f84c7668f6bc2868 | 2026-01-04T14:45:57.057261Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.