Search in sources :

Example 1 with GenericContext

use of com.alipay.sofa.rpc.api.GenericContext 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. 指定超时,结果序列化为People 类
    People 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

GenericObject (com.alipay.hessian.generic.model.GenericObject)1 GenericContext (com.alipay.sofa.rpc.api.GenericContext)1 SofaRpcException (com.alipay.sofa.rpc.core.exception.SofaRpcException)1 People (com.alipay.sofa.rpc.test.generic.bean.People)1