Skip to content

Commit

Permalink
Process task development
Browse files Browse the repository at this point in the history
Some updates to the architecture based on our meeting today.
  • Loading branch information
bures committed Oct 30, 2013
1 parent a88af61 commit 8207286
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 27 deletions.
80 changes: 64 additions & 16 deletions jdeeco-architecture/architecture-26.10.2013.emx

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions jdeeco-core/src/cz/cuni/mff/d3s/deeco/task/EnsembleTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ public EnsembleTask(InstanceEnsemblingController ensemblingController) {
this.ensemblingController = ensemblingController;
}

/* (non-Javadoc)
* @see cz.cuni.mff.d3s.deeco.task.Task#registerTriggers()
*/
@Override
public void registerTriggers() {
// TODO Auto-generated method stub

}

/* (non-Javadoc)
* @see cz.cuni.mff.d3s.deeco.task.Task#unregisterTriggers()
*/
@Override
public void unregisterTriggers() {
// TODO Auto-generated method stub

}

/* (non-Javadoc)
* @see cz.cuni.mff.d3s.deeco.task.Task#invoke()
*/
Expand Down
21 changes: 21 additions & 0 deletions jdeeco-core/src/cz/cuni/mff/d3s/deeco/task/ProcessTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import cz.cuni.mff.d3s.deeco.model.runtime.api.InstanceProcess;

/**
* @author Tomas Bures <bures@d3s.mff.cuni.cz>
*
*/
public class ProcessTask extends Task {

InstanceProcess process;
Expand All @@ -18,4 +22,21 @@ public void invoke() {
// TODO Auto-generated method stub

}

/* (non-Javadoc)
* @see cz.cuni.mff.d3s.deeco.task.Task#registerTriggers()
*/
@Override
public void registerTriggers() {
// TODO Auto-generated method stub

}

/* (non-Javadoc)
* @see cz.cuni.mff.d3s.deeco.task.Task#unregisterTriggers()
*/
@Override
public void unregisterTriggers() {
// TODO Auto-generated method stub
}
}
15 changes: 14 additions & 1 deletion jdeeco-core/src/cz/cuni/mff/d3s/deeco/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,21 @@ public Task(SchedulingSpecification schedulingSpecification) {

public abstract void invoke();

public abstract void registerTriggers();
public abstract void unregisterTriggers();

public void setSchedulingNotificationTarget(NotificationsForScheduler listener) {
this.listener = listener;
if (this.listener != null && listener == null) {
unregisterTriggers();
this.listener = null;

} else if (this.listener == null && listener != null) {
this.listener = listener;
registerTriggers();

} else {
this.listener = listener;
}
}

public long getSchedulingPeriod() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private KnowledgePath createSamplePathInstance() {
}

@Test
public void testEqualsWorkWithKnowledgePath() {
public void testEqualsWorksWithKnowledgePath() {

// WHEN two instance of KnowledgePath designate the same path
KnowledgePath p1 = createSamplePathInstance();
Expand Down
24 changes: 15 additions & 9 deletions jdeeco-core/test/cz/cuni/mff/d3s/deeco/task/ProcessTaskTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -103,25 +104,30 @@ public void testSchedulingPeriod() {

@Test
@Ignore
public void testTrigger() {
public void testTriggerIsDeliveredOnlyWhenListenerIsRegistered() {
InOrder inOrder = inOrder(knowledgeManager);

// GIVEN a ProcessTask initialized with an InstanceProcess
// WHEN a trigger listener is registered
// WHEN a listener (i.e. scheduler) is registered at the task
task.setSchedulingNotificationTarget(schedulingNotificationTarget);
// AND a trigger comes from the knowledge manager
// THEN the task registers a trigger listener on the knowledge manager
verify(knowledgeManager).register(eq(model.trigger), any(TriggerListener.class));

// WHEN a trigger comes from the knowledge manager
taskTriggerListenerCaptor.getValue().triggered(model.trigger);
// THEN the task calls the registered listener
// THEN the task calls the registered listener (i.e. the scheduler)
inOrder.verify(schedulingNotificationTarget).triggered(task);

// WHEN the listener is unregistered
// WHEN the listener (i.e. the scheduler) is unregistered
task.setSchedulingNotificationTarget(null);
// THEN the trigger is unregistered with the knowledge manager
// THEN the trigger is unregistered at the knowledge manager
inOrder.verify(knowledgeManager).unregister(model.trigger, taskTriggerListenerCaptor.getValue());


// WHEN another trigger (possibly spurious) comes from the knowledge manager
taskTriggerListenerCaptor.getValue().triggered(model.trigger);
// THEN nothing is called on the unregistered listener (i.e. scheduler)

verifyNoMoreInteractions(schedulingNotificationTarget);

// TODO: TB@JK: Could you please check whether the above is correct?
}

@Test
Expand Down

0 comments on commit 8207286

Please sign in to comment.