toree-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lrese...@apache.org
Subject incubator-toree git commit: [TOREE-485] Properly parse updated JupyterLab cell metadata
Date Mon, 01 Oct 2018 12:26:28 GMT
Repository: incubator-toree
Updated Branches:
  refs/heads/master 106d6f11e -> f20a9f6ab


[TOREE-485] Properly parse updated JupyterLab cell metadata

Closes #165


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

Branch: refs/heads/master
Commit: f20a9f6ab9ee3c43d0a55f916a62c0272c6dc645
Parents: 106d6f1
Author: Luciano Resende <lresende@apache.org>
Authored: Sun Sep 30 13:36:34 2018 -0700
Committer: Luciano Resende <lresende@apache.org>
Committed: Mon Oct 1 05:26:08 2018 -0700

----------------------------------------------------------------------
 .../v5/handler/CommInfoRequestHandlerSpec.scala       |  8 ++++----
 .../v5/handler/KernelInfoRequestHandlerSpec.scala     |  6 +++---
 .../org/apache/toree/kernel/protocol/v5/package.scala | 14 ++++++++++++--
 .../toree/kernel/protocol/v5/KMBuilderSpec.scala      |  6 +++---
 .../org/apache/toree/kernel/protocol/v5/package.scala |  4 ++--
 5 files changed, 24 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/f20a9f6a/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/handler/CommInfoRequestHandlerSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/handler/CommInfoRequestHandlerSpec.scala
b/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/handler/CommInfoRequestHandlerSpec.scala
index 5b0b676..50c7597 100644
--- a/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/handler/CommInfoRequestHandlerSpec.scala
+++ b/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/handler/CommInfoRequestHandlerSpec.scala
@@ -23,7 +23,7 @@ import com.typesafe.config.ConfigFactory
 import org.apache.toree.comm.CommStorage
 import org.apache.toree.kernel.protocol.v5.content.CommInfoReply
 import org.apache.toree.kernel.protocol.v5.kernel.ActorLoader
-import org.apache.toree.kernel.protocol.v5.{Header, KernelMessage, SystemActorType}
+import org.apache.toree.kernel.protocol.v5.{Header, KernelMessage, Metadata, SystemActorType}
 import org.mockito.AdditionalMatchers.{not => mockNot}
 import org.mockito.Matchers.{eq => mockEq}
 import org.mockito.Mockito._
