use of com.alipay.sofa.rpc.config.ApplicationConfig 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.ApplicationConfig 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.ApplicationConfig in project sofa-rpc by sofastack.
the class RestLookoutTest method beforeMethod.
/**
* invoke
*/
@Before
public void beforeMethod() {
// 只有1个线程 执行
serverConfig = new ServerConfig().setStopTimeout(1000).setPort(8802).setProtocol(RpcConstants.PROTOCOL_TYPE_REST).setContextPath("/xyz");
// .setQueues(100).setCoreThreads(1).setMaxThreads(2);
// 发布一个服务,每个请求要执行1秒
ApplicationConfig serverApplication = new ApplicationConfig();
serverApplication.setAppName("TestLookOutServer");
providerConfig = new ProviderConfig<RestService>().setInterfaceId(RestService.class.getName()).setRef(new RestServiceImpl()).setServer(serverConfig).setBootstrap("rest").setRegister(false).setApplication(serverApplication);
providerConfig.export();
ApplicationConfig clientApplication = new ApplicationConfig();
clientApplication.setAppName("TestLookOutClient");
consumerConfig = new ConsumerConfig<RestService>().setInterfaceId(RestService.class.getName()).setDirectUrl("rest://127.0.0.1:8802/xyz?uniqueId=&version=1" + ".0&timeout=0&delay=-1&id=rpc-cfg-0&dynamic=true&weight=100&accepts=100000" + "&startTime=1523240755024&appName=" + serverApplication.getAppName() + "&pid=22385&language=java&rpcVer=50300").setProtocol("rest").setBootstrap("rest").setTimeout(30000).setConnectionNum(5).setRegister(false).setApplication(clientApplication);
helloService = consumerConfig.refer();
}
use of com.alipay.sofa.rpc.config.ApplicationConfig in project sofa-rpc by sofastack.
the class RestDirectUrlTest method testAll.
@Test
public void testAll() {
// 只有1个线程 执行
ServerConfig serverConfig = new ServerConfig().setPort(12300).setProtocol(RpcConstants.PROTOCOL_TYPE_REST).setDaemon(true);
// 发布一个服务,每个请求要执行1秒
ProviderConfig<RestService> providerConfig = new ProviderConfig<RestService>().setInterfaceId(RestService.class.getName()).setRef(new RestServiceImpl()).setBootstrap("rest").setApplication(new ApplicationConfig().setAppName("serverApp")).setServer(serverConfig).setRegister(false);
providerConfig.export();
final ConsumerConfig<RestService> consumerConfig = new ConsumerConfig<RestService>().setInterfaceId(RestService.class.getName()).setDirectUrl("rest://127.0.0.1:12300").setProtocol(RpcConstants.PROTOCOL_TYPE_REST).setBootstrap("rest").setApplication(new ApplicationConfig().setAppName("clientApp")).setReconnectPeriod(1000);
RestService restService = consumerConfig.refer();
Assert.assertEquals(restService.query(11), "hello world !null");
serverConfig.getServer().stop();
// 关闭后再调用一个抛异常
try {
restService.query(11);
} 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.assertEquals(restService.query(11), "hello world !null");
}
use of com.alipay.sofa.rpc.config.ApplicationConfig in project sofa-rpc by sofastack.
the class RpcLookoutTest method before.
/**
* invoke
*/
@Before
public void before() {
final Registry currentRegistry = Lookout.registry();
// clear all metrics now
Iterator<Metric> itar = currentRegistry.iterator();
while (itar.hasNext()) {
Metric metric = itar.next();
Id id = metric.id();
currentRegistry.removeMetric(id);
}
serverConfig = new ServerConfig().setPort(12201).setCoreThreads(30).setMaxThreads(500).setQueues(600).setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT);
providerConfig = new ProviderConfig<LookoutService>().setInterfaceId(LookoutService.class.getName()).setRef(new LookoutServiceImpl()).setServer(serverConfig).setBootstrap("bolt").setRegister(false).setApplication(new ApplicationConfig().setAppName("TestLookOutServer"));
providerConfig.export();
MethodConfig methodConfigFuture = new MethodConfig().setName("sayFuture").setInvokeType("future");
onReturn = new CountSofaResponseCallback();
MethodConfig methodConfigCallback = new MethodConfig().setName("sayCallback").setInvokeType("callback").setOnReturn(onReturn);
MethodConfig methodConfigOneway = new MethodConfig().setName("sayOneway").setInvokeType("oneway");
List<MethodConfig> methodConfigs = new ArrayList<MethodConfig>();
methodConfigs.add(methodConfigFuture);
methodConfigs.add(methodConfigCallback);
methodConfigs.add(methodConfigOneway);
consumerConfig = new ConsumerConfig<LookoutService>().setInterfaceId(LookoutService.class.getName()).setProtocol("bolt").setBootstrap("bolt").setMethods(methodConfigs).setTimeout(3000).setRegister(false).setDirectUrl("bolt://127.0.0.1:12201?appName=TestLookOutServer").setApplication(new ApplicationConfig().setAppName("TestLookOutClient"));
lookoutService = consumerConfig.refer();
}
Aggregations