Search in sources :

Example 6 with ReferenceComponent

use of com.alipay.sofa.runtime.service.component.ReferenceComponent in project sofa-boot by alipay.

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 7 with ReferenceComponent

use of com.alipay.sofa.runtime.service.component.ReferenceComponent in project sofa-boot by alipay.

the class SofaBindingTest method testReferenceBinding.

@Test
public void testReferenceBinding() {
    ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
    ReferenceComponent serializeTrueViaAnnotation = null;
    ReferenceComponent defaultSerializeFalseViaAnnotation = null;
    ReferenceComponent defaultElement = null;
    ReferenceComponent element = null;
    ReferenceComponent noneUniqueId = null;
    Collection<ComponentInfo> componentInfos = componentManager.getComponentInfosByType(ReferenceComponent.REFERENCE_COMPONENT_TYPE);
    for (ComponentInfo componentInfo : componentInfos) {
        String rawName = componentInfo.getName().getRawName();
        if (rawName.contains(ComponentNameUtil.getReferenceComponentName(SampleService.class, "serializeTrueViaAnnotation").getRawName())) {
            serializeTrueViaAnnotation = (ReferenceComponent) componentInfo;
        } else if (rawName.contains(ComponentNameUtil.getReferenceComponentName(SampleService.class, "defaultSerializeFalseViaAnnotation").getRawName())) {
            defaultSerializeFalseViaAnnotation = (ReferenceComponent) componentInfo;
        } else if (rawName.contains(ComponentNameUtil.getReferenceComponentName(SampleService.class, "default-element").getRawName())) {
            defaultElement = (ReferenceComponent) componentInfo;
        } else if (componentInfo.getName().getRawName().contains(ComponentNameUtil.getReferenceComponentName(SampleService.class, "element").getRawName())) {
            element = (ReferenceComponent) componentInfo;
        } else if (rawName.contains(":#") && rawName.contains(ComponentNameUtil.getReferenceComponentName(SampleService.class, "").getRawName())) {
            noneUniqueId = (ReferenceComponent) componentInfo;
        }
    }
    Assert.assertNotNull(serializeTrueViaAnnotation);
    Assert.assertNotNull(defaultSerializeFalseViaAnnotation);
    Assert.assertNotNull(defaultElement);
    Assert.assertNotNull(element);
    Assert.assertNotNull(noneUniqueId);
    JvmBinding jvmBinding;
    jvmBinding = (JvmBinding) serializeTrueViaAnnotation.getReference().getBinding(JvmBinding.JVM_BINDING_TYPE);
    Assert.assertTrue(jvmBinding.getJvmBindingParam().isSerialize());
    jvmBinding = (JvmBinding) defaultSerializeFalseViaAnnotation.getReference().getBinding(JvmBinding.JVM_BINDING_TYPE);
    Assert.assertFalse(jvmBinding.getJvmBindingParam().isSerialize());
    jvmBinding = (JvmBinding) defaultElement.getReference().getBinding(JvmBinding.JVM_BINDING_TYPE);
    Assert.assertFalse(jvmBinding.getJvmBindingParam().isSerialize());
    jvmBinding = (JvmBinding) element.getReference().getBinding(JvmBinding.JVM_BINDING_TYPE);
    Assert.assertTrue(jvmBinding.getJvmBindingParam().isSerialize());
    jvmBinding = (JvmBinding) noneUniqueId.getReference().getBinding(JvmBinding.JVM_BINDING_TYPE);
    Assert.assertFalse(jvmBinding.getJvmBindingParam().isSerialize());
}
Also used : DefaultSampleService(com.alipay.sofa.runtime.test.beans.service.DefaultSampleService) SampleService(com.alipay.sofa.runtime.test.beans.facade.SampleService) ReferenceComponent(com.alipay.sofa.runtime.service.component.ReferenceComponent) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with ReferenceComponent

use of com.alipay.sofa.runtime.service.component.ReferenceComponent in project sofa-boot by alipay.

the class XsdTimeoutTest method testReferenceTimeout.

@Test
public void testReferenceTimeout() {
    Collection<ComponentInfo> c = sofaRuntimeContext.getComponentManager().getComponentInfosByType(ReferenceComponent.REFERENCE_COMPONENT_TYPE);
    for (ComponentInfo componentInfo : c) {
        if (componentInfo instanceof ReferenceComponent) {
            ReferenceComponent referenceComponent = (ReferenceComponent) componentInfo;
            if (!referenceComponent.getReference().getInterfaceType().equals(WhateverInterface.class)) {
                continue;
            }
            Binding binding = referenceComponent.getReference().getBinding(RpcBindingType.BOLT_BINDING_TYPE);
            if (binding instanceof RpcBinding) {
                RpcBinding rpcBinding = (RpcBinding) binding;
                Assert.assertEquals((long) rpcBinding.getRpcBindingParam().getTimeout(), 10000);
            }
        }
    }
}
Also used : RpcBinding(com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) RpcBinding(com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding) ReferenceComponent(com.alipay.sofa.runtime.service.component.ReferenceComponent) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with ReferenceComponent

use of com.alipay.sofa.runtime.service.component.ReferenceComponent in project sofa-boot by sofastack.

the class XsdTimeoutTest method testReferenceTimeout.

