Make QuerySpec, CrudSpec works

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

Branch: refs/heads/feature/test_daewon
Commit: 395b00f66b851678102f58bf218fcdb36924cc7a
Parents: 0e1c0e0
Author: daewon <[email protected]>
Authored: Tue Dec 29 14:54:22 2015 +0900
Committer: daewon <[email protected]>
Committed: Tue Dec 29 14:54:22 2015 +0900

----------------------------------------------------------------------
 .../scala/com/kakao/s2graph/core/EdgeTest.scala |   28 +
 .../kakao/s2graph/core/Integrate/CrudTest.scala |    6 +-
 .../core/Integrate/IntegrateCommon.scala        |   17 +-
 .../s2graph/core/Integrate/QueryTest.scala      |  694 ++++++++-
 .../test/controllers/BasicCrudSpec.scala        |  498 +++----
 s2rest_play/test/controllers/QuerySpec.scala    | 1386 +++++++++---------
 6 files changed, 1623 insertions(+), 1006 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/395b00f6/s2core/src/test/scala/com/kakao/s2graph/core/EdgeTest.scala
----------------------------------------------------------------------
diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/EdgeTest.scala 
b/s2core/src/test/scala/com/kakao/s2graph/core/EdgeTest.scala
index 6374d43..d86541d 100644
--- a/s2core/src/test/scala/com/kakao/s2graph/core/EdgeTest.scala
+++ b/s2core/src/test/scala/com/kakao/s2graph/core/EdgeTest.scala
@@ -4,8 +4,36 @@ import com.kakao.s2graph.core.mysqls.LabelMeta
 import com.kakao.s2graph.core.types.{InnerVal, InnerValLikeWithTs, VertexId}
 import com.kakao.s2graph.core.utils.logger
 import org.scalatest.FunSuite
