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());
}
}
}
}
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());
}
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);
}
}
}
}
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);
}
}
}
}
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());
}
Aggregations