use of org.apache.dubbo.config.api.DemoService in project dubbo by alibaba.
the class ReferenceBuilderTest method build.
@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).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);
}
use of org.apache.dubbo.config.api.DemoService in project dubbo by alibaba.
the class ReferenceConfigTest method testInjvm.
@Test
@Disabled("Disabled due to Github Actions environment")
public void testInjvm() throws Exception {
ApplicationConfig application = new ApplicationConfig();
application.setName("test-protocol-random-port");
RegistryConfig registry = new RegistryConfig();
registry.setAddress(registryUrl);
ProtocolConfig protocol = new ProtocolConfig();
protocol.setName("dubbo");
ServiceConfig<DemoService> demoService;
demoService = new ServiceConfig<DemoService>();
demoService.setInterface(DemoService.class);
demoService.setRef(new DemoServiceImpl());
demoService.setApplication(application);
demoService.setRegistry(registry);
demoService.setProtocol(protocol);
ReferenceConfig<DemoService> rc = new ReferenceConfig<DemoService>();
rc.setApplication(application);
rc.setRegistry(registry);
rc.setInterface(DemoService.class.getName());
rc.setScope(SCOPE_REMOTE);
try {
System.setProperty("java.net.preferIPv4Stack", "true");
demoService.export();
rc.get();
Assertions.assertTrue(!LOCAL_PROTOCOL.equalsIgnoreCase(rc.getInvoker().getUrl().getProtocol()));
} finally {
System.clearProperty("java.net.preferIPv4Stack");
rc.destroy();
demoService.unexport();
}
// Manually trigger dubbo resource recycling.
DubboBootstrap.getInstance().destroy();
}
use of org.apache.dubbo.config.api.DemoService in project dubbo by alibaba.
the class UrlTestBase method initServConf.
@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);
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.setInterfaceClass(DemoService.class);
methodConfForService.setName("sayName");
regConfForService.setAddress("127.0.0.1:9090");
regConfForService.setProtocol("mockregistry");
application.setName("ConfigTests");
}
use of org.apache.dubbo.config.api.DemoService in project dubbo by alibaba.
the class ReferenceConfigTest method testReferenceRetry.
/**
* unit test for dubbo-1765
*/
@Test
public void testReferenceRetry() {
ApplicationConfig application = new ApplicationConfig();
application.setName("test-reference-retry");
RegistryConfig registry = new RegistryConfig();
registry.setAddress(registryUrl);
ProtocolConfig protocol = new ProtocolConfig();
protocol.setName("mockprotocol");
ReferenceConfig<DemoService> rc = new ReferenceConfig<DemoService>();
rc.setApplication(application);
rc.setRegistry(registry);
rc.setInterface(DemoService.class.getName());
boolean success = false;
DemoService demoService = null;
try {
demoService = rc.get();
success = true;
} catch (Exception e) {
e.printStackTrace();
}
Assertions.assertFalse(success);
Assertions.assertNull(demoService);
ServiceConfig<DemoService> sc = new ServiceConfig<DemoService>();
sc.setInterface(DemoService.class);
sc.setRef(new DemoServiceImpl());
sc.setApplication(application);
sc.setRegistry(registry);
sc.setProtocol(protocol);
try {
System.setProperty("java.net.preferIPv4Stack", "true");
sc.export();
demoService = rc.get();
success = true;
} catch (Exception e) {
e.printStackTrace();
} finally {
rc.destroy();
sc.unexport();
System.clearProperty("java.net.preferIPv4Stack");
}
Assertions.assertTrue(success);
Assertions.assertNotNull(demoService);
}
use of org.apache.dubbo.config.api.DemoService in project dubbo by alibaba.
the class InvokerSideConfigUrlTest method initRefConf.
// ======================================================
// 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);
}
Aggregations