@@ -67,7 +67,7 @@ class CommInfoRequestHandlerSpec extends TestKit(
   describe("Comm Info Request Handler") {
     it("should return a KernelMessage containing a comm info response for a specific target
name") {
       val kernelMessage = new KernelMessage(
-        Seq[Array[Byte]](), "test message", header, header, Map[String, String](), "{\"target_name\":\"test.name\"}"
+        Seq[Array[Byte]](), "test message", header, header, Metadata(), "{\"target_name\":\"test.name\"}"
       )
 
       when(mockCommStorage.getTargets()).thenReturn(Set("test.name"))
@@ -85,7 +85,7 @@ class CommInfoRequestHandlerSpec extends TestKit(
 
   it("should return a KernelMessage containing a comm info response for all comms when target_name
is missing from the message") {
     val kernelMessage = new KernelMessage(
-      Seq[Array[Byte]](), "test message", header, header, Map[String, String](), "{}"
+      Seq[Array[Byte]](), "test message", header, header, Metadata(), "{}"
     )
 
     when(mockCommStorage.getTargets()).thenReturn(Set("test.name1", "test.name2"))
@@ -105,7 +105,7 @@ class CommInfoRequestHandlerSpec extends TestKit(
 
   it("should return a KernelMessage containing an empty comm info response when the target
name value is not found") {
     val kernelMessage = new KernelMessage(
-      Seq[Array[Byte]](), "test message", header, header, Map[String, String](), "{\"target_name\":\"can't_find_me\"}"
+      Seq[Array[Byte]](), "test message", header, header, Metadata(), "{\"target_name\":\"can't_find_me\"}"
     )
 
     when(mockCommStorage.getTargets()).thenReturn(Set("test.name"))

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/f20a9f6a/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/handler/KernelInfoRequestHandlerSpec.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/handler/KernelInfoRequestHandlerSpec.scala
b/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/handler/KernelInfoRequestHandlerSpec.scala
index f477582..6a5d2ea 100644
--- a/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/handler/KernelInfoRequestHandlerSpec.scala
+++ b/kernel/src/test/scala/org/apache/toree/kernel/protocol/v5/handler/KernelInfoRequestHandlerSpec.scala
@@ -17,11 +17,11 @@
 
 package org.apache.toree.kernel.protocol.v5.handler
 import akka.actor.{ActorSelection, ActorSystem, Props}
-import akka.testkit.{TestProbe, ImplicitSender, TestKit}
+import akka.testkit.{ImplicitSender, TestKit, TestProbe}
 import org.apache.toree.Main
 import org.apache.toree.kernel.protocol.v5.content.KernelInfoReply
 import org.apache.toree.kernel.protocol.v5.kernel.ActorLoader
-import org.apache.toree.kernel.protocol.v5.{SystemActorType, Header, KernelMessage, LanguageInfo}
+import org.apache.toree.kernel.protocol.v5._
 import org.mockito.AdditionalMatchers.{not => mockNot}
 import org.mockito.Matchers.{eq => mockEq}
 import com.typesafe.config.ConfigFactory
@@ -56,7 +56,7 @@ class KernelInfoRequestHandlerSpec extends TestKit(
 
   val header = Header("","","","","")
   val kernelMessage = new KernelMessage(
-    Seq[Array[Byte]](), "test message", header, header, Map[String, String](), "{}"
+    Seq[Array[Byte]](), "test message", header, header, Metadata(), "{}"
   )
 
   describe("Kernel Info Request Handler") {

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/f20a9f6a/protocol/src/main/scala/org/apache/toree/kernel/protocol/v5/package.scala
----------------------------------------------------------------------
diff --git a/protocol/src/main/scala/org/apache/toree/kernel/protocol/v5/package.scala b/protocol/src/main/scala/org/apache/toree/kernel/protocol/v5/package.scala
index 606bc06..b84af70 100644
--- a/protocol/src/main/scala/org/apache/toree/kernel/protocol/v5/package.scala
+++ b/protocol/src/main/scala/org/apache/toree/kernel/protocol/v5/package.scala
@@ -29,8 +29,18 @@ package object v5 {
   val ParentHeader = Header
 
   // Provide a Metadata type and object representing a map
-  type Metadata = Map[String, String]
-  val Metadata = Map
+  type Metadata = Map[String, JsValue]
+  object Metadata {
+    def apply(kv:(String, String)*):Metadata = {
+      if(kv.isEmpty) {
+        Map.empty
+      } else {
+        kv.toMap.mapValues(v => Json.parse(v))
+      }
+    }
+
+    val empty = Map.empty
+  }
 
   // Provide a Data type and object representing a map
   type Data = Map[MIMEType, String]

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/f20a9f6a/protocol/src/test/scala/org/apache/toree/kernel/protocol/v5/KMBuilderSpec.scala
----------------------------------------------------------------------
diff --git a/protocol/src/test/scala/org/apache/toree/kernel/protocol/v5/KMBuilderSpec.scala
b/protocol/src/test/scala/org/apache/toree/kernel/protocol/v5/KMBuilderSpec.scala
index 01132a8..3b09ad8 100644
--- a/protocol/src/test/scala/org/apache/toree/kernel/protocol/v5/KMBuilderSpec.scala
+++ b/protocol/src/test/scala/org/apache/toree/kernel/protocol/v5/KMBuilderSpec.scala
@@ -28,7 +28,7 @@ class KMBuilderSpec extends FunSpec with Matchers {
       signature    = "",
       header       = HeaderBuilder.empty,
       parentHeader = HeaderBuilder.empty,
-      metadata     = Metadata(),
+      metadata     = Metadata().empty,
       contentString = ""
     )
     val nonEmptyHeader = Header("1", "user", "2", "msg", "version")
@@ -52,7 +52,7 @@ class KMBuilderSpec extends FunSpec with Matchers {
 
       class KM2 extends KMBuilder {
         override def metadataDefaults : Metadata = {
-          Metadata("foo" -> "bar", "baos" -> "bean")
+          Metadata("foo" -> "123", "abc" -> "1234")
         }
       }
       it("should include default metadata in built message by default") {
@@ -129,7 +129,7 @@ class KMBuilderSpec extends FunSpec with Matchers {
       describe("#withMetadata"){
         it("should produce a KMBuilder with a KernelMessage whose metadata " +
            "contains the given metadata") {
-          val metadata = Metadata("foo" -> "bar", "baos" -> "bean")
+          val metadata = Metadata("foo" -> "123", "abc" -> "1234")
           val builder = KMBuilder().withMetadata(metadata)
           builder.km.metadata should be (metadata)
           val builtKM = builder.build

http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/f20a9f6a/protocol/src/test/scala/org/apache/toree/kernel/protocol/v5/package.scala
----------------------------------------------------------------------
diff --git a/protocol/src/test/scala/org/apache/toree/kernel/protocol/v5/package.scala b/protocol/src/test/scala/org/apache/toree/kernel/protocol/v5/package.scala
index 33d2f6b..5b92d5a 100644
--- a/protocol/src/test/scala/org/apache/toree/kernel/protocol/v5/package.scala
+++ b/protocol/src/test/scala/org/apache/toree/kernel/protocol/v5/package.scala
@@ -20,7 +20,7 @@ package org.apache.toree.kernel.protocol
 //import akka.zeromq.ZMQMessage
 import org.apache.toree.kernel.protocol.v5._
 import org.apache.toree.kernel.protocol.v5.content.{CompleteRequest, ExecuteRequest}
-import play.api.libs.json.Json
+import play.api.libs.json.{JsValue, Json}
 
 package object v5Test {
   //  The header for the message
@@ -41,7 +41,7 @@ package object v5Test {
     contentString =  Json.toJson(MockExecuteRequest).toString
   )
   val MockKernelMessageWithBadExecuteRequest = new KernelMessage(
-    Seq[Array[Byte]](), "test message", MockHeader, MockParenHeader, Map[String, String](),
+    Seq[Array[Byte]](), "test message", MockHeader, MockParenHeader, Metadata(),
     """
         {"code" : 124 }
     """


Mime
View raw message