Skip to content

Commit

Permalink
Ensemble task devel.
Browse files Browse the repository at this point in the history
  • Loading branch information
bures committed Nov 9, 2013
1 parent 4cf823d commit f17a804
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
3 changes: 0 additions & 3 deletions jdeeco-core/src/cz/cuni/mff/d3s/deeco/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public Task(Scheduler scheduler) {
this.scheduler = scheduler;
}

// FIXME TB: Could we somehow know whether the scheduler is calling us because of the trigger or because of the period?
// In case of ensembles, we could take an advantage of this and when called because of a trigger, we wouldn't have to evaluate all potential pairs as we know
// which knowledge manager caused the trigger.
public abstract void invoke(Trigger trigger) throws TaskInvocationException;

protected abstract void registerTriggers();
Expand Down
33 changes: 28 additions & 5 deletions jdeeco-core/test/cz/cuni/mff/d3s/deeco/task/EnsembleTaskTest.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package cz.cuni.mff.d3s.deeco.task;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyCollectionOf;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;

import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;

import org.junit.Before;
import org.junit.Ignore;
Expand Down Expand Up @@ -48,7 +54,9 @@ public class EnsembleTaskTest {
@Mock
private KnowledgeManagersView shadowReplicasAccess;
@Mock
private ReadOnlyKnowledgeManager shadowKnowledgeManager;
private ReadOnlyKnowledgeManager shadowKnowledgeManager1;
@Mock
private ReadOnlyKnowledgeManager shadowKnowledgeManager2;
@Mock
private TaskTriggerListener taskTriggerListener;
@Captor
Expand All @@ -71,6 +79,11 @@ public void setUp() throws Exception {

doNothing().when(knowledgeManager).register(any(Trigger.class), knowledgeManagerTriggerListenerCaptor.capture());
doNothing().when(shadowReplicasAccess).register(any(Trigger.class), shadowReplicasTriggerListenerCaptor.capture());

Collection<ReadOnlyKnowledgeManager> shadowKnowledgeManagersCollection = new LinkedList<ReadOnlyKnowledgeManager>();
shadowKnowledgeManagersCollection.add(shadowKnowledgeManager1);
shadowKnowledgeManagersCollection.add(shadowKnowledgeManager2);
when(shadowReplicasAccess.getOthersKnowledgeManagers()).thenReturn(shadowKnowledgeManagersCollection);

model.setKnowledgeManager(knowledgeManager);
model.setOtherKnowledgeManagersAccess(shadowReplicasAccess);
Expand Down Expand Up @@ -126,7 +139,7 @@ public void testTrigger() {

// WHEN a trigger comes from the shadow replica
reset(taskTriggerListener); // Without this, we would have to say that the verify below verifies two invocations -- because one already occurred above.
shadowReplicasTriggerListenerCaptor.getValue().triggered(shadowKnowledgeManager, triggerCaptor.getValue());
shadowReplicasTriggerListenerCaptor.getValue().triggered(shadowKnowledgeManager1, triggerCaptor.getValue());
// THEN the task calls the registered listener
verify(taskTriggerListener).triggered(eq(task), any(Trigger.class));

Expand All @@ -143,20 +156,30 @@ public void testTrigger() {
verifyNoMoreInteractions(taskTriggerListener);

// WHEN a spurious trigger comes from a shadow replica
shadowReplicasTriggerListenerCaptor.getValue().triggered(shadowKnowledgeManager, triggerCaptor.getValue());
shadowReplicasTriggerListenerCaptor.getValue().triggered(shadowKnowledgeManager1, triggerCaptor.getValue());
// THEN it is not propagated to the listener (i.e. the scheduler)
verifyNoMoreInteractions(taskTriggerListener);
}

@Test
@Ignore
public void testEnsembleTaskInvoke() {
public void testEnsembleTaskInvoke() throws Exception {
// GIVEN an EnsembleTask initialized with an InstanceEnsemblingController
// WHEN invoke on the task is called
model.resetMembershipMethodCallCounter();
model.resetExchangeMethodCallCounter();

// WHEN invoke (with periodic trigger) is called on the task
task.invoke(model.ensemblePeriodicTrigger);
// THEN it gets the needed local knowledge
verify(knowledgeManager).get(anyCollectionOf(KnowledgePath.class));
// AND it retrieves the other knowledge managers
verify(shadowReplicasAccess).getOthersKnowledgeManagers();
// AND it gets knowledge from them
verify(shadowKnowledgeManager1).get(anyCollectionOf(KnowledgePath.class));
verify(shadowKnowledgeManager2).get(anyCollectionOf(KnowledgePath.class));
// AND it executes the membership
assertTrue(model.getMembershipMethodCallCounter() == 2);
assertTrue(model.getExchangeMethodCallCounter() == 1);
// AND it executes knowledge exchange for those for which the membership was satisfied
// AND it updates the instance knowledge with outputs of the knowledge exchange

Expand Down

5 comments on commit f17a804

@mkit
Copy link
Member

@mkit mkit commented on f17a804 Nov 12, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At line 131 in this class (EnsembleTaskTest.java) 'assert' is used instead of assertTrue I believe

@bures
Copy link
Member Author

@bures bures commented on f17a804 Nov 12, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Michal, please where is it? I can't find it.

@mkit
Copy link
Member

@mkit mkit commented on f17a804 Nov 12, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have checked out your code and in the test/cz/cuni/mff/d3s/deeco/task/EnsembleTaskTest.java - line 131
The method is called testTrigger 3rd code line (not counting comments) in the method.

@bures
Copy link
Member Author

@bures bures commented on f17a804 Nov 12, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I see now. I've fixed it and will push it with the next commit. We can do the pull request approval then.

@bures
Copy link
Member Author

@bures bures commented on f17a804 Nov 12, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkit could you please approve it now? Thanks.

Please sign in to comment.