Search in sources :

Example 1 with StatusReporter

use of org.smartdata.protocol.message.StatusReporter in project SSM by Intel-bigdata.

the class TestCmdletExecutor method testCmdletExecutor.

@Test
public void testCmdletExecutor() throws InterruptedException {
    final List<StatusMessage> statusMessages = new ArrayList<>();
    StatusReporter reporter = new StatusReporter() {

        @Override
        public void report(StatusMessage status) {
            statusMessages.add(status);
        }
    };
    CmdletExecutor executor = new CmdletExecutor(new SmartConf());
    StatusReportTask statusReportTask = new StatusReportTask(reporter, executor, new SmartConf());
    ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
    executorService.scheduleAtFixedRate(statusReportTask, 100, 10, TimeUnit.MILLISECONDS);
    SmartAction action = new EchoAction();
    Map<String, String> args = new HashMap<>();
    args.put(EchoAction.PRINT_MESSAGE, "message success");
    action.setArguments(args);
    action.setActionId(101);
    Cmdlet cmdlet = new Cmdlet(Arrays.asList(action));
    executor.execute(cmdlet);
    Thread.sleep(2000);
    StatusReport lastReport = (StatusReport) statusMessages.get(statusMessages.size() - 1);
    ActionStatus status = lastReport.getActionStatuses().get(0);
    Assert.assertTrue(status.isFinished());
    Assert.assertNull(status.getThrowable());
    executor.shutdown();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StatusMessage(org.smartdata.protocol.message.StatusMessage) ActionStatus(org.smartdata.protocol.message.ActionStatus) StatusReport(org.smartdata.protocol.message.StatusReport) SmartAction(org.smartdata.action.SmartAction) SmartConf(org.smartdata.conf.SmartConf) StatusReporter(org.smartdata.protocol.message.StatusReporter) EchoAction(org.smartdata.action.EchoAction) Test(org.junit.Test)

Example 2 with StatusReporter

use of org.smartdata.protocol.message.StatusReporter in project SSM by Intel-bigdata.

the class TestCmdletExecutor method testStop.

@Test
public void testStop() throws InterruptedException {
    final List<StatusMessage> statusMessages = new Vector<>();
    StatusReporter reporter = new StatusReporter() {

        @Override
        public void report(StatusMessage status) {
            statusMessages.add(status);
        }
    };
    CmdletExecutor executor = new CmdletExecutor(new SmartConf());
    StatusReportTask statusReportTask = new StatusReportTask(reporter, executor, new SmartConf());
    ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
    executorService.scheduleAtFixedRate(statusReportTask, 100, 10, TimeUnit.MILLISECONDS);
    SmartAction action = new HangingAction();
    action.setActionId(101);
    Cmdlet cmdlet = new Cmdlet(Arrays.asList(action));
    cmdlet.setId(10);
    executor.execute(cmdlet);
    Thread.sleep(1000);
    executor.stop(10L);
    Thread.sleep(2000);
    StatusReport lastReport = (StatusReport) statusMessages.get(statusMessages.size() - 1);
    ActionStatus status = lastReport.getActionStatuses().get(0);
    Assert.assertTrue(status.isFinished());
    Assert.assertNotNull(status.getThrowable());
    executor.shutdown();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StatusMessage(org.smartdata.protocol.message.StatusMessage) ActionStatus(org.smartdata.protocol.message.ActionStatus) StatusReport(org.smartdata.protocol.message.StatusReport) SmartAction(org.smartdata.action.SmartAction) SmartConf(org.smartdata.conf.SmartConf) Vector(java.util.Vector) StatusReporter(org.smartdata.protocol.message.StatusReporter) Test(org.junit.Test)

Aggregations

ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 Test (org.junit.Test)2 SmartAction (org.smartdata.action.SmartAction)2 SmartConf (org.smartdata.conf.SmartConf)2 ActionStatus (org.smartdata.protocol.message.ActionStatus)2 StatusMessage (org.smartdata.protocol.message.StatusMessage)2 StatusReport (org.smartdata.protocol.message.StatusReport)2 StatusReporter (org.smartdata.protocol.message.StatusReporter)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Vector (java.util.Vector)1 EchoAction (org.smartdata.action.EchoAction)1