use of com.alipay.sofa.runtime.service.binding.JvmBindingParam in project sofa-boot by sofastack.
the class ClientFactoryTest method testBindingInstanceIsNotAssignableFromInterfaceType.
@Test
public void testBindingInstanceIsNotAssignableFromInterfaceType() throws IOException {
String logRootPath = StringUtils.hasText(System.getProperty("logging.path")) ? System.getProperty("logging.path") : "./logs";
File sofaLog = new File(logRootPath + File.separator + "sofa-runtime" + File.separator + "sofa-default.log");
FileUtils.write(sofaLog, "", System.getProperty("file.encoding"));
SofaRuntimeProperties.setServiceInterfaceTypeCheck(true);
JvmBindingParam jvmBindingParam = new JvmBindingParam();
jvmBindingParam.setSerialize(true);
ServiceParam serviceParam = new ServiceParam();
serviceParam.setInstance(new Object());
serviceParam.setInterfaceType(SampleService.class);
serviceParam.addBindingParam(jvmBindingParam);
serviceClient.service(serviceParam);
String content = FileUtils.readFileToString(sofaLog, System.getProperty("file.encoding"));
Assert.assertTrue(content.contains("SOFA-BOOT-01-00104: Bean " + "[com.alipay.sofa.runtime.test.beans.facade.SampleService] " + "type is [class java.lang.Object] not isAssignableFrom " + "[interface com.alipay.sofa.runtime.test.beans.facade.SampleService] , please check it"));
}
use of com.alipay.sofa.runtime.service.binding.JvmBindingParam in project sofa-boot by sofastack.
the class ClientFactoryTest method testWithBindingParam.
/**
* test WithBindingParam in ReferenceClientImpl and ServiceClientImpl
*/
@Test
public void testWithBindingParam() {
JvmBindingParam jvmBindingParam = new JvmBindingParam();
jvmBindingParam.setSerialize(true);
ServiceParam serviceParam = new ServiceParam();
serviceParam.setInstance(new DefaultSampleService("WithBindingParam"));
serviceParam.setInterfaceType(SampleService.class);
serviceParam.setUniqueId("withBindingParam");
serviceParam.addBindingParam(jvmBindingParam);
serviceClient.service(serviceParam);
try {
Thread.sleep(2000);
} catch (Exception e) {
// ignore
}
ReferenceParam<SampleService> referenceParam = new ReferenceParam<>();
referenceParam.setInterfaceType(SampleService.class);
referenceParam.setUniqueId("withBindingParam");
referenceParam.setBindingParam(jvmBindingParam);
SampleService service = referenceClient.reference(referenceParam);
Assert.assertNotNull(service);
Assert.assertEquals("WithBindingParam", service.service());
}
use of com.alipay.sofa.runtime.service.binding.JvmBindingParam in project sofa-boot by sofastack.
the class ReferenceFactoryBean method doAfterPropertiesSet.
@Override
protected void doAfterPropertiesSet() throws Exception {
Reference reference = buildReference();
Assert.isTrue(bindings.size() <= 1, "Found more than one binding in <sofa:reference/>, <sofa:reference/> can only have one binding.");
// default add jvm binding and reference jvm binding should set serialize as false
if (bindings.size() == 0) {
// default reference prefer to ignore serialize
JvmBindingParam jvmBindingParam = new JvmBindingParam();
jvmBindingParam.setSerialize(false);
bindings.add(new JvmBinding().setJvmBindingParam(jvmBindingParam));
}
reference.addBinding(bindings.get(0));
proxy = ReferenceRegisterHelper.registerReference(reference, bindingAdapterFactory, sofaRuntimeContext, applicationContext);
}
use of com.alipay.sofa.runtime.service.binding.JvmBindingParam in project sofa-boot by alipay.
the class ReferenceFactoryBean method doAfterPropertiesSet.
@Override
protected void doAfterPropertiesSet() throws Exception {
Reference reference = buildReference();
Assert.isTrue(bindings.size() <= 1, "Found more than one binding in <sofa:reference/>, <sofa:reference/> can only have one binding.");
// default add jvm binding and reference jvm binding should set serialize as false
if (bindings.size() == 0) {
// default reference prefer to ignore serialize
JvmBindingParam jvmBindingParam = new JvmBindingParam();
jvmBindingParam.setSerialize(false);
bindings.add(new JvmBinding().setJvmBindingParam(jvmBindingParam));
}
reference.addBinding(bindings.get(0));
proxy = ReferenceRegisterHelper.registerReference(reference, bindingAdapterFactory, sofaRuntimeContext, applicationContext);
}
use of com.alipay.sofa.runtime.service.binding.JvmBindingParam in project sofa-boot by alipay.
the class ClientFactoryTest method testWithBindingParam.
/**
* test WithBindingParam in ReferenceClientImpl and ServiceClientImpl
*/
@Test
public void testWithBindingParam() {
JvmBindingParam jvmBindingParam = new JvmBindingParam();
jvmBindingParam.setSerialize(true);
ServiceParam serviceParam = new ServiceParam();
serviceParam.setInstance(new DefaultSampleService("WithBindingParam"));
serviceParam.setInterfaceType(SampleService.class);
serviceParam.setUniqueId("withBindingParam");
serviceParam.addBindingParam(jvmBindingParam);
serviceClient.service(serviceParam);
try {
Thread.sleep(2000);
} catch (Exception e) {
// ignore
}
ReferenceParam<SampleService> referenceParam = new ReferenceParam<>();
referenceParam.setInterfaceType(SampleService.class);
referenceParam.setUniqueId("withBindingParam");
referenceParam.setBindingParam(jvmBindingParam);
SampleService service = referenceClient.reference(referenceParam);
Assert.assertNotNull(service);
Assert.assertEquals("WithBindingParam", service.service());
}
Aggregations