Java Code Examples for com.alipay.sofa.rpc.common.RpcConfigs#putValue()

The following examples show how to use com.alipay.sofa.rpc.common.RpcConfigs#putValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSofaRpcFilterTest.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example 2
Source File: AbstractSofaRpcFilterTest.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example 3
Source File: AbstractSofaRpcFilterTest.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 4
Source File: ApplicationEnvironmentPreparedListener.java    From sofa-rpc-boot-projects with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ApplicationEnvironmentPreparedEvent) {
        Environment env = ((ApplicationEnvironmentPreparedEvent) event).getEnvironment();
        String defaultTracer = env.getProperty(SofaBootRpcProperties.PREFIX + ".defaultTracer");
        if (defaultTracer != null) {
            RpcConfigs.putValue(RpcOptions.DEFAULT_TRACER, defaultTracer);
        }
    }
}
 
Example 5
Source File: Http2ClearTextHttpUpgradeTest.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void adBeforeClass() {
    /**
     * set config parameter to using http2 with 'upgrade h2c' startup frame
     */
    RpcConfigs.putValue(RpcOptions.TRANSPORT_CLIENT_H2C_USE_PRIOR_KNOWLEDGE, false);
    ActivelyDestroyTest.adBeforeClass();
}
 
Example 6
Source File: Http2ClearTextHttpUpgradeTest.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void adAfterClass() {
    ActivelyDestroyTest.adAfterClass();

    /**
     * restore config parameter to previous value
     */
    RpcConfigs.putValue(RpcOptions.TRANSPORT_CLIENT_H2C_USE_PRIOR_KNOWLEDGE, useH2cPriorKnowledge);
}
 
Example 7
Source File: BootstrapsTest.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Before
public void before() {
    oldP = RpcConfigs.getStringValue(RpcOptions.DEFAULT_PROVIDER_BOOTSTRAP);
    oldC = RpcConfigs.getStringValue(RpcOptions.DEFAULT_CONSUMER_BOOTSTRAP);
    RpcConfigs.putValue(RpcOptions.DEFAULT_PROVIDER_BOOTSTRAP, "test");
    RpcConfigs.putValue(RpcOptions.DEFAULT_CONSUMER_BOOTSTRAP, "test");
}
 
Example 8
Source File: FailoverClusterTest.java    From sofa-rpc with Apache License 2.0 4 votes vote down vote up
@Test(expected = SofaRouteException.class)
public void testRpcDirectInvokeFromContextNotAllowed() {

    boolean prev = RpcConfigs.getBooleanValue(RpcOptions.RPC_CREATE_CONN_WHEN_ABSENT);

    // disable create connection from context
    RpcConfigs.putValue(RpcOptions.RPC_CREATE_CONN_WHEN_ABSENT, false);

    try {
        ServerConfig serverConfig = new ServerConfig()
            .setProtocol("bolt")
            .setHost("0.0.0.0")
            .setPort(13900);

        ProviderConfig<HelloService> provider = new ProviderConfig();
        provider.setInterfaceId(HelloService.class.getName())
            .setRef(new HelloServiceImpl("x-demo-invoke"))
            .setApplication(new ApplicationConfig().setAppName("x-test-server"))
            .setProxy("javassist")
            .setSerialization("hessian2")
            .setServer(serverConfig)
            .setTimeout(3000);

        provider.export();

        ConsumerConfig<HelloService> consumer = new ConsumerConfig();
        consumer.setInterfaceId(HelloService.class.getName())
            .setApplication(new ApplicationConfig().setAppName("x-test-client"))
            .setProxy("javassist");

        HelloService proxy = consumer.refer();

        RpcInvokeContext.getContext().setTargetURL("127.0.0.1:13900");
        proxy.sayHello("x-demo-invoke", 1);

        provider.unExport();
        consumer.unRefer();
    } finally {
        RpcConfigs.putValue(RpcOptions.RPC_CREATE_CONN_WHEN_ABSENT, prev);
    }
}
 
Example 9
Source File: ModuleFactoryTest.java    From sofa-rpc with Apache License 2.0 4 votes vote down vote up
@Test
public void testAll() throws Exception {
    String old = RpcConfigs.getStringValue(RpcOptions.MODULE_LOAD_LIST);
    try {
        RpcConfigs.putValue(RpcOptions.MODULE_LOAD_LIST, "*,-test3");

        ModuleFactory.installModules();
        Assert.assertFalse(ModuleFactory.INSTALLED_MODULES.isEmpty());
        Assert.assertTrue(ModuleFactory.INSTALLED_MODULES.containsKey("test"));
        Assert.assertTrue(ModuleFactory.INSTALLED_MODULES.containsKey("test2"));
        Assert.assertFalse(ModuleFactory.INSTALLED_MODULES.containsKey("testNot"));
        Assert.assertEquals("testi", TestModules.test);
        Assert.assertEquals("test2i", TestModules.test2);
        Assert.assertNull(TestModules.testNot);

        TestModules.error = true;
        ModuleFactory.uninstallModule("test");
        Assert.assertTrue(ModuleFactory.INSTALLED_MODULES.containsKey("test"));
        TestModules.error = false;

        TestModules.error = false;
        ModuleFactory.uninstallModule("test");
        Assert.assertFalse(ModuleFactory.INSTALLED_MODULES.containsKey("test"));
        Assert.assertTrue(ModuleFactory.INSTALLED_MODULES.containsKey("test2"));
        Assert.assertEquals("testu", TestModules.test);
        Assert.assertEquals("test2i", TestModules.test2);
        Assert.assertNull(TestModules.testNot);

        TestModules.error = true;
        ModuleFactory.uninstallModules();
        Assert.assertTrue(ModuleFactory.INSTALLED_MODULES.containsKey("test2"));
        TestModules.error = false;

        ModuleFactory.uninstallModules();
        Assert.assertTrue(ModuleFactory.INSTALLED_MODULES.isEmpty());
        Assert.assertEquals("testu", TestModules.test);
        Assert.assertEquals("test2u", TestModules.test2);
        Assert.assertNull(TestModules.testNot);
    } finally {
        if (old != null) {
            RpcConfigs.putValue(RpcOptions.MODULE_LOAD_LIST, old);
        }
    }
}
 
Example 10
Source File: BootstrapsTest.java    From sofa-rpc with Apache License 2.0 4 votes vote down vote up
@After
public void after() {
    RpcConfigs.putValue(RpcOptions.DEFAULT_PROVIDER_BOOTSTRAP, oldP);
    RpcConfigs.putValue(RpcOptions.DEFAULT_CONSUMER_BOOTSTRAP, oldC);
}