Skip to content

Commit

Permalink
Merge convoy test internals used in core and network, log time in convoy
Browse files Browse the repository at this point in the history
tests
  • Loading branch information
vladamatena committed May 20, 2015
1 parent c77179e commit bbd30e6
Show file tree
Hide file tree
Showing 15 changed files with 129 additions and 286 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cz.cuni.mff.d3s.jdeeco.network.demo.convoy;
package cz.cuni.mff.d3s.jdeeco.core.demo.convoy;


import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package cz.cuni.mff.d3s.jdeeco.network.demo.convoy;
package cz.cuni.mff.d3s.jdeeco.core.demo.convoy;

import java.io.PrintStream;

import cz.cuni.mff.d3s.deeco.annotations.Component;
import cz.cuni.mff.d3s.deeco.annotations.In;
import cz.cuni.mff.d3s.deeco.annotations.InOut;
import cz.cuni.mff.d3s.deeco.annotations.Local;
import cz.cuni.mff.d3s.deeco.annotations.PeriodicScheduling;
import cz.cuni.mff.d3s.deeco.annotations.Process;
import cz.cuni.mff.d3s.deeco.task.ParamHolder;
import cz.cuni.mff.d3s.deeco.timer.CurrentTimeProvider;

/**
*
Expand All @@ -23,27 +25,37 @@ public class Follower {
public Waypoint destination = new Waypoint(1, 3);
public Waypoint leaderPosition;

private static PrintStream out;
@Local
public PrintStream out;

@Local
public CurrentTimeProvider clock;

public Follower(String name, PrintStream out) {
public Follower(String name, PrintStream out, CurrentTimeProvider clock) {
this.name = name;
Follower.out = out;
this.out = out;
this.clock = clock;
}

public Follower(PrintStream out) {
this("F", out);
public Follower(PrintStream out, CurrentTimeProvider clock) {
this("F", out, clock);
}

@Process
@PeriodicScheduling(period = 2500)
public static void followProcess(@InOut("position") ParamHolder<Waypoint> me,
@In("destination") Waypoint destination, @In("name") String name, @In("leaderPosition") Waypoint leader) {
public static void followProcess(
@InOut("position") ParamHolder<Waypoint> me,
@In("destination") Waypoint destination,
@In("name") String name,
@In("leaderPosition") Waypoint leader,
@In("out") PrintStream out,
@In("clock") CurrentTimeProvider clock) {

if (!destination.equals(me.value) && leader != null) {
me.value.x += Integer.signum(leader.x - me.value.x);
me.value.y += Integer.signum(leader.y - me.value.y);
}

out.println("Follower " + name + ": me = " + me.value + " leader = " + leader);
out.format("%06d: Follower %s: me = %s leader = %s%n", clock.getCurrentMilliseconds(), name, me.value, leader);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cz.cuni.mff.d3s.jdeeco.network.demo.convoy;
package cz.cuni.mff.d3s.jdeeco.core.demo.convoy;



Expand All @@ -10,9 +10,11 @@
import cz.cuni.mff.d3s.deeco.annotations.Component;
import cz.cuni.mff.d3s.deeco.annotations.In;
import cz.cuni.mff.d3s.deeco.annotations.InOut;
import cz.cuni.mff.d3s.deeco.annotations.Local;
import cz.cuni.mff.d3s.deeco.annotations.PeriodicScheduling;
import cz.cuni.mff.d3s.deeco.annotations.Process;
import cz.cuni.mff.d3s.deeco.task.ParamHolder;
import cz.cuni.mff.d3s.deeco.timer.CurrentTimeProvider;

/**
*
Expand All @@ -27,9 +29,13 @@ public class Leader {
public List<Waypoint> path;
public Waypoint position;

private static PrintStream out;
@Local
public CurrentTimeProvider clock;

public Leader(String name, PrintStream out) {
@Local
public PrintStream out;

public Leader(String name, PrintStream out, CurrentTimeProvider clock) {
path = new LinkedList<Waypoint>(Arrays.asList(
new Waypoint(3, 1),
new Waypoint(2, 1),
Expand All @@ -42,18 +48,21 @@ public Leader(String name, PrintStream out) {
this.name = name;
id = "Leader1";
position = new Waypoint(3, 1);
Leader.out = out;
this.out = out;
this.clock = clock;
}

public Leader(PrintStream out) {
this("L", out);
public Leader(PrintStream out, CurrentTimeProvider clock) {
this("L", out, clock);
}

@Process
@PeriodicScheduling(period=2500)
public static void moveProcess(
@InOut("path") ParamHolder<List<Waypoint>> path,
@In("name") String name,
@In("clock") CurrentTimeProvider clock,
@In("out") PrintStream out,
@InOut("position") ParamHolder<Waypoint> me
) {

Expand All @@ -67,6 +76,6 @@ public static void moveProcess(
me.value.y += Integer.signum(next.y - me.value.y);
}

out.println("Leader " + name + ": " + me.value);
out.format("%06d: Leader: %s: %s%n", clock.getCurrentMilliseconds(), name, me.value);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cz.cuni.mff.d3s.jdeeco.network.demo.convoy;
package cz.cuni.mff.d3s.jdeeco.core.demo.convoy;

import java.io.Serializable;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Component and ensemble definitions for convoy demo
*
* These classes demonstrate jDEECo usage and are used for integration tests
*
*/
package cz.cuni.mff.d3s.jdeeco.core.demo.convoy;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import cz.cuni.mff.d3s.deeco.runtime.DEECoNode;
import cz.cuni.mff.d3s.deeco.timer.DiscreteEventTimer;
import cz.cuni.mff.d3s.deeco.timer.SimulationTimer;
import cz.cuni.mff.d3s.jdeeco.core.demo.convoy.ConvoyEnsemble;
import cz.cuni.mff.d3s.jdeeco.core.demo.convoy.Follower;
import cz.cuni.mff.d3s.jdeeco.core.demo.convoy.Leader;
/**
* @author Ilias Gerostathopoulos <iliasg@d3s.mff.cuni.cz>
*/
Expand Down Expand Up @@ -47,13 +50,13 @@ private void testConvoy(boolean silent) throws AnnotationProcessorException, Int
/* create first deeco node */
DEECoNode deeco1 = realm.createNode(0);
/* deploy components and ensembles */
deeco1.deployComponent(new Leader(outputStream));
deeco1.deployComponent(new Leader(outputStream, simulationTimer));
deeco1.deployEnsemble(ConvoyEnsemble.class);

