Search in sources :

Example 61 with ProviderConfig

use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-boot by alipay.

the class DynamicConfigProcessorTest method test.

@Test
public void test() {
    processor.setDynamicConfig(CONFIG);
    ConsumerConfig consumerConfig = new ConsumerConfig();
    processor.processorConsumer(consumerConfig);
    Assert.assertEquals(CONFIG, consumerConfig.getParameter(DynamicConfigKeys.DYNAMIC_ALIAS));
    ProviderConfig providerConfig = new ProviderConfig();
    processor.processorProvider(providerConfig);
    Assert.assertEquals(CONFIG, providerConfig.getParameter(DynamicConfigKeys.DYNAMIC_ALIAS));
    consumerConfig = new ConsumerConfig();
    consumerConfig.setParameter(DynamicConfigKeys.DYNAMIC_ALIAS, ANOTHER);
    processor.processorConsumer(consumerConfig);
    Assert.assertEquals(ANOTHER, consumerConfig.getParameter(DynamicConfigKeys.DYNAMIC_ALIAS));
    providerConfig = new ProviderConfig();
    providerConfig.setParameter(DynamicConfigKeys.DYNAMIC_ALIAS, ANOTHER);
    processor.processorProvider(providerConfig);
    Assert.assertEquals(ANOTHER, providerConfig.getParameter(DynamicConfigKeys.DYNAMIC_ALIAS));
    processor.setDynamicConfig("");
    consumerConfig = new ConsumerConfig();
    processor.processorConsumer(consumerConfig);
    Assert.assertFalse(StringUtils.hasText(consumerConfig.getParameter(DynamicConfigKeys.DYNAMIC_ALIAS)));
    providerConfig = new ProviderConfig();
    processor.processorProvider(providerConfig);
    Assert.assertFalse(StringUtils.hasText(providerConfig.getParameter(DynamicConfigKeys.DYNAMIC_ALIAS)));
}
Also used : ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) Test(org.junit.Test)

Example 62 with ProviderConfig

use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-rpc by sofastack.

the class DefaultProviderBootstrapTest method includeListTest.

@Test
public void includeListTest() {
    ProviderConfig providerConfig = new ProviderConfig();
    DefaultProviderBootstrap defaultProviderBootstra = new DefaultProviderBootstrap(providerConfig);
    boolean result = defaultProviderBootstra.inList("hello1", "hello2", "hello1");
    Assert.assertTrue(result);
}
Also used : ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) Test(org.junit.Test)

Example 63 with ProviderConfig

use of com.alipay.sofa.rpc.config.ProviderConfig 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 64 with ProviderConfig

use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-rpc by sofastack.

the class DubooServerTest method testConsumerWithNoDubboServiceVersion.

@Test(expected = com.alibaba.dubbo.rpc.RpcException.class)
public // 同步调用,直连,dubbo 消费没有指定dubbo服务版本version
void testConsumerWithNoDubboServiceVersion() {
    // 只有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).setRegister(false).setProtocol("dubbo").setApplication(clientApplication);
    final DemoService demoService = consumerConfig.refer();
    String result = demoService.sayHello("xxx");
    Assert.assertTrue(result.equalsIgnoreCase("hello xxx"));
}
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) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) DemoServiceImpl(com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoServiceImpl) Test(org.junit.Test)

Example 65 with ProviderConfig

use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-rpc by sofastack.

the class FilterChainTest method buildProviderChain.

@Test
public void buildProviderChain() {
    ProviderConfig providerConfig = new ProviderConfig();
    providerConfig.setFilter(Arrays.asList("testChainFilter0", "-testChainFilter8"));
    providerConfig.setInterfaceId(Serializer.class.getName());
    ConsumerConfig consumerConfig = new ConsumerConfig();
    ArrayList<Filter> list = new ArrayList<Filter>();
    consumerConfig.setFilter(Arrays.asList("testChainFilter0", "-testChainFilter8"));
    list.add(new TestChainFilter1());
    list.add(new TestChainFilter2());
    list.add(new TestChainFilter3());
    list.add(new TestChainFilter4());
    list.add(new ExcludeFilter("-testChainFilter5"));
    consumerConfig.setFilterRef(list);
    consumerConfig.setInterfaceId(Serializer.class.getName());
    // mock provider chain (0,6,7)
    FilterChain providerChain = FilterChain.buildProviderChain(providerConfig, new TestProviderFilterInvoker(providerConfig));
    // mock consumer chain(0,7,2,4)
    FilterChain consumerChain = FilterChain.buildConsumerChain(consumerConfig, new TestConsumerFilterInvoker(consumerConfig, providerChain));
    Assert.assertNotNull(consumerChain.getChain());
    SofaRequest request = new SofaRequest();
    request.setMethodArgs(new String[] { "xxx" });
    request.setInvokeType("sync");
    String result = (String) consumerChain.invoke(request).getAppResponse();
    Assert.assertEquals("xxx_q0_q7_q2_q4_q0_q6_q7_s7_s6_s0_s4_s2_s7_s0", result);
    request = new SofaRequest();
    request.setMethodArgs(new String[] { "xxx" });
    request.setInvokeType("callback");
    SofaResponse response = consumerChain.invoke(request);
    consumerChain.onAsyncResponse(consumerConfig, request, response, null);
    result = (String) response.getAppResponse();
    Assert.assertEquals("xxx_q0_q7_q2_q4_q0_q6_q7_a4_a2_a7_a0", result);
}
Also used : SofaRequest(com.alipay.sofa.rpc.core.request.SofaRequest) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) ArrayList(java.util.ArrayList) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) SofaResponse(com.alipay.sofa.rpc.core.response.SofaResponse) Serializer(com.alipay.sofa.rpc.codec.Serializer) Test(org.junit.Test)

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