Search in sources :

Example 1 with RpcBinding

use of com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding in project sofa-boot by sofastack.

the class RpcBindingConverter method convert.

/**
 * convert {@link RpcBindingParam} to concrete {@link RpcBinding}
 *
 * @param bindingParam            binding parameter
 * @param bindingConverterContext binding converter context
 * @return RpcBinding Object
 */
@Override
public RpcBinding convert(RpcBindingParam bindingParam, BindingConverterContext bindingConverterContext) {
    RpcBinding binding = createRpcBinding(bindingParam, bindingConverterContext.getApplicationContext(), bindingConverterContext.isInBinding());
    setCallback(bindingParam, bindingConverterContext);
    binding.setAppName(bindingConverterContext.getAppName());
    binding.setBeanId(bindingConverterContext.getBeanId());
    return binding;
}
Also used : RpcBinding(com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding)

Example 2 with RpcBinding

use of com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding in project sofa-boot by sofastack.

the class XsdTimeoutTest method testBindingMethod.

/**
 * @see RpcBindingConverter#parseMethod
 */
@Test
public void testBindingMethod() {
    // service
    ServiceComponent component = (ServiceComponent) sofaRuntimeContext.getComponentManager().getComponentInfo(new ComponentName(ServiceComponent.SERVICE_COMPONENT_TYPE, MethodElementInterface.class.getName()));
    RpcBinding binding = (RpcBinding) component.getService().getBinding(RpcBindingType.BOLT_BINDING_TYPE);
    Assert.assertEquals(1, binding.getRpcBindingParam().getMethodInfos().size());
    Assert.assertEquals("service", binding.getRpcBindingParam().getMethodInfos().get(0).getName());
    Assert.assertEquals(10000, binding.getRpcBindingParam().getMethodInfos().get(0).getTimeout().intValue());
    // reference
    Collection<ComponentInfo> componentInfos = sofaRuntimeContext.getComponentManager().getComponentInfosByType(ReferenceComponent.REFERENCE_COMPONENT_TYPE);
    for (ComponentInfo componentInfo : componentInfos) {
        if (componentInfo instanceof ReferenceComponent) {
            ReferenceComponent referenceComponent = (ReferenceComponent) componentInfo;
            if (referenceComponent.getReference().getInterfaceType().equals(MethodElementInterface.class)) {
                RpcBinding refBinding = (RpcBinding) referenceComponent.getReference().getBinding(RpcBindingType.BOLT_BINDING_TYPE);
                Assert.assertEquals(1, refBinding.getRpcBindingParam().getMethodInfos().size());
                Assert.assertEquals("service", refBinding.getRpcBindingParam().getMethodInfos().get(0).getName());
            }
        }
    }
}
Also used : RpcBinding(com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding) ServiceComponent(com.alipay.sofa.runtime.service.component.ServiceComponent) ReferenceComponent(com.alipay.sofa.runtime.service.component.ReferenceComponent) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with RpcBinding

use of com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding in project sofa-boot by sofastack.

the class XsdTimeoutTest method testServiceTimeout.

@Test
public void testServiceTimeout() {
    ServiceComponent component = (ServiceComponent) sofaRuntimeContext.getComponentManager().getComponentInfo(new ComponentName(ServiceComponent.SERVICE_COMPONENT_TYPE, WhateverInterface.class.getName()));
    RpcBinding binding = (RpcBinding) component.getService().getBinding(RpcBindingType.BOLT_BINDING_TYPE);
    Assert.assertEquals((long) binding.getRpcBindingParam().getTimeout(), 10000);
}
Also used : RpcBinding(com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding) ServiceComponent(com.alipay.sofa.runtime.service.component.ServiceComponent) ComponentName(com.alipay.sofa.runtime.api.component.ComponentName) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with RpcBinding

use of com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding in project sofa-boot by sofastack.

the class MockBeanConfigTest method testEmptyMockBean.

@Test
public void testEmptyMockBean() {
    RpcBindingParam rpcBindingParam = new BoltBindingParam();
    RpcBinding rpcBinding = new BoltBinding(rpcBindingParam, null, true);
    try {
        consumerConfigHelper.getMockRef(rpcBinding, null);
        Assert.fail();
    } catch (IllegalArgumentException e) {
    // success;
    }
}
Also used : RpcBinding(com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding) BoltBinding(com.alipay.sofa.rpc.boot.runtime.binding.BoltBinding) RpcBindingParam(com.alipay.sofa.rpc.boot.runtime.param.RpcBindingParam) BoltBindingParam(com.alipay.sofa.rpc.boot.runtime.param.BoltBindingParam) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with RpcBinding

use of com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding in project sofa-boot by alipay.

the class RpcBindingConverter method convert.

/**
 * convert {@link RpcBindingParam} to concrete {@link RpcBinding}
 *
 * @param bindingParam            binding parameter
 * @param bindingConverterContext binding converter context
 * @return RpcBinding Object
 */
@Override
public RpcBinding convert(RpcBindingParam bindingParam, BindingConverterContext bindingConverterContext) {
    RpcBinding binding = createRpcBinding(bindingParam, bindingConverterContext.getApplicationContext(), bindingConverterContext.isInBinding());
    setCallback(bindingParam, bindingConverterContext);
    binding.setAppName(bindingConverterContext.getAppName());
    binding.setBeanId(bindingConverterContext.getBeanId());
    return binding;
}
Also used : RpcBinding(com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding)

Aggregations

RpcBinding (com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding)10 Test (org.junit.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 ComponentName (com.alipay.sofa.runtime.api.component.ComponentName)4 ReferenceComponent (com.alipay.sofa.runtime.service.component.ReferenceComponent)4 ServiceComponent (com.alipay.sofa.runtime.service.component.ServiceComponent)4 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)4 BoltBinding (com.alipay.sofa.rpc.boot.runtime.binding.BoltBinding)2 BoltBindingParam (com.alipay.sofa.rpc.boot.runtime.param.BoltBindingParam)2 RpcBindingParam (com.alipay.sofa.rpc.boot.runtime.param.RpcBindingParam)2 Binding (com.alipay.sofa.runtime.spi.binding.Binding)2