Search in sources :

Example 1 with People

use of com.alipay.sofa.rpc.test.generic.bean.People in project sofa-rpc by sofastack.

the class GenericTest method createMyComplexBean.

/**
 * 构建自定义扩展对象构成bean
 */
private ComplexBean createMyComplexBean() {
    ComplexBean complexBean = new ComplexBean();
    complexBean.setStrs(new String[] { null, "123", null });
    complexBean.setClazz(MyList.class);
    complexBean.setJobs(new Job[] { null, new Job("coder"), null });
    ArrayList list = new MyList();
    list.add(null);
    list.add(1);
    list.add(null);
    complexBean.setList(list);
    MyMap map = new MyMap();
    map.put("1", new Job("coder"));
    map.put(1, new People("wang", null));
    complexBean.setMap(map);
    return complexBean;
}
Also used : MyMap(com.alipay.sofa.rpc.test.generic.bean.MyMap) ArrayList(java.util.ArrayList) MyList(com.alipay.sofa.rpc.test.generic.bean.MyList) People(com.alipay.sofa.rpc.test.generic.bean.People) Job(com.alipay.sofa.rpc.test.generic.bean.Job) ComplexBean(com.alipay.sofa.rpc.test.generic.bean.ComplexBean)

Example 2 with People

use of com.alipay.sofa.rpc.test.generic.bean.People in project sofa-rpc by sofastack.

the class GenericTest method testAll.

@Test
public void testAll() throws SofaRpcException, InterruptedException {
    // 发布服务
    ServerConfig serverConfig2 = new ServerConfig().setPort(22222).setDaemon(false);
    List<MethodConfig> methodConfigs = new ArrayList<MethodConfig>();
    MethodConfig config1 = new MethodConfig().setName("helloFuture").setInvokeType("future");
    methodConfigs.add(config1);
    MethodConfig config2 = new MethodConfig().setName("helloCallback").setInvokeType("callback").setOnReturn(new TestCallback());
    methodConfigs.add(config2);
    MethodConfig config21 = new MethodConfig().setName("helloCallbackException").setInvokeType("callback").setOnReturn(new TestCallback());
    methodConfigs.add(config21);
    MethodConfig config3 = new MethodConfig().setName("helloOneway").setInvokeType("oneway");
    methodConfigs.add(config3);
    MethodConfig config4 = new MethodConfig().setName("helloTimeout").setInvokeType("sync");
    methodConfigs.add(config4);
    // C服务的服务端
    ProviderConfig<TestInterface> CProvider = new ProviderConfig<TestInterface>().setInterfaceId(TestInterface.class.getName()).setRef(new TestClass()).setServer(serverConfig2);
    CProvider.export();
    // 引用服务
    ConsumerConfig<GenericService> BConsumer = new ConsumerConfig<GenericService>().setInterfaceId(TestInterface.class.getName()).setGeneric(true).setMethods(methodConfigs).setDirectUrl("bolt://127.0.0.1:22222").setTimeout(3000).setRetries(2);
    GenericService proxy = BConsumer.refer();
    GenericObject genericObject = new GenericObject("com.alipay.sofa.rpc.test.generic.bean.People");
    genericObject.putField("name", "Lilei");
    genericObject.putField("job", new Job("coder"));
    People people = new People();
    people.setName("Lilei");
    people.setJob(new Job("coder"));
    // sync 调用
    assertEquals(proxy.$invoke("hello", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { people }), new TestClass().hello(people));
    People peopleResult = proxy.$genericInvoke("hello", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { genericObject }, People.class);
    assertEquals(peopleResult, new TestClass().hello(people));
    GenericObject result = (GenericObject) proxy.$genericInvoke("hello", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { genericObject });
    isCorrect(result);
    // future 调用
    proxy.$invoke("helloFuture", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { people });
    assertEquals(SofaResponseFuture.getResponse(1000, true), new TestClass().helloFuture(people));
    proxy.$genericInvoke("helloFuture", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { genericObject }, People.class);
    assertEquals(SofaResponseFuture.getResponse(1000, true), new TestClass().helloFuture(people));
    proxy.$genericInvoke("helloFuture", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { genericObject });
    result = (GenericObject) SofaResponseFuture.getResponse(1000, true);
    isCorrect(result);
    // callback调用
    proxy.$invoke("helloCallback", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { people });
    TestCallback.startLatach();
    assertEquals(TestCallback.result, new TestClass().helloCallback(people));
    proxy.$genericInvoke("helloCallback", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { genericObject }, People.class);
    TestCallback.startLatach();
    assertEquals(TestCallback.result, new TestClass().helloCallback(people));
    proxy.$genericInvoke("helloCallback", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { genericObject });
    TestCallback.startLatach();
    isCorrect((GenericObject) TestCallback.result);
    TestCallback.result = null;
    // oneway调用
    proxy.$invoke("helloOneway", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { people });
    proxy.$genericInvoke("helloOneway", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { genericObject }, People.class);
    proxy.$genericInvoke("helloOneway", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { genericObject });
    // callback出现异常
    proxy.$invoke("helloCallbackException", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { people });
    TestCallback.startLatach();
    Assert.assertEquals(((Throwable) TestCallback.result).getMessage(), "Hello~");
    proxy.$genericInvoke("helloCallbackException", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { genericObject }, People.class);
    TestCallback.startLatach();
    Assert.assertEquals(((Throwable) TestCallback.result).getMessage(), "Hello~");
    proxy.$genericInvoke("helloCallbackException", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { genericObject });
    TestCallback.startLatach();
    Assert.assertEquals(((Throwable) TestCallback.result).getMessage(), "Hello~");
    testTimeout(proxy, genericObject, people);
    testComplexBean(proxy);
    testBasicBean(proxy);
}
Also used : GenericService(com.alipay.sofa.rpc.api.GenericService) ArrayList(java.util.ArrayList) People(com.alipay.sofa.rpc.test.generic.bean.People) MethodConfig(com.alipay.sofa.rpc.config.MethodConfig) ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) GenericObject(com.alipay.hessian.generic.model.GenericObject) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig) GenericObject(com.alipay.hessian.generic.model.GenericObject) Job(com.alipay.sofa.rpc.test.generic.bean.Job) Test(org.junit.Test) ActivelyDestroyTest(com.alipay.sofa.rpc.test.ActivelyDestroyTest)

