use of com.alipay.sofa.rpc.config.ProviderConfig in project Sentinel by alibaba.
the class AbstractSofaRpcFilterTest method testNeedToLoadProviderAndConsumer.
@Test
public void testNeedToLoadProviderAndConsumer() {
SentinelSofaRpcProviderFilter providerFilter = new SentinelSofaRpcProviderFilter();
ProviderConfig providerConfig = new ProviderConfig();
providerConfig.setInterfaceId(Serializer.class.getName());
providerConfig.setId("AAA");
FilterInvoker providerInvoker = new FilterInvoker(null, null, providerConfig);
assertTrue(providerFilter.needToLoad(providerInvoker));
SentinelSofaRpcConsumerFilter consumerFilter = new SentinelSofaRpcConsumerFilter();
ConsumerConfig consumerConfig = new ConsumerConfig();
consumerConfig.setInterfaceId(Serializer.class.getName());
consumerConfig.setId("BBB");
FilterInvoker consumerInvoker = new FilterInvoker(null, null, consumerConfig);
assertTrue(consumerFilter.needToLoad(consumerInvoker));
providerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false");
assertFalse(providerFilter.needToLoad(providerInvoker));
assertTrue(consumerFilter.needToLoad(consumerInvoker));
providerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "");
assertTrue(providerFilter.needToLoad(providerInvoker));
RpcConfigs.putValue(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false");
assertFalse(providerFilter.needToLoad(providerInvoker));
assertFalse(consumerFilter.needToLoad(consumerInvoker));
}
use of com.alipay.sofa.rpc.config.ProviderConfig in project Sentinel by alibaba.
the class AbstractSofaRpcFilterTest method testNeedToLoadProvider.
@Test
public void testNeedToLoadProvider() {
SentinelSofaRpcProviderFilter providerFilter = new SentinelSofaRpcProviderFilter();
ProviderConfig providerConfig = new ProviderConfig();
providerConfig.setInterfaceId(Serializer.class.getName());
providerConfig.setId("AAA");
FilterInvoker invoker = new FilterInvoker(null, null, providerConfig);
assertTrue(providerFilter.needToLoad(invoker));
providerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false");
assertFalse(providerFilter.needToLoad(invoker));
providerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "");
assertTrue(providerFilter.needToLoad(invoker));
RpcConfigs.putValue(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false");
assertFalse(providerFilter.needToLoad(invoker));
}
use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-rpc by sofastack.
the class FaultBaseTest method init.
@Before
public void init() {
// 只有1个线程 执行
serverConfig = new ServerConfig().setStopTimeout(60000).setPort(12299).setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT).setQueues(100).setCoreThreads(10).setMaxThreads(20);
ApplicationConfig providerAconfig = new ApplicationConfig();
providerAconfig.setAppName("testApp");
// 发布一个服务,每个请求要执行1秒
providerConfig = new ProviderConfig<FaultHelloService>().setInterfaceId(FaultHelloService.class.getName()).setRef(new HelloServiceTimeOutImpl()).setServer(serverConfig).setRegister(false).setApplication(providerAconfig);
// just for test
consumerConfigNotUse = new ConsumerConfig<FaultHelloService>().setInterfaceId(FaultHelloService.class.getName()).setTimeout(500).setDirectUrl("127.0.0.1:12299").setRegister(false).setUniqueId("xxx").setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT);
ApplicationConfig applicationConfig = new ApplicationConfig();
applicationConfig.setAppName(APP_NAME1);
consumerConfig = new ConsumerConfig<FaultHelloService>().setInterfaceId(FaultHelloService.class.getName()).setTimeout(500).setDirectUrl("127.0.0.1:12299").setRegister(false).setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT).setApplication(applicationConfig);
consumerConfig2 = new ConsumerConfig<FaultHelloService2>().setInterfaceId(FaultHelloService2.class.getName()).setTimeout(500).setDirectUrl("127.0.0.1:12299").setRegister(false).setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT).setApplication(applicationConfig);
consumerConfigAnotherApp = new ConsumerConfig<FaultHelloService>().setInterfaceId(FaultHelloService.class.getName()).setDirectUrl("127.0.0.1:12299").setTimeout(500).setRegister(true).setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT).setApplication(new ApplicationConfig().setAppName(APP_NAME2));
FaultToleranceModule module = (FaultToleranceModule) ExtensionLoaderFactory.getExtensionLoader(Module.class).getExtension("fault-tolerance");
module.getRegulator().init();
}
use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-rpc by sofastack.
the class ProviderPubTest method testPubLookout.
@Test
public void testPubLookout() {
Registry registry = new DefaultRegistry();
if (Lookout.registry() == NoopRegistry.INSTANCE) {
Lookout.setRegistry(registry);
}
LookoutModule lookoutModule = new LookoutModule();
Assert.assertEquals(true, lookoutModule.needLoad());
lookoutModule.install();
ProviderConfig providerConfig = new ProviderConfig();
providerConfig.setInterfaceId("a");
EventBus.post(new ProviderPubEvent(providerConfig));
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
RpcLookoutId rpcLookoutId = new RpcLookoutId();
InfoWrapper result = Lookout.registry().get(rpcLookoutId.fetchProviderPubId());
final Object value = result.value();
Assert.assertTrue(value instanceof ProviderConfig);
providerConfig = (ProviderConfig) value;
Assert.assertEquals("a", providerConfig.getInterfaceId());
}
use of com.alipay.sofa.rpc.config.ProviderConfig in project sofa-rpc by sofastack.
the class TripleServerTest method testExposeTwice.
@Test
public void testExposeTwice() {
ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("triple-server");
int port = 50052;
ServerConfig serverConfig = new ServerConfig().setProtocol(RpcConstants.PROTOCOL_TYPE_TRIPLE).setPort(port);
ProviderConfig<SofaGreeterTriple.IGreeter> providerConfig = new ProviderConfig<SofaGreeterTriple.IGreeter>().setApplication(applicationConfig).setUniqueId("abc").setBootstrap(RpcConstants.PROTOCOL_TYPE_TRIPLE).setInterfaceId(SofaGreeterTriple.IGreeter.class.getName()).setRef(new GreeterImpl()).setServer(serverConfig);
providerConfig.export();
applicationConfig = new ApplicationConfig().setAppName("triple-server");
serverConfig = new ServerConfig().setProtocol(RpcConstants.PROTOCOL_TYPE_TRIPLE).setPort(port);
providerConfig = new ProviderConfig<SofaGreeterTriple.IGreeter>().setApplication(applicationConfig).setUniqueId("abcd").setBootstrap(RpcConstants.PROTOCOL_TYPE_TRIPLE).setInterfaceId(SofaGreeterTriple.IGreeter.class.getName()).setRef(new GreeterImpl()).setServer(serverConfig);
providerConfig.export();
}
Aggregations