use of com.alipay.sofa.runtime.test.beans.facade.SampleService 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.test.beans.facade.SampleService in project sofa-boot by alipay.
the class SofaServiceAndReferenceTest method testSofaReferenceOnStaticField.
@Test
public void testSofaReferenceOnStaticField() throws IOException, NoSuchFieldException {
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"));
Map<String, Object> properties = new HashMap<>();
properties.put("spring.application.name", "SofaServiceAndReferenceTest");
properties.put("logging.path", logRootPath);
SpringApplication springApplication = new SpringApplication(TestSofaReferenceOnMethodConfiguration.class, RuntimeConfiguration.class);
springApplication.setWebApplicationType(WebApplicationType.NONE);
springApplication.setDefaultProperties(properties);
springApplication.run();
SampleService staticSampleService = SofaServiceAndReferenceTest.getStaticSampleService();
Assert.assertNull(staticSampleService);
String content = FileUtils.readFileToString(sofaLog, System.getProperty("file.encoding"));
Assert.assertTrue(content.contains("SofaReference annotation is not supported on static fields: " + SofaServiceAndReferenceTest.class.getDeclaredField("staticSampleService")));
}
use of com.alipay.sofa.runtime.test.beans.facade.SampleService 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());
}
use of com.alipay.sofa.runtime.test.beans.facade.SampleService in project sofa-boot by sofastack.
the class SofaServiceAndReferenceTest method testSofaReferenceOnStaticField.
@Test
public void testSofaReferenceOnStaticField() throws IOException, NoSuchFieldException {
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"));
Map<String, Object> properties = new HashMap<>();
properties.put("spring.application.name", "SofaServiceAndReferenceTest");
properties.put("logging.path", logRootPath);
SpringApplication springApplication = new SpringApplication(TestSofaReferenceOnMethodConfiguration.class, RuntimeConfiguration.class);
springApplication.setWebApplicationType(WebApplicationType.NONE);
springApplication.setDefaultProperties(properties);
springApplication.run();
SampleService staticSampleService = SofaServiceAndReferenceTest.getStaticSampleService();
Assert.assertNull(staticSampleService);
String content = FileUtils.readFileToString(sofaLog, System.getProperty("file.encoding"));
Assert.assertTrue(content.contains("SofaReference annotation is not supported on static fields: " + SofaServiceAndReferenceTest.class.getDeclaredField("staticSampleService")));
}
Aggregations