You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iota.apache.org by to...@apache.org on 2016/07/18 20:43:24 UTC

[01/12] incubator-iota git commit: Adding test dependencies

Repository: incubator-iota
Updated Branches:
  refs/heads/master ae1e9461f -> b7dd7961e


Adding test dependencies


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/7203d6d5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/7203d6d5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/7203d6d5

Branch: refs/heads/master
Commit: 7203d6d5aaa287dfbadfb776019fcb89a62e17d4
Parents: ae1e946
Author: Barbara Gomes <ba...@gmail.com>
Authored: Thu Jul 14 19:34:05 2016 -0700
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Thu Jul 14 19:34:05 2016 -0700

----------------------------------------------------------------------
 project/Build.scala        | 2 +-
 project/Dependencies.scala | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/7203d6d5/project/Build.scala
----------------------------------------------------------------------
diff --git a/project/Build.scala b/project/Build.scala
index 3dc2706..8bff270 100644
--- a/project/Build.scala
+++ b/project/Build.scala
@@ -22,7 +22,7 @@ object ModuleDependencies {
 
   import Dependencies._
   val FeyDependencies           = compile(akka_actor,typesafe_config,playJson,slf4j,log4jbind,sprayCan,
-                                            sprayRouting,jsonValidator,javaFilter,codec,apacheIO)
+                                            sprayRouting,jsonValidator,javaFilter,codec,apacheIO) ++ test(akka_testkit, scala_test)
   val StreamDependencies        = provided(akka_actor, fey)
   val ZMQDependencies           = provided(akka_actor,  fey) ++ compile(zmq)
   val VirtualSensorDependencies = provided(akka_actor,  fey) ++ compile(math3)

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/7203d6d5/project/Dependencies.scala
----------------------------------------------------------------------
diff --git a/project/Dependencies.scala b/project/Dependencies.scala
index e46381f..49c9e3d 100644
--- a/project/Dependencies.scala
+++ b/project/Dependencies.scala
@@ -44,5 +44,8 @@ object Dependencies {
   val sprayCan        = "io.spray"            %%  "spray-can"                 % "1.3.3"
   val sprayRouting    = "io.spray"            %%  "spray-routing"             % "1.3.3"
 
+  //Tests
+  val akka_testkit    = "com.typesafe.akka"   %% "akka-testkit"               % "2.4.2"
+  val scala_test      = "org.scalatest"       %% "scalatest"                   % "3.0.0-RC4"
 
 }


[06/12] incubator-iota git commit: FeyCore.scala tests

Posted by to...@apache.org.
FeyCore.scala tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/0ced6757
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/0ced6757
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/0ced6757

Branch: refs/heads/master
Commit: 0ced67579ba2bc4df507bc785ac3b60289d54dcb
Parents: 2d51565
Author: Barbara Gomes <ba...@gmail.com>
Authored: Fri Jul 15 17:17:24 2016 -0700
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Fri Jul 15 17:17:24 2016 -0700

----------------------------------------------------------------------
 .../org/apache/iota/fey/BaseAkkaSpec.scala      |  3 +-
 .../scala/org/apache/iota/fey/FeyCoreSpec.scala | 28 +++++++++++----
 .../org/apache/iota/fey/Utils_JSONTest.scala    | 36 ++++++++++++++++++++
 3 files changed, 60 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/0ced6757/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala
index b650e88..673538e 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala
@@ -24,6 +24,7 @@ import java.nio.file.Paths
 import akka.actor.{ActorIdentity, ActorRef, ActorSystem, Identify}
 import akka.testkit.{EventFilter, TestActorRef, TestEvent, TestProbe}
 import akka.util.Timeout
+import com.typesafe.config.ConfigFactory
 import org.apache.commons.io.FileUtils
 import org.scalatest.BeforeAndAfterAll
 import play.api.libs.json._
