iota-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tonyfaust...@apache.org
Subject [05/12] incubator-iota git commit: First draft of testing
Date Mon, 18 Jul 2016 20:43:28 GMT
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 <barbaramaltagomes@gmail.com>
Authored: Fri Jul 15 16:23:39 2016 -0700
Committer: Barbara Gomes <barbaramaltagomes@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" : []
+     }"""
+
+
+}


Mime
View raw message