Search in sources :

Example 1 with ReferenceParam

use of com.alipay.sofa.runtime.api.client.param.ReferenceParam 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 ReferenceParam

use of com.alipay.sofa.runtime.api.client.param.ReferenceParam in project sofa-boot by alipay.

the class ClientFactoryTest method testRemoveServiceOrRemoveReference.

/**
 * test removeService and removeReference methods in ReferenceClientImpl and ServiceClientImpl
 */
@Test
public void testRemoveServiceOrRemoveReference() {
    // without unique id
    ServiceParam serviceParam = new ServiceParam();
    serviceParam.setInstance(new PrivateServiceImpl());
    serviceParam.setInterfaceType(PrivateService.class);
    serviceClient.service(serviceParam);
    // with unique id
    serviceParam.setUniqueId("uniqueId");
    serviceClient.service(serviceParam);
    try {
        Thread.sleep(2000);
    } catch (Exception e) {
    // ignore
    }
    // reference without unique id
    ReferenceParam<PrivateService> referenceParam = new ReferenceParam<>();
    referenceParam.setInterfaceType(PrivateService.class);
    Assert.assertEquals(PrivateServiceImpl.class.getName(), referenceClient.reference(referenceParam).service());
    // reference with unique id
    referenceParam.setUniqueId("uniqueId");
    Assert.assertEquals(PrivateServiceImpl.class.getName(), referenceClient.reference(referenceParam).service());
    // remove Reference
    referenceClient.removeReference(PrivateService.class);
    referenceClient.removeReference(referenceParam);
    // remove Service
    try {
        serviceClient.removeService(PrivateService.class, -1);
    } catch (IllegalArgumentException ex) {
        Assert.assertTrue(ex.getMessage().contains("Argument delay must be a positive integer or zero"));
    }
    serviceClient.removeService(PrivateService.class, "uniqueId", 0);
}
Also used : ReferenceParam(com.alipay.sofa.runtime.api.client.param.ReferenceParam) ServiceParam(com.alipay.sofa.runtime.api.client.param.ServiceParam) IOException(java.io.IOException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with ReferenceParam

use of com.alipay.sofa.runtime.api.client.param.ReferenceParam 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 ReferenceParam

use of com.alipay.sofa.runtime.api.client.param.ReferenceParam in project sofa-boot by sofastack.

the class ClientFactoryTest method testRemoveServiceOrRemoveReference.

/**
 * test removeService and removeReference methods in ReferenceClientImpl and ServiceClientImpl
 */
@Test
public void testRemoveServiceOrRemoveReference() {
    // without unique id
    ServiceParam serviceParam = new ServiceParam();
    serviceParam.setInstance(new PrivateServiceImpl());
    serviceParam.setInterfaceType(PrivateService.class);
    serviceClient.service(serviceParam);
    // with unique id
    serviceParam.setUniqueId("uniqueId");
    serviceClient.service(serviceParam);
    try {
        Thread.sleep(2000);
    } catch (Exception e) {
    // ignore
    }
    // reference without unique id
    ReferenceParam<PrivateService> referenceParam = new ReferenceParam<>();
    referenceParam.setInterfaceType(PrivateService.class);
    Assert.assertEquals(PrivateServiceImpl.class.getName(), referenceClient.reference(referenceParam).service());
    // reference with unique id
    referenceParam.setUniqueId("uniqueId");
    Assert.assertEquals(PrivateServiceImpl.class.getName(), referenceClient.reference(referenceParam).service());
    // remove Reference
    referenceClient.removeReference(PrivateService.class);
    referenceClient.removeReference(referenceParam);
    // remove Service
    try {
        serviceClient.removeService(PrivateService.class, -1);
    } catch (IllegalArgumentException ex) {
        Assert.assertTrue(ex.getMessage().contains("Argument delay must be a positive integer or zero"));
    }
    serviceClient.removeService(PrivateService.class, "uniqueId", 0);
}
Also used : ReferenceParam(com.alipay.sofa.runtime.api.client.param.ReferenceParam) ServiceParam(com.alipay.sofa.runtime.api.client.param.ServiceParam) IOException(java.io.IOException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

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