@@ -38,7 +39,7 @@ class BaseAkkaSpec extends BaseSpec with BeforeAndAfterAll{
   CONFIG.loadUserConfiguration(Paths.get(conf.toURI()).toFile().getAbsolutePath)
   copyTestActorToTmp()
 
-  implicit val system = ActorSystem()
+  implicit val system = ActorSystem("FEY-TEST", ConfigFactory.parseString("""akka.loggers = ["akka.testkit.TestEventListener"]"""))
   system.eventStream.publish(TestEvent.Mute(EventFilter.debug()))
   system.eventStream.publish(TestEvent.Mute(EventFilter.info()))
   system.eventStream.publish(TestEvent.Mute(EventFilter.warning()))

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/0ced6757/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
index 411ce24..9fa3299 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
@@ -21,9 +21,9 @@ package org.apache.iota.fey
 import java.io.File
 
 import akka.actor.{ActorRef, PoisonPill, Props}
-import akka.testkit.{EventFilter, TestActorRef, TestProbe}
+import akka.testkit.{EventFilter, TestProbe}
 
-import scala.concurrent.duration.{DurationInt, FiniteDuration}
+import scala.concurrent.duration.DurationInt
 
 class FeyCoreSpec extends BaseAkkaSpec  {
 
@@ -59,9 +59,9 @@ class FeyCoreSpec extends BaseAkkaSpec  {
   var ensemble2Test1ref:ActorRef = _
   var orchestrationref:ActorRef = _
 
+  val orchestration_name = "TEST-ACTOR"
 
   "Sending FeyCore.ORCHESTRATION_RECEIVED with CREATE command to FeyCore" should {
-    val orchestration_name = "TEST-ACTOR"
     feyCoreRef ! FeyCore.ORCHESTRATION_RECEIVED(getJSValueFromString(Utils_JSONTest.create_json_test), new File("/tmp/fey/test/json"))
     s"result in creating an Orchestration child actor with the name '$orchestration_name'" in {
       orchestrationref = TestProbe().expectActor(s"$feyPath/$orchestration_name")
@@ -84,7 +84,6 @@ class FeyCoreSpec extends BaseAkkaSpec  {
   }
 
   "Sending FeyCore.ORCHESTRATION_RECEIVED with UPDATE command to FeyCore" should {
-    val orchestration_name = "TEST-ACTOR"
     s"result in creating a new Performer child actor with the name '$orchestration_name/MY-ENSEMBLE-0001/TEST-0002'" in {
       feyCoreRef ! FeyCore.ORCHESTRATION_RECEIVED(getJSValueFromString(Utils_JSONTest.update_json_test), new File("/tmp/fey/test/json"))
       ensemble1Test2ref = TestProbe().expectActor(s"$feyPath/$orchestration_name/MY-ENSEMBLE-0001/TEST-0002")
@@ -92,7 +91,6 @@ class FeyCoreSpec extends BaseAkkaSpec  {
   }
 
   "Sending FeyCore.ORCHESTRATION_RECEIVED with UPDATE command and DELETE ensemble to FeyCore" should {
-    val orchestration_name = "TEST-ACTOR"
     s"result in termination of Ensemble with the name '$orchestration_name/MY-ENSEMBLE-0001'" in {
       feyCoreRef ! FeyCore.ORCHESTRATION_RECEIVED(getJSValueFromString(Utils_JSONTest.update_delete_json_test), new File("/tmp/fey/test/json"))
       TestProbe().verifyActorTermination(ensemble1ref)
@@ -105,8 +103,23 @@ class FeyCoreSpec extends BaseAkkaSpec  {
     }
   }
 
+  "Sending FeyCore.ORCHESTRATION_RECEIVED with RECREATE command and same Timestamp to FeyCore" should {
+    s"result in logging a 'not recreated' message at Warn " in {
+      EventFilter.warning(pattern = s".*$orchestration_name not recreated.*", occurrences = 1) intercept {
+        feyCoreRef ! FeyCore.ORCHESTRATION_RECEIVED(getJSValueFromString(Utils_JSONTest.recreate_timestamp_json_test), new File("/tmp/fey/test/json"))
+      }
+    }
+  }
+
+  "Sending FeyCore.JSON_TREE to FeyCore" should {
+    s"result in logging a 6 path messages at Info " in {
+      EventFilter.info(pattern = s"^akka://.*/user/.*", occurrences = 6) intercept {
+        feyCoreRef ! FeyCore.JSON_TREE
+      }
+    }
+  }
+
   "Sending FeyCore.ORCHESTRATION_RECEIVED with DELETE command to FeyCore" should {
-    val orchestration_name = "TEST-ACTOR"
     s"result in termination of Orchestration with the name '$orchestration_name'" in {
       feyCoreRef ! FeyCore.ORCHESTRATION_RECEIVED(getJSValueFromString(Utils_JSONTest.delete_json_test), new File("/tmp/fey/test/json"))
       TestProbe().verifyActorTermination(orchestrationref)
@@ -120,6 +133,9 @@ class FeyCoreSpec extends BaseAkkaSpec  {
     s"result in termination of Performer with the name '$orchestration_name/MY-ENSEMBLE-0002/TEST-0001'" in {
       TestProbe().notExpectActor(ensemble2Test1ref.path.toString)
     }
+    s"result in removing key '$orchestration_name' at FEY_CACHE.activeOrchestrations" in {
+      FEY_CACHE.activeOrchestrations should not contain key(orchestration_name)
+    }
   }
 
   "Stopping FeyCore" should {

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/0ced6757/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala b/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
index 3c873dc..e65aafc 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
@@ -147,5 +147,41 @@ object Utils_JSONTest {
        "ensembles" : []
      }"""
 
+  val recreate_timestamp_json_test =
+    """{
+       "guid" : "TEST-ACTOR",
+       "command" : "RECREATE",
+       "timestamp": "213263914979",
+       "name" : "ORCHESTRATION FOR TEST",
+       "ensembles" : [
+         {
+           "guid":"MY-ENSEMBLE-0001",
+           "command": "DELETE",
+           "performers":[
+             {
+               "guid": "TEST-0001",
+               "schedule": 0,
+               "backoff": 0,
+               "source": {
+                 "name": "fey-test-actor.jar",
+                 "classPath": "org.apache.iota.fey.TestActor",
+                 "parameters": {}
+               }
+             },
+             {
+                "guid": "TEST-0002",
+                "schedule": 0,
+                "backoff": 0,
+                "source": {
+                  "name": "fey-test-actor.jar",
+                  "classPath": "org.apache.iota.fey.TestActor",
+                  "parameters": {}
+                }
+              }
+           ],
+           "connections":[]
+         }
+       ]
+     }"""
 
 }


[11/12] incubator-iota git commit: Updating FeyGenericActor test

Posted by to...@apache.org.
Updating FeyGenericActor test


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/555550a1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/555550a1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/555550a1

Branch: refs/heads/master
Commit: 555550a12b13a8098af464851b981f3bf8275817
Parents: ad056da
Author: Barbara Gomes <ba...@gmail.com>
Authored: Mon Jul 18 13:30:37 2016 -0700
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Mon Jul 18 13:30:37 2016 -0700

----------------------------------------------------------------------
 fey-core/src/test/resources/fey-test-actor.jar | Bin 7134 -> 7579 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/555550a1/fey-core/src/test/resources/fey-test-actor.jar
----------------------------------------------------------------------
diff --git a/fey-core/src/test/resources/fey-test-actor.jar b/fey-core/src/test/resources/fey-test-actor.jar
index 8417f0d..385a9b9 100644
Binary files a/fey-core/src/test/resources/fey-test-actor.jar and b/fey-core/src/test/resources/fey-test-actor.jar differ


[05/12] incubator-iota git commit: First draft of testing

Posted by to...@apache.org.
First draft of testing

- Basic TestSpec
- FeyCore test


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/2d515650
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/2d515650
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/2d515650

Branch: refs/heads/master
Commit: 2d515650b0de0c7cbb54f2a4c05c8f5d6bd50746
Parents: f850688
Author: Barbara Gomes <ba...@gmail.com>
Authored: Fri Jul 15 16:23:39 2016 -0700
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Fri Jul 15 16:23:39 2016 -0700

----------------------------------------------------------------------
 fey-core/src/test/resources/fey-test-actor.jar  | Bin 0 -> 7134 bytes
 .../test/resources/test-fey-configuration.conf  |  36 +++++
 .../org/apache/iota/fey/BaseAkkaSpec.scala      | 123 +++++++++++++++
 .../scala/org/apache/iota/fey/BaseSpec.scala    |  24 +++
 .../scala/org/apache/iota/fey/FeyCoreSpec.scala | 131 ++++++++++++++++
 .../org/apache/iota/fey/Utils_JSONTest.scala    | 151 +++++++++++++++++++
 6 files changed, 465 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/2d515650/fey-core/src/test/resources/fey-test-actor.jar
----------------------------------------------------------------------
diff --git a/fey-core/src/test/resources/fey-test-actor.jar b/fey-core/src/test/resources/fey-test-actor.jar
new file mode 100644
index 0000000..8417f0d
Binary files /dev/null and b/fey-core/src/test/resources/fey-test-actor.jar differ

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/2d515650/fey-core/src/test/resources/test-fey-configuration.conf
----------------------------------------------------------------------
diff --git a/fey-core/src/test/resources/test-fey-configuration.conf b/fey-core/src/test/resources/test-fey-configuration.conf
new file mode 100644
index 0000000..d575eda
--- /dev/null
+++ b/fey-core/src/test/resources/test-fey-configuration.conf
@@ -0,0 +1,36 @@
+
+//
+//Licensed to the Apache Software Foundation (ASF) under one or more
+//contributor license agreements.  See the NOTICE file distributed with
+//this work for additional information regarding copyright ownership.
+//The ASF licenses this file to You under the Apache License, Version 2.0
+//(the "License"); you may not use this file except in compliance with
+//the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+//Unless required by applicable law or agreed to in writing, software
+//distributed under the License is distributed on an "AS IS" BASIS,
+//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//See the License for the specific language governing permissions and
+//limitations under the License.
+//
+
+fey-global-configuration {
+
+  enable-checkpoint = false
+
+  checkpoint-directory = "/tmp/fey/test/checkpoint"
+  json-repository = "/tmp/fey/test/json"
+  json-extension = ".json.test"
+  jar-repository = "/tmp/fey/test/jars"
+  dynamic-jar-population {
+    downloaded-repository = "/tmp/fey/test/jars/dynamic"
+    force-pull = false
+  }
+  log-level = "ERROR"
+  log-appender = "STDOUT"
+  auto-scale{
+    messages-per-resize = 500
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/2d515650/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala
new file mode 100644
index 0000000..b650e88
--- /dev/null
+++ b/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala
@@ -0,0 +1,123 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.iota.fey
+
+import java.io.File
+import java.nio.file.Paths
+
+import akka.actor.{ActorIdentity, ActorRef, ActorSystem, Identify}
+import akka.testkit.{EventFilter, TestActorRef, TestEvent, TestProbe}
+import akka.util.Timeout
+import org.apache.commons.io.FileUtils
+import org.scalatest.BeforeAndAfterAll
+import play.api.libs.json._
+
+import scala.concurrent.duration.{DurationInt, FiniteDuration}
+import scala.concurrent.Await
+
+class BaseAkkaSpec extends BaseSpec with BeforeAndAfterAll{
+
+  createFeyTmpDirectoriesForTest()
+  val conf = getClass.getResource("/test-fey-configuration.conf")
+  CONFIG.loadUserConfiguration(Paths.get(conf.toURI()).toFile().getAbsolutePath)
+  copyTestActorToTmp()
+
+  implicit val system = ActorSystem()
+  system.eventStream.publish(TestEvent.Mute(EventFilter.debug()))
+  system.eventStream.publish(TestEvent.Mute(EventFilter.info()))
+  system.eventStream.publish(TestEvent.Mute(EventFilter.warning()))
+  system.eventStream.publish(TestEvent.Mute(EventFilter.error()))
+
+  override protected def afterAll(): Unit = {
+    Await.ready(system.terminate(), 20.seconds)
+  }
+
+  private def copyTestActorToTmp(): Unit = {
+    val jarTest = getClass.getResource("/fey-test-actor.jar")
+    val dest = new File(s"${CONFIG.JAR_REPOSITORY}/fey-test-actor.jar")
+    FileUtils.copyURLToFile(jarTest, dest)
+  }
+
+  private def createFeyTmpDirectoriesForTest(): Unit = {
+    var file = new File(s"/tmp/fey/test/checkpoint")
+    file.mkdirs()
+    file = new File(s"/tmp/fey/test/json")
+    file.mkdirs()
+    file = new File(s"/tmp/fey/test/jars")
+    file.mkdirs()
+    file = new File(s"/tmp/fey/test/jars/dynamic")
+    file.mkdirs()
+  }
+
+  implicit class TestProbeOps(probe: TestProbe) {
+
+    def expectActor(path: String, max: FiniteDuration = 3.seconds): ActorRef = {
+      probe.within(max) {
+        var actor = null: ActorRef
+        probe.awaitAssert {
+          (probe.system actorSelection path).tell(Identify(path), probe.ref)
+          probe.expectMsgPF(100 milliseconds) {
+            case ActorIdentity(`path`, Some(ref)) => actor = ref
+          }
+        }
+        actor
+      }
+    }
+
+    def verifyActorTermination(actor: ActorRef)(implicit system: ActorSystem): Unit = {
+      val watcher = TestProbe()
+      watcher.watch(actor)
+      watcher.expectTerminated(actor)
+    }
+
+    def notExpectActor(path: String, max: FiniteDuration = 3.seconds): Unit = {
+      probe.within(max) {
+        probe.awaitAssert {
+          (probe.system actorSelection path).tell(Identify(path), probe.ref)
+          probe.expectMsgPF(100 milliseconds) {
+            case ActorIdentity(`path`, None) =>
+          }
+        }
+      }
+    }
+
+    def isThreadRunning(threadName: String): Boolean = {
+      Thread.getAllStackTraces.keySet().toArray
+        .map(_.asInstanceOf[Thread])
+        .find(_.getName == threadName) match {
+        case Some(thread) =>
+          if(thread.isAlive) true else false
+        case None => false
+      }
+    }
+  }
+
+  //Utils Functions
+  def getJSValueFromString(json: String): JsValue = {
+    Json.parse(json)
+  }
+
+  def getActorRefFromPath(path: String, timeout: Timeout = 2.seconds): ActorRef = {
+    Await.result(
+      system.actorSelection("akka.tcp://REMOTE@192.168.0.136:2552/user/Testing")
+        .resolveOne()(timeout), 5.seconds)
+  }
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/2d515650/fey-core/src/test/scala/org/apache/iota/fey/BaseSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/BaseSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/BaseSpec.scala
new file mode 100644
index 0000000..8e7c025
--- /dev/null
+++ b/fey-core/src/test/scala/org/apache/iota/fey/BaseSpec.scala
@@ -0,0 +1,24 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.iota.fey
+
+import org.scalactic.TypeCheckedTripleEquals
+import org.scalatest._
+
+abstract class BaseSpec extends WordSpec with Matchers with TypeCheckedTripleEquals with Inspectors
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/2d515650/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
new file mode 100644
index 0000000..411ce24
--- /dev/null
+++ b/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
@@ -0,0 +1,131 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.iota.fey
+
+import java.io.File
+
+import akka.actor.{ActorRef, PoisonPill, Props}
+import akka.testkit.{EventFilter, TestActorRef, TestProbe}
+
+import scala.concurrent.duration.{DurationInt, FiniteDuration}
+
+class FeyCoreSpec extends BaseAkkaSpec  {
+
+  val monitor = TestProbe()
+  val feyCoreRef = system.actorOf(Props(new FeyCore{
+    override val monitoring_actor = monitor.ref
+  }), "FEY-CORE")
+
+  val feyPath = feyCoreRef.path.toString
+
+  "Creating FeyCore" should {
+    s"result in creating a child actor with the name '${FeyCore.IDENTIFIER_NAME}'" in {
+      TestProbe().expectActor(s"/user/FEY-CORE/${FeyCore.IDENTIFIER_NAME}")
+    }
+    "result in sending START message to Monitor actor" in {
+      monitor.expectMsgClass(1.seconds, classOf[Monitor.START])
+    }
+  }
+
+  "Sending FeyCore.START to FeyCore" should {
+    s"result in creating a child actor with the name '${FeyCore.JSON_RECEIVER_NAME}'" in {
+      feyCoreRef ! FeyCore.START
+      TestProbe().expectActor(s"$feyPath/${FeyCore.JSON_RECEIVER_NAME}")
+    }
+    s"result in starting ${GLOBAL_DEFINITIONS.WATCH_SERVICE_THREAD} Thread" in {
+      TestProbe().isThreadRunning(GLOBAL_DEFINITIONS.WATCH_SERVICE_THREAD) should equal(true)
+    }
+  }
+  var ensemble1ref:ActorRef = _
+  var ensemble2ref:ActorRef = _
+  var ensemble1Test1ref:ActorRef = _
+  var ensemble1Test2ref:ActorRef = _
+  var ensemble2Test1ref:ActorRef = _
+  var orchestrationref:ActorRef = _
+
+
+  "Sending FeyCore.ORCHESTRATION_RECEIVED with CREATE command to FeyCore" should {
+    val orchestration_name = "TEST-ACTOR"
+    feyCoreRef ! FeyCore.ORCHESTRATION_RECEIVED(getJSValueFromString(Utils_JSONTest.create_json_test), new File("/tmp/fey/test/json"))
+    s"result in creating an Orchestration child actor with the name '$orchestration_name'" in {
+      orchestrationref = TestProbe().expectActor(s"$feyPath/$orchestration_name")
+    }
+    s"result in creating an Ensemble child actor with the name '$orchestration_name/MY-ENSEMBLE-0001'" in {
+      ensemble1ref = TestProbe().expectActor(s"$feyPath/$orchestration_name/MY-ENSEMBLE-0001")
+    }
+    s"result in creating an Ensemble child actor with the name '$orchestration_name/MY-ENSEMBLE-0002'" in {
+      ensemble2ref = TestProbe().expectActor(s"$feyPath/$orchestration_name/MY-ENSEMBLE-0002")
+    }
+    s"result in creating a Performer child actor with the name '$orchestration_name/MY-ENSEMBLE-0001/TEST-0001'" in {
+      ensemble1Test1ref = TestProbe().expectActor(s"$feyPath/$orchestration_name/MY-ENSEMBLE-0001/TEST-0001")
+    }
+    s"result in creating a Performer child actor with the name '$orchestration_name/MY-ENSEMBLE-0002/TEST-0001'" in {
+      ensemble2Test1ref = TestProbe().expectActor(s"$feyPath/$orchestration_name/MY-ENSEMBLE-0002/TEST-0001")
+    }
+    s"result in new entry to FEY_CACHE.activeOrchestrations with key '$orchestration_name'" in {
+      FEY_CACHE.activeOrchestrations should contain key(orchestration_name)
+    }
+  }
+
+  "Sending FeyCore.ORCHESTRATION_RECEIVED with UPDATE command to FeyCore" should {
+    val orchestration_name = "TEST-ACTOR"
+    s"result in creating a new Performer child actor with the name '$orchestration_name/MY-ENSEMBLE-0001/TEST-0002'" in {
+      feyCoreRef ! FeyCore.ORCHESTRATION_RECEIVED(getJSValueFromString(Utils_JSONTest.update_json_test), new File("/tmp/fey/test/json"))
+      ensemble1Test2ref = TestProbe().expectActor(s"$feyPath/$orchestration_name/MY-ENSEMBLE-0001/TEST-0002")
+    }
+  }
+
+  "Sending FeyCore.ORCHESTRATION_RECEIVED with UPDATE command and DELETE ensemble to FeyCore" should {
+    val orchestration_name = "TEST-ACTOR"
+    s"result in termination of Ensemble with the name '$orchestration_name/MY-ENSEMBLE-0001'" in {
+      feyCoreRef ! FeyCore.ORCHESTRATION_RECEIVED(getJSValueFromString(Utils_JSONTest.update_delete_json_test), new File("/tmp/fey/test/json"))
+      TestProbe().verifyActorTermination(ensemble1ref)
+    }
+    s"result in termination of Performer with the name '$orchestration_name/MY-ENSEMBLE-0001/TEST-0001'" in {
+      TestProbe().notExpectActor(ensemble1Test1ref.path.toString)
+    }
+    s"result in termination of Performer with the name '$orchestration_name/MY-ENSEMBLE-0001/TEST-0002'" in {
+      TestProbe().notExpectActor(ensemble1Test2ref.path.toString)
+    }
+  }
+
+  "Sending FeyCore.ORCHESTRATION_RECEIVED with DELETE command to FeyCore" should {
+    val orchestration_name = "TEST-ACTOR"
+    s"result in termination of Orchestration with the name '$orchestration_name'" in {
+      feyCoreRef ! FeyCore.ORCHESTRATION_RECEIVED(getJSValueFromString(Utils_JSONTest.delete_json_test), new File("/tmp/fey/test/json"))
+      TestProbe().verifyActorTermination(orchestrationref)
+    }
+    "result in sending TERMINATE message to Monitor actor" in {
+      monitor.expectMsgClass(1.seconds, classOf[Monitor.TERMINATE])
+    }
+    s"result in termination of Ensemble with the name '$orchestration_name/MY-ENSEMBLE-0002'" in {
+      TestProbe().notExpectActor(ensemble2ref.path.toString)
+    }
+    s"result in termination of Performer with the name '$orchestration_name/MY-ENSEMBLE-0002/TEST-0001'" in {
+      TestProbe().notExpectActor(ensemble2Test1ref.path.toString)
+    }
+  }
+
+  "Stopping FeyCore" should {
+    "result in sending STOP message to Monitor actor" in {
+      feyCoreRef ! PoisonPill
+      monitor.expectMsgClass(1.seconds, classOf[Monitor.STOP])
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/2d515650/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala b/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
new file mode 100644
index 0000000..3c873dc
--- /dev/null
+++ b/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
@@ -0,0 +1,151 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.iota.fey
+
+object Utils_JSONTest {
+
+  val create_json_test =
+    """{
+       "guid" : "TEST-ACTOR",
+       "command" : "CREATE",
+       "timestamp": "213263914979",
+       "name" : "ORCHESTRATION FOR TEST",
+       "ensembles" : [
+         {
+           "guid":"MY-ENSEMBLE-0001",
+           "command": "NONE",
+           "performers":[
+             {
+               "guid": "TEST-0001",
+               "schedule": 0,
+               "backoff": 0,
+               "source": {
+                 "name": "fey-test-actor.jar",
+                 "classPath": "org.apache.iota.fey.TestActor",
+                 "parameters": {}
+               }
+             }
+           ],
+           "connections":[]
+         },
+         {
+            "guid":"MY-ENSEMBLE-0002",
+            "command": "NONE",
+            "performers":[
+              {
+                "guid": "TEST-0001",
+                "schedule": 0,
+                "backoff": 0,
+                "source": {
+                  "name": "fey-test-actor.jar",
+                  "classPath": "org.apache.iota.fey.TestActor",
+                  "parameters": {}
+                }
+              }
+            ],
+            "connections":[]
+          }
+       ]
+     }"""
+
+  val update_json_test =
+    """{
+       "guid" : "TEST-ACTOR",
+       "command" : "UPDATE",
+       "timestamp": "213263914979",
+       "name" : "ORCHESTRATION FOR TEST",
+       "ensembles" : [
+         {
+           "guid":"MY-ENSEMBLE-0001",
+           "command": "UPDATE",
+           "performers":[
+             {
+               "guid": "TEST-0001",
+               "schedule": 0,
+               "backoff": 0,
+               "source": {
+                 "name": "fey-test-actor.jar",
+                 "classPath": "org.apache.iota.fey.TestActor",
+                 "parameters": {}
+               }
+             },
+             {
+                "guid": "TEST-0002",
+                "schedule": 0,
+                "backoff": 0,
+                "source": {
+                  "name": "fey-test-actor.jar",
+                  "classPath": "org.apache.iota.fey.TestActor",
+                  "parameters": {}
+                }
+              }
+           ],
+           "connections":[]
+         }
+       ]
+     }"""
+
+  val update_delete_json_test =
+    """{
+       "guid" : "TEST-ACTOR",
+       "command" : "UPDATE",
+       "timestamp": "213263914979",
+       "name" : "ORCHESTRATION FOR TEST",
+       "ensembles" : [
+         {
+           "guid":"MY-ENSEMBLE-0001",
+           "command": "DELETE",
+           "performers":[
+             {
+               "guid": "TEST-0001",
+               "schedule": 0,
+               "backoff": 0,
+               "source": {
+                 "name": "fey-test-actor.jar",
+                 "classPath": "org.apache.iota.fey.TestActor",
+                 "parameters": {}
+               }
+             },
+             {
+                "guid": "TEST-0002",
+                "schedule": 0,
+                "backoff": 0,
+                "source": {
+                  "name": "fey-test-actor.jar",
+                  "classPath": "org.apache.iota.fey.TestActor",
+                  "parameters": {}
+                }
+              }
+           ],
+           "connections":[]
+         }
+       ]
+     }"""
+
+  val delete_json_test =
+    """{
+       "guid" : "TEST-ACTOR",
+       "command" : "DELETE",
+       "timestamp": "213263914979",
+       "name" : "ORCHESTRATION FOR TEST",
+       "ensembles" : []
+     }"""
+
+
+}


[09/12] incubator-iota git commit: Adding tests to Orchestration

Posted by to...@apache.org.
Adding tests to Orchestration


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/47a69e84
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/47a69e84
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/47a69e84

Branch: refs/heads/master
Commit: 47a69e845d8b100fc75d84ff87ffbbf8d209675f
Parents: 8722e87
Author: Barbara Gomes <ba...@gmail.com>
Authored: Sat Jul 16 11:59:39 2016 -0700
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Sat Jul 16 11:59:39 2016 -0700

----------------------------------------------------------------------
 .../org/apache/iota/fey/Orchestration.scala     |   8 +-
 .../scala/org/apache/iota/fey/FeyCoreSpec.scala |   4 +
 .../apache/iota/fey/IdentifyFeyActorsSpec.scala |   6 +-
 .../org/apache/iota/fey/OrchestrationSpec.scala | 239 +++++++++++++++++++
 .../org/apache/iota/fey/Utils_JSONTest.scala    |  83 +++++++
 5 files changed, 333 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/47a69e84/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala b/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala
index ad61a37..cb1bcae 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala
@@ -37,7 +37,7 @@ protected class Orchestration(val name: String,
     */
   private val ensembles:HashMap[String, ActorRef] = HashMap.empty[String, ActorRef]
   private val awaitingTermination:HashMap[String, JsObject] = HashMap.empty[String, JsObject]
-  private val monitoring_actor = FEY_MONITOR.actorRef
+  val monitoring_actor = FEY_MONITOR.actorRef
 
   override def receive: Receive = {
 
@@ -55,7 +55,7 @@ protected class Orchestration(val name: String,
       log.warning(s"ACTOR DEAD ${actor.path}")
       ensembles.remove(actor.path.name)
       checkForEnsemblesWaitingTermination(actor.path.name)
-      stopIfNoOrchestrationisRunning()
+      stopIfNoEnsembleIsRunning()
 
     case GetRoutees => //Discard
 
@@ -87,10 +87,10 @@ protected class Orchestration(val name: String,
   }
 
   /**
-    * This method is called everytime the orchestration receives a terminated message.
+    * This method is called every time the orchestration receives a terminated message.
     * It will check if there is no more Ensembles running and will delete the orchestration
    */
-  private def stopIfNoOrchestrationisRunning() = {
+  private def stopIfNoEnsembleIsRunning() = {
     if (ensembles.isEmpty){
       context.parent ! STOP_EMPTY_ORCHESTRATION(guid)
     }

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/47a69e84/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
index 9fa3299..d5162c1 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
@@ -144,4 +144,8 @@ class FeyCoreSpec extends BaseAkkaSpec  {
       monitor.expectMsgClass(1.seconds, classOf[Monitor.STOP])
     }
   }
+
+  //TODO: Test STOP_EMPTY_ORCHESTRATION
+  //TODO: Test restart
+  //TODO: Test checkpoint
 }

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/47a69e84/fey-core/src/test/scala/org/apache/iota/fey/IdentifyFeyActorsSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/IdentifyFeyActorsSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/IdentifyFeyActorsSpec.scala
index 9d64441..f159d19 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/IdentifyFeyActorsSpec.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/IdentifyFeyActorsSpec.scala
@@ -29,7 +29,7 @@ class IdentifyFeyActorsSpec extends BaseAkkaSpec {
       IdentifyFeyActors.actorsPath.size should equal(1)
     }
     s"result in path 'akka://FEY-TEST/user/$globalIdentifierName' " in {
-      IdentifyFeyActors.actorsPath should contain(s"akka://FEY-TEST/user/$globalIdentifierName")
+      IdentifyFeyActors.actorsPath should contain(s"akka://$systemName/user/$globalIdentifierName")
     }
   }
 
@@ -43,8 +43,8 @@ class IdentifyFeyActorsSpec extends BaseAkkaSpec {
       IdentifyFeyActors.actorsPath.size should equal(2)
     }
     s"result in matching paths" in {
-      IdentifyFeyActors.actorsPath should contain(s"akka://FEY-TEST/user/$globalIdentifierName")
-      IdentifyFeyActors.actorsPath should contain("akka://FEY-TEST/user/MONITOR")
+      IdentifyFeyActors.actorsPath should contain(s"akka://$systemName/user/$globalIdentifierName")
+      IdentifyFeyActors.actorsPath should contain(s"akka://$systemName/user/MONITOR")
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/47a69e84/fey-core/src/test/scala/org/apache/iota/fey/OrchestrationSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/OrchestrationSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/OrchestrationSpec.scala
new file mode 100644
index 0000000..4301772
--- /dev/null
+++ b/fey-core/src/test/scala/org/apache/iota/fey/OrchestrationSpec.scala
@@ -0,0 +1,239 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.iota.fey
+
+import play.api.libs.json._
+import akka.actor.{ActorRef, PoisonPill, Props}
+import akka.testkit.{EventFilter, TestActorRef, TestProbe}
+
+import scala.concurrent.duration.DurationInt
+
+class OrchestrationSpec extends BaseAkkaSpec{
+
+  val parent = TestProbe("ORCHESTRATION")
+  val orchName = "ORCHESTRATION-TEST"
+  val monitor = TestProbe()
+  val orchRef = TestActorRef[Orchestration]( Props(new Orchestration("TESTING",orchName,"123124324324"){
+    override val monitoring_actor = monitor.ref
+  }), parent.ref, orchName)
+
+  val orchestrationJson = getJSValueFromString(Utils_JSONTest.create_json_test)
+  val ensembles = (orchestrationJson \ JSON_PATH.ENSEMBLES).as[List[JsObject]]
+  val ensemble1 = ensembles(0)
+  val ensemble2 = ensembles(1)
+  var ensemble1ref:ActorRef = _
+  var ensemble2ref:ActorRef = _
+
+  "Creating an Orchestration " should {
+    "result in sending START message to Monitor actor" in {
+      monitor.expectMsgClass(1.seconds, classOf[Monitor.START])
+    }
+    "result in one paths added to IdentifyFeyActors.actorsPath" in{
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+      Thread.sleep(500)
+      IdentifyFeyActors.actorsPath should have size(1)
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName")
+    }
+  }
+
+  "Sending Orchestration.CREATE_ENSEMBLES to Orchestration" should {
+   s"result in creation of Ensemble '${(ensemble1 \ JSON_PATH.GUID).as[String]}'" in {
+      orchRef ! Orchestration.CREATE_ENSEMBLES(ensembles)
+      ensemble1ref = TestProbe().expectActor(s"${orchRef.path}/${(ensemble1 \ JSON_PATH.GUID).as[String]}")
+    }
+    s"result in creation of Ensemble '${(ensemble2 \ JSON_PATH.GUID).as[String]}'" in {
+      ensemble2ref = TestProbe().expectActor(s"${orchRef.path}/${(ensemble2 \ JSON_PATH.GUID).as[String]}")
+    }
+    s"result in creation of two Performers" in {
+      TestProbe().expectActor(s"${orchRef.path}/${(ensemble2 \ JSON_PATH.GUID).as[String]}/TEST-0001")
+      TestProbe().expectActor(s"${orchRef.path}/${(ensemble1 \ JSON_PATH.GUID).as[String]}/TEST-0001")
+    }
+    s"result in two entries in ORCHESTRATION_CACHE.orchestration_metadata for $orchName" in {
+      ORCHESTRATION_CACHE.orchestration_metadata should contain key(orchName)
+      ORCHESTRATION_CACHE.orchestration_metadata.get(orchName).get should have size(2)
+    }
+    s"result in right entry in ORCHESTRATION_CACHE.orchestration_metadata for $orchName and ${(ensemble1 \ JSON_PATH.GUID).as[String]}" in {
+      ORCHESTRATION_CACHE.orchestration_metadata.get(orchName).get should contain key((ensemble1 \ JSON_PATH.GUID).as[String])
+      ORCHESTRATION_CACHE.orchestration_metadata
+        .get(orchName).get
+        .get((ensemble1 \ JSON_PATH.GUID).as[String]).get should equal(ensemble1)
+    }
+    s"result in right entry in ORCHESTRATION_CACHE.orchestration_metadata for $orchName and ${(ensemble2 \ JSON_PATH.GUID).as[String]}" in {
+      ORCHESTRATION_CACHE.orchestration_metadata.get(orchName).get should contain key((ensemble2 \ JSON_PATH.GUID).as[String])
+      ORCHESTRATION_CACHE.orchestration_metadata
+        .get(orchName).get
+        .get((ensemble2 \ JSON_PATH.GUID).as[String]).get should equal(ensemble2)
+    }
+    "result in five paths added to IdentifyFeyActors.actorsPath" in{
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+      Thread.sleep(500)
+      IdentifyFeyActors.actorsPath should have size(5)
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0001")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0001/TEST-0001")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0002")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0002/TEST-0001")
+    }
+  }
+
+  "Sending Orchestration.CREATE_ENSEMBLES to Orchestration with the same previous created Ensembles" should {
+    s"result in logging 'already exists' at Warn " in {
+      EventFilter.warning(pattern = "^Ensembles.*already exists", occurrences = 2) intercept {
+        orchRef ! Orchestration.CREATE_ENSEMBLES(ensembles)
+      }
+    }
+  }
+
+  val orch2Name = "TEST-ORCH-2"
+  var orch2ref: ActorRef = _
+  var orch2ens: ActorRef = _
+  val orchestration2Json = getJSValueFromString(Utils_JSONTest.orchestration_test_json)
+  val orch2ensembles = (orchestration2Json \ JSON_PATH.ENSEMBLES).as[List[JsObject]]
+  val orch2ensemble1 = orch2ensembles(0)
+  val monitor2 = TestProbe()
+
+  "Creating a second Orchestration" should {
+    s"result in sending START message to Monitor actor" in {
+      orch2ref = TestActorRef[Orchestration]( Props(new Orchestration("TESTING",orch2Name,"123124324324"){
+        override val monitoring_actor = monitor2.ref
+      }), parent.ref, orch2Name)
+      monitor2.expectMsgClass(1.seconds, classOf[Monitor.START])
+    }
+    "result in six paths added to IdentifyFeyActors.actorsPath" in{
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+      Thread.sleep(500)
+      IdentifyFeyActors.actorsPath should have size(6)
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0001")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0001/TEST-0001")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0002")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0002/TEST-0001")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orch2Name")
+    }
+  }
+
+  "Sending Orchestration.CREATE_ENSEMBLES to the second Orchestration" should {
+    s"result in creation of Ensemble '${(orch2ensemble1 \ JSON_PATH.GUID).as[String]}'" in {
+      orch2ref ! Orchestration.CREATE_ENSEMBLES(orch2ensembles)
+      orch2ens = TestProbe().expectActor(s"${orch2ref.path}/${(orch2ensemble1 \ JSON_PATH.GUID).as[String]}")
+    }
+    s"result in creation of one Performers" in {
+      TestProbe().expectActor(s"${orch2ref.path}/${(orch2ensemble1 \ JSON_PATH.GUID).as[String]}/TEST-0001")
+    }
+    s"result in one entries in ORCHESTRATION_CACHE.orchestration_metadata for $orch2Name" in {
+      ORCHESTRATION_CACHE.orchestration_metadata should contain key(orch2Name)
+      ORCHESTRATION_CACHE.orchestration_metadata.get(orch2Name).get should have size(1)
+    }
+    s"result in right entry in ORCHESTRATION_CACHE.orchestration_metadata for $orch2Name and ${(orch2ensemble1 \ JSON_PATH.GUID).as[String]}" in {
+      ORCHESTRATION_CACHE.orchestration_metadata.get(orch2Name).get should contain key((orch2ensemble1 \ JSON_PATH.GUID).as[String])
+      ORCHESTRATION_CACHE.orchestration_metadata
+        .get(orch2Name).get
+        .get((orch2ensemble1 \ JSON_PATH.GUID).as[String]).get should equal(orch2ensemble1)
+    }
+    "result in eight paths added to IdentifyFeyActors.actorsPath" in{
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+      Thread.sleep(500)
+      IdentifyFeyActors.actorsPath should have size(8)
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0001")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0001/TEST-0001")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0002")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0002/TEST-0001")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orch2Name")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orch2Name/MY-ENSEMBLE-0001")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orch2Name/MY-ENSEMBLE-0001/TEST-0001")
+    }
+  }
+
+  "Sending Orchestration.DELETE_ENSEMBLES to the second Orchestration" should {
+    "result in termination of ensembles and the Orchestration itself" in {
+      orch2ref ! Orchestration.DELETE_ENSEMBLES(orch2ensembles)
+      TestProbe().verifyActorTermination(orch2ens)
+    }
+    s"result in sending TERMINATED message to Monitor actor" in {
+      monitor2.expectMsgAllClassOf(classOf[Monitor.TERMINATE])
+    }
+    s"result in FeyCore.STOP_EMPTY_ORCHESTRATION triggered by $orch2Name to parent" in {
+      parent.expectMsg(FeyCore.STOP_EMPTY_ORCHESTRATION(orch2Name))
+    }
+    "result in six paths added to IdentifyFeyActors.actorsPath" in{
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+      Thread.sleep(500)
+      IdentifyFeyActors.actorsPath should have size(6)
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0001")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0001/TEST-0001")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0002")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0002/TEST-0001")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orch2Name")
+    }
+  }
+
+  "Stopping second Orchestration" should {
+    s"result in sending STOP message to Monitor actor" in {
+      orch2ref ! PoisonPill
+      monitor2.expectMsgAllClassOf(classOf[Monitor.STOP])
+    }
+  }
+
+  "Sending Orchestration.UPDATE_ENSEMBLES with Ensemble that does not exist" should {
+    s"result in logging 'no Ensemble' at Warn " in {
+      EventFilter.warning(pattern = s"^There is no Ensemble.*$orchName", occurrences = 1) intercept {
+        val updateEnsemble = (getJSValueFromString(Utils_JSONTest.orchestration_update2_test_json) \ JSON_PATH.ENSEMBLES).as[List[JsObject]]
+        orchRef ! Orchestration.UPDATE_ENSEMBLES(updateEnsemble)
+      }
+    }
+  }
+
+  "Sending Orchestration.UPDATE_ENSEMBLES to Orchestration" should {
+    val updateEnsemble = (getJSValueFromString(Utils_JSONTest.orchestration_update_test_json) \ JSON_PATH.ENSEMBLES).as[List[JsObject]]
+    s"result in termination of Ensemble '$orchName/MY-ENSEMBLE-0001'" in {
+      orchRef ! Orchestration.UPDATE_ENSEMBLES(updateEnsemble)
+      TestProbe().verifyActorTermination(ensemble1ref)
+    }
+    s"result in termination of '$orchName/MY-ENSEMBLE-0001/TEST-0001'" in {
+      TestProbe().notExpectActor(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0001/TEST-0001")
+    }
+    s"result in creation of two new performers" in {
+      TestProbe().expectActor(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0001/TEST-0004")
+      TestProbe().expectActor(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0001/TEST-0005")
+    }
+    "result in six paths added to IdentifyFeyActors.actorsPath" in{
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+      Thread.sleep(500)
+      IdentifyFeyActors.actorsPath should have size(6)
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0001")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0001/TEST-0005")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0001/TEST-0004")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0002")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0002/TEST-0001")
+    }
+    s"result in right entry in ORCHESTRATION_CACHE.orchestration_metadata for $orchName and ${(ensemble1 \ JSON_PATH.GUID).as[String]}" in {
+      ORCHESTRATION_CACHE.orchestration_metadata.get(orchName).get should contain key((ensemble1 \ JSON_PATH.GUID).as[String])
+      ORCHESTRATION_CACHE.orchestration_metadata
+        .get(orchName).get
+        .get((ensemble1 \ JSON_PATH.GUID).as[String]).get should equal(updateEnsemble(0))
+    }
+  }
+
+  //TODO: Test restart
+  //TODO: Test ensembles val in orchRef.underlyingActor
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/47a69e84/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala b/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
index e65aafc..5be25c4 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
@@ -184,4 +184,87 @@ object Utils_JSONTest {
        ]
      }"""
 
+  val orchestration_test_json =
+    """{
+       "guid" : "TEST-ORCH-2",
+       "command" : "CREATE",
+       "timestamp": "213263914979",
+       "name" : "ORCHESTRATION FOR TEST",
+       "ensembles" : [
+         {
+           "guid":"MY-ENSEMBLE-0001",
+           "command": "NONE",
+           "performers":[
+             {
+               "guid": "TEST-0001",
+               "schedule": 0,
+               "backoff": 0,
+               "source": {
+                 "name": "fey-test-actor.jar",
+                 "classPath": "org.apache.iota.fey.TestActor",
+                 "parameters": {}
+               }
+             }
+           ],
+           "connections":[]
+         }
+       ]
+     }"""
+
+  val orchestration_update_test_json =
+    """{
+       "ensembles" : [
+         {
+           "guid":"MY-ENSEMBLE-0001",
+           "command": "UPDATE",
+           "performers":[
+             {
+               "guid": "TEST-0004",
+               "schedule": 0,
+               "backoff": 0,
+               "source": {
+                 "name": "fey-test-actor.jar",
+                 "classPath": "org.apache.iota.fey.TestActor",
+                 "parameters": {}
+               }
+             },
+             {
+               "guid": "TEST-0005",
+               "schedule": 0,
+               "backoff": 0,
+               "source": {
+                 "name": "fey-test-actor.jar",
+                 "classPath": "org.apache.iota.fey.TestActor",
+                 "parameters": {}
+               }
+             }
+           ],
+           "connections":[]
+         }
+       ]
+     }"""
+
+  val orchestration_update2_test_json =
+    """{
+       "ensembles" : [
+         {
+           "guid":"MY-ENSEMBLE-0005",
+           "command": "UPDATE",
+           "performers":[
+             {
+               "guid": "TEST-0004",
+               "schedule": 0,
+               "backoff": 0,
+               "source": {
+                 "name": "fey-test-actor.jar",
+                 "classPath": "org.apache.iota.fey.TestActor",
+                 "parameters": {}
+               }
+             }
+           ],
+           "connections":[]
+         }
+       ]
+     }"""
+
 }


[03/12] incubator-iota git commit: Refactoring MONITOR actor for active better tests results

Posted by to...@apache.org.
Refactoring MONITOR actor for active better tests results

- Avoid instantiation of FeyCore and io.spray when actors being tested send message to static actor Monitor


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/7202f0f2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/7202f0f2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/7202f0f2

Branch: refs/heads/master
Commit: 7202f0f209e14847d1d9dda192b5718d6ffa719a
Parents: c845630
Author: Barbara Gomes <ba...@gmail.com>
Authored: Fri Jul 15 11:22:30 2016 -0700
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Fri Jul 15 11:22:30 2016 -0700

----------------------------------------------------------------------
 .../scala/org/apache/iota/fey/Application.scala | 14 ++++++++++---
 .../scala/org/apache/iota/fey/Ensemble.scala    |  9 +++++----
 .../scala/org/apache/iota/fey/FeyCore.scala     | 10 ++++++----
 .../org/apache/iota/fey/FeyGenericActor.scala   | 21 ++++++++++----------
 .../org/apache/iota/fey/JsonReceiverActor.scala |  7 ++++---
 .../org/apache/iota/fey/Orchestration.scala     | 10 +++++-----
 6 files changed, 42 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/7202f0f2/fey-core/src/main/scala/org/apache/iota/fey/Application.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Application.scala b/fey-core/src/main/scala/org/apache/iota/fey/Application.scala
index 1e5ee69..635bb09 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Application.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Application.scala
@@ -34,18 +34,26 @@ object Application extends App {
 
 }
 
+object FEY_SYSTEM{
+  implicit val system = ActorSystem("FEY-MANAGEMENT-SYSTEM")
+}
+
 object SYSTEM_ACTORS{
 
-  implicit val system = ActorSystem("FEY-MANAGEMENT-SYSTEM")
+  import FEY_SYSTEM._
 
   val fey = system.actorOf(FeyCore.props, name = "FEY-CORE")
   fey ! FeyCore.START
 
   val service = system.actorOf(Props[MyServiceActor], name = "FEY_REST_API")
 
-  val monitoring = system.actorOf(Props[Monitor], "FEY-MONITOR")
-
   implicit val timeout = Timeout(800.seconds)
   IO(Http) ? Http.Bind(SYSTEM_ACTORS.service, interface = "0.0.0.0", port = 16666)
 
 }
+
+object FEY_MONITOR{
+  import FEY_SYSTEM._
+
+  val actorRef = system.actorOf(Props[Monitor], "FEY-MONITOR")
+}

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/7202f0f2/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala b/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
index da3c0bb..cc7640c 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Ensemble.scala
@@ -32,6 +32,7 @@ protected class Ensemble(val orchestrationID: String,
 
   import Ensemble._
 
+  val monitoring_actor = FEY_MONITOR.actorRef
   var performers_metadata: Map[String, Performer] = Map.empty[String, Performer]
   var connectors: Map[String,Array[String]] = Map.empty[String,Array[String]]
   var performer: Map[String,ActorRef] = Map.empty[String,ActorRef]
@@ -50,7 +51,7 @@ protected class Ensemble(val orchestrationID: String,
       context.actorSelection(s"*") ! FeyGenericActor.PRINT_PATH
 
     case Terminated(actor) =>
-      SYSTEM_ACTORS.monitoring  ! Monitor.TERMINATE(actor.path.toString, Utils.getTimestamp)
+      monitoring_actor  ! Monitor.TERMINATE(actor.path.toString, Utils.getTimestamp)
       log.error(s"DEAD nPerformers ${actor.path.name}")
       context.children.foreach{ child =>
         context.unwatch(child)
@@ -80,7 +81,7 @@ protected class Ensemble(val orchestrationID: String,
     */
   override def preStart() : Unit = {
 
-    SYSTEM_ACTORS.monitoring  ! Monitor.START(Utils.getTimestamp)
+    monitoring_actor ! Monitor.START(Utils.getTimestamp)
 
     val connectors_js = (ensembleSpec \ CONNECTIONS).as[List[JsObject]]
     val performers_js = (ensembleSpec \ PERFORMERS).as[List[JsObject]]
@@ -100,11 +101,11 @@ protected class Ensemble(val orchestrationID: String,
   }
 
   override def postStop() : Unit = {
-    SYSTEM_ACTORS.monitoring  ! Monitor.STOP(Utils.getTimestamp)
+    monitoring_actor  ! Monitor.STOP(Utils.getTimestamp)
   }
 
   override def postRestart(reason: Throwable): Unit = {
-    SYSTEM_ACTORS.monitoring  ! Monitor.RESTART(reason, Utils.getTimestamp)
+    monitoring_actor  ! Monitor.RESTART(reason, Utils.getTimestamp)
     preStart()
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/7202f0f2/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala b/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
index 8f0b44f..8028f05 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
@@ -38,6 +38,8 @@ protected class FeyCore extends Actor with ActorLogging{
   import FeyCore._
   import CONFIG._
 
+  val monitoring_actor = FEY_MONITOR.actorRef
+
   val identifier: ActorRef = context.actorOf(Props(classOf[IdentifyFeyActors]), name = IDENTIFIER_NAME)
   context.watch(identifier)
 
@@ -75,7 +77,7 @@ protected class FeyCore extends Actor with ActorLogging{
   }
 
   private def processTerminatedMessage(actorRef: ActorRef) = {
-    SYSTEM_ACTORS.monitoring ! Monitor.TERMINATE(actorRef.path.toString, Utils.getTimestamp)
+    monitoring_actor ! Monitor.TERMINATE(actorRef.path.toString, Utils.getTimestamp)
     log.info(s"TERMINATED ${actorRef.path.name}")
     FEY_CACHE.activeOrchestrations.remove(actorRef.path.name)
     if(!FEY_CACHE.orchestrationsAwaitingTermination.isEmpty) {
@@ -87,19 +89,19 @@ protected class FeyCore extends Actor with ActorLogging{
     * Clean up Fey Cache
     */
   override def postStop(): Unit = {
-    SYSTEM_ACTORS.monitoring ! Monitor.STOP(Utils.getTimestamp)
+    monitoring_actor ! Monitor.STOP(Utils.getTimestamp)
     FEY_CACHE.activeOrchestrations.clear()
     FEY_CACHE.orchestrationsAwaitingTermination.clear()
     ORCHESTRATION_CACHE.orchestration_metadata.clear()
   }
 
   override def preStart(): Unit = {
-    SYSTEM_ACTORS.monitoring ! Monitor.START(Utils.getTimestamp)
+    monitoring_actor ! Monitor.START(Utils.getTimestamp)
     log.info("Starting Fey Core")
   }
 
   override def postRestart(reason: Throwable): Unit = {
-    SYSTEM_ACTORS.monitoring ! Monitor.RESTART(reason, Utils.getTimestamp)
+    monitoring_actor ! Monitor.RESTART(reason, Utils.getTimestamp)
     preStart()
     self ! START
   }

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/7202f0f2/fey-core/src/main/scala/org/apache/iota/fey/FeyGenericActor.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/FeyGenericActor.scala b/fey-core/src/main/scala/org/apache/iota/fey/FeyGenericActor.scala
index 9c6f5c5..f1c94e1 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/FeyGenericActor.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/FeyGenericActor.scala
@@ -51,6 +51,7 @@ abstract class FeyGenericActor(val params: Map[String,String] = Map.empty,
     */
   @volatile private var scheduler: Cancellable = null
   @volatile private var endBackoff: Long = 0
+  private val monitoring_actor = FEY_MONITOR.actorRef
 
   override final def receive: Receive = {
 
@@ -81,27 +82,27 @@ abstract class FeyGenericActor(val params: Map[String,String] = Map.empty,
     postStop()
   }
 
-  override final def preStart() = {
-    SYSTEM_ACTORS.monitoring  ! Monitor.START(Utils.getTimestamp, startMonitorInfo)
+  override final def preStart(): Unit = {
+    monitoring_actor  ! Monitor.START(Utils.getTimestamp, startMonitorInfo)
     onStart()
     startScheduler()
   }
 
-  override final def postStop() = {
-    SYSTEM_ACTORS.monitoring  ! Monitor.STOP(Utils.getTimestamp, stopMonitorInfo)
+  override final def postStop(): Unit = {
+    monitoring_actor  ! Monitor.STOP(Utils.getTimestamp, stopMonitorInfo)
     log.info(s"STOPPED actor ${self.path.name}")
     stopScheduler()
     onStop()
   }
 
-  override final def postRestart(reason: Throwable) = {
-    SYSTEM_ACTORS.monitoring  ! Monitor.RESTART(reason, Utils.getTimestamp)
+  override final def postRestart(reason: Throwable): Unit = {
+    monitoring_actor  ! Monitor.RESTART(reason, Utils.getTimestamp)
     log.info(s"RESTARTED Actor ${self.path.name}")
     preStart()
     onRestart(reason)
   }
 
-  def onRestart(reason: Throwable) = {
+  def onRestart(reason: Throwable): Unit = {
     log.info("RESTARTED method")
   }
 
@@ -118,7 +119,7 @@ abstract class FeyGenericActor(val params: Map[String,String] = Map.empty,
     * Enables the backoff.
     * Actor will drop the PROCESS messages that are sent during the backoff period time.
     */
-  final def startBackoff() = {
+  final def startBackoff(): Unit = {
     this.endBackoff = System.nanoTime() + this.backoff.toNanos
   }
 
@@ -141,7 +142,7 @@ abstract class FeyGenericActor(val params: Map[String,String] = Map.empty,
   /**
     * Called by the scheduler.
     */
-  def execute() = {
+  def execute(): Unit = {
     log.info(s"Executing action in ${self.path.name}")
   }
 
@@ -166,7 +167,7 @@ abstract class FeyGenericActor(val params: Map[String,String] = Map.empty,
     * @param message message to be propagated
     * @tparam T Any
     */
-  final def propagateMessage[T](message: T) = {
+  final def propagateMessage[T](message: T): Unit = {
     connectTo.foreach(linkedActor => {
       linkedActor._2 ! PROCESS(message)
     })

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/7202f0f2/fey-core/src/main/scala/org/apache/iota/fey/JsonReceiverActor.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/JsonReceiverActor.scala b/fey-core/src/main/scala/org/apache/iota/fey/JsonReceiverActor.scala
index 2a05710..6170524 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/JsonReceiverActor.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/JsonReceiverActor.scala
@@ -28,6 +28,7 @@ class JsonReceiverActor extends Actor with ActorLogging {
 
   import JsonReceiverActor._
 
+  val monitoring_actor = FEY_MONITOR.actorRef
   val watchFileTask = new WatchServiceReceiver(self)
   var watchThread = new Thread(watchFileTask, "WatchService")
 
@@ -35,7 +36,7 @@ class JsonReceiverActor extends Actor with ActorLogging {
     prepareDynamicJarRepo()
     processCheckpointFiles()
 
-    SYSTEM_ACTORS.monitoring  ! Monitor.START(Utils.getTimestamp)
+    monitoring_actor  ! Monitor.START(Utils.getTimestamp)
     watchThread.setDaemon(true)
     watchThread.start()
 
@@ -60,13 +61,13 @@ class JsonReceiverActor extends Actor with ActorLogging {
   }
 
   override def postStop() {
-    SYSTEM_ACTORS.monitoring  ! Monitor.STOP(Utils.getTimestamp)
+    monitoring_actor  ! Monitor.STOP(Utils.getTimestamp)
     watchThread.interrupt()
     watchThread.join()
   }
 
   override def postRestart(reason: Throwable): Unit = {
-    SYSTEM_ACTORS.monitoring  ! Monitor.RESTART(reason, Utils.getTimestamp)
+    monitoring_actor  ! Monitor.RESTART(reason, Utils.getTimestamp)
     preStart()
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/7202f0f2/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala b/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala
index 5ec7588..ad61a37 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala
@@ -36,8 +36,8 @@ protected class Orchestration(val name: String,
     * List of map of Ensembles = [EnsembleID, Ensemble]
     */
   private val ensembles:HashMap[String, ActorRef] = HashMap.empty[String, ActorRef]
-
   private val awaitingTermination:HashMap[String, JsObject] = HashMap.empty[String, JsObject]
+  private val monitoring_actor = FEY_MONITOR.actorRef
 
   override def receive: Receive = {
 
@@ -50,7 +50,7 @@ protected class Orchestration(val name: String,
       context.actorSelection(s"*") ! Ensemble.PRINT_ENSEMBLE
 
     case Terminated(actor) =>
-      SYSTEM_ACTORS.monitoring  ! Monitor.TERMINATE(actor.path.toString, Utils.getTimestamp)
+      monitoring_actor  ! Monitor.TERMINATE(actor.path.toString, Utils.getTimestamp)
       context.unwatch(actor)
       log.warning(s"ACTOR DEAD ${actor.path}")
       ensembles.remove(actor.path.name)
@@ -69,19 +69,19 @@ protected class Orchestration(val name: String,
     }
 
   override def preStart(): Unit = {
-    SYSTEM_ACTORS.monitoring  ! Monitor.START(Utils.getTimestamp)
+    monitoring_actor  ! Monitor.START(Utils.getTimestamp)
     if (ORCHESTRATION_CACHE.orchestration_metadata.contains(guid)){
       replayOrchestrationState()
     }
   }
 
   override def postStop() = {
-    SYSTEM_ACTORS.monitoring  ! Monitor.STOP(Utils.getTimestamp)
+    monitoring_actor  ! Monitor.STOP(Utils.getTimestamp)
     log.info(s"STOPPED ${self.path.name}")
   }
 
   override def postRestart(reason: Throwable): Unit = {
-    SYSTEM_ACTORS.monitoring  ! Monitor.RESTART(reason, Utils.getTimestamp)
+    monitoring_actor  ! Monitor.RESTART(reason, Utils.getTimestamp)
     log.info(s"RESTARTED ${self.path}")
     preStart()
   }


[07/12] incubator-iota git commit: IdentifyFeyActors tests

Posted by to...@apache.org.
IdentifyFeyActors tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/619d3e0e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/619d3e0e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/619d3e0e

Branch: refs/heads/master
Commit: 619d3e0e090f09a6b94d9906ba46bb4d653c75fe
Parents: 0ced675
Author: Barbara Gomes <ba...@gmail.com>
Authored: Fri Jul 15 18:30:14 2016 -0700
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Fri Jul 15 18:30:14 2016 -0700

----------------------------------------------------------------------
 .../org/apache/iota/fey/IdentifyFeyActors.scala |  2 +-
 .../org/apache/iota/fey/BaseAkkaSpec.scala      |  3 +-
 .../apache/iota/fey/IdentifyFeyActorsSpec.scala | 63 ++++++++++++++++++++
 3 files changed, 66 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/619d3e0e/fey-core/src/main/scala/org/apache/iota/fey/IdentifyFeyActors.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/IdentifyFeyActors.scala b/fey-core/src/main/scala/org/apache/iota/fey/IdentifyFeyActors.scala
index 9a09df4..f3852fe 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/IdentifyFeyActors.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/IdentifyFeyActors.scala
@@ -27,7 +27,7 @@ protected class IdentifyFeyActors extends Actor with ActorLogging {
 
   import IdentifyFeyActors._
 
-  def receive = {
+  override def receive: Receive = {
     case IDENTIFY_TREE(startPath) =>
       log.info("Current Actors in system:")
       actorsPath = HashSet.empty

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/619d3e0e/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala
index 673538e..3476718 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala
@@ -39,7 +39,8 @@ class BaseAkkaSpec extends BaseSpec with BeforeAndAfterAll{
   CONFIG.loadUserConfiguration(Paths.get(conf.toURI()).toFile().getAbsolutePath)
   copyTestActorToTmp()
 
-  implicit val system = ActorSystem("FEY-TEST", ConfigFactory.parseString("""akka.loggers = ["akka.testkit.TestEventListener"]"""))
+  val systemName = "FEY-TEST"
+  implicit val system = ActorSystem(systemName, ConfigFactory.parseString("""akka.loggers = ["akka.testkit.TestEventListener"]"""))
   system.eventStream.publish(TestEvent.Mute(EventFilter.debug()))
   system.eventStream.publish(TestEvent.Mute(EventFilter.info()))
   system.eventStream.publish(TestEvent.Mute(EventFilter.warning()))

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/619d3e0e/fey-core/src/test/scala/org/apache/iota/fey/IdentifyFeyActorsSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/IdentifyFeyActorsSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/IdentifyFeyActorsSpec.scala
new file mode 100644
index 0000000..7a618fc
--- /dev/null
+++ b/fey-core/src/test/scala/org/apache/iota/fey/IdentifyFeyActorsSpec.scala
@@ -0,0 +1,63 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.iota.fey
+
+import akka.actor.{ActorRef, Props}
+
+class IdentifyFeyActorsSpec extends BaseAkkaSpec {
+
+  val identifyRef = system.actorOf(Props[IdentifyFeyActors],"IDENTIFIER")
+
+  "Sending IdentifyFeyActors.IDENTIFY_TREE to IdentifyFeyActors" should {
+    s"result in one path added to IdentifyFeyActors.actorsPath" in {
+      identifyRef ! IdentifyFeyActors.IDENTIFY_TREE(s"akka://$systemName/user")
+      Thread.sleep(1000)
+      IdentifyFeyActors.actorsPath.size should equal(1)
+    }
+    s"result in path 'akka://FEY-TEST/user/IDENTIFIER' " in {
+      IdentifyFeyActors.actorsPath should contain("akka://FEY-TEST/user/IDENTIFIER")
+    }
+  }
+
+  var actor2: ActorRef = _
+
+  "Creating a new actor in the system and sending IdentifyFeyActors.IDENTIFY_TREE to IdentifyFeyActors" should {
+    s"result in two paths added to IdentifyFeyActors.actorsPath" in {
+      actor2 = system.actorOf(Props[Monitor],"MONITOR")
+      identifyRef ! IdentifyFeyActors.IDENTIFY_TREE(s"akka://$systemName/user")
+      Thread.sleep(1000)
+      IdentifyFeyActors.actorsPath.size should equal(2)
+    }
+    s"result in matching paths" in {
+      IdentifyFeyActors.actorsPath should contain("akka://FEY-TEST/user/IDENTIFIER")
+      IdentifyFeyActors.actorsPath should contain("akka://FEY-TEST/user/MONITOR")
+    }
+  }
+
+  "Stopping precious added actor and sending IdentifyFeyActors.IDENTIFY_TREE to IdentifyFeyActors" should {
+    "result in going back to have just one path added to IdentifyFeyActors.actorsPath" in {
+      identifyRef ! IdentifyFeyActors.IDENTIFY_TREE(s"akka://$systemName/user")
+      Thread.sleep(1000)
+      IdentifyFeyActors.actorsPath.size should equal(2)
+    }
+    s"result in path 'akka://FEY-TEST/user/IDENTIFIER' " in {
+      IdentifyFeyActors.actorsPath should contain("akka://FEY-TEST/user/IDENTIFIER")
+    }
+  }
+}


[10/12] incubator-iota git commit: TODOs: - Test ensembles val in orchRef.underlyingActor - OrchestrationSpec - Test STOP_EMPTY_ORCHESTRATION - FeyCoreSpec

Posted by to...@apache.org.
TODOs:
 - Test ensembles val in orchRef.underlyingActor - OrchestrationSpec
 - Test STOP_EMPTY_ORCHESTRATION - FeyCoreSpec


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/ad056da3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/ad056da3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/ad056da3

Branch: refs/heads/master
Commit: ad056da3d38217284400730ff7e89fc513f21322
Parents: 47a69e8
Author: Barbara Gomes <ba...@gmail.com>
Authored: Mon Jul 18 10:22:20 2016 -0700
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Mon Jul 18 10:22:20 2016 -0700

----------------------------------------------------------------------
 .../org/apache/iota/fey/Orchestration.scala     |  4 +-
 .../scala/org/apache/iota/fey/FeyCoreSpec.scala | 18 ++++++++-
 .../org/apache/iota/fey/OrchestrationSpec.scala | 40 +++++++++++++++++---
 3 files changed, 54 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/ad056da3/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala b/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala
index cb1bcae..dc2e64d 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Orchestration.scala
@@ -35,8 +35,8 @@ protected class Orchestration(val name: String,
   /**
     * List of map of Ensembles = [EnsembleID, Ensemble]
     */
-  private val ensembles:HashMap[String, ActorRef] = HashMap.empty[String, ActorRef]
-  private val awaitingTermination:HashMap[String, JsObject] = HashMap.empty[String, JsObject]
+  val ensembles:HashMap[String, ActorRef] = HashMap.empty[String, ActorRef]
+  val awaitingTermination:HashMap[String, JsObject] = HashMap.empty[String, JsObject]
   val monitoring_actor = FEY_MONITOR.actorRef
 
   override def receive: Receive = {

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/ad056da3/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
index d5162c1..b5a2ca9 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/FeyCoreSpec.scala
@@ -138,6 +138,23 @@ class FeyCoreSpec extends BaseAkkaSpec  {
     }
   }
 
+  "Sending FeyCore.STOP_EMPTY_ORCHESTRATION to FeyCore" should {
+    s"result in termination of 'TEST-ORCH-2'" in {
+      feyCoreRef ! FeyCore.ORCHESTRATION_RECEIVED(getJSValueFromString(Utils_JSONTest.orchestration_test_json), new File("/tmp/fey/test/json"))
+      val ref = TestProbe().expectActor(s"$feyPath/TEST-ORCH-2")
+      FEY_CACHE.activeOrchestrations should have size(1)
+      FEY_CACHE.activeOrchestrations should contain key("TEST-ORCH-2")
+      feyCoreRef ! FeyCore.STOP_EMPTY_ORCHESTRATION("TEST-ORCH-2")
+      TestProbe().verifyActorTermination(ref)
+    }
+    s"result in sending Terminate message to Monitor actor" in{
+      monitor.expectMsgClass(1.seconds, classOf[Monitor.TERMINATE])
+    }
+    s"result in empty FEY_CACHE.activeOrchestrations" in {
+      FEY_CACHE.activeOrchestrations shouldBe empty
+    }
+  }
+
   "Stopping FeyCore" should {
     "result in sending STOP message to Monitor actor" in {
       feyCoreRef ! PoisonPill
@@ -145,7 +162,6 @@ class FeyCoreSpec extends BaseAkkaSpec  {
     }
   }
 
-  //TODO: Test STOP_EMPTY_ORCHESTRATION
   //TODO: Test restart
   //TODO: Test checkpoint
 }

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/ad056da3/fey-core/src/test/scala/org/apache/iota/fey/OrchestrationSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/OrchestrationSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/OrchestrationSpec.scala
index 4301772..8719f36 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/OrchestrationSpec.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/OrchestrationSpec.scala
@@ -32,6 +32,7 @@ class OrchestrationSpec extends BaseAkkaSpec{
   val orchRef = TestActorRef[Orchestration]( Props(new Orchestration("TESTING",orchName,"123124324324"){
     override val monitoring_actor = monitor.ref
   }), parent.ref, orchName)
+  val orchState = orchRef.underlyingActor
 
   val orchestrationJson = getJSValueFromString(Utils_JSONTest.create_json_test)
   val ensembles = (orchestrationJson \ JSON_PATH.ENSEMBLES).as[List[JsObject]]
@@ -50,6 +51,9 @@ class OrchestrationSpec extends BaseAkkaSpec{
       IdentifyFeyActors.actorsPath should have size(1)
       IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName")
     }
+    "result in empty Orchestration.ensembles state variable" in{
+      orchState.ensembles shouldBe empty
+    }
   }
 
   "Sending Orchestration.CREATE_ENSEMBLES to Orchestration" should {
@@ -64,6 +68,13 @@ class OrchestrationSpec extends BaseAkkaSpec{
       TestProbe().expectActor(s"${orchRef.path}/${(ensemble2 \ JSON_PATH.GUID).as[String]}/TEST-0001")
       TestProbe().expectActor(s"${orchRef.path}/${(ensemble1 \ JSON_PATH.GUID).as[String]}/TEST-0001")
     }
+    s"result in two entries in Orchestration.ensembles matching the craeted ensembles" in {
+      orchState.ensembles should have size(2)
+      orchState.ensembles should contain key((ensemble1 \ JSON_PATH.GUID).as[String])
+      orchState.ensembles should contain key((ensemble2 \ JSON_PATH.GUID).as[String])
+      orchState.ensembles.get((ensemble1 \ JSON_PATH.GUID).as[String]).get should equal(ensemble1ref)
+      orchState.ensembles.get((ensemble2 \ JSON_PATH.GUID).as[String]).get should equal(ensemble2ref)
+    }
     s"result in two entries in ORCHESTRATION_CACHE.orchestration_metadata for $orchName" in {
       ORCHESTRATION_CACHE.orchestration_metadata should contain key(orchName)
       ORCHESTRATION_CACHE.orchestration_metadata.get(orchName).get should have size(2)
@@ -98,15 +109,23 @@ class OrchestrationSpec extends BaseAkkaSpec{
         orchRef ! Orchestration.CREATE_ENSEMBLES(ensembles)
       }
     }
+    s"not change state variable Orchestration.ensembles" in {
+      orchState.ensembles should have size(2)
+      orchState.ensembles should contain key((ensemble1 \ JSON_PATH.GUID).as[String])
+      orchState.ensembles should contain key((ensemble2 \ JSON_PATH.GUID).as[String])
+      orchState.ensembles.get((ensemble1 \ JSON_PATH.GUID).as[String]).get should equal(ensemble1ref)
+      orchState.ensembles.get((ensemble2 \ JSON_PATH.GUID).as[String]).get should equal(ensemble2ref)
+    }
   }
 
   val orch2Name = "TEST-ORCH-2"
-  var orch2ref: ActorRef = _
-  var orch2ens: ActorRef = _
+  var orch2ref: TestActorRef[Orchestration] = _
+  var orch2ensRef: ActorRef = _
   val orchestration2Json = getJSValueFromString(Utils_JSONTest.orchestration_test_json)
   val orch2ensembles = (orchestration2Json \ JSON_PATH.ENSEMBLES).as[List[JsObject]]
   val orch2ensemble1 = orch2ensembles(0)
   val monitor2 = TestProbe()
+  var orch2state:Orchestration = null
 
   "Creating a second Orchestration" should {
     s"result in sending START message to Monitor actor" in {
@@ -114,6 +133,10 @@ class OrchestrationSpec extends BaseAkkaSpec{
         override val monitoring_actor = monitor2.ref
       }), parent.ref, orch2Name)
       monitor2.expectMsgClass(1.seconds, classOf[Monitor.START])
+      orch2state = orch2ref.underlyingActor
+    }
+    "result in empty Orchestration.ensembles state variable" in{
+      orch2state.ensembles shouldBe empty
     }
     "result in six paths added to IdentifyFeyActors.actorsPath" in{
       globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
@@ -131,11 +154,16 @@ class OrchestrationSpec extends BaseAkkaSpec{
   "Sending Orchestration.CREATE_ENSEMBLES to the second Orchestration" should {
     s"result in creation of Ensemble '${(orch2ensemble1 \ JSON_PATH.GUID).as[String]}'" in {
       orch2ref ! Orchestration.CREATE_ENSEMBLES(orch2ensembles)
-      orch2ens = TestProbe().expectActor(s"${orch2ref.path}/${(orch2ensemble1 \ JSON_PATH.GUID).as[String]}")
+      orch2ensRef = TestProbe().expectActor(s"${orch2ref.path}/${(orch2ensemble1 \ JSON_PATH.GUID).as[String]}")
     }
     s"result in creation of one Performers" in {
       TestProbe().expectActor(s"${orch2ref.path}/${(orch2ensemble1 \ JSON_PATH.GUID).as[String]}/TEST-0001")
     }
+    s"result in one entry in Orchestration.ensembles matching the craeted ensemble" in {
+      orch2state.ensembles should have size(1)
+      orch2state.ensembles should contain key((orch2ensemble1 \ JSON_PATH.GUID).as[String])
+      orch2state.ensembles.get((orch2ensemble1 \ JSON_PATH.GUID).as[String]).get should equal(orch2ensRef)
+    }
     s"result in one entries in ORCHESTRATION_CACHE.orchestration_metadata for $orch2Name" in {
       ORCHESTRATION_CACHE.orchestration_metadata should contain key(orch2Name)
       ORCHESTRATION_CACHE.orchestration_metadata.get(orch2Name).get should have size(1)
@@ -164,7 +192,7 @@ class OrchestrationSpec extends BaseAkkaSpec{
   "Sending Orchestration.DELETE_ENSEMBLES to the second Orchestration" should {
     "result in termination of ensembles and the Orchestration itself" in {
       orch2ref ! Orchestration.DELETE_ENSEMBLES(orch2ensembles)
-      TestProbe().verifyActorTermination(orch2ens)
+      TestProbe().verifyActorTermination(orch2ensRef)
     }
     s"result in sending TERMINATED message to Monitor actor" in {
       monitor2.expectMsgAllClassOf(classOf[Monitor.TERMINATE])
@@ -183,6 +211,9 @@ class OrchestrationSpec extends BaseAkkaSpec{
       IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orchName/MY-ENSEMBLE-0002/TEST-0001")
       IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/$orch2Name")
     }
+    "result in empty state variable Orchestration.ensembles" in {
+      orch2state.ensembles shouldBe empty
+    }
   }
 
   "Stopping second Orchestration" should {
@@ -234,6 +265,5 @@ class OrchestrationSpec extends BaseAkkaSpec{
   }
 
   //TODO: Test restart
-  //TODO: Test ensembles val in orchRef.underlyingActor
 
 }


[08/12] incubator-iota git commit: Creating global Identifier actor to be used in the tests

Posted by to...@apache.org.
Creating global Identifier actor to be used in the tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/8722e873
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/8722e873
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/8722e873

Branch: refs/heads/master
Commit: 8722e873cc44a7ee4794db2d1baef7608d48fec1
Parents: 619d3e0
Author: Barbara Gomes <ba...@gmail.com>
Authored: Sat Jul 16 09:11:49 2016 -0700
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Sat Jul 16 09:11:49 2016 -0700

----------------------------------------------------------------------
 .../org/apache/iota/fey/BaseAkkaSpec.scala      |  5 ++++-
 .../apache/iota/fey/IdentifyFeyActorsSpec.scala | 20 +++++++++-----------
 2 files changed, 13 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/8722e873/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala
index 3476718..60fb3aa 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/BaseAkkaSpec.scala
@@ -21,7 +21,7 @@ package org.apache.iota.fey
 import java.io.File
 import java.nio.file.Paths
 
-import akka.actor.{ActorIdentity, ActorRef, ActorSystem, Identify}
+import akka.actor.{ActorIdentity, ActorRef, ActorSystem, Identify, Props}
 import akka.testkit.{EventFilter, TestActorRef, TestEvent, TestProbe}
 import akka.util.Timeout
 import com.typesafe.config.ConfigFactory
@@ -46,6 +46,9 @@ class BaseAkkaSpec extends BaseSpec with BeforeAndAfterAll{
   system.eventStream.publish(TestEvent.Mute(EventFilter.warning()))
   system.eventStream.publish(TestEvent.Mute(EventFilter.error()))
 
+  val globalIdentifierName = "GLOBAL-IDENTIFIER"
+  val globalIdentifierRef = system.actorOf(Props[IdentifyFeyActors],globalIdentifierName)
+
   override protected def afterAll(): Unit = {
     Await.ready(system.terminate(), 20.seconds)
   }

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/8722e873/fey-core/src/test/scala/org/apache/iota/fey/IdentifyFeyActorsSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/IdentifyFeyActorsSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/IdentifyFeyActorsSpec.scala
index 7a618fc..9d64441 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/IdentifyFeyActorsSpec.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/IdentifyFeyActorsSpec.scala
@@ -22,16 +22,14 @@ import akka.actor.{ActorRef, Props}
 
 class IdentifyFeyActorsSpec extends BaseAkkaSpec {
 
-  val identifyRef = system.actorOf(Props[IdentifyFeyActors],"IDENTIFIER")
-
   "Sending IdentifyFeyActors.IDENTIFY_TREE to IdentifyFeyActors" should {
     s"result in one path added to IdentifyFeyActors.actorsPath" in {
-      identifyRef ! IdentifyFeyActors.IDENTIFY_TREE(s"akka://$systemName/user")
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(s"akka://$systemName/user")
       Thread.sleep(1000)
       IdentifyFeyActors.actorsPath.size should equal(1)
     }
-    s"result in path 'akka://FEY-TEST/user/IDENTIFIER' " in {
-      IdentifyFeyActors.actorsPath should contain("akka://FEY-TEST/user/IDENTIFIER")
+    s"result in path 'akka://FEY-TEST/user/$globalIdentifierName' " in {
+      IdentifyFeyActors.actorsPath should contain(s"akka://FEY-TEST/user/$globalIdentifierName")
     }
   }
 
@@ -40,24 +38,24 @@ class IdentifyFeyActorsSpec extends BaseAkkaSpec {
   "Creating a new actor in the system and sending IdentifyFeyActors.IDENTIFY_TREE to IdentifyFeyActors" should {
     s"result in two paths added to IdentifyFeyActors.actorsPath" in {
       actor2 = system.actorOf(Props[Monitor],"MONITOR")
-      identifyRef ! IdentifyFeyActors.IDENTIFY_TREE(s"akka://$systemName/user")
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(s"akka://$systemName/user")
       Thread.sleep(1000)
       IdentifyFeyActors.actorsPath.size should equal(2)
     }
     s"result in matching paths" in {
-      IdentifyFeyActors.actorsPath should contain("akka://FEY-TEST/user/IDENTIFIER")
+      IdentifyFeyActors.actorsPath should contain(s"akka://FEY-TEST/user/$globalIdentifierName")
       IdentifyFeyActors.actorsPath should contain("akka://FEY-TEST/user/MONITOR")
     }
   }
 
-  "Stopping precious added actor and sending IdentifyFeyActors.IDENTIFY_TREE to IdentifyFeyActors" should {
+  "Stopping previous added actor and sending IdentifyFeyActors.IDENTIFY_TREE to IdentifyFeyActors" should {
     "result in going back to have just one path added to IdentifyFeyActors.actorsPath" in {
-      identifyRef ! IdentifyFeyActors.IDENTIFY_TREE(s"akka://$systemName/user")
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(s"akka://$systemName/user")
       Thread.sleep(1000)
       IdentifyFeyActors.actorsPath.size should equal(2)
     }
-    s"result in path 'akka://FEY-TEST/user/IDENTIFIER' " in {
-      IdentifyFeyActors.actorsPath should contain("akka://FEY-TEST/user/IDENTIFIER")
+    s"result in path 'akka://FEY-TEST/user/$globalIdentifierName' " in {
+      IdentifyFeyActors.actorsPath should contain(s"akka://FEY-TEST/user/$globalIdentifierName")
     }
   }
 }


[04/12] incubator-iota git commit: Adding Global name for WatchService thread

Posted by to...@apache.org.
Adding Global name for WatchService thread


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/f850688b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/f850688b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/f850688b

Branch: refs/heads/master
Commit: f850688b91b3607929a20b6816e2d7c0777c7aeb
Parents: 7202f0f
Author: Barbara Gomes <ba...@gmail.com>
Authored: Fri Jul 15 16:22:56 2016 -0700
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Fri Jul 15 16:22:56 2016 -0700

----------------------------------------------------------------------
 .../src/main/scala/org/apache/iota/fey/JsonReceiverActor.scala   | 2 +-
 fey-core/src/main/scala/org/apache/iota/fey/Utils.scala          | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/f850688b/fey-core/src/main/scala/org/apache/iota/fey/JsonReceiverActor.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/JsonReceiverActor.scala b/fey-core/src/main/scala/org/apache/iota/fey/JsonReceiverActor.scala
index 6170524..1664478 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/JsonReceiverActor.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/JsonReceiverActor.scala
@@ -30,7 +30,7 @@ class JsonReceiverActor extends Actor with ActorLogging {
 
   val monitoring_actor = FEY_MONITOR.actorRef
   val watchFileTask = new WatchServiceReceiver(self)
-  var watchThread = new Thread(watchFileTask, "WatchService")
+  var watchThread = new Thread(watchFileTask, GLOBAL_DEFINITIONS.WATCH_SERVICE_THREAD)
 
   override def preStart() {
     prepareDynamicJarRepo()

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/f850688b/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala b/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
index bd30d9c..8402485 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Utils.scala
@@ -293,6 +293,10 @@ object CONFIG{
   }
 }
 
+object GLOBAL_DEFINITIONS {
+  val WATCH_SERVICE_THREAD = "FeyWatchService"
+}
+
 
 
 case class NetworkAlreadyDefined(message:String)  extends Exception(message)


[02/12] incubator-iota git commit: Adjusting FeyCore for better way of testing

Posted by to...@apache.org.
Adjusting FeyCore for better way of testing


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/c8456305
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/c8456305
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/c8456305

Branch: refs/heads/master
Commit: c84563056003b858f4e08a3b9bcb882542e001db
Parents: 7203d6d
Author: Barbara Gomes <ba...@gmail.com>
Authored: Thu Jul 14 19:36:08 2016 -0700
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Thu Jul 14 19:36:08 2016 -0700

----------------------------------------------------------------------
 fey-core/src/main/scala/org/apache/iota/fey/Application.scala  | 2 +-
 fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala      | 4 +---
 .../main/scala/org/apache/iota/fey/WatchServiceReceiver.scala  | 6 ++++--
 3 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/c8456305/fey-core/src/main/scala/org/apache/iota/fey/Application.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/Application.scala b/fey-core/src/main/scala/org/apache/iota/fey/Application.scala
index c11815a..1e5ee69 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/Application.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/Application.scala
@@ -39,6 +39,7 @@ object SYSTEM_ACTORS{
   implicit val system = ActorSystem("FEY-MANAGEMENT-SYSTEM")
 
   val fey = system.actorOf(FeyCore.props, name = "FEY-CORE")
+  fey ! FeyCore.START
 
   val service = system.actorOf(Props[MyServiceActor], name = "FEY_REST_API")
 
@@ -47,5 +48,4 @@ object SYSTEM_ACTORS{
   implicit val timeout = Timeout(800.seconds)
   IO(Http) ? Http.Bind(SYSTEM_ACTORS.service, interface = "0.0.0.0", port = 16666)
 
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/c8456305/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala b/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
index 8ae3056..8f0b44f 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/FeyCore.scala
@@ -96,14 +96,12 @@ protected class FeyCore extends Actor with ActorLogging{
   override def preStart(): Unit = {
     SYSTEM_ACTORS.monitoring ! Monitor.START(Utils.getTimestamp)
     log.info("Starting Fey Core")
-    self ! START
   }
 
-
-
   override def postRestart(reason: Throwable): Unit = {
     SYSTEM_ACTORS.monitoring ! Monitor.RESTART(reason, Utils.getTimestamp)
     preStart()
+    self ! START
   }
 
   override val supervisorStrategy =

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/c8456305/fey-core/src/main/scala/org/apache/iota/fey/WatchServiceReceiver.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/main/scala/org/apache/iota/fey/WatchServiceReceiver.scala b/fey-core/src/main/scala/org/apache/iota/fey/WatchServiceReceiver.scala
index 58d25b0..a20ce54 100644
--- a/fey-core/src/main/scala/org/apache/iota/fey/WatchServiceReceiver.scala
+++ b/fey-core/src/main/scala/org/apache/iota/fey/WatchServiceReceiver.scala
@@ -97,9 +97,11 @@ class WatchServiceReceiver(receiverActor: ActorRef) extends JsonReceiver{
   }
 
   override def exceptionOnRun(e: Exception): Unit = {
-    log.error("Watch Service stopped", e)
+    e match {
+      case e: InterruptedException =>
+      case e: Exception => log.error("Watch Service stopped", e)
+    }
     watchService.close()
-    throw e
   }
 
 }


[12/12] incubator-iota git commit: Test for Ensemble.scala

Posted by to...@apache.org.
Test for Ensemble.scala


Project: http://git-wip-us.apache.org/repos/asf/incubator-iota/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-iota/commit/b7dd7961
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/b7dd7961
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/b7dd7961

Branch: refs/heads/master
Commit: b7dd7961ed6acc81838b4add05d774859460c341
Parents: 555550a
Author: Barbara Gomes <ba...@gmail.com>
Authored: Mon Jul 18 13:31:03 2016 -0700
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Mon Jul 18 13:31:03 2016 -0700

----------------------------------------------------------------------
 .../org/apache/iota/fey/EnsembleSpec.scala      | 221 +++++++++++++++++++
 .../org/apache/iota/fey/Utils_JSONTest.scala    |  56 +++++
 2 files changed, 277 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/b7dd7961/fey-core/src/test/scala/org/apache/iota/fey/EnsembleSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/EnsembleSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/EnsembleSpec.scala
new file mode 100644
index 0000000..3878dcc
--- /dev/null
+++ b/fey-core/src/test/scala/org/apache/iota/fey/EnsembleSpec.scala
@@ -0,0 +1,221 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.iota.fey
+
+import akka.actor.{ActorRef, PoisonPill, Props}
+import akka.testkit.{EventFilter, TestActorRef, TestProbe}
+import play.api.libs.json.JsObject
+
+import scala.concurrent.duration.{DurationInt, FiniteDuration}
+import JSON_PATH._
+
+
+class EnsembleSpec extends BaseAkkaSpec{
+
+  val ensembleJson = getJSValueFromString(Utils_JSONTest.simple_ensemble_test_json)
+  val orchestrationID = "ORCH-TEST-ENSEMBLE"
+  val parent = TestProbe("ENSEMBLE")
+  val monitor = TestProbe()
+
+  val ensembleRef = TestActorRef[Ensemble]( Props(new Ensemble(orchestrationID,"ORCH-NAME", ensembleJson.as[JsObject]){
+    override val monitoring_actor = monitor.ref
+  }), parent.ref, (ensembleJson \ JSON_PATH.GUID).as[String])
+
+  val ensembleState = ensembleRef.underlyingActor
+
+  var simplePerformerRef: ActorRef = _
+
+  s"Creating a simple Ensemble ${(ensembleJson \ JSON_PATH.GUID).as[String]}" should {
+    s"result in creation of Ensemble actor '${parent.ref.path}/${(ensembleJson \ JSON_PATH.GUID).as[String]}'" in {
+      TestProbe().expectActor(s"${parent.ref.path}/${(ensembleJson \ JSON_PATH.GUID).as[String]}")
+    }
+    s"result in sending START to monitor actor" in {
+      monitor.expectMsgClass(classOf[Monitor.START])
+    }
+    s"result in creation of Performer 'TEST-0004'" in{
+      simplePerformerRef = TestProbe().expectActor(s"${parent.ref.path}/${(ensembleJson \ JSON_PATH.GUID).as[String]}/TEST-0004")
+    }
+    s"result in Empty state variable Ensemble.connectors" in {
+      ensembleState.connectors shouldBe empty
+    }
+    s"result in one entry added to state variable Ensemble.performer" in{
+      ensembleState.performer should have size(1)
+      ensembleState.performer should contain key("TEST-0004")
+      ensembleState.performer.get("TEST-0004").get should equal(simplePerformerRef)
+    }
+    s"result in one right entry to state variable Ensemble.performers_metadata" in {
+      ensembleState.performers_metadata should have size(1)
+      val performers = (ensembleJson \ PERFORMERS).as[List[JsObject]]
+      val performerSpec = performers(0)
+      val performer = ensembleState.performers_metadata.get("TEST-0004").get
+
+      performer.controlAware should equal(false)
+      performer.jarName should equal((performerSpec \ SOURCE \ SOURCE_NAME).as[String])
+      performer.jarLocation should equal(CONFIG.JAR_REPOSITORY)
+      performer.autoScale should equal(0)
+      performer.backoff should equal((performerSpec \ BACKOFF).as[Int].millisecond)
+      performer.classPath should equal((performerSpec \ SOURCE \ SOURCE_CLASSPATH).as[String])
+      performer.uid should equal((performerSpec \ GUID).as[String])
+      performer.schedule should equal((performerSpec \ SCHEDULE).as[Int].millisecond)
+      performer.parameters shouldBe empty
+    }
+    "result in two paths added to IdentifyFeyActors.actorsPath" in{
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+      Thread.sleep(500)
+      IdentifyFeyActors.actorsPath should have size(2)
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/${(ensembleJson \ JSON_PATH.GUID).as[String]}")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/${(ensembleJson \ JSON_PATH.GUID).as[String]}/TEST-0004")
+    }
+  }
+
+  s"Sending Ensemble.STOP_PERFORMERS to Ensemble" should {
+    s"result in Terminate message of actor 'TEST-0004' and throw RestartEnsemble Exception" in {
+      EventFilter[RestartEnsemble](occurrences = 1) intercept {
+        ensembleRef ! Ensemble.STOP_PERFORMERS
+        TestProbe().verifyActorTermination(simplePerformerRef)
+      }
+    }
+    //s"result in Performer 'TEST-0004' restarted" in {
+    //  val newPerformer = TestProbe().expectActor(s"${parent.ref.path}/${(ensembleJson \ JSON_PATH.GUID).as[String]}/TEST-0004")
+    //  newPerformer.compareTo(simplePerformerRef) should be(0)
+    //}
+    "result in two paths added to IdentifyFeyActors.actorsPath" in{
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+      Thread.sleep(500)
+      IdentifyFeyActors.actorsPath should have size(2)
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/${(ensembleJson \ JSON_PATH.GUID).as[String]}")
+      IdentifyFeyActors.actorsPath should contain(s"${parent.ref.path}/${(ensembleJson \ JSON_PATH.GUID).as[String]}/TEST-0004")
+    }
+  }
+
+  s"Sending PoisonPill to Ensemble" should{
+    s"result in termination of actor '${(ensembleJson \ JSON_PATH.GUID).as[String]}'" in {
+      ensembleRef ! PoisonPill
+      TestProbe().verifyActorTermination(ensembleRef)
+    }
+    s"result in sending TERMINATE to monitor actor" in {
+      monitor.expectMsgClass(classOf[Monitor.TERMINATE])
+    }
+    "result in termination of ensemble and performer" in {
+      TestProbe().notExpectActor(s"${parent.ref.path}/${(ensembleJson \ JSON_PATH.GUID).as[String]}")
+      TestProbe().notExpectActor(s"${parent.ref.path}/${(ensembleJson \ JSON_PATH.GUID).as[String]}/TEST-0004")
+    }
+    "result in empty IdentifyFeyActors.actorsPath" in{
+      globalIdentifierRef ! IdentifyFeyActors.IDENTIFY_TREE(parent.ref.path.toString)
+      Thread.sleep(500)
+      IdentifyFeyActors.actorsPath shouldBe empty
+    }
+  }
+
+  val advEnsembleJson = getJSValueFromString(Utils_JSONTest.ensemble_test_json)
+  var advEnsembleRef:TestActorRef[Ensemble] = _
+  var advEnsembleState: Ensemble = ensembleRef.underlyingActor
+  var paramsRef: ActorRef = _
+  var scheduleRef: ActorRef = _
+  val generalScheduleTB = TestProbe("GENERAL-SCHEDULE")
+  val schedulerScheduleTB = TestProbe("SCHEDULER-SCHEDULE")
+  val generalParamsTB = TestProbe("GENERAL-PARAMS")
+  val processParamsTB = TestProbe("PROCESS-PARAMS")
+
+  s"creating more detailed Ensemble" should {
+    s"result in creation of Ensemble actor " in {
+      advEnsembleRef = TestActorRef[Ensemble]( Props(new Ensemble(orchestrationID,"ORCH-NAME", advEnsembleJson.as[JsObject]){
+        override val monitoring_actor = monitor.ref
+      }), parent.ref, (advEnsembleJson \ JSON_PATH.GUID).as[String])
+      advEnsembleState = advEnsembleRef.underlyingActor
+      TestProbe().expectActor(s"${parent.ref.path}/${(advEnsembleJson \ JSON_PATH.GUID).as[String]}")
+    }
+    s"result in creation of Performer 'PERFORMER-SCHEDULER'" in{
+      scheduleRef = TestProbe().expectActor(s"${parent.ref.path}/${(advEnsembleJson \ JSON_PATH.GUID).as[String]}/PERFORMER-SCHEDULER")
+    }
+    s"result in creation of Performer 'PERFORMER-PARAMS'" in{
+      paramsRef = TestProbe().expectActor(s"${parent.ref.path}/${(advEnsembleJson \ JSON_PATH.GUID).as[String]}/PERFORMER-PARAMS")
+    }
+    s"create connection PERFORMER-SCHEDULER -> PERFORMER-PARAMS" in {
+      advEnsembleState.connectors should have size(1)
+      advEnsembleState.connectors should contain key("PERFORMER-SCHEDULER")
+      advEnsembleState.connectors.get("PERFORMER-SCHEDULER").get should equal(Array("PERFORMER-PARAMS"))
+    }
+    s"create 'PERFORMER-SCHEDULER' with schedule time equal to 200ms" in{
+      advEnsembleState.performers_metadata.get("PERFORMER-SCHEDULER").get.schedule should  equal(200.millisecond)
+    }
+    s"create 'PERFORMER-SCHEDULER' with connection to 'PERFORMER-PARAMS'" in{
+      scheduleRef ! ((schedulerScheduleTB.ref,system.deadLetters,generalScheduleTB.ref))
+      scheduleRef ! "GET_CONNECTIONS"
+      generalScheduleTB.expectMsg(Map("PERFORMER-PARAMS" -> paramsRef))
+    }
+    s"create 'PERFORMER-PARAMS' with no connections" in{
+      paramsRef ! ((system.deadLetters,processParamsTB.ref, generalParamsTB.ref))
+      paramsRef ! "GET_CONNECTIONS"
+      generalParamsTB.expectMsg(Map.empty)
+    }
+    s"create 'PERFORMER-PARAMS' with specified params" in{
+      val params = advEnsembleState.performers_metadata.get("PERFORMER-PARAMS").get.parameters
+      params should contain key("param-1")
+      params should contain key("param-2")
+      params.get("param-1").get should equal("test")
+      params.get("param-2").get should equal("test2")
+    }
+  }
+
+  s"'PERFORMER-SCHEDULER'" should{
+    "produce 5 messages in 1 seconds" in{
+      schedulerScheduleTB.expectMsg("EXECUTE")
+      Thread.sleep(100)
+      schedulerScheduleTB.receiveN(5, 1.seconds)
+    }
+    "produce 10 messages in 2 seconds" in{
+      schedulerScheduleTB.expectMsg("EXECUTE")
+      Thread.sleep(100)
+      schedulerScheduleTB.receiveN(10, 2.seconds)
+    }
+  }
+
+  s"'PERFORMER-PARAMS'" should{
+    "process 5 messages in 1 seconds" in{
+      schedulerScheduleTB.expectMsg("EXECUTE")
+      Thread.sleep(100)
+      processParamsTB.receiveN(5, 1.seconds)
+    }
+    "produce 10 messages in 2 seconds" in{
+      schedulerScheduleTB.expectMsg("EXECUTE")
+      Thread.sleep(100)
+      processParamsTB.receiveN(10, 2.seconds)
+    }
+  }
+
+  "Stopping any Performer that belongs to the Ensemble" should {
+    "force restart of entire Ensemble" in {
+      EventFilter[RestartEnsemble](occurrences = 1) intercept {
+        paramsRef ! PoisonPill
+        TestProbe().verifyActorTermination(paramsRef)
+      }
+    }
+    s"result in sending STOP - RESTART to monitor actor" in {
+      monitor.expectMsgClass(classOf[Monitor.STOP])
+      monitor.expectMsgClass(classOf[Monitor.RESTART])
+    }
+    //"keep actorRef when restarted" in {
+    //  TestProbe().expectActor(s"${parent.ref.path}/${(advEnsembleJson \ JSON_PATH.GUID).as[String]}").compareTo(advEnsembleRef) should be(0)
+    //  TestProbe().expectActor(s"${parent.ref.path}/${(advEnsembleJson \ JSON_PATH.GUID).as[String]}/PERFORMER-SCHEDULER").compareTo(scheduleRef) should be(0)
+    //  TestProbe().expectActor(s"${parent.ref.path}/${(advEnsembleJson \ JSON_PATH.GUID).as[String]}/PERFORMER-PARAMS").compareTo(paramsRef) should be(0)
+    //}
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/b7dd7961/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala b/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
index 5be25c4..4df7671 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/Utils_JSONTest.scala
@@ -267,4 +267,60 @@ object Utils_JSONTest {
        ]
      }"""
 
+  val simple_ensemble_test_json =
+    """
+     {
+       "guid":"MY-ENSEMBLE-0005",
+       "command": "UPDATE",
+       "performers":[
+         {
+           "guid": "TEST-0004",
+           "schedule": 0,
+           "backoff": 0,
+           "source": {
+             "name": "fey-test-actor.jar",
+             "classPath": "org.apache.iota.fey.TestActor",
+             "parameters": {}
+           }
+         }
+       ],
+       "connections":[]
+     }
+    """
+
+  val ensemble_test_json =
+    """
+     {
+       "guid":"MY-ENSEMBLE-0005",
+       "command": "NONE",
+       "performers":[
+         {
+           "guid": "PERFORMER-SCHEDULER",
+           "schedule": 200,
+           "backoff": 0,
+           "source": {
+             "name": "fey-test-actor.jar",
+             "classPath": "org.apache.iota.fey.TestActor",
+             "parameters": {}
+           }
+         },
+          {
+           "guid": "PERFORMER-PARAMS",
+           "schedule": 0,
+           "backoff": 0,
+           "source": {
+             "name": "fey-test-actor.jar",
+             "classPath": "org.apache.iota.fey.TestActor",
+             "parameters": {
+               "param-1" : "test",
+               "param-2" : "test2"
+             }
+           }
+         }
+       ],
+       "connections":[
+        {"PERFORMER-SCHEDULER":["PERFORMER-PARAMS"]}
+       ]
+     }
+    """
 }