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)));
}
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);
}
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);
}
}
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"));
}
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);
}
Aggregations