/* create second deeco node */
DEECoNode deeco2 = realm.createNode(1);
/* deploy components and ensembles */
deeco2.deployComponent(new Follower(outputStream));
deeco2.deployComponent(new Follower(outputStream, simulationTimer));
deeco2.deployEnsemble(ConvoyEnsemble.class);

/* WHEN simulation is performed */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import cz.cuni.mff.d3s.deeco.runtime.DEECoNode;
import cz.cuni.mff.d3s.deeco.timer.DiscreteEventTimer;
import cz.cuni.mff.d3s.deeco.timer.SimulationTimer;
import cz.cuni.mff.d3s.jdeeco.core.demo.convoy.ConvoyEnsemble;
import cz.cuni.mff.d3s.jdeeco.core.demo.convoy.Follower;
import cz.cuni.mff.d3s.jdeeco.core.demo.convoy.Leader;
/**
* @author Ilias Gerostathopoulos <iliasg@d3s.mff.cuni.cz>
*/
Expand Down Expand Up @@ -48,12 +51,12 @@ private void testConvoy(boolean silent) throws AnnotationProcessorException, Int
DEECoNode deeco = realm.createNode(0);
/* deploy components and ensembles */

deeco.deployComponent(new Leader(outputStream));
deeco.deployComponent(new Follower(outputStream));
deeco.deployComponent(new Leader(outputStream, simulationTimer));
deeco.deployComponent(new Follower(outputStream, simulationTimer));
deeco.deployEnsemble(ConvoyEnsemble.class);

/* WHEN simulation is performed */
realm.start(2000);
realm.start(10000);

// THEN the follower reaches his destination
if (silent)
Expand Down
48 changes: 0 additions & 48 deletions jdeeco-core/test/cz/cuni/mff/d3s/deeco/demo/convoy/Follower.java

This file was deleted.

67 changes: 0 additions & 67 deletions jdeeco-core/test/cz/cuni/mff/d3s/deeco/demo/convoy/Leader.java

This file was deleted.

Loading

0 comments on commit bbd30e6

Please sign in to comment.