use of com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoServiceImpl in project sofa-rpc by sofastack.
the class DubboProviderBootstrapTest method setUp.
@Before
public void setUp() throws Exception {
ApplicationConfig serverApplacation = new ApplicationConfig();
serverApplacation.setAppName("server");
ProviderConfig providerConfig = new ProviderConfig<DemoService>().setInterfaceId(DemoService.class.getName()).setRef(new DemoServiceImpl()).setBootstrap("dubbo").setParameter("version", "1.0.1").setRegister(false).setApplication(serverApplacation);
dubboProviderBootstrap = new DubboProviderBootstrap(providerConfig);
}
use of com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoServiceImpl 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);
}
use of com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoServiceImpl 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");
}
use of com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoServiceImpl 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);
}
}
use of com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoServiceImpl 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);
}
Aggregations