Search in sources :

Example 1 with DemoService

use of com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoService in project sofa-rpc by sofastack.

the class DubooServerTest method testOneWay.

@Test
public // 单向调用
void testOneWay() {
    // 只有1个线程 执行
    ServerConfig serverConfig = new ServerConfig().setStopTimeout(60000).setPort(20880).setProtocol("dubbo").setQueues(100).setCoreThreads(1).setMaxThreads(2);
    // 发布一个服务,每个请求要执行1秒
    ApplicationConfig serverApplacation = new ApplicationConfig();
    serverApplacation.setAppName("server");
    providerConfig = new ProviderConfig<DemoService>().setInterfaceId(DemoService.class.getName()).setRef(new DemoServiceImpl()).setServer(serverConfig).setBootstrap("dubbo").setRegister(false).setApplication(serverApplacation);
    providerConfig.export();
    ApplicationConfig clientApplication = new ApplicationConfig();
    clientApplication.setAppName("client");
    List<MethodConfig> methodConfigs = new ArrayList<MethodConfig>();
    MethodConfig methodConfig = new MethodConfig();
    methodConfig.setInvokeType(RpcConstants.INVOKER_TYPE_ONEWAY);
    methodConfig.setName("sayHello");
    methodConfigs.add(methodConfig);
    consumerConfig = new ConsumerConfig<DemoService>().setInterfaceId(DemoService.class.getName()).setDirectUrl("dubbo://127.0.0.1:20880").setTimeout(30000).setRegister(false).setProtocol("dubbo").setBootstrap("dubbo").setApplication(clientApplication).setInvokeType(RpcConstants.INVOKER_TYPE_ONEWAY).setMethods(methodConfigs);
    final DemoService demoService = consumerConfig.refer();
    String tmp = demoService.sayHello("xxx");
    Assert.assertEquals(null, tmp);
}
Also used : MethodConfig(com.alipay.sofa.rpc.config.MethodConfig) ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) ArrayList(java.util.ArrayList) DemoService(com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoService) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) DemoServiceImpl(com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoServiceImpl) Test(org.junit.Test)

Example 2 with DemoService

use of com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoService in project sofa-rpc by sofastack.

the class DubooServerTest method testGenericSync.

@Test
public // 同步泛化调用,直连
void testGenericSync() {
    // 只有1个线程 执行
    ServerConfig serverConfig = new ServerConfig().setStopTimeout(60000).setPort(20880).setProtocol("dubbo").setQueues(100).setCoreThreads(1).setMaxThreads(2);
    // 发布一个服务,每个请求要执行1秒
    ApplicationConfig serverApplacation = new ApplicationConfig();
    serverApplacation.setAppName("server");
    providerConfig = new ProviderConfig<DemoService>().setInterfaceId(DemoService.class.getName()).setRef(new DemoServiceImpl()).setBootstrap("dubbo").setServer(serverConfig).setRegister(false).setApplication(serverApplacation);
    providerConfig.export();
    ApplicationConfig clientApplication = new ApplicationConfig();
    clientApplication.setAppName("client");
    consumerConfig = new ConsumerConfig<DemoService>().setInterfaceId(DemoService.class.getName()).setDirectUrl("dubbo://127.0.0.1:20880").setBootstrap("dubbo").setTimeout(30000).setRegister(false).setProtocol("dubbo").setApplication(clientApplication).setGeneric(true);
    final GenericService demoService = (GenericService) consumerConfig.refer();
    String result = (String) demoService.$invoke("sayHello", new String[] { "java.lang.String" }, new Object[] { "xxx" });
    Assert.assertEquals(result, "Hello xxx");
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) GenericService(com.alibaba.dubbo.rpc.service.GenericService) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) DemoService(com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoService) DemoServiceImpl(com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoServiceImpl) Test(org.junit.Test)

Example 3 with DemoService

use of com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoService in project sofa-rpc by sofastack.

the class DubooServerTest method testWithParameterWithVersion.

