@Test ()
public void testShutdown() throws InterruptedException
{
System.out.println("START TestCMTaskExecutor.testShutdown()");
HelixTaskExecutor executor = new HelixTaskExecutor();
HelixManager manager = new MockClusterManager();
TestMessageHandlerFactory factory = new TestMessageHandlerFactory();
executor.registerMessageHandlerFactory(factory.getMessageType(), factory);
TestMessageHandlerFactory2 factory2 = new TestMessageHandlerFactory2();
executor.registerMessageHandlerFactory(factory2.getMessageType(), factory2);
CancellableHandlerFactory factory3 = new CancellableHandlerFactory();
executor.registerMessageHandlerFactory(factory3.getMessageType(), factory3);
int nMsg1 = 10, nMsg2 = 10, nMsg3 = 10;
List<Message> msgList = new ArrayList<Message>();
for(int i = 0; i < nMsg1; i++)
{
Message msg = new Message(factory.getMessageType(), UUID.randomUUID().toString());
msg.setTgtSessionId("*");
msg.setTgtName("Localhost_1123");
msg.setSrcName("127.101.1.23_2234");
msgList.add(msg);
}
for(int i = 0; i < nMsg2; i++)
{
Message msg = new Message(factory2.getMessageType(), UUID.randomUUID().toString());
msg.setTgtSessionId("*");
msgList.add(msg);
msg.setTgtName("Localhost_1123");
msg.setSrcName("127.101.1.23_2234");
msgList.add(msg);
}
for(int i = 0; i < nMsg3; i++)
{
Message msg = new Message(factory3.getMessageType(), UUID.randomUUID().toString());
msg.setTgtSessionId("*");
msgList.add(msg);
msg.setTgtName("Localhost_1123");
msg.setSrcName("127.101.1.23_2234");
msgList.add(msg);
}
NotificationContext changeContext = new NotificationContext(manager);
executor.onMessage("some", msgList, changeContext);
Thread.sleep(500);
for(ExecutorService svc : executor._executorMap.values())
{
Assert.assertFalse(svc.isShutdown());
}
Assert.assertTrue(factory._processedMsgIds.size() > 0);
executor.shutdown();
for(ExecutorService svc : executor._executorMap.values())
{
Assert.assertTrue(svc.isShutdown());
}
System.out.println("END TestCMTaskExecutor.testShutdown()");