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);
}
Aggregations