use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-rpc by sofastack.
the class ZookeeperAuthBoltServerTest method testUseCorrentAuth.
@Test
public void testUseCorrentAuth() {
parameters.put("scheme", "digest");
// 如果存在多个认证信息,则在参数形式为为user1:passwd1,user2:passwd2
parameters.put("addAuth", "sofazk:rpc1");
registryConfig = new RegistryConfig().setProtocol(RpcConstants.REGISTRY_PROTOCOL_ZK).setAddress("127.0.0.1:2181/authtest").setParameters(parameters);
serverConfig = new ServerConfig().setProtocol(// 设置一个协议,默认bolt
"bolt").setPort(// 设置一个端口,默认12200
12200).setDaemon(// 非守护线程
false);
ProviderConfig<EchoService> providerConfig = new ProviderConfig<EchoService>().setRegistry(registryConfig).setInterfaceId(// 指定接口
EchoService.class.getName()).setRef(// 指定实现
new EchoServiceImpl()).setServer(// 指定服务端
serverConfig);
// 发布服务
providerConfig.export();
ConsumerConfig<EchoService> consumerConfig = new ConsumerConfig<EchoService>().setRegistry(registryConfig).setInterfaceId(// 指定接口
EchoService.class.getName()).setProtocol(// 指定协议
"bolt").setTimeout(3000).setConnectTimeout(10 * 1000);
EchoService echoService = consumerConfig.refer();
String result = echoService.echoStr("auth test");
Assert.assertEquals("auth test", result);
}
use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-rpc by sofastack.
the class BoltDirectUrlTest method testAll.
// @Test
// FIXME 目前bolt的IO线程关闭时未释放,暂不支持本测试用例
public void testAll() {
// 只有2个线程 执行
ServerConfig serverConfig = new ServerConfig().setPort(12300).setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT).setDaemon(true);
// 发布一个服务,每个请求要执行1秒
ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>().setInterfaceId(HelloService.class.getName()).setRef(new HelloServiceImpl()).setBootstrap("bolt").setApplication(new ApplicationConfig().setAppName("serverApp")).setServer(serverConfig).setRegister(false);
providerConfig.export();
final ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>().setInterfaceId(HelloService.class.getName()).setDirectUrl("bolt://127.0.0.1:12300").setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT).setBootstrap("bolt").setApplication(new ApplicationConfig().setAppName("clientApp")).setReconnectPeriod(1000);
HelloService helloService = consumerConfig.refer();
Assert.assertNotNull(helloService.sayHello("xx", 22));
serverConfig.getServer().stop();
// 关闭后再调用一个抛异常
try {
helloService.sayHello("xx", 22);
} catch (Exception e) {
// 应该抛出异常
Assert.assertTrue(e instanceof SofaRpcException);
}
Assert.assertTrue(TestUtils.delayGet(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return CommonUtils.isEmpty(consumerConfig.getConsumerBootstrap().getCluster().getConnectionHolder().getAvailableConnections());
}
}, true, 50, 40));
serverConfig.getServer().start();
// 等待客户端重连服务端
Assert.assertTrue(TestUtils.delayGet(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return CommonUtils.isNotEmpty(consumerConfig.getConsumerBootstrap().getCluster().getConnectionHolder().getAvailableConnections());
}
}, true, 50, 60));
Assert.assertNotNull(helloService.sayHello("xx", 22));
}
use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-rpc by sofastack.
the class H2cDirectUrlTest method testAll.
@Test
public void testAll() throws InterruptedException {
// 只有1个线程 执行
ServerConfig serverConfig = new ServerConfig().setPort(12300).setProtocol(RpcConstants.PROTOCOL_TYPE_H2C).setDaemon(true);
// 发布一个服务,每个请求要执行1秒
ProviderConfig<HttpService> providerConfig = new ProviderConfig<HttpService>().setInterfaceId(HttpService.class.getName()).setRef(new HttpServiceImpl()).setBootstrap("h2c").setApplication(new ApplicationConfig().setAppName("serverApp")).setServer(serverConfig).setRegister(false);
providerConfig.export();
final ConsumerConfig<HttpService> consumerConfig = new ConsumerConfig<HttpService>().setInterfaceId(HttpService.class.getName()).setDirectUrl("h2c://127.0.0.1:12300").setProtocol(RpcConstants.PROTOCOL_TYPE_H2C).setBootstrap("h2c").setApplication(new ApplicationConfig().setAppName("clientApp")).setReconnectPeriod(1000);
HttpService httpService = consumerConfig.refer();
ExampleObj request = new ExampleObj();
request.setId(200);
request.setName("yyy");
ExampleObj response = httpService.object(request);
Assert.assertEquals(200, response.getId());
Assert.assertEquals("yyyxx", response.getName());
serverConfig.getServer().stop();
// 关闭后再调用一个抛异常
try {
httpService.object(request);
} catch (Exception e) {
// 应该抛出异常
Assert.assertTrue(e instanceof SofaRpcException);
}
Assert.assertTrue(TestUtils.delayGet(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return CommonUtils.isEmpty(consumerConfig.getConsumerBootstrap().getCluster().getConnectionHolder().getAvailableConnections());
}
}, true, 50, 40));
serverConfig.getServer().start();
// 等待客户端重连服务端
Assert.assertTrue(TestUtils.delayGet(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return CommonUtils.isNotEmpty(consumerConfig.getConsumerBootstrap().getCluster().getConnectionHolder().getAvailableConnections());
}
}, true, 50, 60));
response = httpService.object(request);
Assert.assertEquals(200, response.getId());
Assert.assertEquals("yyyxx", response.getName());
}
use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-rpc by sofastack.
the class CustomizeFilterTest method beforeClass.
@BeforeClass
public static void beforeClass() {
customizeContainerRequestTestFilter = new CustomizeContainerRequestTestFilter();
customizeContainerResponseTestFilter = new CustomizeContainerResponseTestFilter();
customizeClientRequestTestFilter = new CustomizeClientRequestTestFilter();
customizeClientResponseTestFilter = new CustomizeClientResponseTestFilter();
JAXRSProviderManager.registerCustomProviderInstance(customizeContainerRequestTestFilter);
JAXRSProviderManager.registerCustomProviderInstance(customizeContainerResponseTestFilter);
JAXRSProviderManager.registerCustomProviderInstance(customizeClientRequestTestFilter);
JAXRSProviderManager.registerCustomProviderInstance(customizeClientResponseTestFilter);
providerFilter = new CustomizeTestFilter();
List<Filter> providerFilters = new ArrayList<Filter>(2);
providerFilters.add(providerFilter);
ServerConfig restServer = new ServerConfig().setPort(8583).setProtocol(RpcConstants.PROTOCOL_TYPE_REST);
List<ServerConfig> servers = new ArrayList<ServerConfig>(2);
servers.add(restServer);
providerConfig = new ProviderConfig<RestService>().setInterfaceId(RestService.class.getName()).setRef(new RestServiceImpl()).setRegister(false).setServer(servers).setFilterRef(providerFilters);
providerConfig.export();
// rest服务
clientFilter = new CustomizeTestFilter();
List<Filter> clientFilters = new ArrayList<Filter>(2);
clientFilters.add(clientFilter);
ConsumerConfig<RestService> consumerConfigRest = new ConsumerConfig<RestService>().setInterfaceId(RestService.class.getName()).setProtocol(RpcConstants.PROTOCOL_TYPE_REST).setDirectUrl("rest://127.0.0.1:8583").setTimeout(1000).setFilterRef(clientFilters).setApplication(new ApplicationConfig().setAppName("TestClientRest"));
filterRestService = consumerConfigRest.refer();
}
use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-rpc by sofastack.
the class HystrixFilterAsyncTest method defaultServer.
private ProviderConfig<HystrixService> defaultServer(int sleep) {
InvokeCounterHystrixService hystrixService = new InvokeCounterHystrixService(sleep);
serverConfig = new ServerConfig().setPort(22222).setDaemon(false);
return new ProviderConfig<HystrixService>().setInterfaceId(HystrixService.class.getName()).setRef(hystrixService).setServer(serverConfig).setRepeatedExportLimit(-1);
}
Aggregations