Search in sources :

Example 1 with SampleService

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());
}
Also used : DefaultSampleService(com.alipay.sofa.runtime.test.beans.service.DefaultSampleService) DefaultSampleService(com.alipay.sofa.runtime.test.beans.service.DefaultSampleService) SampleService(com.alipay.sofa.runtime.test.beans.facade.SampleService) ReferenceParam(com.alipay.sofa.runtime.api.client.param.ReferenceParam) ServiceParam(com.alipay.sofa.runtime.api.client.param.ServiceParam) IOException(java.io.IOException) JvmBindingParam(com.alipay.sofa.runtime.service.binding.JvmBindingParam) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with SampleService

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")));
}
Also used : HashMap(java.util.HashMap) DefaultSampleService(com.alipay.sofa.runtime.test.beans.service.DefaultSampleService) SampleService(com.alipay.sofa.runtime.test.beans.facade.SampleService) SpringApplication(org.springframework.boot.SpringApplication) File(java.io.File) Test(org.junit.Test)

Example 3 with SampleService

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());
}
Also used : DefaultSampleService(com.alipay.sofa.runtime.test.beans.service.DefaultSampleService) DefaultSampleService(com.alipay.sofa.runtime.test.beans.service.DefaultSampleService) SampleService(com.alipay.sofa.runtime.test.beans.facade.SampleService) ReferenceParam(com.alipay.sofa.runtime.api.client.param.ReferenceParam) ServiceParam(com.alipay.sofa.runtime.api.client.param.ServiceParam) IOException(java.io.IOException) JvmBindingParam(com.alipay.sofa.runtime.service.binding.JvmBindingParam) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with SampleService

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")));
}
Also used : HashMap(java.util.HashMap) DefaultSampleService(com.alipay.sofa.runtime.test.beans.service.DefaultSampleService) SampleService(com.alipay.sofa.runtime.test.beans.facade.SampleService) SpringApplication(org.springframework.boot.SpringApplication) File(java.io.File) Test(org.junit.Test)

Aggregations

SampleService (com.alipay.sofa.runtime.test.beans.facade.SampleService)4 DefaultSampleService (com.alipay.sofa.runtime.test.beans.service.DefaultSampleService)4 Test (org.junit.Test)4 ReferenceParam (com.alipay.sofa.runtime.api.client.param.ReferenceParam)2 ServiceParam (com.alipay.sofa.runtime.api.client.param.ServiceParam)2 JvmBindingParam (com.alipay.sofa.runtime.service.binding.JvmBindingParam)2 File (java.io.File)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 SpringApplication (org.springframework.boot.SpringApplication)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2