Search in sources :

Example 1 with GreetingsService

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);
}
Also used : RegistryConfig(com.alibaba.dubbo.config.RegistryConfig) ApplicationConfig(com.alibaba.dubbo.config.ApplicationConfig) ReferenceConfig(com.alibaba.dubbo.config.ReferenceConfig) GreetingsService(com.baeldung.dubbo.remote.GreetingsService) Test(org.junit.Test)

Example 2 with GreetingsService

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);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) GreetingsService(com.baeldung.dubbo.remote.GreetingsService) Test(org.junit.Test)

Example 3 with GreetingsService

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);
}
Also used : List(java.util.List) Assert.assertNotNull(org.junit.Assert.assertNotNull) After(org.junit.After) OptionalDouble(java.util.OptionalDouble) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) GreetingsService(com.baeldung.dubbo.remote.GreetingsService) ExecutorService(java.util.concurrent.ExecutorService) Executors(java.util.concurrent.Executors) Before(org.junit.Before) ArrayList(java.util.ArrayList) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) GreetingsService(com.baeldung.dubbo.remote.GreetingsService) ArrayList(java.util.ArrayList) OptionalDouble(java.util.OptionalDouble) Test(org.junit.Test)

Example 4 with GreetingsService

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();
}
Also used : RegistryConfig(com.alibaba.dubbo.config.RegistryConfig) ApplicationConfig(com.alibaba.dubbo.config.ApplicationConfig) ServiceConfig(com.alibaba.dubbo.config.ServiceConfig) GreetingsService(com.baeldung.dubbo.remote.GreetingsService) GreetingsServiceImpl(com.baeldung.dubbo.remote.GreetingsServiceImpl) Before(org.junit.Before)

Example 5 with GreetingsService

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);
}
Also used : Assert.assertNotNull(org.junit.Assert.assertNotNull) OptionalDouble(java.util.OptionalDouble) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Callable(java.util.concurrent.Callable) GreetingsService(com.baeldung.dubbo.remote.GreetingsService) Executors(java.util.concurrent.Executors) ArrayList(java.util.ArrayList) List(java.util.List) After(org.junit.After) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ExecutorService(java.util.concurrent.ExecutorService) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Before(org.junit.Before) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) GreetingsService(com.baeldung.dubbo.remote.GreetingsService) ArrayList(java.util.ArrayList) OptionalDouble(java.util.OptionalDouble) Test(org.junit.Test)

Aggregations

GreetingsService (com.baeldung.dubbo.remote.GreetingsService)9 Test (org.junit.Test)8 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)7 Before (org.junit.Before)3 ApplicationConfig (com.alibaba.dubbo.config.ApplicationConfig)2 RegistryConfig (com.alibaba.dubbo.config.RegistryConfig)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 OptionalDouble (java.util.OptionalDouble)2 ExecutorService (java.util.concurrent.ExecutorService)2 Executors (java.util.concurrent.Executors)2 After (org.junit.After)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 ReferenceConfig (com.alibaba.dubbo.config.ReferenceConfig)1 ServiceConfig (com.alibaba.dubbo.config.ServiceConfig)1 GreetingsServiceImpl (com.baeldung.dubbo.remote.GreetingsServiceImpl)1 Callable (java.util.concurrent.Callable)1 SECONDS (java.util.concurrent.TimeUnit.SECONDS)1