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