EntryImpl implements ISchedulerEntry { @Override public void scheduleNext(final long time) throws EntryScheduleException { try { ITimerTask tt = timerTask.get(); if (null == tt) { if (isCancelled) { try { storage.delete(this); } catch (EntryNotFoundException ignore) { } return; } tt = this.timerTask.getAndSet(storage.getTimer().schedule(this.task, time)); if (null != tt) { tt.cancel(); } } else { tt.reschedule(time); } lastScheduledTime = time; storage.notifyActive(this); } catch (TaskScheduleException | EntryStorageAccessException e) { throw new EntryScheduleException("Could not reschedule entry.", e); } } EntryImpl(
            final IObject state,
            final ISchedulingStrategy strategy,
            final ISchedulerEntryStorage storage,
            final ISchedulerAction action,
            final boolean isSavedRemotely); static EntryImpl newEntry(final IObject args, final ISchedulerEntryStorage storage); static EntryImpl restoreEntry(final IObject savedState, final ISchedulerEntryStorage storage); @Override IObject getState(); @Override void save(); @Override void cancel(); @Override void scheduleNext(final long time); @Override long getLastTime(); @Override String getId(); @Override void suspend(); @Override void awake(); @Override boolean isAwake(); @Override void pause(); @Override void unpause();  }
@Test public void Should_sendMessageWhenTaskExecuted() throws Exception { IObject state = IOC.resolve(Keys.getOrAdd("info.smart_tools.smartactors.iobject.iobject.IObject"), "{'entryId':'trust-methis-isa-guid', 'message':{'this is':'the message'}}".replace('\'','"')); ISchedulerEntry entry = new EntryImpl(state, strategy, storage, action, false); entry.scheduleNext(0); ArgumentCaptor<ITask> taskArgumentCaptor = ArgumentCaptor.forClass(ITask.class); ArgumentCaptor<IObject> iObjectArgumentCaptor = ArgumentCaptor.forClass(IObject.class); verify(timer).schedule(taskArgumentCaptor.capture(), eq(0L)); IMessageBusHandler messageBusHandler = mock(IMessageBusHandler.class); ScopeProvider.getCurrentScope().setValue(MessageBus.getMessageBusKey(), messageBusHandler); taskArgumentCaptor.getValue().execute(); verify(messageBusHandler).handle(iObjectArgumentCaptor.capture()); verify(strategy).postProcess(same(entry)); assertEquals("{'this is':'the message'}".replace('\'','"'), iObjectArgumentCaptor.getValue().serialize()); }