// Path: oncue-common/src/main/java/oncue/common/messages/SimpleMessages.java
// public enum SimpleMessage {
// 	AGENT_HEARTBEAT, AGENT_REGISTERED, AGENT_SHUTDOWN, AGENT_DEAD, LIST_AGENTS, CHECK_AGENTS, SCHEDULE_JOBS, JOB_SUMMARY, BROADCAST_JOBS
// }
// 
// Path: oncue-tests/src/test/java/oncue/tests/base/ActorSystemTest.java
// public abstract class ActorSystemTest {
// 
// 	protected Config config;
// 
// 	protected LoggingAdapter log;
// 
// 	protected Settings settings;
// 
// 	protected ActorSystem system;
// 
// 	// By default ActorSystemTest children will wait for all actors to finish before shutting down
// 	// the test system. If you want to shut down the test system while e.g. workers are still
// 	// running, set this to false.
// 	protected boolean waitForRunningJobs = true;
// 
// 	// Required for naming agents uniquely
// 	private int agentCount = 0;
// 
// 	/**
// 	 * Construct a Agent without a probe
// 	 */
// 	public ActorRef createAgent(ActorSystem system, final Set<String> workers) {
// 		return createAgent(system, workers, null);
// 	}
// 
// 	/**
// 	 * Create an agent component, with a set of workers and an optional probe
// 	 * 
// 	 * @param probe can be null
// 	 */
// 	@SuppressWarnings("serial")
// 	public ActorRef createAgent(ActorSystem system, final Set<String> workers,
// 			final ActorRef probe) {
// 		agentCount++;
// 		return system.actorOf(new Props(new UntypedActorFactory() {
// 
// 			@Override
// 			public Actor create() throws Exception {
// 				AbstractAgent agent = (AbstractAgent) Class.forName(settings.AGENT_CLASS)
// 						.getConstructor(Set.class).newInstance(workers);
// 				if (probe != null)
// 					agent.injectProbe(probe);
// 				return agent;
// 			}
// 		}), settings.AGENT_NAME + agentCount);
// 	}
// 
// 	/**
// 	 * Construct a Scheduler without a probe
// 	 */
// 	public ActorRef createScheduler(ActorSystem system) {
// 		return createScheduler(system, null);
// 	}
// 
// 	/**
// 	 * Create a scheduler component, with an optional probe
// 	 * 
// 	 * @param probe can be null
// 	 */
// 	@SuppressWarnings("serial")
// 	public ActorRef createScheduler(ActorSystem system, final ActorRef probe) {
// 		return system.actorOf(new Props(new UntypedActorFactory() {
// 
// 			@Override
// 			public Actor create() throws Exception {
// 				Class<?> schedulerClass = Class.forName(settings.SCHEDULER_CLASS);
// 				Class<?> backingStoreClass = null;
// 				if (settings.SCHEDULER_BACKING_STORE_CLASS != null)
// 					backingStoreClass = Class.forName(settings.SCHEDULER_BACKING_STORE_CLASS);
// 
// 				@SuppressWarnings("rawtypes")
// 				AbstractScheduler scheduler = (AbstractScheduler) schedulerClass
// 						.getConstructor(Class.class).newInstance(backingStoreClass);
// 				if (probe != null)
// 					scheduler.injectProbe(probe);
// 				return scheduler;
// 			}
// 		}), settings.SCHEDULER_NAME);
// 	}
// 
// 	@Before
// 	public void startActorSystem() {
// 		/*
// 		 * Load configuration specific to this test and fall back to the reference configuration
// 		 */
// 		config = ConfigFactory.load();
// 		config = ConfigFactory.load(getClass().getSimpleName()).withFallback(config);
// 
// 		system = ActorSystem.create("oncue-test", config);
// 		settings = SettingsProvider.SettingsProvider.get(system);
// 		log = Logging.getLogger(system, this);
// 	}
// 
// 	@After
// 	public void stopActorSystem() throws Exception {
// 		system.shutdown();
// 		if (waitForRunningJobs) {
// 			while (!system.isTerminated()) {
// 				log.debug("Waiting for system to shut down...");
// 				Thread.sleep(500);
// 			}
// 		}
// 		log.debug("System shut down");
// 	}
// 
// 	@Before
// 	@After
// 	public void cleanRedis() {
// 		try (RedisConnection redis = new RedisConnection()) {
// 			redis.flushDB();
// 		}
// 	}
// }
// 
// Path: oncue-tests/src/test/java/oncue/tests/workers/TestWorker.java
// public class TestWorker extends AbstractWorker {
// 
// 	@Override
// 	public void doWork(Job job) throws InterruptedException {
// 		processJob();
// 	}
// 
// 	private void processJob() throws InterruptedException {
// 		double progress = 0.0;
// 		for (int i = 0; i < 3; i++) {
// 			progress += 0.25;
// 			Thread.sleep(500);
// 			reportProgress(progress);
// 		}
// 		Thread.sleep(500);
// 	}
// 
// 	@Override
// 	protected void redoWork(Job job) throws Exception {
// 		processJob();
// 	}
// 
// }


