Search in sources :

Example 26 with ProviderConfig

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);
}
Also used : RegistryConfig(com.alipay.sofa.rpc.config.RegistryConfig) ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) EchoService(com.alipay.sofa.rpc.test.EchoService) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) EchoServiceImpl(com.alipay.sofa.rpc.test.EchoServiceImpl) Test(org.junit.Test) BaseZkTest(com.alipay.sofa.rpc.registry.base.BaseZkTest)

Example 27 with ProviderConfig

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));
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) HelloService(com.alipay.sofa.rpc.test.HelloService) HelloServiceImpl(com.alipay.sofa.rpc.test.HelloServiceImpl) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) Callable(java.util.concurrent.Callable)

Example 28 with ProviderConfig

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());
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) ExampleObj(com.alipay.sofa.rpc.server.http.ExampleObj) HttpService(com.alipay.sofa.rpc.server.http.HttpService) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) HttpServiceImpl(com.alipay.sofa.rpc.server.http.HttpServiceImpl) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException) Callable(java.util.concurrent.Callable) Test(org.junit.Test) ActivelyDestroyTest(com.alipay.sofa.rpc.test.ActivelyDestroyTest)

Example 29 with ProviderConfig

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();
}
Also used : ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) ArrayList(java.util.ArrayList) ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) Filter(com.alipay.sofa.rpc.filter.Filter) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) BeforeClass(org.junit.BeforeClass)

Example 30 with ProviderConfig

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);
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig)

Aggregations

ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)121 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)88 Test (org.junit.Test)73 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)52 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)47 HelloService (com.alipay.sofa.rpc.test.HelloService)33 HelloServiceImpl (com.alipay.sofa.rpc.test.HelloServiceImpl)33 ActivelyDestroyTest (com.alipay.sofa.rpc.test.ActivelyDestroyTest)28 RegistryConfig (com.alipay.sofa.rpc.config.RegistryConfig)21 CountDownLatch (java.util.concurrent.CountDownLatch)19 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)17 ProviderGroup (com.alipay.sofa.rpc.client.ProviderGroup)10 Filter (com.alipay.sofa.rpc.filter.Filter)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 EchoService (com.alipay.sofa.rpc.test.EchoService)9 ArrayList (java.util.ArrayList)9 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)8 EchoServiceImpl (com.alipay.sofa.rpc.test.EchoServiceImpl)8 MethodConfig (com.alipay.sofa.rpc.config.MethodConfig)7 RpcInvokeContext (com.alipay.sofa.rpc.context.RpcInvokeContext)7