package org.deeplearning4j.scaleout.actor;

import static org.junit.Assert.*;

import akka.actor.ActorSystem;
import akka.actor.Props;
import org.deeplearning4j.scaleout.actor.core.actor.WorkerActor;
import org.deeplearning4j.scaleout.conf.Configuration;
import org.deeplearning4j.scaleout.conf.DeepLearningConfigurable;
import org.deeplearning4j.scaleout.job.Job;
import org.deeplearning4j.scaleout.api.statetracker.StateTracker;
import org.deeplearning4j.scaleout.statetracker.hazelcast.HazelCastStateTracker;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * Created by agibsonccc on 11/27/14.
 */
public class WorkerActorTest implements DeepLearningConfigurable {

    private StateTracker stateTracker;
    private ActorSystem testSystem;
    private Props test;
    private Configuration conf;
    private TestPerformer testPerformer;

    @Before
    public void before() throws Exception {
        stateTracker = new HazelCastStateTracker();
        if(testSystem == null)
            testSystem = ActorSystem.create();
        conf = new Configuration();
        testPerformer = new TestPerformer();
        test = WorkerActor.propsFor(conf, stateTracker,testPerformer);


    }

    @After
    public void after() {
        if(stateTracker != null) {
            stateTracker.finish();
            stateTracker.shutdown();
        }
        if(testSystem != null)
            testSystem.shutdown();
    }


    @Test
    public void testActor() throws Exception {
        testSystem.actorOf(test);
        Thread.sleep(10000);
        assertTrue(!stateTracker.workers().isEmpty());
        String id = stateTracker.workers().get(0);
        Job testJob = new Job("hello",id);
        stateTracker.addJobToCurrent(testJob);
        while(!testPerformer.isPerformCalled()) {
            Thread.sleep(10000);
        }



    }


    @Override
    public void setup(Configuration conf) {

    }
}

@@ -128,16 +128,53 @@
 .Props;%0A
+import com.hazelcast.core.Hazelcast;%0A
 import o
@@ -1465,24 +1465,57 @@
 shutdown();%0A
+        Hazelcast.shutdownAll();%0A
     %7D%0A%0A%0A    

fix drop wizard resource shutdown