import java.util.Arrays;
import java.util.HashSet;
import oncue.common.messages.SimpleMessages.SimpleMessage;
import oncue.tests.base.ActorSystemTest;
import oncue.tests.workers.TestWorker;
import org.junit.Test;
import akka.actor.ActorRef;
import akka.testkit.JavaTestKit;

				// Stop the Agent and associated heartbeat
				system.stop(agent);
				expectNoMsg(settings.AGENT_HEARTBEAT_FREQUENCY);
			}
		};
	}

	/**
	 * When an agent dies, it should eventually be de-registered from the
	 * scheduler.
	 */
	@Test
	public void agentDies() {
		new JavaTestKit(system) {
			{
				// Ignore everything except heartbeats and dead agents
				new IgnoreMsg() {
					protected boolean ignore(Object message) {
						if (message.equals(SimpleMessage.AGENT_HEARTBEAT) || message.equals(SimpleMessage.AGENT_DEAD))
							return false;
						else
							return true;
					}
				};

				// Create a scheduler with a probe
				createScheduler(system, getRef());

				// Create an agent
// Path: oncue-common/src/main/java/oncue/common/messages/SimpleMessages.java
// public enum SimpleMessage {
// 	AGENT_HEARTBEAT, AGENT_REGISTERED, AGENT_SHUTDOWN, AGENT_DEAD, LIST_AGENTS, CHECK_AGENTS, SCHEDULE_JOBS, JOB_SUMMARY, BROADCAST_JOBS
// }
// 
// Path: oncue-tests/src/test/java/oncue/tests/base/ActorSystemTest.java
// public abstract class ActorSystemTest {
// 
// 	protected Config config;
// 
// 	protected LoggingAdapter log;
// 
// 	protected Settings settings;
// 
// 	protected ActorSystem system;
// 
// 	// By default ActorSystemTest children will wait for all actors to finish before shutting down
// 	// the test system. If you want to shut down the test system while e.g. workers are still
// 	// running, set this to false.
// 	protected boolean waitForRunningJobs = true;
// 
// 	// Required for naming agents uniquely
// 	private int agentCount = 0;
// 
// 	/**
// 	 * Construct a Agent without a probe
// 	 */
// 	public ActorRef createAgent(ActorSystem system, final Set<String> workers) {
// 		return createAgent(system, workers, null);
// 	}
// 
// 	/**
// 	 * Create an agent component, with a set of workers and an optional probe
// 	 * 
// 	 * @param probe can be null
// 	 */
// 	@SuppressWarnings("serial")
// 	public ActorRef createAgent(ActorSystem system, final Set<String> workers,
// 			final ActorRef probe) {
// 		agentCount++;
// 		return system.actorOf(new Props(new UntypedActorFactory() {
// 
// 			@Override
// 			public Actor create() throws Exception {
// 				AbstractAgent agent = (AbstractAgent) Class.forName(settings.AGENT_CLASS)
// 						.getConstructor(Set.class).newInstance(workers);
// 				if (probe != null)
// 					agent.injectProbe(probe);
// 				return agent;
// 			}
// 		}), settings.AGENT_NAME + agentCount);
// 	}
// 
// 	/**
// 	 * Construct a Scheduler without a probe
// 	 */
// 	public ActorRef createScheduler(ActorSystem system) {
// 		return createScheduler(system, null);
// 	}
// 
// 	/**
// 	 * Create a scheduler component, with an optional probe
// 	 * 
// 	 * @param probe can be null
// 	 */
// 	@SuppressWarnings("serial")
// 	public ActorRef createScheduler(ActorSystem system, final ActorRef probe) {
// 		return system.actorOf(new Props(new UntypedActorFactory() {
// 
// 			@Override
// 			public Actor create() throws Exception {
// 				Class<?> schedulerClass = Class.forName(settings.SCHEDULER_CLASS);
// 				Class<?> backingStoreClass = null;
// 				if (settings.SCHEDULER_BACKING_STORE_CLASS != null)
// 					backingStoreClass = Class.forName(settings.SCHEDULER_BACKING_STORE_CLASS);
// 
// 				@SuppressWarnings("rawtypes")
// 				AbstractScheduler scheduler = (AbstractScheduler) schedulerClass
// 						.getConstructor(Class.class).newInstance(backingStoreClass);
// 				if (probe != null)
// 					scheduler.injectProbe(probe);
// 				return scheduler;
// 			}
// 		}), settings.SCHEDULER_NAME);
// 	}
// 
// 	@Before
// 	public void startActorSystem() {
// 		/*
// 		 * Load configuration specific to this test and fall back to the reference configuration
// 		 */
// 		config = ConfigFactory.load();
// 		config = ConfigFactory.load(getClass().getSimpleName()).withFallback(config);
// 
// 		system = ActorSystem.create("oncue-test", config);
// 		settings = SettingsProvider.SettingsProvider.get(system);
// 		log = Logging.getLogger(system, this);
// 	}
// 
// 	@After
// 	public void stopActorSystem() throws Exception {
// 		system.shutdown();
// 		if (waitForRunningJobs) {
// 			while (!system.isTerminated()) {
// 				log.debug("Waiting for system to shut down...");
// 				Thread.sleep(500);
// 			}
// 		}
// 		log.debug("System shut down");
// 	}
// 
// 	@Before
// 	@After
// 	public void cleanRedis() {
// 		try (RedisConnection redis = new RedisConnection()) {
// 			redis.flushDB();
// 		}
// 	}
// }
// 
// Path: oncue-tests/src/test/java/oncue/tests/workers/TestWorker.java
// public class TestWorker extends AbstractWorker {
// 
// 	@Override
// 	public void doWork(Job job) throws InterruptedException {
// 		processJob();
// 	}
// 
// 	private void processJob() throws InterruptedException {
// 		double progress = 0.0;
// 		for (int i = 0; i < 3; i++) {
// 			progress += 0.25;
// 			Thread.sleep(500);
// 			reportProgress(progress);
// 		}
// 		Thread.sleep(500);
// 	}
// 
// 	@Override
// 	protected void redoWork(Job job) throws Exception {
// 		processJob();
// 	}
// 
// }


// Path: oncue-tests/src/test/java/oncue/tests/AgentPresenceTest.java
import java.util.Arrays;
import java.util.HashSet;
import oncue.common.messages.SimpleMessages.SimpleMessage;
import oncue.tests.base.ActorSystemTest;
import oncue.tests.workers.TestWorker;
import org.junit.Test;
import akka.actor.ActorRef;
import akka.testkit.JavaTestKit;


				// Stop the Agent and associated heartbeat
				system.stop(agent);
				expectNoMsg(settings.AGENT_HEARTBEAT_FREQUENCY);
			}
		};
	}

	/**
	 * When an agent dies, it should eventually be de-registered from the
	 * scheduler.
	 */
	@Test
	public void agentDies() {
		new JavaTestKit(system) {
			{
				// Ignore everything except heartbeats and dead agents
				new IgnoreMsg() {
					protected boolean ignore(Object message) {
						if (message.equals(SimpleMessage.AGENT_HEARTBEAT) || message.equals(SimpleMessage.AGENT_DEAD))
							return false;
						else
							return true;
					}
				};

				// Create a scheduler with a probe
				createScheduler(system, getRef());

				// Create an agent
				ActorRef agent = createAgent(system, new HashSet<String>(Arrays.asList(TestWorker.class.getName())),