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/21 23:38:00 UTC
[09/10] incubator-iota git commit: Adding tests to
WatchServiceReceiver.scala
Adding tests to WatchServiceReceiver.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/b21fb6b3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-iota/tree/b21fb6b3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-iota/diff/b21fb6b3
Branch: refs/heads/master
Commit: b21fb6b331509fc488341386bebfe52ec464393f
Parents: e892b5d
Author: Barbara Gomes <ba...@gmail.com>
Authored: Thu Jul 21 12:35:11 2016 -0700
Committer: Barbara Gomes <ba...@gmail.com>
Committed: Thu Jul 21 12:35:11 2016 -0700
----------------------------------------------------------------------
.../apache/iota/fey/WatchServiceReceiver.scala | 2 +-
.../org/apache/iota/fey/JsonReceiverSpec.scala | 1 -
.../scala/org/apache/iota/fey/TestSetup.scala | 6 +-
.../iota/fey/WatchServiceReceiverSpec.scala | 84 ++++++++++++++++++++
4 files changed, 90 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/b21fb6b3/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 a20ce54..a07a8d2 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
@@ -67,7 +67,7 @@ class WatchServiceReceiver(receiverActor: ActorRef) extends JsonReceiver{
key.reset()
}
- private def processJson(path: String, file: File) = {
+ private[fey] def processJson(path: String, file: File) = {
try{
getJsonObject(path) match {
case Some(orchestrationJSON) =>
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/b21fb6b3/fey-core/src/test/scala/org/apache/iota/fey/JsonReceiverSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/JsonReceiverSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/JsonReceiverSpec.scala
index 5904f2b..1cf25ee 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/JsonReceiverSpec.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/JsonReceiverSpec.scala
@@ -16,7 +16,6 @@
* limitations under the License.
*/
-
package org.apache.iota.fey
import java.nio.file.{Files, Paths}
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/b21fb6b3/fey-core/src/test/scala/org/apache/iota/fey/TestSetup.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/TestSetup.scala b/fey-core/src/test/scala/org/apache/iota/fey/TestSetup.scala
index 2db22a1..12a33d7 100644
--- a/fey-core/src/test/scala/org/apache/iota/fey/TestSetup.scala
+++ b/fey-core/src/test/scala/org/apache/iota/fey/TestSetup.scala
@@ -22,6 +22,7 @@ import java.io.File
import java.nio.file.Paths
import org.apache.commons.io.FileUtils
+import org.scalatest.Tag
object TestSetup {
@@ -59,11 +60,14 @@ object TestSetup {
file.mkdirs()
file = new File(s"/tmp/fey/test/json")
file.mkdirs()
+ file = new File(s"/tmp/fey/test/json/watchtest")
+ file.mkdirs()
file = new File(s"/tmp/fey/test/jars")
file.mkdirs()
file = new File(s"/tmp/fey/test/jars/dynamic")
file.mkdirs()
}
-
}
+
+object SlowTest extends Tag("org.apache.iota.fey.SlowTest")
http://git-wip-us.apache.org/repos/asf/incubator-iota/blob/b21fb6b3/fey-core/src/test/scala/org/apache/iota/fey/WatchServiceReceiverSpec.scala
----------------------------------------------------------------------
diff --git a/fey-core/src/test/scala/org/apache/iota/fey/WatchServiceReceiverSpec.scala b/fey-core/src/test/scala/org/apache/iota/fey/WatchServiceReceiverSpec.scala
new file mode 100644
index 0000000..131b3ae
--- /dev/null
+++ b/fey-core/src/test/scala/org/apache/iota/fey/WatchServiceReceiverSpec.scala
@@ -0,0 +1,84 @@
+
+/*
+ * 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.nio.file.{Files, Paths}
+import java.nio.charset.StandardCharsets
+
+import akka.testkit.{EventFilter, TestProbe}
+
+import scala.concurrent.duration.{DurationInt, FiniteDuration}
+import java.io.File
+
+import ch.qos.logback.classic.Level
+
+class WatchServiceReceiverSpec extends BaseAkkaSpec{
+
+ val watcherTB = TestProbe("WATCH-SERVICE")
+ var watchFileTask:WatchServiceReceiver = _
+ val watchTestDir = s"${CONFIG.JSON_REPOSITORY}/watchtest"
+
+ "Creating WatchServiceReceiver" should {
+ "process initial files in the JSON repository" in {
+ CONFIG.JSON_EXTENSION = "json.not"
+ watchFileTask = new WatchServiceReceiver(watcherTB.ref)
+ watcherTB.expectMsgAllClassOf(classOf[JsonReceiverActor.JSON_RECEIVED])
+ CONFIG.JSON_EXTENSION = "json.test"
+ }
+ }
+
+ var watchThread: Thread = _
+ "Start a Thread with WatchServiceReceiver" should {
+ "Start Thread" in {
+ watchThread = new Thread(watchFileTask, "TESTING-WATCHER-IN-THREAD")
+ watchThread.setDaemon(true)
+ watchThread.start()
+ TestProbe().isThreadRunning("TESTING-WATCHER-IN-THREAD") should be(true)
+ }
+ }
+
+ "Start watching directory" should {
+ "Starting receiving CREATED event" taggedAs(SlowTest) in {
+ watchFileTask.watch(Paths.get(watchTestDir))
+ Files.write(Paths.get(s"$watchTestDir/watched.json.test"), Utils_JSONTest.create_json_test.getBytes(StandardCharsets.UTF_8))
+ watcherTB.expectMsgAllClassOf(20.seconds, classOf[JsonReceiverActor.JSON_RECEIVED])
+ }
+ "Starting receiving UPDATE event" taggedAs(SlowTest) in {
+ Files.write(Paths.get(s"$watchTestDir/watched-update.json.test"), Utils_JSONTest.delete_json_test.getBytes(StandardCharsets.UTF_8))
+ Thread.sleep(200)
+ Files.write(Paths.get(s"$watchTestDir/watched-update.json.test"), Utils_JSONTest.create_json_test.getBytes(StandardCharsets.UTF_8))
+ watcherTB.expectMsgAllClassOf(20.seconds, classOf[JsonReceiverActor.JSON_RECEIVED])
+ }
+ }
+
+ "processJson" should {
+ "log to warn level when json has invalid schema" in {
+ Files.write(Paths.get(s"$watchTestDir/watched-invalid.json.test"), Utils_JSONTest.test_json_schema_invalid.getBytes(StandardCharsets.UTF_8))
+ watchFileTask.processJson(s"$watchTestDir/watched-invalid.json.test",new File(s"$watchTestDir/watched-invalid.json.test"))
+ s"File $watchTestDir/watched-invalid.json.test not processed. Incorrect JSON schema" should beLoggedAt(Level.WARN)
+ }
+ }
+
+ "interrupt watchservice" should{
+ "interrupt thread" in {
+ watchThread.interrupt()
+ }
+ }
+
+}