[VariablesTest] passed all.

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

Branch: refs/heads/master
Commit: 9d175a768853299574f649a67acccd789f467e72
Parents: 8cb6209
Author: DO YUNG YOON <[email protected]>
Authored: Wed Apr 26 15:44:51 2017 +0900
Committer: DO YUNG YOON <[email protected]>
Committed: Wed Apr 26 15:44:51 2017 +0900

----------------------------------------------------------------------
 .../scala/org/apache/s2graph/core/S2Graph.scala |  6 ++-
 .../core/features/S2GraphVariables.scala        | 41 ++++++++++++++++++++
 2 files changed, 45 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/9d175a76/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala 
b/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala
index 2586173..a45d080 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala
@@ -27,6 +27,7 @@ import com.typesafe.config.{Config, ConfigFactory}
 import org.apache.commons.configuration.{BaseConfiguration, Configuration}
 import org.apache.s2graph.core.GraphExceptions.{FetchTimeoutException, 
LabelNotExistException}
 import org.apache.s2graph.core.JSONParser._
+import org.apache.s2graph.core.features.S2GraphVariables
 import org.apache.s2graph.core.mysqls._
 import org.apache.s2graph.core.storage.hbase.AsynchbaseStorage
 import org.apache.s2graph.core.storage.{SKeyValue, Storage}
@@ -584,9 +585,10 @@ object S2Graph {
   // passed: all, failed: none, all ignored
 
   // not yet supported
+//  new 
Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.VariablesTest", 
method="*", reason="no"), // all failed since implementation is missing.
   new 
Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.SerializationTest", 
method="*", reason="no"), // 10/16 failed.
   new 
Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.TransactionTest", 
method="*", reason="no"), // all ignored since supportTransaction is false.
-  new 
Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.VariablesTest", 
method="*", reason="no"), // all failed since implementation is missing.
+
 
   new 
Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.io.IoCustomTest", 
method="*", reason="no"), // all ignored.
   new 
Graph.OptOut(test="org.apache.tinkerpop.gremlin.structure.io.IoEdgeTest", 
method="*", reason="no"), // all failed.
@@ -1590,7 +1592,7 @@ class S2Graph(_config: Config)(implicit val ec: 
ExecutionContext) extends Graph
     ???
   }
 
-  override def variables(): Variables = ???
+  override def variables(): Variables = new S2GraphVariables()
 
   override def configuration(): Configuration = apacheConfiguration
 

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/9d175a76/s2core/src/main/scala/org/apache/s2graph/core/features/S2GraphVariables.scala
----------------------------------------------------------------------
diff --git 
a/s2core/src/main/scala/org/apache/s2graph/core/features/S2GraphVariables.scala 
b/s2core/src/main/scala/org/apache/s2graph/core/features/S2GraphVariables.scala
new file mode 100644
index 0000000..8e963f5
--- /dev/null
+++ 
b/s2core/src/main/scala/org/apache/s2graph/core/features/S2GraphVariables.scala
@@ -0,0 +1,41 @@
+package org.apache.s2graph.core.features
+
+import java.util
+import java.util.Optional
+import scala.collection.JavaConversions._
+import org.apache.tinkerpop.gremlin.structure.Graph
+
+class S2GraphVariables extends Graph.Variables {
+  import scala.collection.mutable
+  private val variables = mutable.Map.empty[String, Any]
+
+  override def set(key: String, value: scala.Any): Unit = {
+    if (key == null) throw Graph.Variables.Exceptions.variableKeyCanNotBeNull()
+    if (key.isEmpty) throw 
Graph.Variables.Exceptions.variableKeyCanNotBeEmpty()
+    if (value == null) throw 
Graph.Variables.Exceptions.variableValueCanNotBeNull()
+
+    variables.put(key, value)
+  }
+
+  override def keys(): util.Set[String] = variables.keySet
+
+  override def remove(key: String): Unit = {
+    if (key == null) throw Graph.Variables.Exceptions.variableKeyCanNotBeNull()
+    if (key.isEmpty) throw 
Graph.Variables.Exceptions.variableKeyCanNotBeEmpty()
+
+    variables.remove(key)
+  }
+
+  override def get[R](key: String): Optional[R] = {
+    if (key == null) throw Graph.Variables.Exceptions.variableKeyCanNotBeNull()
+    if (key.isEmpty) throw 
Graph.Variables.Exceptions.variableKeyCanNotBeEmpty()
+    variables.get(key) match {
+      case None => Optional.empty()
+      case Some(value) => if (value == null) Optional.empty() else 
Optional.of(value.asInstanceOf[R])
+    }
+  }
+
+  override def toString: String = {
+    s"variables[size:${variables.keys.size()}]"
+  }
+}
\ No newline at end of file

Reply via email to