Example 3 with People

use of com.alipay.sofa.rpc.test.generic.bean.People in project sofa-rpc by sofastack.

the class GenericTest method testTimeout.

private void testTimeout(final GenericService proxy, GenericObject genericObject, People people) {
    // 1. 构造GenericContext 对象
    GenericContext genericContext = new GenericContext();
    genericContext.setClientTimeout(5000);
    // 2. 未指定参数,发生超时
    boolean isSuccess = true;
    try {
        proxy.$genericInvoke("helloTimeout", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { people });
    } catch (Exception e) {
        isSuccess = false;
    }
    Assert.assertFalse(isSuccess);
    // 3. 指定超时,结果序列化为PeoplePeople peopleResult = proxy.$genericInvoke("helloTimeout", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { genericObject }, People.class, genericContext);
    assertEquals(peopleResult, people);
    // 4. 指定超时,结果序列化为GenericObject
    GenericObject result = (GenericObject) proxy.$genericInvoke("helloTimeout", new String[] { "com.alipay.sofa.rpc.test.generic.bean.People" }, new Object[] { genericObject }, genericContext);
    isCorrect(result);
}
Also used : GenericContext(com.alipay.sofa.rpc.api.GenericContext) People(com.alipay.sofa.rpc.test.generic.bean.People) GenericObject(com.alipay.hessian.generic.model.GenericObject) GenericObject(com.alipay.hessian.generic.model.GenericObject) SofaRpcException(com.alipay.sofa.rpc.core.exception.SofaRpcException)

Aggregations

People (com.alipay.sofa.rpc.test.generic.bean.People)3 GenericObject (com.alipay.hessian.generic.model.GenericObject)2 Job (com.alipay.sofa.rpc.test.generic.bean.Job)2 ArrayList (java.util.ArrayList)2 GenericContext (com.alipay.sofa.rpc.api.GenericContext)1 GenericService (com.alipay.sofa.rpc.api.GenericService)1 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)1 MethodConfig (com.alipay.sofa.rpc.config.MethodConfig)1 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)1 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)1 ActivelyDestroyTest (com.alipay.sofa.rpc.test.ActivelyDestroyTest)1 ComplexBean (com.alipay.sofa.rpc.test.generic.bean.ComplexBean)1 MyList (com.alipay.sofa.rpc.test.generic.bean.MyList)1 MyMap (com.alipay.sofa.rpc.test.generic.bean.MyMap)1 Test (org.junit.Test)1