@Test
public void testReferenceTimeout() {
    Collection<ComponentInfo> c = sofaRuntimeContext.getComponentManager().getComponentInfosByType(ReferenceComponent.REFERENCE_COMPONENT_TYPE);
    for (ComponentInfo componentInfo : c) {
        if (componentInfo instanceof ReferenceComponent) {
            ReferenceComponent referenceComponent = (ReferenceComponent) componentInfo;
            if (!referenceComponent.getReference().getInterfaceType().equals(WhateverInterface.class)) {
                continue;
            }
            Binding binding = referenceComponent.getReference().getBinding(RpcBindingType.BOLT_BINDING_TYPE);
            if (binding instanceof RpcBinding) {
                RpcBinding rpcBinding = (RpcBinding) binding;
                Assert.assertEquals((long) rpcBinding.getRpcBindingParam().getTimeout(), 10000);
            }
        }
    }
}
Also used : RpcBinding(com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding) Binding(com.alipay.sofa.runtime.spi.binding.Binding) RpcBinding(com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding) ReferenceComponent(com.alipay.sofa.runtime.service.component.ReferenceComponent) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with ReferenceComponent

use of com.alipay.sofa.runtime.service.component.ReferenceComponent in project sofa-boot by sofastack.

the class SofaBindingTest method testReferenceBinding.

@Test
public void testReferenceBinding() {
    ComponentManager componentManager = sofaRuntimeContext.getComponentManager();
    ReferenceComponent serializeTrueViaAnnotation = null;
    ReferenceComponent defaultSerializeFalseViaAnnotation = null;
    ReferenceComponent defaultElement = null;
    ReferenceComponent element = null;
    ReferenceComponent noneUniqueId = null;
    Collection<ComponentInfo> componentInfos = componentManager.getComponentInfosByType(ReferenceComponent.REFERENCE_COMPONENT_TYPE);
    for (ComponentInfo componentInfo : componentInfos) {
        String rawName = componentInfo.getName().getRawName();
        if (rawName.contains(ComponentNameUtil.getReferenceComponentName(SampleService.class, "serializeTrueViaAnnotation").getRawName())) {
            serializeTrueViaAnnotation = (ReferenceComponent) componentInfo;
        } else if (rawName.contains(ComponentNameUtil.getReferenceComponentName(SampleService.class, "defaultSerializeFalseViaAnnotation").getRawName())) {
            defaultSerializeFalseViaAnnotation = (ReferenceComponent) componentInfo;
        } else if (rawName.contains(ComponentNameUtil.getReferenceComponentName(SampleService.class, "default-element").getRawName())) {
            defaultElement = (ReferenceComponent) componentInfo;
        } else if (componentInfo.getName().getRawName().contains(ComponentNameUtil.getReferenceComponentName(SampleService.class, "element").getRawName())) {
            element = (ReferenceComponent) componentInfo;
        } else if (rawName.contains(":#") && rawName.contains(ComponentNameUtil.getReferenceComponentName(SampleService.class, "").getRawName())) {
            noneUniqueId = (ReferenceComponent) componentInfo;
        }
    }
    Assert.assertNotNull(serializeTrueViaAnnotation);
    Assert.assertNotNull(defaultSerializeFalseViaAnnotation);
    Assert.assertNotNull(defaultElement);
    Assert.assertNotNull(element);
    Assert.assertNotNull(noneUniqueId);
    JvmBinding jvmBinding;
    jvmBinding = (JvmBinding) serializeTrueViaAnnotation.getReference().getBinding(JvmBinding.JVM_BINDING_TYPE);
    Assert.assertTrue(jvmBinding.getJvmBindingParam().isSerialize());
    jvmBinding = (JvmBinding) defaultSerializeFalseViaAnnotation.getReference().getBinding(JvmBinding.JVM_BINDING_TYPE);
    Assert.assertFalse(jvmBinding.getJvmBindingParam().isSerialize());
    jvmBinding = (JvmBinding) defaultElement.getReference().getBinding(JvmBinding.JVM_BINDING_TYPE);
    Assert.assertFalse(jvmBinding.getJvmBindingParam().isSerialize());
    jvmBinding = (JvmBinding) element.getReference().getBinding(JvmBinding.JVM_BINDING_TYPE);
    Assert.assertTrue(jvmBinding.getJvmBindingParam().isSerialize());
    jvmBinding = (JvmBinding) noneUniqueId.getReference().getBinding(JvmBinding.JVM_BINDING_TYPE);
    Assert.assertFalse(jvmBinding.getJvmBindingParam().isSerialize());
}
Also used : DefaultSampleService(com.alipay.sofa.runtime.test.beans.service.DefaultSampleService) SampleService(com.alipay.sofa.runtime.test.beans.facade.SampleService) ReferenceComponent(com.alipay.sofa.runtime.service.component.ReferenceComponent) ComponentManager(com.alipay.sofa.runtime.spi.component.ComponentManager) ComponentInfo(com.alipay.sofa.runtime.spi.component.ComponentInfo) JvmBinding(com.alipay.sofa.runtime.service.binding.JvmBinding) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ReferenceComponent (com.alipay.sofa.runtime.service.component.ReferenceComponent)10 ComponentInfo (com.alipay.sofa.runtime.spi.component.ComponentInfo)10 JvmBinding (com.alipay.sofa.runtime.service.binding.JvmBinding)6 Binding (com.alipay.sofa.runtime.spi.binding.Binding)6 ComponentManager (com.alipay.sofa.runtime.spi.component.ComponentManager)6 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 RpcBinding (com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding)4 DefaultImplementation (com.alipay.sofa.runtime.spi.component.DefaultImplementation)4 ComponentName (com.alipay.sofa.runtime.api.component.ComponentName)2 ServiceComponent (com.alipay.sofa.runtime.service.component.ServiceComponent)2 SampleService (com.alipay.sofa.runtime.test.beans.facade.SampleService)2 DefaultSampleService (com.alipay.sofa.runtime.test.beans.service.DefaultSampleService)2 ServiceRuntimeException (com.alipay.sofa.runtime.api.ServiceRuntimeException)1