MockStorage storage = new MockStorage();
storage.setValue(configuration, ProcessTask.ROW_KEY, "localhost", commandTab.toString());
MockNodeStatus nodeStatus = new MockNodeStatus();
AgentProcessManager processManager = new AgentProcessManager(new AgentProcessMap(AgentProcessMap.buildDefaultMap()), configuration, nodeStatus);
ProcessTask processTask = new ProcessTask(configuration, processManager, storage);
processTask.execute();
Assert.assertTrue(nodeStatus.getFlushLatch().await(5, TimeUnit.SECONDS));
for ( int i = 0; i < 5; ++i )
{
Assert.assertEquals(nodeStatus.getOperations().size(), 1);
Assert.assertEquals(nodeStatus.getOperations().get(0), "flush");
TimeUnit.SECONDS.sleep(1);
}
commandObject = new JSONObject();
commandObject.put(FIELD_COMMAND, COMMAND_STOP);
commandObject.put(FIELD_ID, "1");
commandTab = new JSONArray();
commandTab.put(commandObject);
storage.setValue(configuration, ProcessTask.ROW_KEY, "localhost", commandTab.toString());
processTask.execute();
Assert.assertTrue(processManager.closeAndWaitForCompletion(5, TimeUnit.SECONDS));
Assert.assertEquals(processManager.getActiveProcesses().size(), 0);
}