@Test
public // 同步调用,直连,dubbo 服务指定版本version
void testWithParameterWithVersion() {
    try {
        // 只有1个线程 执行
        ServerConfig serverConfig = new ServerConfig().setStopTimeout(60000).setPort(20880).setProtocol("dubbo").setQueues(100).setCoreThreads(1).setMaxThreads(2);
        // 发布一个服务,每个请求要执行1秒
        ApplicationConfig serverApplacation = new ApplicationConfig();
        serverApplacation.setAppName("server");
        providerConfig = new ProviderConfig<DemoService>().setInterfaceId(DemoService.class.getName()).setRef(new DemoServiceImpl()).setBootstrap("dubbo").setServer(serverConfig).setParameter("version", "1.0.1").setRegister(false).setApplication(serverApplacation);
        providerConfig.export();
        ApplicationConfig clientApplication = new ApplicationConfig();
        clientApplication.setAppName("client");
        consumerConfig = new ConsumerConfig<DemoService>().setInterfaceId(DemoService.class.getName()).setDirectUrl("dubbo://127.0.0.1:20880").setBootstrap("dubbo").setTimeout(30000).setParameter("version", "1.0.1").setRegister(false).setProtocol("dubbo").setApplication(clientApplication);
        final DemoService demoService = consumerConfig.refer();
        String result = demoService.sayHello("xxx");
        Assert.assertTrue(result.equalsIgnoreCase("hello xxx"));
    } catch (Exception e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) DemoService(com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoService) ExecutionException(java.util.concurrent.ExecutionException) DemoServiceImpl(com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoServiceImpl) Test(org.junit.Test)

Example 4 with DemoService

use of com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoService in project sofa-rpc by sofastack.

the class DubooServerTest method testFuture.

@Test
public // future调用,从future中取值.
void testFuture() {
    // 只有1个线程 执行
    ServerConfig serverConfig = new ServerConfig().setStopTimeout(60000).setPort(20880).setProtocol("dubbo").setQueues(100).setCoreThreads(1).setMaxThreads(2);
    // 发布一个服务,每个请求要执行1秒
    ApplicationConfig serverApplacation = new ApplicationConfig();
    serverApplacation.setAppName("server");
    providerConfig = new ProviderConfig<DemoService>().setInterfaceId(DemoService.class.getName()).setRef(new DemoServiceImpl()).setServer(serverConfig).setBootstrap("dubbo").setRegister(false).setApplication(serverApplacation);
    providerConfig.export();
    ApplicationConfig clientApplication = new ApplicationConfig();
    clientApplication.setAppName("client");
    List<MethodConfig> methodConfigs = new ArrayList<MethodConfig>();
    MethodConfig methodConfig = new MethodConfig();
    methodConfig.setInvokeType(RpcConstants.INVOKER_TYPE_FUTURE);
    methodConfig.setName("sayHello");
    consumerConfig = new ConsumerConfig<DemoService>().setInterfaceId(DemoService.class.getName()).setDirectUrl("dubbo://127.0.0.1:20880").setTimeout(30000).setRegister(false).setProtocol("dubbo").setBootstrap("dubbo").setApplication(clientApplication).setInvokeType(RpcConstants.INVOKER_TYPE_FUTURE).setMethods(methodConfigs);
    final DemoService demoService = consumerConfig.refer();
    String result = demoService.sayHello("xxx");
    Assert.assertEquals(null, result);
    Future<Object> future = RpcContext.getContext().getFuture();
    String futureResult = null;
    try {
        futureResult = (String) future.get();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
    Assert.assertEquals("Hello xxx", futureResult);
}
Also used : ArrayList(java.util.ArrayList) DemoService(com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoService) MethodConfig(com.alipay.sofa.rpc.config.MethodConfig) ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) ExecutionException(java.util.concurrent.ExecutionException) DemoServiceImpl(com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoServiceImpl) Test(org.junit.Test)

Example 5 with DemoService

use of com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoService in project sofa-rpc by sofastack.

the class DubooServerTest method testSync.

@Test
public // 同步调用,直连
void testSync() {
    try {
        // 只有1个线程 执行
        ServerConfig serverConfig = new ServerConfig().setStopTimeout(60000).setPort(20880).setProtocol("dubbo").setQueues(100).setCoreThreads(1).setMaxThreads(2);
        // 发布一个服务,每个请求要执行1秒
        ApplicationConfig serverApplacation = new ApplicationConfig();
        serverApplacation.setAppName("server");
        providerConfig = new ProviderConfig<DemoService>().setInterfaceId(DemoService.class.getName()).setRef(new DemoServiceImpl()).setBootstrap("dubbo").setServer(serverConfig).setRegister(false).setApplication(serverApplacation);
        providerConfig.export();
        ApplicationConfig clientApplication = new ApplicationConfig();
        clientApplication.setAppName("client");
        consumerConfig = new ConsumerConfig<DemoService>().setInterfaceId(DemoService.class.getName()).setDirectUrl("dubbo://127.0.0.1:20880").setBootstrap("dubbo").setTimeout(30000).setRegister(false).setProtocol("dubbo").setApplication(clientApplication);
        final DemoService demoService = consumerConfig.refer();
        String result = demoService.sayHello("xxx");
        Assert.assertTrue(result.equalsIgnoreCase("hello xxx"));
    } catch (Exception e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) DemoService(com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoService) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) ExecutionException(java.util.concurrent.ExecutionException) DemoServiceImpl(com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoServiceImpl) Test(org.junit.Test)

Aggregations

DemoService (com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoService)6 DemoServiceImpl (com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoServiceImpl)6 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)6 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)6 Test (org.junit.Test)6 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)4 ExecutionException (java.util.concurrent.ExecutionException)3 MethodConfig (com.alipay.sofa.rpc.config.MethodConfig)2 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)2 ArrayList (java.util.ArrayList)2 GenericService (com.alibaba.dubbo.rpc.service.GenericService)1