Search in sources :

Example 76 with ConsumerConfig

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));
}
Also used : SofaRequest(com.alipay.sofa.rpc.core.request.SofaRequest) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TestChainRouter3(com.alipay.sofa.rpc.client.router.TestChainRouter3) TestChainRouter2(com.alipay.sofa.rpc.client.router.TestChainRouter2) ConsumerBootstrap(com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap) TestChainRouter1(com.alipay.sofa.rpc.client.router.TestChainRouter1) TestChainRouter4(com.alipay.sofa.rpc.client.router.TestChainRouter4) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) Test(org.junit.Test)

Example 77 with ConsumerConfig

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);
}
Also used : ConsumerBootstrap(com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) Test(org.junit.Test)

Example 78 with ConsumerConfig

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);
    }
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) DemoService(com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoService) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) ExecutionException(java.util.concurrent.ExecutionException) DemoServiceImpl(com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoServiceImpl) Test(org.junit.Test)

Example 79 with ConsumerConfig

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"));
}
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 80 with ConsumerConfig

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());
}
Also used : ChannelListener(com.alipay.sofa.rpc.listener.ChannelListener) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) Test(org.junit.Test)

Aggregations

ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)139 Test (org.junit.Test)86 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)68 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)61 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)44 ActivelyDestroyTest (com.alipay.sofa.rpc.test.ActivelyDestroyTest)40 HelloService (com.alipay.sofa.rpc.test.HelloService)38 CountDownLatch (java.util.concurrent.CountDownLatch)27 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)21 HelloServiceImpl (com.alipay.sofa.rpc.test.HelloServiceImpl)21 ArrayList (java.util.ArrayList)19 ProviderGroup (com.alipay.sofa.rpc.client.ProviderGroup)18 SofaResponseCallback (com.alipay.sofa.rpc.core.invoke.SofaResponseCallback)14 RegistryConfig (com.alipay.sofa.rpc.config.RegistryConfig)12 RequestBase (com.alipay.sofa.rpc.core.request.RequestBase)12 MethodConfig (com.alipay.sofa.rpc.config.MethodConfig)10 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 ConsumerBootstrap (com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap)8 SofaTimeOutException (com.alipay.sofa.rpc.core.exception.SofaTimeOutException)8