Search in sources :

Example 1 with ProviderConfig

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));
}
Also used : FilterInvoker(com.alipay.sofa.rpc.filter.FilterInvoker) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) Serializer(com.alipay.sofa.rpc.codec.Serializer) Test(org.junit.Test)

Example 2 with ProviderConfig

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));
}
Also used : FilterInvoker(com.alipay.sofa.rpc.filter.FilterInvoker) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) Serializer(com.alipay.sofa.rpc.codec.Serializer) Test(org.junit.Test)

Example 3 with ProviderConfig

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();
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) FaultHelloService2(com.alipay.sofa.rpc.client.aft.bean.FaultHelloService2) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) FaultToleranceModule(com.alipay.sofa.rpc.module.FaultToleranceModule) FaultHelloService(com.alipay.sofa.rpc.client.aft.bean.FaultHelloService) HelloServiceTimeOutImpl(com.alipay.sofa.rpc.client.aft.bean.HelloServiceTimeOutImpl) Before(org.junit.Before)

Example 4 with ProviderConfig

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());
}
Also used : ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) DefaultRegistry(com.alipay.lookout.core.DefaultRegistry) RpcLookoutId(com.alipay.sofa.rpc.metrics.lookout.RpcLookoutId) NoopRegistry(com.alipay.lookout.api.NoopRegistry) Registry(com.alipay.lookout.api.Registry) DefaultRegistry(com.alipay.lookout.core.DefaultRegistry) ProviderPubEvent(com.alipay.sofa.rpc.event.ProviderPubEvent) InfoWrapper(com.alipay.lookout.core.InfoWrapper) Test(org.junit.Test)

Example 5 with ProviderConfig

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();
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) SofaGreeterTriple(io.grpc.examples.helloworld.SofaGreeterTriple) ApplicationConfig(com.alipay.sofa.rpc.config.ApplicationConfig) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) Test(org.junit.Test)

Aggregations

ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)121 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)88 Test (org.junit.Test)73 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)52 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)47 HelloService (com.alipay.sofa.rpc.test.HelloService)33 HelloServiceImpl (com.alipay.sofa.rpc.test.HelloServiceImpl)33 ActivelyDestroyTest (com.alipay.sofa.rpc.test.ActivelyDestroyTest)28 RegistryConfig (com.alipay.sofa.rpc.config.RegistryConfig)21 CountDownLatch (java.util.concurrent.CountDownLatch)19 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)17 ProviderGroup (com.alipay.sofa.rpc.client.ProviderGroup)10 Filter (com.alipay.sofa.rpc.filter.Filter)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 EchoService (com.alipay.sofa.rpc.test.EchoService)9 ArrayList (java.util.ArrayList)9 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)8 EchoServiceImpl (com.alipay.sofa.rpc.test.EchoServiceImpl)8 MethodConfig (com.alipay.sofa.rpc.config.MethodConfig)7 RpcInvokeContext (com.alipay.sofa.rpc.context.RpcInvokeContext)7