+import org.scalatest.matchers.Matcher
 
 class EdgeTest extends FunSuite with TestCommon with TestCommonWithModels {
+
+  test("toLogString") {
+    val testLabelName = labelNameV2
+    val bulkQueries = List(
+      ("1445240543366", "update", "{\"is_blocked\":true}"),
+      ("1445240543362", "insert", "{\"is_hidden\":false}"),
+      ("1445240543364", "insert", "{\"is_hidden\":false,\"weight\":10}"),
+      ("1445240543363", "delete", "{}"),
+      ("1445240543365", "update", "{\"time\":1, \"weight\":-10}"))
+
+    val (srcId, tgtId, labelName) = ("1", "2", testLabelName)
+
+    val bulkEdge = (for ((ts, op, props) <- bulkQueries) yield {
+      Management.toEdge(ts.toLong, op, srcId, tgtId, labelName, "out", 
props).toLogString
+    }).mkString("\n")
+
+    val expected = Seq(
+      Seq("1445240543366", "update", "e", "1", "2", "s2graph_label_test", 
"{\"is_blocked\":true}"),
+      Seq("1445240543362", "insert", "e", "1", "2", "s2graph_label_test", 
"{\"is_hidden\":false}"),
+      Seq("1445240543364", "insert", "e", "1", "2", "s2graph_label_test", 
"{\"is_hidden\":false,\"weight\":10}"),
+      Seq("1445240543363", "delete", "e", "1", "2", "s2graph_label_test"),
+      Seq("1445240543365", "update", "e", "1", "2", "s2graph_label_test", 
"{\"time\":1,\"weight\":-10}")
+    ).map(_.mkString("\t")).mkString("\n")
+
+    assert(bulkEdge === expected)
+  }
+
   test("buildOperation") {
     val schemaVersion = "v2"
     val vertexId = VertexId(0, InnerVal.withStr("dummy", schemaVersion))

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/395b00f6/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/CrudTest.scala
----------------------------------------------------------------------
diff --git 
a/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/CrudTest.scala 
b/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/CrudTest.scala
index a093dcc..d178419 100644
--- a/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/CrudTest.scala
+++ b/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/CrudTest.scala
@@ -169,10 +169,10 @@ class CrudTest extends IntegrateCommon {
         /** insert edges */
         println(s"---- TC${tcNum}_init ----")
         val bulkEdges = (for ((ts, op, props) <- opWithProps) yield {
-          TestHelper.toEdge(ts, op, "e", srcId, tgtId, labelName, props)
+          Util.toEdge(ts, op, "e", srcId, tgtId, labelName, props)
         })
 
-        TestHelper.insertEdges(bulkEdges:_*)
+        Util.insertEdges(bulkEdges:_*)
 
         for {
           label <- Label.findByName(labelName)
@@ -187,7 +187,7 @@ class CrudTest extends IntegrateCommon {
           val qId = if (labelName == testLabelName) id else "\"" + id + "\""
           val query = queryJson(serviceName, columnName, labelName, qId, 
direction, cacheTTL)
 
-          val jsResult = TestHelper.getEdges(query)
+          val jsResult = Util.getEdges(query)
 
           val results = jsResult \ "results"
           val deegrees = (jsResult \ "degrees").as[List[JsObject]]

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/395b00f6/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/IntegrateCommon.scala
----------------------------------------------------------------------
diff --git 
a/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/IntegrateCommon.scala 
b/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/IntegrateCommon.scala
index 2aa8abf..6db250d 100644
--- 
a/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/IntegrateCommon.scala
+++ 
b/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/IntegrateCommon.scala
@@ -15,7 +15,7 @@ trait IntegrateCommon extends FunSuite with Matchers with 
BeforeAndAfterAll {
   var parser: RequestParser = _
   var config: Config = _
 
-  override def beforeAll(): Unit = {
+  override def beforeAll = {
     config = ConfigFactory.load()
     graph = new Graph(config)(ExecutionContext.Implicits.global)
     parser = new RequestParser(graph.config)
@@ -78,7 +78,18 @@ trait IntegrateCommon extends FunSuite with Matchers with 
BeforeAndAfterAll {
   /**
     * Test Helpers
     */
-  object TestHelper {
+  object Util {
+//    def checkEdgeQueryJson(params: Seq[(String, String, String, String)]) = {
+//      val arr = for {
+//        (label, dir, from, to) <- params
+//      } yield {
+//        Json.obj("label" -> label, "direction" -> dir, "from" -> from, "to" 
-> to)
+//      }
+//
+//      val s = Json.toJson(arr)
+//      s
+//    }
+
     def getEdges(queryJson: JsValue): JsValue = {
       val ret = graph.getEdges(parser.toQuery(queryJson))
       val result = Await.result(ret, HttpRequestWaitingTime)
@@ -90,6 +101,8 @@ trait IntegrateCommon extends FunSuite with Matchers with 
BeforeAndAfterAll {
     def insertEdges(bulkEdges: String*) = {
       val req = 
graph.mutateElements(parser.toGraphElements(bulkEdges.mkString("\n")), withWait 
= true)
       val jsResult = Await.result(req, HttpRequestWaitingTime)
+
+      jsResult
     }
 
     def toEdge(elems: Any*): String = elems.mkString("\t")

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/395b00f6/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/QueryTest.scala
----------------------------------------------------------------------
diff --git 
a/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/QueryTest.scala 
b/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/QueryTest.scala
index 53696b0..505927b 100644
--- a/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/QueryTest.scala
+++ b/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/QueryTest.scala
@@ -1,63 +1,639 @@
 package com.kakao.s2graph.core.Integrate
 
-import com.kakao.s2graph.core.Management
-import com.kakao.s2graph.core.mysqls._
-import play.api.libs.json.{JsValue, Json}
-
-class QueryTest extends IntegrateCommon {
-
-//  test("test Query") {
-//
-//  }
-//
-//  test("test returnTree") {
-//    def queryParents(id: Long) = Json.parse(
-//      s"""
-//        {
-//          "returnTree": true,
-//          "srcVertices": [
-//          { "serviceName": "${testServiceName}",
-//            "columnName": "${testColumnName}",
-//            "id": ${id}
-//           }],
-//          "steps": [
-//          [ {
-//              "label": "${testLabelName}",
-//              "direction": "out",
-//              "offset": 0,
-//              "limit": 2
-//            }
-//          ],[{
-//              "label": "${testLabelName}",
-//              "direction": "in",
-//              "offset": 0,
-//              "limit": -1
-//            }
-//          ]]
-//        }""".stripMargin)
-//
-//    val src = 100
-//    val tgt = 200
-//    val labelName = testLabelName
-//
-//    insertEdges(
-//      toEdge(1001, "insert", "e", src, tgt, labelName)
-//    )
-//
-//    val result = getEdges(queryParents(src))
-//    val parents = (result \ "results").as[Seq[JsValue]]
-//    val ret = parents.forall { edge => (edge \ 
"parents").as[Seq[JsValue]].size == 1 }
-//
-//    ret === true
-//  }
-
-  override def beforeAll(): Unit = {
-    super.beforeAll()
-
-
-  }
-
-  override def afterAll(): Unit = {
-    super.afterAll()
+import com.kakao.s2graph.core.GraphExceptions.BadQueryException
+import org.scalatest.BeforeAndAfterEach
+import play.api.libs.json.{JsNull, JsNumber, JsValue, Json}
+
+import scala.util.{Success, Try}
+
+class QueryTest extends IntegrateCommon with BeforeAndAfterEach {
+
+  import Util._
+
+  val insert = "insert"
+  val e = "e"
+  val weight = "weight"
+  val is_hidden = "is_hidden"
+
+  test("interval") {
+    def queryWithInterval(id: Int, index: String, prop: String, fromVal: Int, 
toVal: Int) = Json.parse(
+      s"""
+        { "srcVertices": [
+          { "serviceName": "$testServiceName",
+            "columnName": "$testColumnName",
+            "id": $id
+           }],
+          "steps": [
+          [ {
+              "label": "$testLabelName",
+              "index": "$index",
+              "interval": {
+                  "from": [ { "$prop": $fromVal } ],
+                  "to": [ { "$prop": $toVal } ]
+              }
+            }
+          ]]
+        }
+        """)
+
+    var edges = getEdges(queryWithInterval(0, index2, "_timestamp", 1000, 
1001)) // test interval on timestamp index
+    (edges \ "size").toString should be("1")
+
+    edges = getEdges(queryWithInterval(0, index2, "_timestamp", 1000, 2000)) 
// test interval on timestamp index
+    (edges \ "size").toString should be("2")
+
+    edges = getEdges(queryWithInterval(2, index1, "weight", 10, 11)) // test 
interval on weight index
+    (edges \ "size").toString should be("1")
+
+    edges = getEdges(queryWithInterval(2, index1, "weight", 10, 20)) // test 
interval on weight index
+    (edges \ "size").toString should be("2")
+  }
+
+  test("get edge with where condition") {
+    def queryWhere(id: Int, where: String) = Json.parse(
+      s"""
+        { "srcVertices": [
+          { "serviceName": "${testServiceName}",
+            "columnName": "${testColumnName}",
+            "id": ${id}
+           }],
+          "steps": [
+          [ {
+              "label": "${testLabelName}",
+              "direction": "out",
+              "offset": 0,
+              "limit": 100,
+              "where": "${where}"
+            }
+          ]]
+        }""")
+
+    var result = getEdges(queryWhere(0, "is_hidden=false and _from in (-1, 
0)"))
+    (result \ "results").as[List[JsValue]].size should be(1)
+
+    result = getEdges(queryWhere(0, "is_hidden=true and _to in (1)"))
+    (result \ "results").as[List[JsValue]].size should be(1)
+
+    result = getEdges(queryWhere(0, "_from=0"))
+    (result \ "results").as[List[JsValue]].size should be(2)
+
+    result = getEdges(queryWhere(2, "_from=2 or weight in (-1)"))
+    (result \ "results").as[List[JsValue]].size should be(2)
+
+    result = getEdges(queryWhere(2, "_from=2 and weight in (10, 20)"))
+    (result \ "results").as[List[JsValue]].size should be(2)
+  }
+
+  test("get edge exclude") {
+    def queryExclude(id: Int) = Json.parse(
+      s"""
+        { "srcVertices": [
+          { "serviceName": "${testServiceName}",
+            "columnName": "${testColumnName}",
+            "id": ${id}
+           }],
+          "steps": [
+          [ {
+              "label": "${testLabelName}",
+              "direction": "out",
+              "offset": 0,
+              "limit": 2
+            },
+            {
+              "label": "${testLabelName}",
+              "direction": "in",
+              "offset": 0,
+              "limit": 2,
+              "exclude": true
+            }
+          ]]
+        }""")
+
+    val result = getEdges(queryExclude(0))
+    (result \ "results").as[List[JsValue]].size should be(1)
+  }
+
+  test("get edge groupBy property") {
+    def queryGroupBy(id: Int, props: Seq[String]): JsValue = {
+      Json.obj(
+        "groupBy" -> props,
+        "srcVertices" -> Json.arr(
+          Json.obj("serviceName" -> testServiceName, "columnName" -> 
testColumnName, "id" -> id)
+        ),
+        "steps" -> Json.arr(
+          Json.obj(
+            "step" -> Json.arr(
+              Json.obj(
+                "label" -> testLabelName
+              )
+            )
+          )
+        )
+      )
+    }
+
+    val result = getEdges(queryGroupBy(0, Seq("weight")))
+    (result \ "size").as[Int] should be(2)
+    val weights = (result \\ "groupBy").map { js =>
+      (js \ "weight").as[Int]
+    }
+    weights should contain(30)
+    weights should contain(40)
+
+    weights should not contain (10)
+  }
+
+  test("edge transform") {
+    def queryTransform(id: Int, transforms: String) = Json.parse(
+      s"""
+        { "srcVertices": [
+          { "serviceName": "${testServiceName}",
+            "columnName": "${testColumnName}",
+            "id": ${id}
+           }],
+          "steps": [
+          [ {
+              "label": "${testLabelName}",
+              "direction": "out",
+              "offset": 0,
+              "transform": $transforms
+            }
+          ]]
+        }""")
+
+    var result = getEdges(queryTransform(0, "[[\"_to\"]]"))
+    (result \ "results").as[List[JsValue]].size should be(2)
+
+    result = getEdges(queryTransform(0, "[[\"weight\"]]"))
+    (result \\ "to").map(_.toString).sorted should be((result \\ 
"weight").map(_.toString).sorted)
+
+    result = getEdges(queryTransform(0, "[[\"_from\"]]"))
+    val results = (result \ "results").as[JsValue]
+    (result \\ "to").map(_.toString).sorted should be((results \\ 
"from").map(_.toString).sorted)
+  }
+
+  test("index") {
+    def queryIndex(ids: Seq[Int], indexName: String) = {
+      val $from = Json.arr(
+        Json.obj("serviceName" -> testServiceName,
+          "columnName" -> testColumnName,
+          "ids" -> ids))
+
+      val $step = Json.arr(Json.obj("label" -> testLabelName, "index" -> 
indexName))
+      val $steps = Json.arr(Json.obj("step" -> $step))
+
+      val js = Json.obj("withScore" -> false, "srcVertices" -> $from, "steps" 
-> $steps)
+      js
+    }
+
+    // weight order
+    var result = getEdges(queryIndex(Seq(0), "idx_1"))
+    ((result \ "results").as[List[JsValue]].head \\ "weight").head should 
be(JsNumber(40))
+
+    // timestamp order
+    result = getEdges(queryIndex(Seq(0), "idx_2"))
+    ((result \ "results").as[List[JsValue]].head \\ "weight").head should 
be(JsNumber(30))
+  }
+
+  //    "checkEdges" in {
+  //      running(FakeApplication()) {
+  //        val json = Json.parse( s"""
+  //         [{"from": 0, "to": 1, "label": "$testLabelName"},
+  //          {"from": 0, "to": 2, "label": "$testLabelName"}]
+  //        """)
+  //
+  //        def checkEdges(queryJson: JsValue): JsValue = {
+  //          val ret = route(FakeRequest(POST, 
"/graphs/checkEdges").withJsonBody(queryJson)).get
+  //          contentAsJson(ret)
+  //        }
+  //
+  //        val res = checkEdges(json)
+  //        val typeRes = res.isInstanceOf[JsArray]
+  //        typeRes must equalTo(true)
+  //
+  //        val fst = res.as[Seq[JsValue]].head \ "to"
+  //        fst.as[Int] must equalTo(1)
+  //
+  //        val snd = res.as[Seq[JsValue]].last \ "to"
+  //        snd.as[Int] must equalTo(2)
+  //      }
+  //    }
+
+
+  test("duration") {
+    def queryDuration(ids: Seq[Int], from: Int, to: Int) = {
+      val $from = Json.arr(
+        Json.obj("serviceName" -> testServiceName,
+          "columnName" -> testColumnName,
+          "ids" -> ids))
+
+      val $step = Json.arr(Json.obj(
+        "label" -> testLabelName, "direction" -> "out", "offset" -> 0, "limit" 
-> 100,
+        "duration" -> Json.obj("from" -> from, "to" -> to)))
+
+      val $steps = Json.arr(Json.obj("step" -> $step))
+
+      Json.obj("srcVertices" -> $from, "steps" -> $steps)
+    }
+
+    // get all
+    var result = getEdges(queryDuration(Seq(0, 2), from = 0, to = 5000))
+    (result \ "results").as[List[JsValue]].size should be(4)
+    // inclusive, exclusive
+    result = getEdges(queryDuration(Seq(0, 2), from = 1000, to = 4000))
+    (result \ "results").as[List[JsValue]].size should be(3)
+
+    result = getEdges(queryDuration(Seq(0, 2), from = 1000, to = 2000))
+    (result \ "results").as[List[JsValue]].size should be(1)
+
+    val bulkEdges = Seq(
+      toEdge(1001, insert, e, 0, 1, testLabelName, Json.obj(weight -> 10, 
is_hidden -> true)),
+      toEdge(2002, insert, e, 0, 2, testLabelName, Json.obj(weight -> 20, 
is_hidden -> false)),
+      toEdge(3003, insert, e, 2, 0, testLabelName, Json.obj(weight -> 30)),
+      toEdge(4004, insert, e, 2, 1, testLabelName, Json.obj(weight -> 40))
+    )
+    insertEdges(bulkEdges: _*)
+
+    // duration test after udpate
+    // get all
+    result = getEdges(queryDuration(Seq(0, 2), from = 0, to = 5000))
+    (result \ "results").as[List[JsValue]].size should be(4)
+
+    // inclusive, exclusive
+    result = getEdges(queryDuration(Seq(0, 2), from = 1000, to = 4000))
+    (result \ "results").as[List[JsValue]].size should be(3)
+
+    result = getEdges(queryDuration(Seq(0, 2), from = 1000, to = 2000))
+    (result \ "results").as[List[JsValue]].size should be(1)
+
+    def a: JsValue = getEdges(queryDuration(Seq(0, 2), from = 3000, to = 2000))
+    Try(a).recover {
+      case e: BadQueryException => JsNull
+    } should be(Success(JsNull))
+  }
+
+  test("return tree") {
+    def queryParents(id: Long) = Json.parse(
+      s"""
+        {
+          "returnTree": true,
+          "srcVertices": [
+          { "serviceName": "$testServiceName",
+            "columnName": "$testColumnName",
+            "id": $id
+           }],
+          "steps": [
+          [ {
+              "label": "$testLabelName",
+              "direction": "out",
+              "offset": 0,
+              "limit": 2
+            }
+          ],[{
+              "label": "$testLabelName",
+              "direction": "in",
+              "offset": 0,
+              "limit": -1
+            }
+          ]]
+        }""".stripMargin)
+
+    val src = 100
+    val tgt = 200
+
+    insertEdges(toEdge(1001, "insert", "e", src, tgt, testLabelName))
+
+    val result = Util.getEdges(queryParents(src))
+    val parents = (result \ "results").as[Seq[JsValue]]
+    val ret = parents.forall {
+      edge => (edge \ "parents").as[Seq[JsValue]].size == 1
+    }
+
+    ret should be(true)
+  }
+
+
+
+  test("pagination and _to") {
+    def querySingleWithTo(id: Int, offset: Int = 0, limit: Int = 100, to: Int) 
= Json.parse(
+      s"""
+        { "srcVertices": [
+          { "serviceName": "${testServiceName}",
+            "columnName": "${testColumnName}",
+            "id": ${id}
+           }],
+          "steps": [
+          [ {
+              "label": "${testLabelName}",
+              "direction": "out",
+              "offset": $offset,
+              "limit": $limit,
+              "_to": $to
+            }
+          ]]
+        }
+        """)
+
+    val src = System.currentTimeMillis().toInt
+
+    val bulkEdges = Seq(
+      toEdge(1001, insert, e, src, 1, testLabelName, Json.obj(weight -> 10, 
is_hidden -> true)),
+      toEdge(2002, insert, e, src, 2, testLabelName, Json.obj(weight -> 20, 
is_hidden -> false)),
+      toEdge(3003, insert, e, src, 3, testLabelName, Json.obj(weight -> 30)),
+      toEdge(4004, insert, e, src, 4, testLabelName, Json.obj(weight -> 40))
+    )
+    insertEdges(bulkEdges: _*)
+
+    var result = getEdges(querySingle(src, offset = 0, limit = 2))
+    var edges = (result \ "results").as[List[JsValue]]
+
+    edges.size should be(2)
+    (edges(0) \ "to").as[Long] should be(4)
+    (edges(1) \ "to").as[Long] should be(3)
+
+    result = getEdges(querySingle(src, offset = 1, limit = 2))
+
+    edges = (result \ "results").as[List[JsValue]]
+    edges.size should be(2)
+    (edges(0) \ "to").as[Long] should be(3)
+    (edges(1) \ "to").as[Long] should be(2)
+
+    result = getEdges(querySingleWithTo(src, offset = 0, limit = -1, to = 1))
+    edges = (result \ "results").as[List[JsValue]]
+    edges.size should be(1)
+  }
+  test("order by") {
+    def queryScore(id: Int, scoring: Map[String, Int]): JsValue = Json.obj(
+      "srcVertices" -> Json.arr(
+        Json.obj(
+          "serviceName" -> testServiceName,
+          "columnName" -> testColumnName,
+          "id" -> id
+        )
+      ),
+      "steps" -> Json.arr(
+        Json.obj(
+          "step" -> Json.arr(
+            Json.obj(
+              "label" -> testLabelName,
+              "scoring" -> scoring
+            )
+          )
+        )
+      )
+    )
+    def queryOrderBy(id: Int, scoring: Map[String, Int], props: 
Seq[Map[String, String]]): JsValue = Json.obj(
+      "orderBy" -> props,
+      "srcVertices" -> Json.arr(
+        Json.obj("serviceName" -> testServiceName, "columnName" -> 
testColumnName, "id" -> id)
+      ),
+      "steps" -> Json.arr(
+        Json.obj(
+          "step" -> Json.arr(
+            Json.obj(
+              "label" -> testLabelName,
+              "scoring" -> scoring
+            )
+          )
+        )
+      )
+    )
+
+    val bulkEdges = Seq(
+      toEdge(1001, insert, e, 0, 1, testLabelName, Json.obj(weight -> 10, 
is_hidden -> true)),
+      toEdge(2002, insert, e, 0, 2, testLabelName, Json.obj(weight -> 20, 
is_hidden -> false)),
+      toEdge(3003, insert, e, 2, 0, testLabelName, Json.obj(weight -> 30)),
+      toEdge(4004, insert, e, 2, 1, testLabelName, Json.obj(weight -> 40))
+    )
+
+    insertEdges(bulkEdges: _*)
+
+    // get edges
+    val edges = getEdges(queryScore(0, Map("weight" -> 1)))
+    val orderByScore = getEdges(queryOrderBy(0, Map("weight" -> 1), 
Seq(Map("score" -> "DESC", "timestamp" -> "DESC"))))
+    val ascOrderByScore = getEdges(queryOrderBy(0, Map("weight" -> 1), 
Seq(Map("score" -> "ASC", "timestamp" -> "DESC"))))
+
+    val edgesTo = edges \ "results" \\ "to"
+    val orderByTo = orderByScore \ "results" \\ "to"
+    val ascOrderByTo = ascOrderByScore \ "results" \\ "to"
+
+    edgesTo should be(Seq(JsNumber(2), JsNumber(1)))
+    edgesTo should be(orderByTo)
+    ascOrderByTo should be(Seq(JsNumber(1), JsNumber(2)))
+    edgesTo.reverse should be(ascOrderByTo)
+  }
+
+  test("query with sampling") {
+    def queryWithSampling(id: Int, sample: Int) = Json.parse(
+      s"""
+        { "srcVertices": [
+          { "serviceName": "$testServiceName",
+            "columnName": "$testColumnName",
+            "id": $id
+           }],
+          "steps": [
+            {
+              "step": [{
+                "label": "$testLabelName",
+                "direction": "out",
+                "offset": 0,
+                "limit": 100,
+                "sample": $sample
+                }]
+            }
+          ]
+        }""")
+
+    def twoStepQueryWithSampling(id: Int, sample: Int) = Json.parse(
+      s"""
+        { "srcVertices": [
+          { "serviceName": "$testServiceName",
+            "columnName": "$testColumnName",
+            "id": $id
+           }],
+          "steps": [
+            {
+              "step": [{
+                "label": "$testLabelName",
+                "direction": "out",
+                "offset": 0,
+                "limit": 100,
+                "sample": $sample
+                }]
+            },
+            {
+               "step": [{
+                 "label": "$testLabelName",
+                 "direction": "out",
+                 "offset": 0,
+                 "limit": 100,
+                 "sample": $sample
+               }]
+            }
+          ]
+        }""")
+
+    def twoQueryWithSampling(id: Int, sample: Int) = Json.parse(
+      s"""
+        { "srcVertices": [
+          { "serviceName": "$testServiceName",
+            "columnName": "$testColumnName",
+            "id": $id
+           }],
+          "steps": [
+            {
+              "step": [{
+                "label": "$testLabelName",
+                "direction": "out",
+                "offset": 0,
+                "limit": 50,
+                "sample": $sample
+              },
+              {
+                "label": "$testLabelName2",
+                "direction": "out",
+                "offset": 0,
+                "limit": 50
+              }]
+            }
+          ]
+        }""")
+
+    val sampleSize = 2
+    val ts = "1442985659166"
+    val testId = 22
+
+    val bulkEdges = Seq(
+      toEdge(ts, insert, e, testId, 122, testLabelName),
+      toEdge(ts, insert, e, testId, 222, testLabelName),
+      toEdge(ts, insert, e, testId, 322, testLabelName),
+
+      toEdge(ts, insert, e, testId, 922, testLabelName2),
+      toEdge(ts, insert, e, testId, 222, testLabelName2),
+      toEdge(ts, insert, e, testId, 322, testLabelName2),
+
+      toEdge(ts, insert, e, 122, 1122, testLabelName),
+      toEdge(ts, insert, e, 122, 1222, testLabelName),
+      toEdge(ts, insert, e, 122, 1322, testLabelName),
+      toEdge(ts, insert, e, 222, 2122, testLabelName),
+      toEdge(ts, insert, e, 222, 2222, testLabelName),
+      toEdge(ts, insert, e, 222, 2322, testLabelName),
+      toEdge(ts, insert, e, 322, 3122, testLabelName),
+      toEdge(ts, insert, e, 322, 3222, testLabelName),
+      toEdge(ts, insert, e, 322, 3322, testLabelName)
+    )
+
+    insertEdges(bulkEdges: _*)
+
+    val result1 = getEdges(queryWithSampling(testId, sampleSize))
+    (result1 \ "results").as[List[JsValue]].size should 
be(math.min(sampleSize, bulkEdges.size))
+
+    val result2 = getEdges(twoStepQueryWithSampling(testId, sampleSize))
+    (result2 \ "results").as[List[JsValue]].size should be(math.min(sampleSize 
* sampleSize, bulkEdges.size * bulkEdges.size))
+
+    val result3 = getEdges(twoQueryWithSampling(testId, sampleSize))
+    (result3 \ "results").as[List[JsValue]].size should be(sampleSize + 3) // 
edges in testLabelName2 = 3
+  }
+
+  test("limit") {
+    insertEdges(
+      toEdge(1001, insert, e, 0, 1, testLabelName, Json.obj(weight -> 10, 
is_hidden -> true)),
+      toEdge(2002, insert, e, 0, 2, testLabelName, Json.obj(weight -> 20, 
is_hidden -> false)),
+      toEdge(3003, insert, e, 2, 0, testLabelName, Json.obj(weight -> 30)),
+      toEdge(4004, insert, e, 2, 1, testLabelName, Json.obj(weight -> 40)))
+
+    val edges = getEdges(querySingle(0, limit = 1))
+    val limitEdges = getEdges(queryGlobalLimit(0, 1))
+
+    val edgesTo = edges \ "results" \\ "to"
+    val limitEdgesTo = limitEdges \ "results" \\ "to"
+
+    edgesTo should be(limitEdgesTo)
+  }
+
+  //  test("union query") {
+  //    def queryUnion(id: Int, size: Int) = JsArray(List.tabulate(size)(_ => 
querySingle(id)))
+  //
+  //    var result = getEdges(queryUnion(0, 2))
+  //    result.as[List[JsValue]].size should be (2)
+  //
+  //    result = getEdges(queryUnion(0, 3))
+  //    result.as[List[JsValue]].size should be (3)
+  //
+  //    result = getEdges(queryUnion(0, 4))
+  //    result.as[List[JsValue]].size should be (4)
+  //
+  //    result = getEdges(queryUnion(0, 5))
+  //    result.as[List[JsValue]].size should be (5)
+  //
+  //    val union = result.as[List[JsValue]].head
+  //    val single = getEdges(querySingle(0))
+  //
+  //    (union \\ "from").map(_.toString).sorted should be ((single \\ 
"from").map(_.toString).sorted)
+  //    (union \\ "to").map(_.toString).sorted should be ((single \\ 
"to").map(_.toString).sorted)
+  //    (union \\ "weight").map(_.toString).sorted should be ((single \\ 
"weight").map(_.toString).sorted)
+  //  }
+
+  def querySingle(id: Int, offset: Int = 0, limit: Int = 100) = Json.parse(
+    s"""
+          { "srcVertices": [
+            { "serviceName": "$testServiceName",
+              "columnName": "$testColumnName",
+              "id": $id
+             }],
+            "steps": [
+            [ {
+                "label": "$testLabelName",
+                "direction": "out",
+                "offset": $offset,
+                "limit": $limit
+              }
+            ]]
+          }
+          """)
+
+  def queryGlobalLimit(id: Int, limit: Int): JsValue = Json.obj(
+    "limit" -> limit,
+    "srcVertices" -> Json.arr(
+      Json.obj("serviceName" -> testServiceName, "columnName" -> 
testColumnName, "id" -> id)
+    ),
+    "steps" -> Json.arr(
+      Json.obj(
+        "step" -> Json.arr(
+          Json.obj(
+            "label" -> testLabelName
+          )
+        )
+      )
+    )
+  )
+
+  // called by each test, each
+  override def beforeEach = initTestData()
+
+  // called by start test, once
+  override def initTestData(): Unit = {
+    super.initTestData()
+
+    insertEdges(
+      toEdge(1000, insert, e, 0, 1, testLabelName, Json.obj(weight -> 40, 
is_hidden -> true)),
+      toEdge(2000, insert, e, 0, 2, testLabelName, Json.obj(weight -> 30, 
is_hidden -> false)),
+      toEdge(3000, insert, e, 2, 0, testLabelName, Json.obj(weight -> 20)),
+      toEdge(4000, insert, e, 2, 1, testLabelName, Json.obj(weight -> 10)),
+      toEdge(3000, insert, e, 10, 20, testLabelName, Json.obj(weight -> 20)),
+      toEdge(4000, insert, e, 20, 20, testLabelName, Json.obj(weight -> 10)),
+      toEdge(1, insert, e, -1, 1000, testLabelName),
+      toEdge(1, insert, e, -1, 2000, testLabelName),
+      toEdge(1, insert, e, -1, 3000, testLabelName),
+      toEdge(1, insert, e, 1000, 10000, testLabelName),
+      toEdge(1, insert, e, 1000, 11000, testLabelName),
+      toEdge(1, insert, e, 2000, 11000, testLabelName),
+      toEdge(1, insert, e, 2000, 12000, testLabelName),
+      toEdge(1, insert, e, 3000, 12000, testLabelName),
+      toEdge(1, insert, e, 3000, 13000, testLabelName),
+      toEdge(1, insert, e, 10000, 100000, testLabelName),
+      toEdge(2, insert, e, 11000, 200000, testLabelName),
+      toEdge(3, insert, e, 12000, 300000, testLabelName)
+    )
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/395b00f6/s2rest_play/test/controllers/BasicCrudSpec.scala
----------------------------------------------------------------------
diff --git a/s2rest_play/test/controllers/BasicCrudSpec.scala 
b/s2rest_play/test/controllers/BasicCrudSpec.scala
index 07419b3..9da2abd 100644
--- a/s2rest_play/test/controllers/BasicCrudSpec.scala
+++ b/s2rest_play/test/controllers/BasicCrudSpec.scala
@@ -1,249 +1,249 @@
-package controllers
-
-import com.kakao.s2graph.core.Management
-import com.kakao.s2graph.core.mysqls._
-
-//import com.kakao.s2graph.core.models._
-
-import play.api.libs.json._
-import play.api.test.Helpers._
-import play.api.test.{FakeApplication, FakeRequest}
-
-import scala.concurrent.Await
-
-
-class BasicCrudSpec extends SpecCommon {
-  var seed = 0
-  def runTC(tcNum: Int, tcString: String, opWithProps: List[(Long, String, 
String)], expected: Map[String, String]) = {
-    for {
-      labelName <- List(testLabelName, testLabelName2)
-      i <- 0 until NUM_OF_EACH_TEST
-    } {
-      seed += 1
-//      val srcId = ((tcNum * 1000) + i).toString
-//      val tgtId = if (labelName == testLabelName) s"${srcId + 1000 + i}" 
else s"${srcId + 1000 + i}abc"
-      val srcId = seed.toString
-      val tgtId = srcId
-
-      val maxTs = opWithProps.map(t => t._1).max
-
-      /** insert edges */
-      println(s"---- TC${tcNum}_init ----")
-      val bulkEdge = (for ((ts, op, props) <- opWithProps) yield {
-        List(ts, op, "e", srcId, tgtId, labelName, props).mkString("\t")
-      }).mkString("\n")
-
-      val req = EdgeController.mutateAndPublish(bulkEdge, withWait = true)
-      val res = Await.result(req, HTTP_REQ_WAITING_TIME)
-
-      res.header.status must equalTo(200)
-
-      println(s"---- TC${tcNum}_init ----")
-//      Thread.sleep(100)
-
-      for {
-        label <- Label.findByName(labelName)
-        direction <- List("out", "in")
-        cacheTTL <- List(-1L)
-      } {
-        val (serviceName, columnName, id, otherId) = direction match {
-          case "out" => (label.srcService.serviceName, 
label.srcColumn.columnName, srcId, tgtId)
-          case "in" => (label.tgtService.serviceName, 
label.tgtColumn.columnName, tgtId, srcId)
-        }
-        val qId = if (labelName == testLabelName) id else "\"" + id + "\""
-        val query = queryJson(serviceName, columnName, labelName, qId, 
direction, cacheTTL)
-        val ret = route(FakeRequest(POST, 
"/graphs/getEdges").withJsonBody(query)).get
-        val jsResult = commonCheck(ret)
-
-        val results = jsResult \ "results"
-        val deegrees = (jsResult \ "degrees").as[List[JsObject]]
-        val propsLs = (results \\ "props").seq
-        (deegrees.head \ LabelMeta.degree.name).as[Int] must equalTo(1)
-
-        val from = (results \\ "from").seq.last.toString.replaceAll("\"", "")
-        val to = (results \\ "to").seq.last.toString.replaceAll("\"", "")
-
-        from must equalTo(id.toString)
-        to must equalTo(otherId.toString)
-//        (results \\ "_timestamp").seq.last.as[Long] must equalTo(maxTs)
-        for ((key, expectedVal) <- expected) {
-          propsLs.last.as[JsObject].keys.contains(key) must equalTo(true)
-          (propsLs.last \ key).toString must equalTo(expectedVal)
-        }
-        Await.result(ret, HTTP_REQ_WAITING_TIME)
-      }
-    }
-  }
-
-  init()
-  "Basic Crud " should {
-    "tc1" in {
-      running(FakeApplication()) {
-
-        var tcNum = 0
-        var tcString = ""
-        var bulkQueries = List.empty[(Long, String, String)]
-        var expected = Map.empty[String, String]
-
-        tcNum = 7
-        tcString = "[t1 -> t2 -> t3 test case] insert(t1) delete(t2) 
insert(t3) test "
-        bulkQueries = List(
-          (t1, "insert", "{\"time\": 10}"),
-          (t2, "delete", ""),
-          (t3, "insert", "{\"time\": 10, \"weight\": 20}"))
-        expected = Map("time" -> "10", "weight" -> "20")
-
-        runTC(tcNum, tcString, bulkQueries, expected)
-
-        tcNum = 8
-        tcString = "[t1 -> t2 -> t3 test case] insert(t1) delete(t2) 
insert(t3) test "
-        bulkQueries = List(
-          (t1, "insert", "{\"time\": 10}"),
-          (t3, "insert", "{\"time\": 10, \"weight\": 20}"),
-          (t2, "delete", ""))
-        expected = Map("time" -> "10", "weight" -> "20")
-
-        runTC(tcNum, tcString, bulkQueries, expected)
-
-        tcNum = 9
-        tcString = "[t3 -> t2 -> t1 test case] insert(t3) delete(t2) 
insert(t1) test "
-        bulkQueries = List(
-          (t3, "insert", "{\"time\": 10, \"weight\": 20}"),
-          (t2, "delete", ""),
-          (t1, "insert", "{\"time\": 10}"))
-        expected = Map("time" -> "10", "weight" -> "20")
-
-        runTC(tcNum, tcString, bulkQueries, expected)
-
-        tcNum = 10
-        tcString = "[t3 -> t1 -> t2 test case] insert(t3) insert(t1) 
delete(t2) test "
-        bulkQueries = List(
-          (t3, "insert", "{\"time\": 10, \"weight\": 20}"),
-          (t1, "insert", "{\"time\": 10}"),
-          (t2, "delete", ""))
-        expected = Map("time" -> "10", "weight" -> "20")
-
-        runTC(tcNum, tcString, bulkQueries, expected)
-
-        tcNum = 11
-        tcString = "[t2 -> t1 -> t3 test case] delete(t2) insert(t1) 
insert(t3) test"
-        bulkQueries = List(
-          (t2, "delete", ""),
-          (t1, "insert", "{\"time\": 10}"),
-          (t3, "insert", "{\"time\": 10, \"weight\": 20}"))
-        expected = Map("time" -> "10", "weight" -> "20")
-
-        runTC(tcNum, tcString, bulkQueries, expected)
-
-        tcNum = 12
-        tcString = "[t2 -> t3 -> t1 test case] delete(t2) insert(t3) 
insert(t1) test "
-        bulkQueries = List(
-          (t2, "delete", ""),
-          (t3, "insert", "{\"time\": 10, \"weight\": 20}"),
-          (t1, "insert", "{\"time\": 10}"))
-        expected = Map("time" -> "10", "weight" -> "20")
-
-        runTC(tcNum, tcString, bulkQueries, expected)
-
-        tcNum = 13
-        tcString = "[t1 -> t2 -> t3 test case] update(t1) delete(t2) 
update(t3) test "
-        bulkQueries = List(
-          (t1, "update", "{\"time\": 10}"),
-          (t2, "delete", ""),
-          (t3, "update", "{\"time\": 10, \"weight\": 20}"))
-        expected = Map("time" -> "10", "weight" -> "20")
-
-        runTC(tcNum, tcString, bulkQueries, expected)
-        tcNum = 14
-        tcString = "[t1 -> t3 -> t2 test case] update(t1) update(t3) 
delete(t2) test "
-        bulkQueries = List(
-          (t1, "update", "{\"time\": 10}"),
-          (t3, "update", "{\"time\": 10, \"weight\": 20}"),
-          (t2, "delete", ""))
-        expected = Map("time" -> "10", "weight" -> "20")
-
-        runTC(tcNum, tcString, bulkQueries, expected)
-        tcNum = 15
-        tcString = "[t2 -> t1 -> t3 test case] delete(t2) update(t1) 
update(t3) test "
-        bulkQueries = List(
-          (t2, "delete", ""),
-          (t1, "update", "{\"time\": 10}"),
-          (t3, "update", "{\"time\": 10, \"weight\": 20}"))
-        expected = Map("time" -> "10", "weight" -> "20")
-
-        runTC(tcNum, tcString, bulkQueries, expected)
-        tcNum = 16
-        tcString = "[t2 -> t3 -> t1 test case] delete(t2) update(t3) 
update(t1) test"
-        bulkQueries = List(
-          (t2, "delete", ""),
-          (t3, "update", "{\"time\": 10, \"weight\": 20}"),
-          (t1, "update", "{\"time\": 10}"))
-        expected = Map("time" -> "10", "weight" -> "20")
-
-        runTC(tcNum, tcString, bulkQueries, expected)
-        tcNum = 17
-        tcString = "[t3 -> t2 -> t1 test case] update(t3) delete(t2) 
update(t1) test "
-        bulkQueries = List(
-          (t3, "update", "{\"time\": 10, \"weight\": 20}"),
-          (t2, "delete", ""),
-          (t1, "update", "{\"time\": 10}"))
-        expected = Map("time" -> "10", "weight" -> "20")
-
-        runTC(tcNum, tcString, bulkQueries, expected)
-        tcNum = 18
-        tcString = "[t3 -> t1 -> t2 test case] update(t3) update(t1) 
delete(t2) test "
-        bulkQueries = List(
-          (t3, "update", "{\"time\": 10, \"weight\": 20}"),
-          (t1, "update", "{\"time\": 10}"),
-          (t2, "delete", ""))
-        expected = Map("time" -> "10", "weight" -> "20")
-
-        runTC(tcNum, tcString, bulkQueries, expected)
-
-        tcNum = 19
-        tcString = "[t5 -> t1 -> t3 -> t2 -> t4 test case] update(t5) 
insert(t1) insert(t3) delete(t2) update(t4) test "
-        bulkQueries = List(
-          (t5, "update", "{\"is_blocked\": true}"),
-          (t1, "insert", "{\"is_hidden\": false}"),
-          (t3, "insert", "{\"is_hidden\": false, \"weight\": 10}"),
-          (t2, "delete", ""),
-          (t4, "update", "{\"time\": 1, \"weight\": -10}"))
-        expected = Map("time" -> "1", "weight" -> "-10", "is_hidden" -> 
"false", "is_blocked" -> "true")
-
-        runTC(tcNum, tcString, bulkQueries, expected)
-        true
-      }
-    }
-  }
-
-  "toLogString" in {
-    running(FakeApplication()) {
-      val bulkQueries = List(
-        ("1445240543366", "update", "{\"is_blocked\":true}"),
-        ("1445240543362", "insert", "{\"is_hidden\":false}"),
-        ("1445240543364", "insert", "{\"is_hidden\":false,\"weight\":10}"),
-        ("1445240543363", "delete", "{}"),
-        ("1445240543365", "update", "{\"time\":1, \"weight\":-10}"))
-
-      val (srcId, tgtId, labelName) = ("1", "2", testLabelName)
-
-      val bulkEdge = (for ((ts, op, props) <- bulkQueries) yield {
-        Management.toEdge(ts.toLong, op, srcId, tgtId, labelName, "out", 
props).toLogString
-      }).mkString("\n")
-
-      val expected = Seq(
-        Seq("1445240543366", "update", "e", "1", "2", "s2graph_label_test", 
"{\"is_blocked\":true}"),
-        Seq("1445240543362", "insert", "e", "1", "2", "s2graph_label_test", 
"{\"is_hidden\":false}"),
-        Seq("1445240543364", "insert", "e", "1", "2", "s2graph_label_test", 
"{\"is_hidden\":false,\"weight\":10}"),
-        Seq("1445240543363", "delete", "e", "1", "2", "s2graph_label_test"),
-        Seq("1445240543365", "update", "e", "1", "2", "s2graph_label_test", 
"{\"time\":1,\"weight\":-10}")
-      ).map(_.mkString("\t")).mkString("\n")
-
-      bulkEdge must equalTo(expected)
-
-      true
-    }
-  }
-}
-
-
+//package controllers
+//
+//import com.kakao.s2graph.core.Management
+//import com.kakao.s2graph.core.mysqls._
+//
+////import com.kakao.s2graph.core.models._
+//
+//import play.api.libs.json._
+//import play.api.test.Helpers._
+//import play.api.test.{FakeApplication, FakeRequest}
+//
+//import scala.concurrent.Await
+//
+//
+//class BasicCrudSpec extends SpecCommon {
+//  var seed = 0
+//  def runTC(tcNum: Int, tcString: String, opWithProps: List[(Long, String, 
String)], expected: Map[String, String]) = {
+//    for {
+//      labelName <- List(testLabelName, testLabelName2)
+//      i <- 0 until NUM_OF_EACH_TEST
+//    } {
+//      seed += 1
+////      val srcId = ((tcNum * 1000) + i).toString
+////      val tgtId = if (labelName == testLabelName) s"${srcId + 1000 + i}" 
else s"${srcId + 1000 + i}abc"
+//      val srcId = seed.toString
+//      val tgtId = srcId
+//
+//      val maxTs = opWithProps.map(t => t._1).max
+//
+//      /** insert edges */
+//      println(s"---- TC${tcNum}_init ----")
+//      val bulkEdge = (for ((ts, op, props) <- opWithProps) yield {
+//        List(ts, op, "e", srcId, tgtId, labelName, props).mkString("\t")
+//      }).mkString("\n")
+//
+//      val req = EdgeController.mutateAndPublish(bulkEdge, withWait = true)
+//      val res = Await.result(req, HTTP_REQ_WAITING_TIME)
+//
+//      res.header.status must equalTo(200)
+//
+//      println(s"---- TC${tcNum}_init ----")
+////      Thread.sleep(100)
+//
+//      for {
+//        label <- Label.findByName(labelName)
+//        direction <- List("out", "in")
+//        cacheTTL <- List(-1L)
+//      } {
+//        val (serviceName, columnName, id, otherId) = direction match {
+//          case "out" => (label.srcService.serviceName, 
label.srcColumn.columnName, srcId, tgtId)
+//          case "in" => (label.tgtService.serviceName, 
label.tgtColumn.columnName, tgtId, srcId)
+//        }
+//        val qId = if (labelName == testLabelName) id else "\"" + id + "\""
+//        val query = queryJson(serviceName, columnName, labelName, qId, 
direction, cacheTTL)
+//        val ret = route(FakeRequest(POST, 
"/graphs/getEdges").withJsonBody(query)).get
+//        val jsResult = commonCheck(ret)
+//
+//        val results = jsResult \ "results"
+//        val deegrees = (jsResult \ "degrees").as[List[JsObject]]
+//        val propsLs = (results \\ "props").seq
+//        (deegrees.head \ LabelMeta.degree.name).as[Int] must equalTo(1)
+//
+//        val from = (results \\ "from").seq.last.toString.replaceAll("\"", "")
+//        val to = (results \\ "to").seq.last.toString.replaceAll("\"", "")
+//
+//        from must equalTo(id.toString)
+//        to must equalTo(otherId.toString)
+////        (results \\ "_timestamp").seq.last.as[Long] must equalTo(maxTs)
+//        for ((key, expectedVal) <- expected) {
+//          propsLs.last.as[JsObject].keys.contains(key) must equalTo(true)
+//          (propsLs.last \ key).toString must equalTo(expectedVal)
+//        }
+//        Await.result(ret, HTTP_REQ_WAITING_TIME)
+//      }
+//    }
+//  }
+//
+//  init()
+//  "Basic Crud " should {
+//    "tc1" in {
+//      running(FakeApplication()) {
+//
+//        var tcNum = 0
+//        var tcString = ""
+//        var bulkQueries = List.empty[(Long, String, String)]
+//        var expected = Map.empty[String, String]
+//
+//        tcNum = 7
+//        tcString = "[t1 -> t2 -> t3 test case] insert(t1) delete(t2) 
insert(t3) test "
+//        bulkQueries = List(
+//          (t1, "insert", "{\"time\": 10}"),
+//          (t2, "delete", ""),
+//          (t3, "insert", "{\"time\": 10, \"weight\": 20}"))
+//        expected = Map("time" -> "10", "weight" -> "20")
+//
+//        runTC(tcNum, tcString, bulkQueries, expected)
+//
+//        tcNum = 8
+//        tcString = "[t1 -> t2 -> t3 test case] insert(t1) delete(t2) 
insert(t3) test "
+//        bulkQueries = List(
+//          (t1, "insert", "{\"time\": 10}"),
+//          (t3, "insert", "{\"time\": 10, \"weight\": 20}"),
+//          (t2, "delete", ""))
+//        expected = Map("time" -> "10", "weight" -> "20")
+//
+//        runTC(tcNum, tcString, bulkQueries, expected)
+//
+//        tcNum = 9
+//        tcString = "[t3 -> t2 -> t1 test case] insert(t3) delete(t2) 
insert(t1) test "
+//        bulkQueries = List(
+//          (t3, "insert", "{\"time\": 10, \"weight\": 20}"),
+//          (t2, "delete", ""),
+//          (t1, "insert", "{\"time\": 10}"))
+//        expected = Map("time" -> "10", "weight" -> "20")
+//
+//        runTC(tcNum, tcString, bulkQueries, expected)
+//
+//        tcNum = 10
+//        tcString = "[t3 -> t1 -> t2 test case] insert(t3) insert(t1) 
delete(t2) test "
+//        bulkQueries = List(
+//          (t3, "insert", "{\"time\": 10, \"weight\": 20}"),
+//          (t1, "insert", "{\"time\": 10}"),
+//          (t2, "delete", ""))
+//        expected = Map("time" -> "10", "weight" -> "20")
+//
+//        runTC(tcNum, tcString, bulkQueries, expected)
+//
+//        tcNum = 11
+//        tcString = "[t2 -> t1 -> t3 test case] delete(t2) insert(t1) 
insert(t3) test"
+//        bulkQueries = List(
+//          (t2, "delete", ""),
+//          (t1, "insert", "{\"time\": 10}"),
+//          (t3, "insert", "{\"time\": 10, \"weight\": 20}"))
+//        expected = Map("time" -> "10", "weight" -> "20")
+//
+//        runTC(tcNum, tcString, bulkQueries, expected)
+//
+//        tcNum = 12
+//        tcString = "[t2 -> t3 -> t1 test case] delete(t2) insert(t3) 
insert(t1) test "
+//        bulkQueries = List(
+//          (t2, "delete", ""),
+//          (t3, "insert", "{\"time\": 10, \"weight\": 20}"),
+//          (t1, "insert", "{\"time\": 10}"))
+//        expected = Map("time" -> "10", "weight" -> "20")
+//
+//        runTC(tcNum, tcString, bulkQueries, expected)
+//
+//        tcNum = 13
+//        tcString = "[t1 -> t2 -> t3 test case] update(t1) delete(t2) 
update(t3) test "
+//        bulkQueries = List(
+//          (t1, "update", "{\"time\": 10}"),
+//          (t2, "delete", ""),
+//          (t3, "update", "{\"time\": 10, \"weight\": 20}"))
+//        expected = Map("time" -> "10", "weight" -> "20")
+//
+//        runTC(tcNum, tcString, bulkQueries, expected)
+//        tcNum = 14
+//        tcString = "[t1 -> t3 -> t2 test case] update(t1) update(t3) 
delete(t2) test "
+//        bulkQueries = List(
+//          (t1, "update", "{\"time\": 10}"),
+//          (t3, "update", "{\"time\": 10, \"weight\": 20}"),
+//          (t2, "delete", ""))
+//        expected = Map("time" -> "10", "weight" -> "20")
+//
+//        runTC(tcNum, tcString, bulkQueries, expected)
+//        tcNum = 15
+//        tcString = "[t2 -> t1 -> t3 test case] delete(t2) update(t1) 
update(t3) test "
+//        bulkQueries = List(
+//          (t2, "delete", ""),
+//          (t1, "update", "{\"time\": 10}"),
+//          (t3, "update", "{\"time\": 10, \"weight\": 20}"))
+//        expected = Map("time" -> "10", "weight" -> "20")
+//
+//        runTC(tcNum, tcString, bulkQueries, expected)
+//        tcNum = 16
+//        tcString = "[t2 -> t3 -> t1 test case] delete(t2) update(t3) 
update(t1) test"
+//        bulkQueries = List(
+//          (t2, "delete", ""),
+//          (t3, "update", "{\"time\": 10, \"weight\": 20}"),
+//          (t1, "update", "{\"time\": 10}"))
+//        expected = Map("time" -> "10", "weight" -> "20")
+//
+//        runTC(tcNum, tcString, bulkQueries, expected)
+//        tcNum = 17
+//        tcString = "[t3 -> t2 -> t1 test case] update(t3) delete(t2) 
update(t1) test "
+//        bulkQueries = List(
+//          (t3, "update", "{\"time\": 10, \"weight\": 20}"),
+//          (t2, "delete", ""),
+//          (t1, "update", "{\"time\": 10}"))
+//        expected = Map("time" -> "10", "weight" -> "20")
+//
+//        runTC(tcNum, tcString, bulkQueries, expected)
+//        tcNum = 18
+//        tcString = "[t3 -> t1 -> t2 test case] update(t3) update(t1) 
delete(t2) test "
+//        bulkQueries = List(
+//          (t3, "update", "{\"time\": 10, \"weight\": 20}"),
+//          (t1, "update", "{\"time\": 10}"),
+//          (t2, "delete", ""))
+//        expected = Map("time" -> "10", "weight" -> "20")
+//
+//        runTC(tcNum, tcString, bulkQueries, expected)
+//
+//        tcNum = 19
+//        tcString = "[t5 -> t1 -> t3 -> t2 -> t4 test case] update(t5) 
insert(t1) insert(t3) delete(t2) update(t4) test "
+//        bulkQueries = List(
+//          (t5, "update", "{\"is_blocked\": true}"),
+//          (t1, "insert", "{\"is_hidden\": false}"),
+//          (t3, "insert", "{\"is_hidden\": false, \"weight\": 10}"),
+//          (t2, "delete", ""),
+//          (t4, "update", "{\"time\": 1, \"weight\": -10}"))
+//        expected = Map("time" -> "1", "weight" -> "-10", "is_hidden" -> 
"false", "is_blocked" -> "true")
+//
+//        runTC(tcNum, tcString, bulkQueries, expected)
+//        true
+//      }
+//    }
+//  }
+//
+//  "toLogString" in {
+//    running(FakeApplication()) {
+//      val bulkQueries = List(
+//        ("1445240543366", "update", "{\"is_blocked\":true}"),
+//        ("1445240543362", "insert", "{\"is_hidden\":false}"),
+//        ("1445240543364", "insert", "{\"is_hidden\":false,\"weight\":10}"),
+//        ("1445240543363", "delete", "{}"),
+//        ("1445240543365", "update", "{\"time\":1, \"weight\":-10}"))
+//
+//      val (srcId, tgtId, labelName) = ("1", "2", testLabelName)
+//
+//      val bulkEdge = (for ((ts, op, props) <- bulkQueries) yield {
+//        Management.toEdge(ts.toLong, op, srcId, tgtId, labelName, "out", 
props).toLogString
+//      }).mkString("\n")
+//
+//      val expected = Seq(
+//        Seq("1445240543366", "update", "e", "1", "2", "s2graph_label_test", 
"{\"is_blocked\":true}"),
+//        Seq("1445240543362", "insert", "e", "1", "2", "s2graph_label_test", 
"{\"is_hidden\":false}"),
+//        Seq("1445240543364", "insert", "e", "1", "2", "s2graph_label_test", 
"{\"is_hidden\":false,\"weight\":10}"),
+//        Seq("1445240543363", "delete", "e", "1", "2", "s2graph_label_test"),
+//        Seq("1445240543365", "update", "e", "1", "2", "s2graph_label_test", 
"{\"time\":1,\"weight\":-10}")
+//      ).map(_.mkString("\t")).mkString("\n")
+//
+//      bulkEdge must equalTo(expected)
+//
+//      true
+//    }
+//  }
+//}
+//
+//

Reply via email to