use of com.alibaba.otter.node.common.communication.NodeCommmunicationClient in project otter by alibaba.
the class RpcPipeTest method test_ok.
@Test
public void test_ok() {
final DbBatch source = new DbBatch();
RowBatch rowBatch = new RowBatch();
Identity identity = new Identity();
identity.setChannelId(100L);
identity.setPipelineId(100L);
identity.setProcessId(100L);
rowBatch.setIdentity(identity);
source.setRowBatch(rowBatch);
final RowDataRpcPipe pipe = new RowDataRpcPipe();
try {
pipe.afterPropertiesSet();
} catch (Exception e) {
want.fail();
}
Mockit.setUpMock(NodeCommmunicationClient.class, new Object() {
@Mock
public Object call(Long nid, final Event event) {
try {
return TestUtils.invokeMethod(pipe, "onGet", event);
} catch (Exception e) {
want.fail();
}
return null;
}
});
Mockit.setUpMock(RowDataRpcPipe.class, new Object() {
@Mock
private Long getNid() {
return 1L;
}
});
pipe.setNodeCommmunicationClient(new NodeCommmunicationClient());
RpcPipeKey key = pipe.put(source);
DbBatch target = pipe.get(key);
// identify相等
want.bool(source.getRowBatch().getIdentity().equals(target.getRowBatch().getIdentity())).is(true);
}
use of com.alibaba.otter.node.common.communication.NodeCommmunicationClient in project otter by alibaba.
the class RpcPipeTest method test_timeout.
@Test
public void test_timeout() {
final DbBatch source = new DbBatch();
RowBatch rowBatch = new RowBatch();
Identity identity = new Identity();
identity.setChannelId(100L);
identity.setPipelineId(100L);
identity.setProcessId(100L);
rowBatch.setIdentity(identity);
source.setRowBatch(rowBatch);
final RowDataRpcPipe pipe = new RowDataRpcPipe();
// 1s后超时
pipe.setTimeout(1 * 1000L);
try {
pipe.afterPropertiesSet();
} catch (Exception e) {
want.fail();
}
Mockit.setUpMock(NodeCommmunicationClient.class, new Object() {
@Mock
public Object call(Long nid, final Event event) {
try {
return TestUtils.invokeMethod(pipe, "onGet", event);
} catch (Exception e) {
want.fail();
}
return null;
}
});
Mockit.setUpMock(RowDataRpcPipe.class, new Object() {
@Mock
private Long getNid() {
return 1L;
}
});
pipe.setNodeCommmunicationClient(new NodeCommmunicationClient());
RpcPipeKey key = pipe.put(source);
try {
Thread.sleep(1500L);
} catch (InterruptedException e) {
want.fail();
}
DbBatch target = pipe.get(key);
// 返回结果为空
want.bool(target == null).is(true);
}
Aggregations