You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@toree.apache.org by lb...@apache.org on 2016/01/22 23:07:22 UTC
[14/51] [abbrv] incubator-toree git commit: Moved scala files to new
locations based on new package
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/handler/GenericSocketMessageHandlerSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/handler/GenericSocketMessageHandlerSpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/handler/GenericSocketMessageHandlerSpec.scala
deleted file mode 100644
index 54ebdc8..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/handler/GenericSocketMessageHandlerSpec.scala
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2014 IBM Corp.
- *
- * Licensed 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 com.ibm.spark.kernel.protocol.v5.handler
-
-import akka.actor.{ActorSystem, Props, ActorRef, ActorSelection}
-import akka.testkit.{ImplicitSender, TestKit, TestProbe}
-import com.ibm.spark.kernel.protocol.v5._
-import com.ibm.spark.kernel.protocol.v5.kernel.ActorLoader
-import com.ibm.spark.kernel.protocol.v5Test._
-import org.mockito.Mockito._
-import org.scalatest.mock.MockitoSugar
-import org.scalatest.{Matchers, FunSpecLike, FunSpec}
-
-class GenericSocketMessageHandlerSpec extends TestKit(ActorSystem("GenericSocketMessageHandlerSystem"))
-with ImplicitSender with FunSpecLike with Matchers with MockitoSugar {
- describe("GenericSocketMessageHandler( ActorLoader, SocketType )") {
- // Create a mock ActorLoader for the Relay we are going to test
- val actorLoader: ActorLoader = mock[ActorLoader]
-
- // Create a probe for the ActorSelection that the ActorLoader will return
- val selectionProbe: TestProbe = TestProbe()
- val selection: ActorSelection = system.actorSelection(selectionProbe.ref.path.toString)
- when(actorLoader.load(SocketType.Control)).thenReturn(selection)
-
- // The Relay we are going to be testing against
- val genericHandler: ActorRef = system.actorOf(
- Props(classOf[GenericSocketMessageHandler], actorLoader, SocketType.Control)
- )
-
- describe("#receive( KernelMessage )") {
- genericHandler ! MockKernelMessage
-
- it("should send the message to the selected actor"){
- selectionProbe.expectMsg(MockKernelMessage)
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/handler/InputRequestReplyHandlerSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/handler/InputRequestReplyHandlerSpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/handler/InputRequestReplyHandlerSpec.scala
deleted file mode 100644
index 57114bb..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/handler/InputRequestReplyHandlerSpec.scala
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright 2015 IBM Corp.
- *
- * Licensed 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 com.ibm.spark.kernel.protocol.v5.handler
-
-import java.util.UUID
-import java.util.concurrent.ConcurrentHashMap
-
-import akka.actor.{Props, ActorRef, ActorSystem}
-import akka.testkit.{TestProbe, ImplicitSender, TestKit}
-import com.ibm.spark.kernel.protocol.v5.content.InputReply
-import com.ibm.spark.kernel.protocol.v5.{HeaderBuilder, MessageType, KMBuilder, SystemActorType}
-import com.ibm.spark.kernel.protocol.v5.kernel.ActorLoader
-import org.scalatest.concurrent.Eventually
-import org.scalatest.mock.MockitoSugar
-import org.scalatest.time.{Milliseconds, Span}
-import org.scalatest.{BeforeAndAfter, FunSpecLike, Matchers}
-import scala.concurrent.duration._
-
-import org.mockito.Mockito._
-
-import collection.JavaConverters._
-
-class InputRequestReplyHandlerSpec
- extends TestKit(ActorSystem("InputRequestReplyHandlerSystem"))
- with ImplicitSender with FunSpecLike with Matchers with MockitoSugar
- with BeforeAndAfter with Eventually
-{
- implicit override val patienceConfig = PatienceConfig(
- timeout = scaled(Span(200, Milliseconds)),
- interval = scaled(Span(5, Milliseconds))
- )
-
- private var fakeSender: TestProbe = _
- private var kernelMessageRelayProbe: TestProbe = _
- private var mockActorLoader: ActorLoader = _
- private var responseMap: collection.mutable.Map[String, ActorRef] = _
-
- private var inputRequestReplyHandler: ActorRef = _
-
- before {
- fakeSender = TestProbe()
-
- kernelMessageRelayProbe = TestProbe()
- mockActorLoader = mock[ActorLoader]
- doReturn(system.actorSelection(kernelMessageRelayProbe.ref.path.toString))
- .when(mockActorLoader).load(SystemActorType.KernelMessageRelay)
-
- responseMap = new ConcurrentHashMap[String, ActorRef]().asScala
-
- inputRequestReplyHandler = system.actorOf(Props(
- classOf[InputRequestReplyHandler], mockActorLoader, responseMap
- ))
- }
-
- describe("InputRequestReplyHandler") {
- describe("#receive") {
- it("should store the sender under the session if input_request") {
- val session = UUID.randomUUID().toString
- val inputRequestMessage = KMBuilder()
- .withParentHeader(HeaderBuilder.empty.copy(session = session))
- .withHeader(MessageType.Outgoing.InputRequest)
- .build
-
- fakeSender.send(inputRequestReplyHandler, inputRequestMessage)
-
- eventually {
- responseMap(session) should be (fakeSender.ref)
- }
- }
-
- it("should forward message to relay if input_request") {
- val inputRequestMessage = KMBuilder()
- .withHeader(MessageType.Outgoing.InputRequest)
- .build
-
- fakeSender.send(inputRequestReplyHandler, inputRequestMessage)
-
- kernelMessageRelayProbe.expectMsg(inputRequestMessage)
- }
-
- it("should send the received message value to the stored sender with " +
- "the same session if input_reply") {
- val expected = "some value"
- val session = UUID.randomUUID().toString
-
- // Build the message to "get back from the world"
- val inputReplyMessage = KMBuilder()
- .withHeader(HeaderBuilder.empty.copy(
- msg_type = MessageType.Incoming.InputReply.toString,
- session = session
- ))
- .withContentString(InputReply(expected))
- .build
-
- // Add our fake sender actor to the receiving end of the message
- responseMap(session) = fakeSender.ref
-
- fakeSender.send(inputRequestReplyHandler, inputReplyMessage)
-
- // Sender should receive a response
- fakeSender.expectMsg(expected)
- }
-
- it("should do nothing if the session is not found for input_reply") {
- val expected = "some value"
- val session = UUID.randomUUID().toString
-
- // Build the message to "get back from the world"
- val inputReplyMessage = KMBuilder()
- .withHeader(HeaderBuilder.empty.copy(
- msg_type = MessageType.Incoming.InputReply.toString,
- session = session
- ))
- .withContentString(InputReply(expected))
- .build
-
- fakeSender.send(inputRequestReplyHandler, inputReplyMessage)
-
- // Sender should not receive a response
- fakeSender.expectNoMsg(300.milliseconds)
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/handler/KernelInfoRequestHandlerSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/handler/KernelInfoRequestHandlerSpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/handler/KernelInfoRequestHandlerSpec.scala
deleted file mode 100644
index af44443..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/handler/KernelInfoRequestHandlerSpec.scala
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2014 IBM Corp.
- *
- * Licensed 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 com.ibm.spark.kernel.protocol.v5.handler
-
-import akka.actor.{ActorRef, ActorSelection, ActorSystem, Props}
-import akka.testkit.{TestProbe, ImplicitSender, TestKit}
-import com.ibm.spark.kernel.protocol.v5.content.KernelInfoReply
-import com.ibm.spark.kernel.protocol.v5.kernel.ActorLoader
-import com.ibm.spark.kernel.protocol.v5.{SystemActorType, Header, KernelMessage}
-import org.mockito.AdditionalMatchers.{not => mockNot}
-import org.mockito.Matchers.{eq => mockEq}
-import com.typesafe.config.ConfigFactory
-import org.mockito.Mockito._
-import org.scalatest.mock.MockitoSugar
-import org.scalatest.{FunSpecLike, Matchers}
-import play.api.libs.json.Json
-
-import scala.concurrent.duration._
-
-object KernelInfoRequestHandlerSpec {
- val config = """
- akka {
- loglevel = "WARNING"
- }"""
-}
-
-class KernelInfoRequestHandlerSpec extends TestKit(
- ActorSystem("KernelInfoRequestHandlerSpec",
- ConfigFactory.parseString(KernelInfoRequestHandlerSpec.config))
-) with ImplicitSender with FunSpecLike with Matchers with MockitoSugar {
- val actorLoader: ActorLoader = mock[ActorLoader]
- val actor = system.actorOf(Props(classOf[KernelInfoRequestHandler], actorLoader))
-
- val relayProbe : TestProbe = TestProbe()
- val relaySelection : ActorSelection =
- system.actorSelection(relayProbe.ref.path)
- when(actorLoader.load(SystemActorType.KernelMessageRelay))
- .thenReturn(relaySelection)
- when(actorLoader.load(mockNot(mockEq(SystemActorType.KernelMessageRelay))))
- .thenReturn(system.actorSelection(""))
-
- val header = Header("","","","","")
- val kernelMessage = new KernelMessage(
- Seq[String](), "test message", header, header, Map[String, String](), "{}"
- )
-
- describe("Kernel Info Request Handler") {
- it("should return a KernelMessage containing kernel info response") {
- actor ! kernelMessage
- val reply = relayProbe.receiveOne(1.seconds).asInstanceOf[KernelMessage]
- val kernelInfo = Json.parse(reply.contentString).as[KernelInfoReply]
- kernelInfo.implementation should be ("spark")
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/interpreter/tasks/ExecuteRequestTaskActorSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/interpreter/tasks/ExecuteRequestTaskActorSpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/interpreter/tasks/ExecuteRequestTaskActorSpec.scala
deleted file mode 100644
index be982cb..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/interpreter/tasks/ExecuteRequestTaskActorSpec.scala
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Copyright 2014 IBM Corp.
- *
- * Licensed 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 com.ibm.spark.kernel.protocol.v5.interpreter.tasks
-
-import java.io.OutputStream
-
-import akka.actor.{ActorSystem, Props}
-import akka.testkit.{ImplicitSender, TestKit}
-import com.ibm.spark.interpreter._
-import com.ibm.spark.kernel.protocol.v5._
-import com.ibm.spark.kernel.protocol.v5.content._
-import com.typesafe.config.ConfigFactory
-import org.mockito.Mockito._
-import org.mockito.Matchers.{eq => mockEq, anyString, anyBoolean}
-import org.scalatest.mock.MockitoSugar
-import org.scalatest.{Matchers, FunSpecLike}
-
-import scala.concurrent.duration._
-
-object ExecuteRequestTaskActorSpec {
- val config = """
- akka {
- loglevel = "WARNING"
- }"""
-}
-
-class ExecuteRequestTaskActorSpec extends TestKit(
- ActorSystem(
- "ExecuteRequestTaskActorSpec",
- ConfigFactory.parseString(ExecuteRequestTaskActorSpec.config)
- )
-) with ImplicitSender with FunSpecLike with Matchers with MockitoSugar
-{
- describe("ExecuteRequestTaskActor") {
- describe("#receive") {
- it("should return an ExecuteReplyOk if the interpreter returns success") {
- val mockInterpreter = mock[Interpreter]
- doReturn((Results.Success, Left(new ExecuteOutput))).when(mockInterpreter)
- .interpret(anyString(), anyBoolean())
-
- val executeRequestTask =
- system.actorOf(Props(
- classOf[ExecuteRequestTaskActor],
- mockInterpreter
- ))
-
- val executeRequest = (ExecuteRequest(
- "val x = 3", false, false,
- UserExpressions(), false
- ), mock[KernelMessage], mock[OutputStream])
-
- executeRequestTask ! executeRequest
-
- val result =
- receiveOne(5.seconds)
- .asInstanceOf[Either[ExecuteOutput, ExecuteError]]
-
- result.isLeft should be (true)
- result.left.get shouldBe an [ExecuteOutput]
- }
-
- it("should return an ExecuteReplyAbort if the interpreter returns aborted") {
- val mockInterpreter = mock[Interpreter]
- doReturn((Results.Aborted, Right(mock[ExecuteAborted]))).when(mockInterpreter)
- .interpret(anyString(), anyBoolean())
-
- val executeRequestTask =
- system.actorOf(Props(
- classOf[ExecuteRequestTaskActor],
- mockInterpreter
- ))
-
- val executeRequest = (ExecuteRequest(
- "val x = 3", false, false,
- UserExpressions(), false
- ), mock[KernelMessage], mock[OutputStream])
-
- executeRequestTask ! executeRequest
-
- val result =
- receiveOne(5.seconds)
- .asInstanceOf[Either[ExecuteOutput, ExecuteFailure]]
-
- result.isRight should be (true)
- result.right.get shouldBe an [ExecuteAborted]
- }
-
- it("should return an ExecuteReplyError if the interpreter returns error") {
- val mockInterpreter = mock[Interpreter]
- doReturn((Results.Error, Right(mock[ExecuteError]))).when(mockInterpreter)
- .interpret(anyString(), anyBoolean())
-
- val executeRequestTask =
- system.actorOf(Props(
- classOf[ExecuteRequestTaskActor],
- mockInterpreter
- ))
-
- val executeRequest = (ExecuteRequest(
- "val x = 3", false, false,
- UserExpressions(), false
- ), mock[KernelMessage], mock[OutputStream])
-
- executeRequestTask ! executeRequest
-
- val result =
- receiveOne(5.seconds)
- .asInstanceOf[Either[ExecuteOutput, ExecuteError]]
-
- result.isRight should be (true)
- result.right.get shouldBe an [ExecuteError]
- }
-
- it("should return ExecuteReplyError if interpreter returns incomplete") {
- val mockInterpreter = mock[Interpreter]
- doReturn((Results.Incomplete, Right(""))).when(mockInterpreter)
- .interpret(anyString(), anyBoolean())
-
- val executeRequestTask =
- system.actorOf(Props(
- classOf[ExecuteRequestTaskActor],
- mockInterpreter
- ))
-
- val executeRequest = (ExecuteRequest(
- "(1 + 2", false, false,
- UserExpressions(), false
- ), mock[KernelMessage], mock[OutputStream])
-
- executeRequestTask ! executeRequest
-
- val result =
- receiveOne(5.seconds)
- .asInstanceOf[Either[ExecuteOutput, ExecuteError]]
-
- result.isLeft should be (false)
- result.right.get shouldBe an [ExecuteError]
- }
-
- it("should return an ExecuteReplyOk when receiving empty code.") {
- val mockInterpreter = mock[Interpreter]
- doReturn((Results.Incomplete, Right(""))).when(mockInterpreter)
- .interpret(anyString(), anyBoolean())
-
- val executeRequestTask =
- system.actorOf(Props(
- classOf[ExecuteRequestTaskActor],
- mockInterpreter
- ))
-
- val executeRequest = (ExecuteRequest(
- " ", false, false,
- UserExpressions(), false
- ), mock[KernelMessage], mock[OutputStream])
-
- executeRequestTask ! executeRequest
-
- val result =
- receiveOne(5.seconds)
- .asInstanceOf[Either[ExecuteOutput, ExecuteError]]
-
- result.isLeft should be (true)
- result.isRight should be (false)
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/ActorLoaderSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/ActorLoaderSpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/ActorLoaderSpec.scala
deleted file mode 100644
index 8bb5f40..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/ActorLoaderSpec.scala
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2014 IBM Corp.
- *
- * Licensed 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 com.ibm.spark.kernel.protocol.v5.kernel
-
-import akka.actor.{ActorSystem, Props}
-import akka.testkit.{ImplicitSender, TestKit, TestProbe}
-import com.ibm.spark.kernel.protocol.v5.{MessageType, SocketType}
-import org.scalatest.mock.MockitoSugar
-import org.scalatest.{FunSpecLike, Matchers}
-import test.utils.TestProbeProxyActor
-
-import scala.concurrent.duration._
-
-class ActorLoaderSpec extends TestKit(ActorSystem("ActorLoaderSpecSystem"))
-with ImplicitSender with FunSpecLike with Matchers with MockitoSugar {
- describe("ActorLoader"){
- describe("#load( MessageType )"){
- it("should load an ActorSelection that has been loaded into the system"){
- val testProbe: TestProbe = TestProbe()
- system.actorOf(Props(classOf[TestProbeProxyActor], testProbe),
- MessageType.Outgoing.ClearOutput.toString)
- val actorLoader: ActorLoader = SimpleActorLoader(system)
- actorLoader.load(MessageType.Outgoing.ClearOutput) ! "<Test Message>"
- testProbe.expectMsg("<Test Message>")
- }
-
- it("should expect no message when there is no actor"){
- val testProbe: TestProbe = TestProbe()
- val actorLoader: ActorLoader = SimpleActorLoader(system)
- actorLoader.load(MessageType.Outgoing.CompleteReply) ! "<Test Message>"
- testProbe.expectNoMsg(25.millis)
- // This is to test to see if there the messages go to the actor inbox or the dead mail inbox
- system.actorOf(Props(classOf[TestProbeProxyActor], testProbe),
- MessageType.Outgoing.CompleteReply.toString)
- testProbe.expectNoMsg(25.millis)
- }
- }
- describe("#load( SocketType )"){
- it("should load an ActorSelection that has been loaded into the system"){
- val testProbe: TestProbe = TestProbe()
- system.actorOf(Props(classOf[TestProbeProxyActor], testProbe), SocketType.Shell.toString)
- val actorLoader: ActorLoader = SimpleActorLoader(system)
- actorLoader.load(SocketType.Shell) ! "<Test Message>"
- testProbe.expectMsg("<Test Message>")
- }
-
- it("should expect no message when there is no actor"){
- val testProbe: TestProbe = TestProbe()
- val actorLoader: ActorLoader = SimpleActorLoader(system)
- actorLoader.load(SocketType.IOPub) ! "<Test Message>"
- testProbe.expectNoMsg(25.millis)
- // This is to test to see if there the messages go to the actor inbox or the dead mail inbox
- system.actorOf(Props(classOf[TestProbeProxyActor], testProbe), SocketType.IOPub.toString)
- testProbe.expectNoMsg(25.millis)
- }
-
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/SimpleActorLoaderSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/SimpleActorLoaderSpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/SimpleActorLoaderSpec.scala
deleted file mode 100644
index 65f0990..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/SimpleActorLoaderSpec.scala
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2014 IBM Corp.
- *
- * Licensed 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 com.ibm.spark.kernel.protocol.v5.kernel
-
-import akka.actor.{ActorSelection, ActorSystem, Props}
-import akka.testkit.{TestKit, TestProbe}
-import com.ibm.spark.kernel.protocol.v5.MessageType
-import org.scalatest.{FunSpecLike, Matchers}
-import test.utils.TestProbeProxyActor
-
-class SimpleActorLoaderSpec extends TestKit(ActorSystem("SimpleActorLoaderSpecSystem"))
- with FunSpecLike with Matchers
-{
- describe("SimpleActorLoader") {
- //val system = ActorSystem("SimpleActorLoaderSystem")
- val testMessage: String = "Hello Message"
-
- describe("#load( MessageType )") {
- it("should load a MessageType Actor"){
- // Create a new test probe to verify our selection works
- val messageTypeProbe: TestProbe = new TestProbe(system)
-
- // Add an actor to the system to send a message to
- system.actorOf(
- Props(classOf[TestProbeProxyActor], messageTypeProbe),
- name = MessageType.Outgoing.ExecuteInput.toString
- )
-
- // Create the ActorLoader with our test system
- val actorLoader: SimpleActorLoader = SimpleActorLoader(system)
-
- // Get the actor and send it a message
- val loadedMessageActor: ActorSelection =
- actorLoader.load(MessageType.Outgoing.ExecuteInput)
-
- loadedMessageActor ! testMessage
-
- // Assert the probe received the message
- messageTypeProbe.expectMsg(testMessage)
- }
- }
-
- }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/UtilitiesSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/UtilitiesSpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/UtilitiesSpec.scala
deleted file mode 100644
index 67c6eeb..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/UtilitiesSpec.scala
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright 2014 IBM Corp.
- *
- * Licensed 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 com.ibm.spark.kernel.protocol.v5.kernel
-
-import akka.util.ByteString
-import com.ibm.spark.communication.ZMQMessage
-import com.ibm.spark.kernel.protocol.v5._
-import org.scalatest.{FunSpec, Matchers}
-
-/**
- * Refactored from old KernelMessageSpec.
- */
-class UtilitiesSpec extends FunSpec with Matchers {
- val header: Header = Header(
- "<UUID>", "<STRING>", "<UUID>", "<STRING>", "<FLOAT>"
- )
- val parentHeader : ParentHeader = ParentHeader(
- "<PARENT-UUID>", "<PARENT-STRING>", "<PARENT-UUID>", "<PARENT-STRING>", "<PARENT-FLOAT>"
- )
- val kernelMessage = KernelMessage(
- Seq("<STRING-1>","<STRING-2>"),
- "<SIGNATURE>", header, parentHeader, Map(), "<STRING>"
- )
-
- val zmqMessage = ZMQMessage(
- ByteString("<STRING-1>".replaceAll("""\s""", "").getBytes),
- ByteString("<STRING-2>".replaceAll("""\s""", "").getBytes),
- ByteString("<IDS|MSG>".replaceAll("""\s""", "").getBytes),
- ByteString("<SIGNATURE>".replaceAll("""\s""", "").getBytes),
- ByteString(
- """
- {
- "msg_id": "<UUID>",
- "username": "<STRING>",
- "session": "<UUID>",
- "msg_type": "<STRING>",
- "version": "<FLOAT>"
- }
- """.stripMargin.replaceAll("""\s""", "").getBytes),
- ByteString(
- """
- {
- "msg_id": "<PARENT-UUID>",
- "username": "<PARENT-STRING>",
- "session": "<PARENT-UUID>",
- "msg_type": "<PARENT-STRING>",
- "version": "<PARENT-FLOAT>"
- }
- """.stripMargin.replaceAll("""\s""", "").getBytes),
- ByteString("{}".replaceAll("""\s""", "").getBytes),
- ByteString("<STRING>".replaceAll("""\s""", "").getBytes)
- )
-
- describe("Utilities") {
- describe("implicit #KernelMessageToZMQMessage") {
- it("should correctly convert a kernel message to a ZMQMessage") {
- Utilities.KernelMessageToZMQMessage(kernelMessage) should be (zmqMessage)
- }
- }
-
- describe("implicit #ZMQMessageToKernelMessage") {
- it("should correctly convert a ZMQMessage to a kernel message") {
- Utilities.ZMQMessageToKernelMessage(zmqMessage) should be (kernelMessage)
- }
- }
-
- describe("implicit conversions should be inverses of each other") {
- it("should convert back to the original message, ZMQ -> Kernel -> ZMQ") {
- Utilities.KernelMessageToZMQMessage(
- Utilities.ZMQMessageToKernelMessage(zmqMessage)
- ) should be (zmqMessage)
- }
- it("should convert back to the original message, Kernel -> ZMQ -> Kernel") {
- Utilities.ZMQMessageToKernelMessage(
- Utilities.KernelMessageToZMQMessage(kernelMessage)
- ) should be (kernelMessage)
- }
- }
-
- describe("implicit #StringToByteString") {
- it("should correctly convert a string to a ByteString") {
- val someString = "some content"
- val expected = ByteString(someString)
-
- Utilities.StringToByteString(someString) should be (expected)
- }
- }
-
- describe("implicit #ByteStringToString") {
- it("should correctly convert a ByteString to a string") {
- val expected = "some content"
- val byteString = ByteString(expected)
-
- Utilities.ByteStringToString(byteString) should be (expected)
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/HeartbeatSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/HeartbeatSpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/HeartbeatSpec.scala
deleted file mode 100644
index 388f466..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/HeartbeatSpec.scala
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2014 IBM Corp.
- *
- * Licensed 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 com.ibm.spark.kernel.protocol.v5.kernel.socket
-
-import akka.actor.{ActorRef, ActorSystem, Props}
-import akka.testkit.{ImplicitSender, TestKit, TestProbe}
-import akka.util.ByteString
-import com.ibm.spark.communication.ZMQMessage
-import com.typesafe.config.ConfigFactory
-import org.mockito.Matchers._
-import org.mockito.Mockito._
-import org.scalatest.mock.MockitoSugar
-import org.scalatest.{FunSpecLike, Matchers}
-
-object HeartbeatSpec {
- val config = """
- akka {
- loglevel = "WARNING"
- }"""
-}
-
-class HeartbeatSpec extends TestKit(ActorSystem("HeartbeatActorSpec", ConfigFactory.parseString(HeartbeatSpec.config)))
-with ImplicitSender with FunSpecLike with Matchers with MockitoSugar {
- val SomeMessage: String = "some message"
- val SomeZMQMessage: ZMQMessage = ZMQMessage(ByteString(SomeMessage.getBytes))
-
- describe("HeartbeatActor") {
- val socketFactory = mock[SocketFactory]
- val probe : TestProbe = TestProbe()
- when(socketFactory.Heartbeat(any(classOf[ActorSystem]), any(classOf[ActorRef]))).thenReturn(probe.ref)
-
- val heartbeat = system.actorOf(Props(classOf[Heartbeat], socketFactory))
-
- describe("send heartbeat") {
- it("should receive and send same ZMQMessage") {
- heartbeat ! SomeZMQMessage
- probe.expectMsg(SomeZMQMessage)
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/IOPubSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/IOPubSpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/IOPubSpec.scala
deleted file mode 100644
index 6e6fdb3..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/IOPubSpec.scala
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2014 IBM Corp.
- *
- * Licensed 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 com.ibm.spark.kernel.protocol.v5.kernel.socket
-
-import akka.actor.{ActorSystem, Props}
-import akka.testkit.{ImplicitSender, TestKit, TestProbe}
-import com.ibm.spark.communication.ZMQMessage
-import com.ibm.spark.kernel.protocol.v5.kernel.Utilities
-import com.ibm.spark.kernel.protocol.v5Test._
-import Utilities._
-import com.typesafe.config.ConfigFactory
-import org.mockito.Matchers._
-import org.mockito.Mockito._
-import org.scalatest.mock.MockitoSugar
-import org.scalatest.{FunSpecLike, Matchers}
-
-object IOPubSpec {
- val config ="""
- akka {
- loglevel = "WARNING"
- }"""
-}
-
-class IOPubSpec extends TestKit(ActorSystem("IOPubActorSpec", ConfigFactory.parseString(IOPubSpec.config)))
-with ImplicitSender with FunSpecLike with Matchers with MockitoSugar {
-
- describe("IOPubActor") {
- val socketFactory = mock[SocketFactory]
- val probe : TestProbe = TestProbe()
- when(socketFactory.IOPub(any(classOf[ActorSystem]))).thenReturn(probe.ref)
-
- val socket = system.actorOf(Props(classOf[IOPub], socketFactory))
-
- // TODO test that the response type changed
- describe("#receive") {
- it("should reply with a ZMQMessage") {
- // Use the implicit to convert the KernelMessage to ZMQMessage
- val MockZMQMessage : ZMQMessage = MockKernelMessage
-
- socket ! MockKernelMessage
- probe.expectMsg(MockZMQMessage)
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/ShellSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/ShellSpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/ShellSpec.scala
deleted file mode 100644
index d28a5ae..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/ShellSpec.scala
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright 2014 IBM Corp.
- *
- * Licensed 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 com.ibm.spark.kernel.protocol.v5.kernel.socket
-
-import java.nio.charset.Charset
-
-import akka.actor.{ActorSelection, ActorRef, ActorSystem, Props}
-import akka.testkit.{ImplicitSender, TestKit, TestProbe}
-import akka.util.ByteString
-import com.ibm.spark.communication.ZMQMessage
-import com.ibm.spark.kernel.protocol.v5._
-import com.ibm.spark.kernel.protocol.v5.kernel.{ActorLoader, Utilities}
-import com.ibm.spark.kernel.protocol.v5Test._
-import Utilities._
-import com.typesafe.config.ConfigFactory
-import org.mockito.Matchers._
-import org.mockito.Mockito._
-import org.scalatest.mock.MockitoSugar
-import org.scalatest.{FunSpecLike, Matchers}
-
-object ShellSpec {
- val config ="""
- akka {
- loglevel = "WARNING"
- }"""
-}
-
-class ShellSpec extends TestKit(ActorSystem("ShellActorSpec", ConfigFactory.parseString(ShellSpec.config)))
- with ImplicitSender with FunSpecLike with Matchers with MockitoSugar {
-
- describe("Shell") {
- val socketFactory = mock[SocketFactory]
- val actorLoader = mock[ActorLoader]
- val socketProbe : TestProbe = TestProbe()
- when(socketFactory.Shell(any(classOf[ActorSystem]), any(classOf[ActorRef]))).thenReturn(socketProbe.ref)
-
- val relayProbe : TestProbe = TestProbe()
- val relaySelection : ActorSelection = system.actorSelection(relayProbe.ref.path)
- when(actorLoader.load(SystemActorType.KernelMessageRelay)).thenReturn(relaySelection)
-
- val shell = system.actorOf(Props(classOf[Shell], socketFactory, actorLoader))
-
- describe("#receive") {
- it("( KernelMessage ) should reply with a ZMQMessage via the socket") {
- // Use the implicit to convert the KernelMessage to ZMQMessage
- val MockZMQMessage : ZMQMessage = MockKernelMessage
-
- shell ! MockKernelMessage
- socketProbe.expectMsg(MockZMQMessage)
- }
-
- it("( ZMQMessage ) should forward ZMQ Strings and KernelMessage to Relay") {
- // Use the implicit to convert the KernelMessage to ZMQMessage
- val MockZMQMessage : ZMQMessage = MockKernelMessage
-
- shell ! MockZMQMessage
-
- // Should get the last four (assuming no buffer) strings in UTF-8
- val zmqStrings = MockZMQMessage.frames.map((byteString: ByteString) =>
- new String(byteString.toArray, Charset.forName("UTF-8"))
- ).takeRight(4)
-
- val kernelMessage: KernelMessage = MockZMQMessage
-
- relayProbe.expectMsg((zmqStrings, kernelMessage))
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/SocketConfigSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/SocketConfigSpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/SocketConfigSpec.scala
deleted file mode 100644
index b36f734..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/SocketConfigSpec.scala
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright 2014 IBM Corp.
- *
- * Licensed 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 com.ibm.spark.kernel.protocol.v5.kernel.socket
-
-import com.typesafe.config.ConfigFactory
-import org.scalatest.{FunSpec, Matchers}
-import org.slf4j.LoggerFactory
-import play.api.data.validation.ValidationError
-import play.api.libs.json.{JsPath, JsValue, Json}
-
-class SocketConfigSpec extends FunSpec with Matchers {
- val logger = LoggerFactory.getLogger("jt4")
- //logger.error("WOOT!")
-
- private val jsonString: String =
- """
- {
- "stdin_port": 10000,
- "control_port": 10001,
- "hb_port": 10002,
- "shell_port": 10003,
- "iopub_port": 10004,
- "ip": "1.2.3.4",
- "transport": "tcp",
- "signature_scheme": "hmac-sha256",
- "key": ""
- }
- """.stripMargin
-
- val socketConfigJson: JsValue = Json.parse(jsonString)
-
- val socketConfigFromConfig = SocketConfig.fromConfig(ConfigFactory.parseString(jsonString))
-
- val socketConfig = SocketConfig(
- 10000, 10001, 10002, 10003, 10004, "1.2.3.4", "tcp", "hmac-sha256", ""
- )
-
- describe("SocketConfig") {
- describe("implicit conversions") {
- it("should implicitly convert from valid json to a SocketConfig instance") {
- // This is the least safe way to convert as an error is thrown if it fails
- socketConfigJson.as[SocketConfig] should be (socketConfig)
- }
-
- it("should also work with asOpt") {
- // This is safer, but we lose the error information as it returns
- // None if the conversion fails
- val newCompleteRequest = socketConfigJson.asOpt[SocketConfig]
-
- newCompleteRequest.get should be (socketConfig)
- }
-
- it("should also work with validate") {
- // This is the safest as it collects all error information (not just first error) and reports it
- val CompleteRequestResults = socketConfigJson.validate[SocketConfig]
-
- CompleteRequestResults.fold(
- (invalid: Seq[(JsPath, Seq[ValidationError])]) => println("Failed!"),
- (valid: SocketConfig) => valid
- ) should be (socketConfig)
- }
-
- it("should implicitly convert from a SocketConfig instance to valid json") {
- Json.toJson(socketConfig) should be (socketConfigJson)
- }
- }
- describe("#toConfig") {
- it("should implicitly convert from valid json to a SocketConfig instance") {
- // This is the least safe way to convert as an error is thrown if it fails
- socketConfigFromConfig should be (socketConfig)
- }
-
- it("should convert json file to SocketConfig object") {
- socketConfigFromConfig.stdin_port should be (10000)
- }
- }
- }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/SocketConnectionSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/SocketConnectionSpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/SocketConnectionSpec.scala
deleted file mode 100644
index f33ddc0..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/SocketConnectionSpec.scala
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2014 IBM Corp.
- *
- * Licensed 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 com.ibm.spark.kernel.protocol.v5.kernel.socket
-
-import org.scalatest.{FunSpec, Matchers}
-
-class SocketConnectionSpec extends FunSpec with Matchers {
- describe("SocketConnection"){
- describe("#toString"){
- it("should properly format connection string"){
- val connection: SocketConnection = SocketConnection("tcp", "127.0.0.1", 1234)
- connection.toString should be ("tcp://127.0.0.1:1234")
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/SocketFactorySpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/SocketFactorySpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/SocketFactorySpec.scala
deleted file mode 100644
index abefdb3..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/SocketFactorySpec.scala
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2014 IBM Corp.
- *
- * Licensed 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 com.ibm.spark.kernel.protocol.v5.kernel.socket
-
-import org.scalatest.{FunSpec, Matchers}
-
-class SocketFactorySpec extends FunSpec with Matchers {
- describe("SocketFactory"){
- describe("HeartbeatConnection"){
- it("should be composed of transport ip and heartbeat port"){
- val config: SocketConfig = SocketConfig(-1,-1,8000,-1, -1, "<STRING-IP>", "<STRING-TRANSPORT>","<STRING-SCHEME>","<STRING-KEY>")
- val factory: SocketFactory = SocketFactory(config)
- factory.HeartbeatConnection.toString should be ("<STRING-TRANSPORT>://<STRING-IP>:8000")
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/StdinSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/StdinSpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/StdinSpec.scala
deleted file mode 100644
index 2103904..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/kernel/socket/StdinSpec.scala
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2015 IBM Corp.
- *
- * Licensed 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 com.ibm.spark.kernel.protocol.v5.kernel.socket
-
-import java.nio.charset.Charset
-
-import akka.actor.{Props, ActorSelection, ActorRef, ActorSystem}
-import akka.testkit.{TestProbe, ImplicitSender, TestKit}
-import akka.util.ByteString
-import com.ibm.spark.communication.ZMQMessage
-import com.ibm.spark.kernel.protocol.v5.kernel.Utilities._
-import com.ibm.spark.kernel.protocol.v5Test._
-import com.ibm.spark.kernel.protocol.v5.{KernelMessage, SystemActorType}
-import com.ibm.spark.kernel.protocol.v5.kernel.ActorLoader
-import com.typesafe.config.ConfigFactory
-import org.scalatest.mock.MockitoSugar
-import org.scalatest.{Matchers, FunSpecLike}
-import org.mockito.Mockito._
-import org.mockito.Matchers._
-
-object StdinSpec {
- val config ="""
- akka {
- loglevel = "WARNING"
- }"""
-}
-
-class StdinSpec extends TestKit(ActorSystem(
- "StdinActorSpec", ConfigFactory.parseString(StdinSpec.config)
-)) with ImplicitSender with FunSpecLike with Matchers with MockitoSugar {
- describe("Stdin") {
- val socketFactory = mock[SocketFactory]
- val actorLoader = mock[ActorLoader]
- val socketProbe : TestProbe = TestProbe()
- when(socketFactory.Stdin(any(classOf[ActorSystem]), any(classOf[ActorRef]))).thenReturn(socketProbe.ref)
-
- val relayProbe : TestProbe = TestProbe()
- val relaySelection : ActorSelection = system.actorSelection(relayProbe.ref.path)
- when(actorLoader.load(SystemActorType.KernelMessageRelay)).thenReturn(relaySelection)
-
- val stdin = system.actorOf(Props(classOf[Stdin], socketFactory, actorLoader))
-
- describe("#receive") {
- it("( KernelMessage ) should reply with a ZMQMessage via the socket") {
- // Use the implicit to convert the KernelMessage to ZMQMessage
- val MockZMQMessage : ZMQMessage = MockKernelMessage
-
- stdin ! MockKernelMessage
- socketProbe.expectMsg(MockZMQMessage)
- }
-
- it("( ZMQMessage ) should forward ZMQ Strings and KernelMessage to Relay") {
- // Use the implicit to convert the KernelMessage to ZMQMessage
- val MockZMQMessage : ZMQMessage = MockKernelMessage
-
- stdin ! MockZMQMessage
-
- // Should get the last four (assuming no buffer) strings in UTF-8
- val zmqStrings = MockZMQMessage.frames.map((byteString: ByteString) =>
- new String(byteString.toArray, Charset.forName("UTF-8"))
- ).takeRight(4)
-
- val kernelMessage: KernelMessage = MockZMQMessage
-
- relayProbe.expectMsg((zmqStrings, kernelMessage))
- }
- }
- }
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/magic/MagicParserSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/magic/MagicParserSpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/magic/MagicParserSpec.scala
deleted file mode 100644
index ba3415f..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/magic/MagicParserSpec.scala
+++ /dev/null
@@ -1,237 +0,0 @@
-package com.ibm.spark.kernel.protocol.v5.magic
-
-import com.ibm.spark.magic.MagicLoader
-import org.scalatest.mock.MockitoSugar
-import org.scalatest.{FunSpec, Matchers}
-import org.mockito.Mockito._
-import org.mockito.Matchers._
-
-class MagicParserSpec extends FunSpec with Matchers with MockitoSugar {
- describe("#parse") {
- it("should call parseCell if the code is a cell magic invocation") {
- val codeBlob =
- """
- |%%magic
- |foo
- |bean
- """.stripMargin
- val parser = spy(new MagicParser(mock[MagicLoader]))
- parser.parse(codeBlob)
- verify(parser).parseCell(codeBlob.trim)
- }
-
- it("should call parseLines if the code is not a cell magic") {
- val codeBlob = """%magic foo bean"""
- val parser = spy(new MagicParser(mock[MagicLoader]))
- parser.parse(codeBlob)
- verify(parser).parseLines(codeBlob.trim)
- }
- }
-
- describe("#parseCell") {
- it("should substitute the magic code for kernel code when magic is valid") {
- val magicLoader = mock[MagicLoader]
- doReturn(true).when(magicLoader).hasCellMagic(anyString())
-
- val magicName = "magic"
- val args = "foo\nbean\nbar"
- val codeBlob =
- s"""%%$magicName
- |$args
- """.stripMargin
- val parser = spy(new MagicParser(magicLoader))
- val result = parser.parseCell(codeBlob)
-
- verify(parser).substitute(magicName, args)
- result.isLeft should be(true)
- }
-
- it("should return an error if the magic invocation is invalid") {
- val magicLoader = mock[MagicLoader]
- doReturn(false).when(magicLoader).hasCellMagic(anyString())
-
- val magicName = "magic"
- val args = "foo\nbean\nbar"
- val codeBlob =
- s"""%%$magicName
- |$args
- """.stripMargin
- val parser = spy(new MagicParser(magicLoader))
- val result = parser.parseCell(codeBlob)
-
- verify(parser, times(0)).substitute(anyString(), anyString())
- result.isRight should be(true)
- }
-
- it("should return original code if code contains no magic invocations") {
- val magicLoader = mock[MagicLoader]
- doReturn(false).when(magicLoader).hasCellMagic(anyString())
-
- val codeBlob =
- s"""val x = 3
- |println(x + 2)
- """.stripMargin
- val parser = spy(new MagicParser(magicLoader))
- val result = parser.parseCell(codeBlob)
-
- verify(parser, times(0)).substitute(anyString(), anyString())
- result.isLeft should be(true)
- result.left.get should be(codeBlob)
- }
- }
-
- describe("#parseLines") {
- it("should call substituteLine for each line of code " +
- "when there are no invalid magic invocations") {
- val magicLoader = mock[MagicLoader]
- doReturn(true).when(magicLoader).hasLineMagic(anyString())
-
- val codeBlob =
- s"""val x = 3
- |%lineMagic
- """.stripMargin
- val parser = spy(new MagicParser(magicLoader))
- val result = parser.parseLines(codeBlob)
-
- verify(parser, times(2)).substituteLine(anyString())
- result.isLeft should be(true)
- }
-
- it("should return an error when there are invalid magic invocations") {
- val magicLoader = mock[MagicLoader]
- doReturn(false).when(magicLoader).hasLineMagic(anyString())
-
- val codeBlob =
- s"""val x = 3
- |%lineMagic
- """.stripMargin
- val parser = spy(new MagicParser(magicLoader))
- val result = parser.parseLines(codeBlob)
-
- verify(parser, times(0)).substituteLine(anyString())
- result.isRight should be(true)
- }
-
- it("should return original code when there are no magic invocations") {
- val magicLoader = mock[MagicLoader]
- doReturn(false).when(magicLoader).hasLineMagic(anyString())
-
- val codeBlob =
- s"""val x = 3
- |val y = x + 2
- """.stripMargin
- val parser = spy(new MagicParser(magicLoader))
- val result = parser.parseLines(codeBlob.trim)
-
- result.isLeft should be(true)
- result.left.get should be(codeBlob.trim)
- }
- }
-
- describe("#parseMagic") {
- it("should extract the cell name and arguments from a valid invocation") {
- val magicName = "foobar"
- val magicArgs = "baz\nbean"
- val codeBlob = s"""%%$magicName\n$magicArgs"""
- val parser = new MagicParser(mock[MagicLoader])
- parser.parseMagic(codeBlob) should be(Some((magicName, magicArgs)))
- }
-
- it("should extract the line name and arguments from a valid invocation") {
- val magicName = "foobar"
- val magicArgs = "baz\nbean"
- val codeBlob = s"""%$magicName $magicArgs"""
- val parser = new MagicParser(mock[MagicLoader])
- parser.parseMagic(codeBlob) should be(Some((magicName, magicArgs)))
- }
-
- it("should return none if the invocation was not valid") {
- val magicName = "foobar"
- val magicArgs = "baz\nbean"
- val codeBlob = s"""$magicName\n$magicArgs"""
- val parser = new MagicParser(mock[MagicLoader])
- parser.parseMagic(codeBlob) should be(None)
- }
- }
-
- describe("#substituteLine") {
- it("should call substitute when a codeLine is a valid magic invocation") {
- val magicName = "magic"
- val args = "-v foo bar"
- val codeLine = s"""%$magicName $args"""
- val parser = spy(new MagicParser(mock[MagicLoader]))
- doReturn(true).when(parser).isValidLineMagic(anyString())
- parser.substituteLine(codeLine)
- verify(parser).substitute(magicName, args)
- }
-
- it("should return original line of code when it's not a valid +" +
- "magic invocation") {
- val codeLine = """val x = 3"""
- val parser = spy(new MagicParser(mock[MagicLoader]))
- doReturn(false).when(parser).isValidLineMagic(anyString())
- parser.substituteLine(codeLine) should be(codeLine)
- }
- }
-
- describe("#substitute") {
- // pointless?
- it("should replace a magic invocation with an equivalent kernel call") {
- val magicName = "magic"
- val args = "foo bean"
- val parser = new MagicParser(mock[MagicLoader])
-
- val equivalent =
- s"""${parser.kernelObjectName}.$magicName(\"\"\"$args\"\"\")"""
- parser.substitute(magicName, args) should be(equivalent)
- }
- }
-
- describe("#parseOutInvalidMagics") {
- it("it should return the names of invalid magics") {
- val magicOne = "foo"
- val magicTwo = "qux"
- val codeBlob =
- s"""
- |%$magicOne bar baz
- |%$magicTwo quo bean
- """.stripMargin
- val parser = spy(new MagicParser(mock[MagicLoader]))
- doReturn(false).when(parser).isValidLineMagic(anyString())
-
- parser.parseOutInvalidMagics(codeBlob) should be(List(magicOne, magicTwo))
- }
-
- it("it should nothing if all magic invocations are valid") {
- val magicOne = "foo"
- val magicTwo = "qux"
- val codeBlob =
- s"""
- |%$magicOne bar baz
- |%$magicTwo quo bean
- """.stripMargin
- val parser = spy(new MagicParser(mock[MagicLoader]))
- doReturn(true).when(parser).isValidLineMagic(anyString())
-
- parser.parseOutInvalidMagics(codeBlob) should be(Nil)
- }
- }
-
- describe("#isValidLineMagic") {
- it("should return true if the line magic invocation is valid") {
- val magicLoader = mock[MagicLoader]
- doReturn(true).when(magicLoader).hasLineMagic(anyString())
-
- val parser = new MagicParser(magicLoader)
- parser.isValidLineMagic("%foobar baz") should be(true)
- }
-
- it("should return false if the line magic invocation is not valid") {
- val magicLoader = mock[MagicLoader]
- doReturn(false).when(magicLoader).hasLineMagic(anyString())
-
- val parser = new MagicParser(magicLoader)
- parser.isValidLineMagic("%foobar baz") should be(false)
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/magic/PostProcessorSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/magic/PostProcessorSpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/magic/PostProcessorSpec.scala
deleted file mode 100644
index 1557460..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/magic/PostProcessorSpec.scala
+++ /dev/null
@@ -1,123 +0,0 @@
-package com.ibm.spark.kernel.protocol.v5.magic
-
-import com.ibm.spark.interpreter.Interpreter
-import com.ibm.spark.kernel.protocol.v5._
-import com.ibm.spark.magic.{CellMagicOutput, LineMagicOutput}
-import org.mockito.Matchers._
-import org.mockito.Mockito._
-import org.scalatest.mock.MockitoSugar
-import org.scalatest.{FunSpec, Matchers}
-
-class PostProcessorSpec extends FunSpec with Matchers with MockitoSugar{
- describe("#matchCellMagic") {
- it("should return the cell magic output when the Left contains a " +
- "CellMagicOutput") {
- val processor = new PostProcessor(mock[Interpreter])
- val codeOutput = "some output"
- val cmo = CellMagicOutput()
- val left = Left(cmo)
- processor.matchCellMagic(codeOutput, left) should be(cmo)
- }
-
- it("should package the original code when the Left does not contain a " +
- "CellMagicOutput") {
- val processor = new PostProcessor(mock[Interpreter])
- val codeOutput = "some output"
- val left = Left("")
- val data = Data(MIMEType.PlainText -> codeOutput)
- processor.matchCellMagic(codeOutput, left) should be(data)
- }
- }
-
- describe("#matchLineMagic") {
- it("should process the code output when the Right contains a " +
- "LineMagicOutput") {
- val processor = spy(new PostProcessor(mock[Interpreter]))
- val codeOutput = "some output"
- val lmo = LineMagicOutput
- val right = Right(lmo)
- processor.matchLineMagic(codeOutput, right)
- verify(processor).processLineMagic(codeOutput)
- }
-
- it("should package the original code when the Right does not contain a " +
- "LineMagicOutput") {
- val processor = new PostProcessor(mock[Interpreter])
- val codeOutput = "some output"
- val right = Right("")
- val data = Data(MIMEType.PlainText -> codeOutput)
- processor.matchLineMagic(codeOutput, right) should be(data)
- }
- }
-
- describe("#processLineMagic") {
- it("should remove the result of the magic invocation if it is the last " +
- "line") {
- val processor = new PostProcessor(mock[Interpreter])
- val x = "hello world"
- val codeOutput = s"$x\nsome other output"
- val data = Data(MIMEType.PlainText -> x)
- processor.processLineMagic(codeOutput) should be(data)
- }
- }
-
- describe("#process") {
- it("should call matchCellMagic when the last variable is a Left") {
- val intp = mock[Interpreter]
- val left = Left("")
- // Need to mock lastExecutionVariableName as it is being chained with
- // the read method
- doReturn(Some("")).when(intp).lastExecutionVariableName
- doReturn(Some(left)).when(intp).read(anyString())
-
- val processor = spy(new PostProcessor(intp))
- val codeOutput = "hello"
- processor.process(codeOutput)
- verify(processor).matchCellMagic(codeOutput, left)
- }
-
- it("should call matchLineMagic when the last variable is a Right") {
- val intp = mock[Interpreter]
- val right = Right("")
- // Need to mock lastExecutionVariableName as it is being chained with
- // the read method
- doReturn(Some("")).when(intp).lastExecutionVariableName
- doReturn(Some(right)).when(intp).read(anyString())
-
- val processor = spy(new PostProcessor(intp))
- val codeOutput = "hello"
- processor.process(codeOutput)
- verify(processor).matchLineMagic(codeOutput, right)
- }
-
- it("should package the original code output when the Left is not a " +
- "Left[CellMagicOutput, Nothing]") {
- val intp = mock[Interpreter]
- val left = Left("")
- // Need to mock lastExecutionVariableName as it is being chained with
- // the read method
- doReturn(Some("")).when(intp).lastExecutionVariableName
- doReturn(Some(left)).when(intp).read(anyString())
-
- val processor = spy(new PostProcessor(intp))
- val codeOutput = "hello"
- val data = Data(MIMEType.PlainText -> codeOutput)
- processor.process(codeOutput) should be(data)
- }
-
- it("should package the original code output when the Right is not a " +
- "Right[LineMagicOutput, Nothing]") {
- val intp = mock[Interpreter]
- val right = Right("")
- // Need to mock lastExecutionVariableName as it is being chained with
- // the read method
- doReturn(Some("")).when(intp).lastExecutionVariableName
- doReturn(Some(right)).when(intp).read(anyString())
-
- val processor = spy(new PostProcessor(intp))
- val codeOutput = "hello"
- val data = Data(MIMEType.PlainText -> codeOutput)
- processor.process(codeOutput) should be(data)
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/relay/ExecuteRequestRelaySpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/relay/ExecuteRequestRelaySpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/relay/ExecuteRequestRelaySpec.scala
deleted file mode 100644
index 7adf620..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/relay/ExecuteRequestRelaySpec.scala
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright 2014 IBM Corp.
- *
- * Licensed 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 com.ibm.spark.kernel.protocol.v5.relay
-
-import java.io.OutputStream
-
-import akka.actor._
-import akka.testkit.{ImplicitSender, TestKit, TestProbe}
-import com.ibm.spark.interpreter.{ExecuteAborted, ExecuteError}
-import com.ibm.spark.kernel.protocol.v5._
-import com.ibm.spark.kernel.protocol.v5.content._
-import com.ibm.spark.kernel.protocol.v5.kernel.ActorLoader
-import com.ibm.spark.kernel.protocol.v5.magic.{MagicParser, PostProcessor}
-import com.ibm.spark.magic.MagicLoader
-import com.ibm.spark.magic.dependencies.DependencyMap
-import com.typesafe.config.ConfigFactory
-import org.mockito.Mockito._
-import org.scalatest.mock.MockitoSugar
-import org.scalatest.{BeforeAndAfter, FunSpecLike, Matchers}
-
-object ExecuteRequestRelaySpec {
- val config = """
- akka {
- loglevel = "WARNING"
- }"""
-}
-
-class ExecuteRequestRelaySpec extends TestKit(
- ActorSystem(
- "ExecuteRequestRelayActorSystem",
- ConfigFactory.parseString(ExecuteRequestRelaySpec.config)
- )
-) with ImplicitSender with FunSpecLike with Matchers with MockitoSugar
- with BeforeAndAfter
-{
- var mockActorLoader: ActorLoader = _
- var interpreterActorProbe: TestProbe = _
-
- before {
- mockActorLoader = mock[ActorLoader]
- interpreterActorProbe = new TestProbe(system)
- val mockInterpreterActorSelection =
- system.actorSelection(interpreterActorProbe.ref.path.toString)
- doReturn(mockInterpreterActorSelection).when(mockActorLoader)
- .load(SystemActorType.Interpreter)
- }
-
- describe("ExecuteRequestRelay") {
- describe("#receive(KernelMessage)") {
- it("should handle an abort returned by the InterpreterActor") {
- val executeRequest =
- ExecuteRequest("%myMagic", false, true, UserExpressions(), true)
-
- val mockMagicLoader = mock[MagicLoader]
- val mockPostProcessor = mock[PostProcessor]
- val mockDependencyMap = mock[DependencyMap]
- doReturn(mockDependencyMap).when(mockMagicLoader).dependencyMap
-
- val mockMagicParser = mock[MagicParser]
- doReturn(Left(executeRequest.code))
- .when(mockMagicParser).parse(executeRequest.code)
-
- val executeRequestRelay = system.actorOf(Props(
- classOf[ExecuteRequestRelay], mockActorLoader,
- mockMagicLoader, mockMagicParser, mockPostProcessor
- ))
-
- // Send the message to the ExecuteRequestRelay
- executeRequestRelay !
- ((executeRequest, mock[KernelMessage], mock[OutputStream]))
-
- // Expected does not actually match real return of magic, which
- // is a tuple of ExecuteReply and ExecuteResult
- val expected = new ExecuteAborted()
- interpreterActorProbe.expectMsgClass(
- classOf[(ExecuteRequest, KernelMessage, OutputStream)]
- )
-
- // Reply with an error
- interpreterActorProbe.reply(Right(expected))
-
- expectMsg(
- (ExecuteReplyAbort(1), ExecuteResult(1, Data(), Metadata()))
- )
- }
-
- it("should handle an error returned by the InterpreterActor") {
- val executeRequest =
- ExecuteRequest("%myMagic", false, true, UserExpressions(), true)
-
- val mockMagicLoader = mock[MagicLoader]
- val mockPostProcessor = mock[PostProcessor]
- val mockDependencyMap = mock[DependencyMap]
- doReturn(mockDependencyMap).when(mockMagicLoader).dependencyMap
-
- val mockMagicParser = mock[MagicParser]
- doReturn(Left(executeRequest.code))
- .when(mockMagicParser).parse(executeRequest.code)
-
- val executeRequestRelay = system.actorOf(Props(
- classOf[ExecuteRequestRelay], mockActorLoader,
- mockMagicLoader, mockMagicParser, mockPostProcessor
- ))
-
- // Send the message to the ExecuteRequestRelay
- executeRequestRelay !
- ((executeRequest, mock[KernelMessage], mock[OutputStream]))
-
- // Expected does not actually match real return of magic, which
- // is a tuple of ExecuteReply and ExecuteResult
- val expected = ExecuteError("NAME", "MESSAGE", List())
- interpreterActorProbe.expectMsgClass(
- classOf[(ExecuteRequest, KernelMessage, OutputStream)]
- )
-
- // Reply with an error
- interpreterActorProbe.reply(Right(expected))
-
- expectMsg((
- ExecuteReplyError(1, Some(expected.name), Some(expected.value),
- Some(expected.stackTrace.map(_.toString).toList)),
- ExecuteResult(1, Data("text/plain" -> expected.toString), Metadata())
- ))
- }
-
- it("should return an (ExecuteReply, ExecuteResult) on interpreter " +
- "success") {
- val expected = "SOME OTHER VALUE"
- val executeRequest =
- ExecuteRequest("notAMagic", false, true, UserExpressions(), true)
-
- val mockMagicLoader = mock[MagicLoader]
- val mockPostProcessor = mock[PostProcessor]
- doReturn(Data(MIMEType.PlainText -> expected))
- .when(mockPostProcessor).process(expected)
-
- val mockDependencyMap = mock[DependencyMap]
- doReturn(mockDependencyMap).when(mockMagicLoader).dependencyMap
-
- val mockMagicParser = mock[MagicParser]
- doReturn(Left(executeRequest.code))
- .when(mockMagicParser).parse(executeRequest.code)
-
- val executeRequestRelay = system.actorOf(Props(
- classOf[ExecuteRequestRelay], mockActorLoader,
- mockMagicLoader, mockMagicParser, mockPostProcessor
- ))
-
- // Send the message to the ExecuteRequestRelay
- executeRequestRelay !
- ((executeRequest, mock[KernelMessage], mock[OutputStream]))
-
- // Expected does not actually match real return of interpreter, which
- // is a tuple of ExecuteReply and ExecuteResult
- interpreterActorProbe.expectMsgClass(
- classOf[(ExecuteRequest, KernelMessage, OutputStream)]
- )
-
- // Reply with a successful interpret
- interpreterActorProbe.reply(Left(expected))
-
- expectMsg((
- ExecuteReplyOk(1, Some(Payloads()), Some(UserExpressions())),
- ExecuteResult(1, Data(MIMEType.PlainText -> expected), Metadata())
- ))
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/relay/KernelMessageRelaySpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/relay/KernelMessageRelaySpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/relay/KernelMessageRelaySpec.scala
deleted file mode 100644
index 63fa50c..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/relay/KernelMessageRelaySpec.scala
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Copyright 2014 IBM Corp.
- *
- * Licensed 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 com.ibm.spark.kernel.protocol.v5.relay
-
-import akka.actor._
-import akka.testkit.{ImplicitSender, TestKit, TestProbe}
-import com.ibm.spark.communication.ZMQMessage
-import com.ibm.spark.communication.security.SecurityActorType
-import com.ibm.spark.kernel.protocol.v5._
-import com.ibm.spark.kernel.protocol.v5.kernel.{ActorLoader, Utilities}
-import Utilities._
-import org.mockito.Mockito._
-import org.scalatest.concurrent.{PatienceConfiguration, ScalaFutures}
-import org.scalatest.mock.MockitoSugar
-import org.scalatest.time.{Millis, Seconds, Span}
-import org.scalatest.{BeforeAndAfter, FunSpecLike, Matchers}
-import org.mockito.Matchers.{eq => mockEq}
-import org.mockito.AdditionalMatchers.{not => mockNot}
-import scala.concurrent.duration._
-import com.ibm.spark.kernel.protocol.v5.KernelMessage
-import scala.concurrent._
-import akka.pattern.pipe
-import scala.util.Random
-import ExecutionContext.Implicits.global
-
-class KernelMessageRelaySpec extends TestKit(ActorSystem("RelayActorSystem"))
- with ImplicitSender with FunSpecLike with Matchers with MockitoSugar
- with BeforeAndAfter with ScalaFutures {
- private val IncomingMessageType = MessageType.Incoming.CompleteRequest.toString
- private val OutgoingMessageType = MessageType.Outgoing.CompleteReply.toString
-
- private val header: Header = Header("<UUID>", "<USER>", "<SESSION>",
- "<TYPE>", "<VERSION>")
- private val parentHeader: Header = Header("<PARENT-UUID>", "<PARENT-USER>",
- "<PARENT-SESSION>", "<PARENT-TYPE>", "<PARENT-VERSION>")
- private val incomingKernelMessage: KernelMessage = KernelMessage(Seq("<ID>"),
- "<SIGNATURE>", header.copy(msg_type = IncomingMessageType),
- parentHeader, Metadata(), "<CONTENT>")
- private val outgoingKernelMessage: KernelMessage = KernelMessage(Seq("<ID>"),
- "<SIGNATURE>", header.copy(msg_type = OutgoingMessageType),
- incomingKernelMessage.header, Metadata(), "<CONTENT>")
- private val incomingZmqStrings = "1" :: "2" :: "3" :: "4" :: Nil
-
- private var actorLoader: ActorLoader = _
- private var signatureProbe: TestProbe = _
- private var signatureSelection: ActorSelection = _
- private var captureProbe: TestProbe = _
- private var captureSelection: ActorSelection = _
- private var handlerProbe: TestProbe = _
- private var handlerSelection: ActorSelection = _
- private var relayWithoutSignatureManager: ActorRef = _
- private var relayWithSignatureManager: ActorRef = _
-
- before {
- // Create a mock ActorLoader for the Relay we are going to test
- actorLoader = mock[ActorLoader]
-
- // Create a probe for the signature manager and mock the ActorLoader to
- // return the associated ActorSelection
- signatureProbe = TestProbe()
- signatureSelection = system.actorSelection(signatureProbe.ref.path.toString)
- when(actorLoader.load(SecurityActorType.SignatureManager))
- .thenReturn(signatureSelection)
-
- // Create a probe to capture output from the relay for testing
- captureProbe = TestProbe()
- captureSelection = system.actorSelection(captureProbe.ref.path.toString)
- when(actorLoader.load(mockNot(mockEq(SecurityActorType.SignatureManager))))
- .thenReturn(captureSelection)
-
- relayWithoutSignatureManager = system.actorOf(Props(
- classOf[KernelMessageRelay], actorLoader, false,
- mock[Map[String, String]], mock[Map[String, String]]
- ))
-
- relayWithSignatureManager = system.actorOf(Props(
- classOf[KernelMessageRelay], actorLoader, true,
- mock[Map[String, String]], mock[Map[String, String]]
- ))
- }
-
- describe("Relay") {
- describe("#receive") {
- describe("when not using the signature manager") {
- it("should not send anything to SignatureManager for incoming") {
- relayWithoutSignatureManager ! true // Mark as ready for incoming
- relayWithoutSignatureManager ! incomingKernelMessage
- signatureProbe.expectNoMsg(25.millis)
- }
-
- it("should not send anything to SignatureManager for outgoing") {
- relayWithoutSignatureManager ! outgoingKernelMessage
- signatureProbe.expectNoMsg(25.millis)
- }
-
- it("should relay KernelMessage for incoming") {
- relayWithoutSignatureManager ! true // Mark as ready for incoming
- relayWithoutSignatureManager !
- ((incomingZmqStrings, incomingKernelMessage))
- captureProbe.expectMsg(incomingKernelMessage)
- }
-
- it("should relay KernelMessage for outgoing") {
- relayWithoutSignatureManager ! outgoingKernelMessage
- captureProbe.expectMsg(outgoingKernelMessage)
- }
- }
-
- describe("when using the signature manager") {
- it("should verify the signature if the message is incoming") {
- relayWithSignatureManager ! true // Mark as ready for incoming
- relayWithSignatureManager ! incomingKernelMessage
- signatureProbe.expectMsg(incomingKernelMessage)
- }
-
- it("should construct the signature if the message is outgoing") {
- relayWithSignatureManager ! outgoingKernelMessage
- signatureProbe.expectMsg(outgoingKernelMessage)
- }
- }
-
- describe("when not ready") {
- it("should not relay the message if it is incoming") {
- val incomingMessage: ZMQMessage = incomingKernelMessage
-
- relayWithoutSignatureManager ! incomingMessage
- captureProbe.expectNoMsg(25.millis)
- }
-
- it("should relay the message if it is outgoing") {
- relayWithoutSignatureManager ! outgoingKernelMessage
- captureProbe.expectMsg(outgoingKernelMessage)
- }
- }
-
- describe("when ready") {
- it("should relay the message if it is incoming") {
- relayWithoutSignatureManager ! true // Mark as ready for incoming
- relayWithoutSignatureManager !
- ((incomingZmqStrings, incomingKernelMessage))
- captureProbe.expectMsg(incomingKernelMessage)
- }
-
- it("should relay the message if it is outgoing") {
- relayWithoutSignatureManager ! true // Mark as ready for incoming
- relayWithoutSignatureManager ! outgoingKernelMessage
- captureProbe.expectMsg(outgoingKernelMessage)
- }
- }
-
- describe("multiple messages in order"){
- it("should relay messages in the order they were received") {
- // Setup the base actor system and the relay
- val actorLoader = mock[ActorLoader]
- val kernelMessageRelay = system.actorOf(Props(
- classOf[KernelMessageRelay], actorLoader, true,
- mock[Map[String, String]], mock[Map[String, String]]
- ))
- // Where all of the messages are relayed to, otherwise NPE
- val captureProbe = TestProbe()
- val captureSelection = system.actorSelection(captureProbe.ref.path.toString)
- when(actorLoader.load(MessageType.Incoming.CompleteRequest))
- .thenReturn(captureSelection)
-
-
- val n = 5
- val chaoticPromise: Promise[String] = Promise()
- var actual : List[String] = List()
- val expected = (0 until n).map(_.toString).toList
-
- // setup a ChaoticActor to accumulate message values
- // A promise succeeds after n messages have been accumulated
- val chaoticActor: ActorRef = system.actorOf(Props(
- classOf[ChaoticActor[Boolean]],
- (paramVal: Any) => {
- val tuple = paramVal.asInstanceOf[(String, Seq[_])]
- actual = actual :+ tuple._1
- if (actual.length == n) chaoticPromise.success("Done")
- true
- }
- ))
-
- when(actorLoader.load(SecurityActorType.SignatureManager))
- .thenReturn(system.actorSelection(chaoticActor.path))
-
- kernelMessageRelay ! true
-
- // Sends messages with contents = to values of increasing counter
- sendKernelMessages(n, kernelMessageRelay)
- // Message values should be accumulated in the proper order
- whenReady(chaoticPromise.future,
- PatienceConfiguration.Timeout(Span(3, Seconds)),
- PatienceConfiguration.Interval(Span(100, Millis))) {
- case _: String =>
- actual should be(expected)
- }
-
- }
- }
- }
- }
- def sendKernelMessages(n: Int, kernelMessageRelay: ActorRef): Unit ={
- // Sends n messages to the relay
- (0 until n).foreach (i => {
- val km = KernelMessage(Seq("<ID>"), s"${i}",
- header.copy(msg_type = IncomingMessageType), parentHeader,
- Metadata(), s"${i}")
- kernelMessageRelay ! Tuple2(Seq("SomeString"), km)
- })
-
- }
-}
-
-
-case class ChaoticActor[U](receiveFunc : Any => U) extends Actor {
- override def receive: Receive = {
- case fVal: Any =>
- // The test actor system runs the actors on a single thread, so we must
- // simulate asynchronous behaviour by staring a new thread
- val promise = Promise[U]()
- promise.future pipeTo sender
- new Thread(new Runnable {
- override def run(): Unit = {
- Thread.sleep(Random.nextInt(30) * 10)
- promise.success(receiveFunc(fVal))
- }
- }).start()
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/68f7ddd6/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/stream/KernelInputStreamSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/stream/KernelInputStreamSpec.scala b/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/stream/KernelInputStreamSpec.scala
deleted file mode 100644
index 5d06cb6..0000000
--- a/kernel/src/test/scala/com/ibm/spark/kernel/protocol/v5/stream/KernelInputStreamSpec.scala
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright 2015 IBM Corp.
- *
- * Licensed 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 com.ibm.spark.kernel.protocol.v5.stream
-
-import akka.actor.{ActorRef, Actor, ActorSystem}
-import akka.testkit.{TestActorRef, TestKit, TestProbe}
-import com.ibm.spark.kernel.protocol.v5._
-import com.ibm.spark.kernel.protocol.v5.content.InputRequest
-import com.ibm.spark.kernel.protocol.v5.kernel.ActorLoader
-import org.mockito.Mockito._
-import org.scalatest._
-import org.scalatest.mock.MockitoSugar
-import play.api.libs.json.Json
-
-import scala.concurrent.duration._
-
-class KernelInputStreamSpec
- extends TestKit(ActorSystem("KernelInputStreamActorSystem"))
- with FunSpecLike with Matchers with GivenWhenThen with BeforeAndAfter
- with MockitoSugar
-{
-
- private var mockActorLoader: ActorLoader = _
- private var mockKMBuilder: KMBuilder = _
- private var kernelInputOutputHandlerProbe: TestProbe = _
- private var kernelInputStream: KernelInputStream = _
- private var fakeInputOutputHandlerActor: ActorRef = _
-
- private val TestReplyString = "some reply"
-
- before {
- mockActorLoader = mock[ActorLoader]
- mockKMBuilder = KMBuilder() // No need to really mock this
-
- kernelInputStream = new KernelInputStream(mockActorLoader, mockKMBuilder)
-
- kernelInputOutputHandlerProbe = TestProbe()
- fakeInputOutputHandlerActor = TestActorRef(new Actor {
- override def receive: Receive = {
- // Handle case for getting an input_request
- case kernelMessage: KernelMessage =>
- val messageType = kernelMessage.header.msg_type
- kernelInputOutputHandlerProbe.ref ! kernelMessage
- if (messageType == MessageType.Outgoing.InputRequest.toString)
- sender ! TestReplyString
- }
- })
-
- // Add the actor that routes to our test probe and responds with a fake
- // set of data
- doReturn(system.actorSelection(fakeInputOutputHandlerActor.path.toString))
- .when(mockActorLoader).load(MessageType.Incoming.InputReply)
- }
-
- describe("KernelInputStream") {
- describe("#available") {
- it("should be zero when no input has been read") {
- kernelInputStream.available() should be (0)
- }
-
- it("should match the bytes remaining internally") {
- kernelInputStream.read()
-
- kernelInputStream.available() should be (TestReplyString.length - 1)
- }
- }
-
- describe("#read") {
- it("should send a request for more data if the buffer is empty") {
- // Fresh input stream has nothing in its buffer
- kernelInputStream.read()
-
- // Verify that a message was sent out requesting data
- kernelInputOutputHandlerProbe.expectMsgPF() {
- case KernelMessage(_, _, header, _, _, _)
- if header.msg_type == MessageType.Outgoing.InputRequest.toString =>
- true
- }
- }
-
- it("should use the provided prompt in its requests") {
- val expected = KernelInputStream.DefaultPrompt
-
- // Fresh input stream has nothing in its buffer
- kernelInputStream.read()
-
- // Verify that a message was sent out requesting data with the
- // specific prompt
- kernelInputOutputHandlerProbe.expectMsgPF() {
- case KernelMessage(_, _, header, _, _, contentString)
- if header.msg_type == MessageType.Outgoing.InputRequest.toString =>
- Json.parse(contentString).as[InputRequest].prompt should be (expected)
- }
- }
-
- it("should use the provided password flag in its requests") {
- val expected = KernelInputStream.DefaultPassword
-
- // Fresh input stream has nothing in its buffer
- kernelInputStream.read()
-
- // Verify that a message was sent out requesting data with the
- // specific prompt
- kernelInputOutputHandlerProbe.expectMsgPF() {
- case KernelMessage(_, _, header, _, _, contentString)
- if header.msg_type == MessageType.Outgoing.InputRequest.toString =>
- Json.parse(contentString).as[InputRequest].password should be (expected)
- }
- }
-
- it("should return the next byte from the current buffer") {
- kernelInputStream.read() should be (TestReplyString.head)
- }
-
- it("should not send a request for more data if data is in the buffer") {
- // Run read for length of message (avoiding sending out a second
- // request)
- val readLength = TestReplyString.length
-
- for (i <- 1 to readLength)
- kernelInputStream.read() should be (TestReplyString.charAt(i - 1))
-
- kernelInputOutputHandlerProbe.expectMsgClass(classOf[KernelMessage])
- kernelInputOutputHandlerProbe.expectNoMsg(300.milliseconds)
- }
- }
- }
-}