Search in sources :

Example 6 with ConsumerBootstrap

use of com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap 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 7 with ConsumerBootstrap

use of com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap in project sofa-rpc by sofastack.

the class RouterChainTest method buildProviderChain.

@Test
public void buildProviderChain() {
    ConsumerConfig config = new ConsumerConfig();
    config.setBootstrap("test");
    ArrayList<Router> list = new ArrayList<Router>();
    config.setRouter(Arrays.asList("testChainRouter0", "-testChainRouter8", "notExistChainRouter"));
    list.add(new TestChainRouter1());
    list.add(new TestChainRouter2());
    list.add(new TestChainRouter3());
    list.add(new TestChainRouter4());
    list.add(new ExcludeRouter("-testChainRouter5"));
    config.setRouterRef(list);
    ConsumerBootstrap consumerBootstrap = Bootstraps.from(config);
    RouterChain chain = RouterChain.buildConsumerChain(consumerBootstrap);
    // build test data
    SofaRequest request = new SofaRequest();
    request.setMethodArgs(new String[] { "xxx" });
    request.setInvokeType("sync");
    List<ProviderInfo> providerInfos = new ArrayList<ProviderInfo>();
    ProviderInfo providerInfo = new ProviderInfo();
    providerInfo.setHost("127.0.0.1");
    providerInfo.setPort(12200);
    providerInfos.add(providerInfo);
    chain.route(request, providerInfos);
    Assert.assertEquals("r0>r7>r2>r4", RpcInternalContext.getContext().getAttachment(RpcConstants.INTERNAL_KEY_ROUTER_RECORD));
}
Also used : SofaRequest(com.alipay.sofa.rpc.core.request.SofaRequest) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TestChainRouter3(com.alipay.sofa.rpc.client.router.TestChainRouter3) TestChainRouter2(com.alipay.sofa.rpc.client.router.TestChainRouter2) ConsumerBootstrap(com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap) TestChainRouter1(com.alipay.sofa.rpc.client.router.TestChainRouter1) TestChainRouter4(com.alipay.sofa.rpc.client.router.TestChainRouter4) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) Test(org.junit.Test)

Example 8 with ConsumerBootstrap

use of com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap in project sofa-rpc by sofastack.

the class AddressHolderFactoryTest method getAddressHolder.

@Test
public void getAddressHolder() throws Exception {
    ConsumerConfig consumerConfig = new ConsumerConfig().setBootstrap("test").setAddressHolder("test");
    ConsumerBootstrap bootstrap = Bootstraps.from(consumerConfig);
    Assert.assertEquals(AddressHolderFactory.getAddressHolder(bootstrap).getClass(), TestAddressHolder.class);
    boolean error = false;
    try {
        consumerConfig.setAddressHolder("xasdsa");
        AddressHolderFactory.getAddressHolder(bootstrap);
    } catch (Exception e) {
        error = true;
    }
    Assert.assertTrue(error);
}
Also used : ConsumerBootstrap(com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) Test(org.junit.Test)

Example 9 with ConsumerBootstrap

use of com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap in project sofa-rpc by sofastack.

the class RpcRuntimeContext method destroy.

/**
 * 销毁方法
 *
 * @param active 是否主动销毁
 */
private static void destroy(boolean active) {
    // TODO 检查是否有其它需要释放的资源
    RpcRunningState.setShuttingDown(true);
    for (Destroyable.DestroyHook destroyHook : DESTROY_HOOKS) {
        destroyHook.preDestroy();
    }
    List<ProviderConfig> providerConfigs = new ArrayList<ProviderConfig>();
    for (ProviderBootstrap bootstrap : EXPORTED_PROVIDER_CONFIGS) {
        providerConfigs.add(bootstrap.getProviderConfig());
    }
    // 先反注册服务端
    List<Registry> registries = RegistryFactory.getRegistries();
    if (CommonUtils.isNotEmpty(registries) && CommonUtils.isNotEmpty(providerConfigs)) {
        for (Registry registry : registries) {
            registry.batchUnRegister(providerConfigs);
        }
    }
    // 关闭启动的端口
    ServerFactory.destroyAll();
    // 关闭发布的服务
    for (ProviderBootstrap bootstrap : EXPORTED_PROVIDER_CONFIGS) {
        bootstrap.unExport();
    }
    // 关闭调用的服务
    for (ConsumerBootstrap bootstrap : REFERRED_CONSUMER_CONFIGS) {
        ConsumerConfig config = bootstrap.getConsumerConfig();
        if (!CommonUtils.isFalse(config.getParameter(RpcConstants.HIDDEN_KEY_DESTROY))) {
            // 除非不让主动unrefer
            bootstrap.unRefer();
        }
    }
    // 关闭注册中心
    RegistryFactory.destroyAll();
    // 关闭客户端的一些公共资源
    ClientTransportFactory.closeAll();
    // 卸载模块
    if (!RpcRunningState.isUnitTestMode()) {
        ModuleFactory.uninstallModules();
    }
    // 卸载钩子
    for (Destroyable.DestroyHook destroyHook : DESTROY_HOOKS) {
        destroyHook.postDestroy();
    }
    // 清理缓存
    RpcCacheManager.clearAll();
    RpcRunningState.setShuttingDown(false);
    if (LOGGER.isWarnEnabled()) {
        LOGGER.warn("SOFA RPC Framework has been release all resources {}...", active ? "actively " : "");
    }
}
Also used : ConsumerBootstrap(com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap) Destroyable(com.alipay.sofa.rpc.base.Destroyable) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) Registry(com.alipay.sofa.rpc.registry.Registry) ProviderBootstrap(com.alipay.sofa.rpc.bootstrap.ProviderBootstrap)

Aggregations

ConsumerBootstrap (com.alipay.sofa.rpc.bootstrap.ConsumerBootstrap)9 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)4 Destroyable (com.alipay.sofa.rpc.base.Destroyable)2 SofaRequest (com.alipay.sofa.rpc.core.request.SofaRequest)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ProviderBootstrap (com.alipay.sofa.rpc.bootstrap.ProviderBootstrap)1 AddressHolder (com.alipay.sofa.rpc.client.AddressHolder)1 ProviderGroup (com.alipay.sofa.rpc.client.ProviderGroup)1 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)1 TestChainRouter1 (com.alipay.sofa.rpc.client.router.TestChainRouter1)1 TestChainRouter2 (com.alipay.sofa.rpc.client.router.TestChainRouter2)1 TestChainRouter3 (com.alipay.sofa.rpc.client.router.TestChainRouter3)1 TestChainRouter4 (com.alipay.sofa.rpc.client.router.TestChainRouter4)1 ApplicationConfig (com.alipay.sofa.rpc.config.ApplicationConfig)1 MethodConfig (com.alipay.sofa.rpc.config.MethodConfig)1 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)1 RegistryConfig (com.alipay.sofa.rpc.config.RegistryConfig)1 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)1