}
}
@Test
public void testRPC2() throws Exception {
Peer peer1 = null;
Peer peer2 = null;
try {
peer1 = new PeerMaker(new Number160(rnd)).setWorkerThreads(1).setPorts(4001).setEnableTask(true)
.makeAndListen();
peer2 = new PeerMaker(new Number160(rnd)).setWorkerThreads(1).setPorts(4002).setEnableTask(true)
.makeAndListen();
FutureChannelCreator futureChannelCreator = peer1.getConnectionBean().getConnectionReservation().reserve(5);
futureChannelCreator.awaitUninterruptibly();
Number160 taskId1 = new Number160(11);
Number160 taskId2 = new Number160(12);
Number160 taskId3 = new Number160(13);
Map<Number160, Data> dataMap = new HashMap<Number160, Data>();
dataMap.put(new Number160(22), new Data("testme"));
FutureResponse futureResponse1 = peer1.getTaskRPC().sendTask(peer1.getPeerAddress(),
futureChannelCreator.getChannelCreator(), taskId1, dataMap, new MyWorker2(), null, false, false);
futureResponse1.awaitUninterruptibly();
FutureResponse futureResponse2 = peer1.getTaskRPC().sendTask(peer1.getPeerAddress(),
futureChannelCreator.getChannelCreator(), taskId2, dataMap, new MyWorker2(), null, false, false);
futureResponse2.awaitUninterruptibly();
FutureResponse futureResponse3 = peer1.getTaskRPC().sendTask(peer1.getPeerAddress(),
futureChannelCreator.getChannelCreator(), taskId3, dataMap, new MyWorker2(), null, false, false);
futureResponse3.awaitUninterruptibly();
Assert.assertEquals(true, futureResponse1.isSuccess());
Assert.assertEquals(true, futureResponse2.isSuccess());
Assert.assertEquals(true, futureResponse3.isSuccess());
Collection<Number160> taskIDs = new ArrayList<Number160>();
taskIDs.add(taskId1);
taskIDs.add(taskId2);
taskIDs.add(taskId3);
FutureResponse futureResponse4 = peer1.getTaskRPC().taskStatus(peer1.getPeerAddress(),
futureChannelCreator.getChannelCreator(), taskIDs, false);
futureResponse4.awaitUninterruptibly();
Assert.assertEquals(3, futureResponse4.getResponse().getDataMap().size());
Map<Number160, Data> map = futureResponse4.getResponse().getDataMap();
TaskStatus status1 = (TaskStatus) map.get(taskId1).getObject();
TaskStatus status2 = (TaskStatus) map.get(taskId2).getObject();
TaskStatus status3 = (TaskStatus) map.get(taskId3).getObject();
Assert.assertEquals(TaskStatus.Status.STARTED, status1.getStatus());
Assert.assertEquals(TaskStatus.Status.QUEUE, status2.getStatus());
Assert.assertEquals(0, status2.getQueuePosition());
Assert.assertEquals(TaskStatus.Status.QUEUE, status3.getStatus());
Assert.assertEquals(1, status3.getQueuePosition());
Thread.sleep(1000);
FutureResponse futureResponse5 = peer1.getTaskRPC().taskStatus(peer1.getPeerAddress(),
futureChannelCreator.getChannelCreator(), taskIDs, false);
Utils.addReleaseListenerAll(futureResponse5, peer1.getConnectionBean().getConnectionReservation(),
futureChannelCreator.getChannelCreator());
futureResponse5.awaitUninterruptibly();
Assert.assertEquals(3, futureResponse5.getResponse().getDataMap().size());
map = futureResponse5.getResponse().getDataMap();
status1 = (TaskStatus) map.get(taskId1).getObject();
status2 = (TaskStatus) map.get(taskId2).getObject();
status3 = (TaskStatus) map.get(taskId3).getObject();
Assert.assertEquals(TaskStatus.Status.SUCCESS_RESULT_SENT, status1.getStatus());
Assert.assertEquals(TaskStatus.Status.SUCCESS_RESULT_SENT, status2.getStatus());
Assert.assertEquals(TaskStatus.Status.SUCCESS_RESULT_SENT, status3.getStatus());
} finally {
if (peer1 != null) {
peer1.halt();
}
if (peer2 != null) {
peer2.halt();
}
}
}