use of com.baeldung.dubbo.remote.GreetingsService in project tutorials by eugenp.
the class APIConfigurationLiveTest method givenProviderConsumer_whenSayHi_thenGotResponse.
@Test
public void givenProviderConsumer_whenSayHi_thenGotResponse() {
ApplicationConfig application = new ApplicationConfig();
application.setName("demo-consumer");
application.setVersion("1.0");
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress("multicast://224.1.1.1:9090");
ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>();
reference.setApplication(application);
reference.setRegistry(registryConfig);
reference.setInterface(GreetingsService.class);
GreetingsService greetingsService = reference.get();
String hiMessage = greetingsService.sayHi("baeldung");
assertEquals("hi, baeldung", hiMessage);
}
use of com.baeldung.dubbo.remote.GreetingsService in project tutorials by eugenp.
the class ClusterFailsafeLiveTest method givenProviderCluster_whenConsumerSaysHi_thenGotFailsafeResponse.
@Test
public void givenProviderCluster_whenConsumerSaysHi_thenGotFailsafeResponse() {
ClassPathXmlApplicationContext localContext = new ClassPathXmlApplicationContext("cluster/consumer-app-failtest.xml");
localContext.start();
GreetingsService greetingsService = (GreetingsService) localContext.getBean("greetingsService");
String hiMessage = greetingsService.sayHi("baeldung");
assertNull(hiMessage);
}
use of com.baeldung.dubbo.remote.GreetingsService in project tutorials by eugenp.
the class ClusterLoadBalanceLiveTest method givenProviderCluster_whenConsumerSaysHi_thenResponseBalanced.
@Test
public void givenProviderCluster_whenConsumerSaysHi_thenResponseBalanced() {
ClassPathXmlApplicationContext localContext = new ClassPathXmlApplicationContext("cluster/consumer-app-lb.xml");
localContext.start();
GreetingsService greetingsService = (GreetingsService) localContext.getBean("greetingsService");
List<Long> elapseList = new ArrayList<>(6);
for (int i = 0; i < 6; i++) {
long current = System.currentTimeMillis();
String hiMessage = greetingsService.sayHi("baeldung");
assertNotNull(hiMessage);
elapseList.add(System.currentTimeMillis() - current);
}
OptionalDouble avgElapse = elapseList.stream().mapToLong(e -> e).average();
assertTrue(avgElapse.isPresent());
System.out.println(avgElapse.getAsDouble());
assertTrue(avgElapse.getAsDouble() > 2500.0);
}
use of com.baeldung.dubbo.remote.GreetingsService in project tutorials by eugenp.
the class APIConfigurationLiveTest method initProvider.
@Before
public void initProvider() {
ApplicationConfig application = new ApplicationConfig();
application.setName("demo-provider");
application.setVersion("1.0");
RegistryConfig registryConfig = new RegistryConfig();
registryConfig.setAddress("multicast://224.1.1.1:9090");
ServiceConfig<GreetingsService> service = new ServiceConfig<>();
service.setApplication(application);
service.setRegistry(registryConfig);
service.setInterface(GreetingsService.class);
service.setRef(new GreetingsServiceImpl());
service.export();
}
use of com.baeldung.dubbo.remote.GreetingsService in project tutorials by eugenp.
the class ClusterDynamicLoadBalanceLiveTest method givenProviderCluster_whenConsumerSaysHi_thenResponseBalanced.
@Test
public void givenProviderCluster_whenConsumerSaysHi_thenResponseBalanced() throws InterruptedException {
ClassPathXmlApplicationContext localContext = new ClassPathXmlApplicationContext("cluster/consumer-app-lb.xml");
localContext.start();
GreetingsService greetingsService = (GreetingsService) localContext.getBean("greetingsService");
List<Long> elapseList = new ArrayList<>(6);
for (int i = 0; i < 6; i++) {
long current = System.currentTimeMillis();
String hiMessage = greetingsService.sayHi("baeldung");
assertNotNull(hiMessage);
elapseList.add(System.currentTimeMillis() - current);
SECONDS.sleep(1);
}
OptionalDouble avgElapse = elapseList.stream().mapToLong(e -> e).average();
assertTrue(avgElapse.isPresent());
assertTrue(avgElapse.getAsDouble() > 1666.0);
}
Aggregations