public void testRetryOnce() throws InterruptedException {
// Logger.getRootLogger().setLevel(Level.INFO);
// String p = "test_";
// System.out.println(p.substring(p.lastIndexOf('_')+1));
HelixTaskExecutor executor = new HelixTaskExecutor();
HelixManager manager = new MockClusterManager();
CancellableHandlerFactory factory = new CancellableHandlerFactory();
executor.registerMessageHandlerFactory(factory.getMessageType(), factory);
NotificationContext changeContext = new NotificationContext(manager);
List<Message> msgList = new ArrayList<Message>();
// factory.reset();
// msgList.clear();
// Test the case that the message are executed for the second time
int nMsgs2 = 4;
for (int i = 0; i < nMsgs2; i++) {
Message msg = new Message(factory.getMessageType(), UUID.randomUUID().toString());
msg.setTgtSessionId("*");
msg.setTgtName("Localhost_1123");
msg.setSrcName("127.101.1.23_2234");
msg.setExecutionTimeout((i + 1) * 600);
msg.setRetryCount(1);
msgList.add(msg);
}
executor.onMessage("someInstance", msgList, changeContext);
Thread.sleep(3500);
AssertJUnit.assertEquals(factory._processedMsgIds.size(), 3);
AssertJUnit.assertTrue(msgList.get(0).getRecord().getSimpleField("Cancelcount").equals("2"));
AssertJUnit.assertTrue(msgList.get(1).getRecord().getSimpleField("Cancelcount").equals("1"));
AssertJUnit.assertEquals(factory._timedOutMsgIds.size(), 2);