Search in sources :

Example 71 with ConsumerConfig

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

use of com.alipay.sofa.rpc.config.ConsumerConfig in project Sentinel by alibaba.

the class AbstractSofaRpcFilterTest method testNeedToLoadConsumer.

@Test
public void testNeedToLoadConsumer() {
    SentinelSofaRpcConsumerFilter consumerFilter = new SentinelSofaRpcConsumerFilter();
    ConsumerConfig consumerConfig = new ConsumerConfig();
    consumerConfig.setInterfaceId(Serializer.class.getName());
    consumerConfig.setId("BBB");
    FilterInvoker invoker = new FilterInvoker(null, null, consumerConfig);
    assertTrue(consumerFilter.needToLoad(invoker));
    consumerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false");
    assertFalse(consumerFilter.needToLoad(invoker));
    consumerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "");
    assertTrue(consumerFilter.needToLoad(invoker));
    RpcConfigs.putValue(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false");
    assertFalse(consumerFilter.needToLoad(invoker));
}
Also used : FilterInvoker(com.alipay.sofa.rpc.filter.FilterInvoker) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) Serializer(com.alipay.sofa.rpc.codec.Serializer) Test(org.junit.Test)

Example 73 with ConsumerConfig

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

the class BoltClientProxyInvokerTest method testParseSerializeType.

@Test
public void testParseSerializeType() throws Exception {
    ConsumerConfig consumerConfig = new ConsumerConfig().setProtocol("bolt");
    ConsumerBootstrap bootstrap = Bootstraps.from(consumerConfig);
    BoltClientProxyInvoker invoker = new BoltClientProxyInvoker(bootstrap);
    byte actual = invoker.parseSerializeType(RpcConstants.SERIALIZE_HESSIAN2);
    assertEquals(RemotingConstants.SERIALIZE_CODE_HESSIAN, actual);
}
Also used : ConsumerBootstrap(com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) Test(org.junit.Test)

Example 74 with ConsumerConfig

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

the class BoltClientProxyInvokerTest method testParseSerializeTypeException.

@Test(expected = SofaRpcRuntimeException.class)
public void testParseSerializeTypeException() {
    ConsumerConfig consumerConfig = new ConsumerConfig().setProtocol("bolt");
    ConsumerBootstrap bootstrap = Bootstraps.from(consumerConfig);
    BoltClientProxyInvoker invoker = new BoltClientProxyInvoker(bootstrap);
    invoker.parseSerializeType("unknown");
}
Also used : ConsumerBootstrap(com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) Test(org.junit.Test)

Example 75 with ConsumerConfig

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

the class DubooServerTest method testFuture.

@Test
public // future调用,从future中取值.
void testFuture() {
    // 只有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()).setServer(serverConfig).setBootstrap("dubbo").setRegister(false).setApplication(serverApplacation);
    providerConfig.export();
    ApplicationConfig clientApplication = new ApplicationConfig();
    clientApplication.setAppName("client");
    List<MethodConfig> methodConfigs = new ArrayList<MethodConfig>();
    MethodConfig methodConfig = new MethodConfig();
    methodConfig.setInvokeType(RpcConstants.INVOKER_TYPE_FUTURE);
    methodConfig.setName("sayHello");
    consumerConfig = new ConsumerConfig<DemoService>().setInterfaceId(DemoService.class.getName()).setDirectUrl("dubbo://127.0.0.1:20880").setTimeout(30000).setRegister(false).setProtocol("dubbo").setBootstrap("dubbo").setApplication(clientApplication).setInvokeType(RpcConstants.INVOKER_TYPE_FUTURE).setMethods(methodConfigs);
    final DemoService demoService = consumerConfig.refer();
    String result = demoService.sayHello("xxx");
    Assert.assertEquals(null, result);
    Future<Object> future = RpcContext.getContext().getFuture();
    String futureResult = null;
    try {
        futureResult = (String) future.get();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
    Assert.assertEquals("Hello xxx", futureResult);
}
Also used : ArrayList(java.util.ArrayList) DemoService(com.alipay.sofa.rpc.bootstrap.dubbo.demo.DemoService) MethodConfig(com.alipay.sofa.rpc.config.MethodConfig) ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) 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)

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