use of com.alipay.sofa.rpc.config.ConsumerConfig in project sofa-rpc by sofastack.
the class RouterChainTest method buildProviderChain.
@Test
public void buildProviderChain() {
ConsumerConfig config = new ConsumerConfig();
config.setBootstrap("test");
ArrayList<Router> list = new ArrayList<Router>();
config.setRouter(Arrays.asList("testChainRouter0", "-testChainRouter8", "notExistChainRouter"));
list.add(new TestChainRouter1());
list.add(new TestChainRouter2());
list.add(new TestChainRouter3());
list.add(new TestChainRouter4());
list.add(new ExcludeRouter("-testChainRouter5"));
config.setRouterRef(list);
ConsumerBootstrap consumerBootstrap = Bootstraps.from(config);
RouterChain chain = RouterChain.buildConsumerChain(consumerBootstrap);
// build test data
SofaRequest request = new SofaRequest();
request.setMethodArgs(new String[] { "xxx" });
request.setInvokeType("sync");
List<ProviderInfo> providerInfos = new ArrayList<ProviderInfo>();
ProviderInfo providerInfo = new ProviderInfo();
providerInfo.setHost("127.0.0.1");
providerInfo.setPort(12200);
providerInfos.add(providerInfo);
chain.route(request, providerInfos);
Assert.assertEquals("r0>r7>r2>r4", RpcInternalContext.getContext().getAttachment(RpcConstants.INTERNAL_KEY_ROUTER_RECORD));
}
use of com.alipay.sofa.rpc.config.ConsumerConfig in project sofa-rpc by sofastack.
the class AddressHolderFactoryTest method getAddressHolder.
@Test
public void getAddressHolder() throws Exception {
ConsumerConfig consumerConfig = new ConsumerConfig().setBootstrap("test").setAddressHolder("test");
ConsumerBootstrap bootstrap = Bootstraps.from(consumerConfig);
Assert.assertEquals(AddressHolderFactory.getAddressHolder(bootstrap).getClass(), TestAddressHolder.class);
boolean error = false;
try {
consumerConfig.setAddressHolder("xasdsa");
AddressHolderFactory.getAddressHolder(bootstrap);
} catch (Exception e) {
error = true;
}
Assert.assertTrue(error);
}
use of com.alipay.sofa.rpc.config.ConsumerConfig in project sofa-rpc by sofastack.
the class DubooServerTest method testSync.
@Test
public // 同步调用,直连
void testSync() {
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).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"));
} catch (Exception e) {
e.printStackTrace();
Assert.assertTrue(false);
}
}
use of com.alipay.sofa.rpc.config.ConsumerConfig 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.ConsumerConfig in project sofa-rpc by sofastack.
the class ClientTransportConfigTest method testAll.
@Test
public void testAll() {
ClientTransportConfig config = new ClientTransportConfig();
config.setProviderInfo(ProviderHelper.toProviderInfo("127.0.0.1"));
config.setContainer("xxx");
config.setChannelListeners(Collections.<ChannelListener>singletonList(new ChannelListener() {
@Override
public void onConnected(AbstractChannel channel) {
}
@Override
public void onDisconnected(AbstractChannel channel) {
}
}));
config.setConnectionNum(22);
config.setConnectTimeout(3333);
config.setConsumerConfig(new ConsumerConfig());
config.setDisconnectTimeout(4444);
config.setInvokeTimeout(5555);
config.setPayload(666666);
config.setUseEpoll(true);
Assert.assertNotNull(config.getConsumerConfig());
Assert.assertNotNull(config.getProviderInfo());
Assert.assertNotNull(config.getChannelListeners());
Assert.assertEquals("xxx", config.getContainer());
Assert.assertEquals(22, config.getConnectionNum());
Assert.assertEquals(3333, config.getConnectTimeout());
Assert.assertEquals(4444, config.getDisconnectTimeout());
Assert.assertEquals(5555, config.getInvokeTimeout());
Assert.assertEquals(666666, config.getPayload());
Assert.assertTrue(config.isUseEpoll());
}
Aggregations