Move VertexSpec to s2core, remove unused dependency
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/5c0af72a Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/5c0af72a Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/5c0af72a Branch: refs/heads/feature/test_daewon Commit: 5c0af72a36a95161d14f32a3fbaee92e69fc55fa Parents: 610d519 Author: daewon <[email protected]> Authored: Tue Dec 29 19:06:31 2015 +0900 Committer: daewon <[email protected]> Committed: Tue Dec 29 19:06:31 2015 +0900 ---------------------------------------------------------------------- build.sbt | 8 +- s2core/src/main/resources/logback.xml | 26 +- s2core/src/main/resources/reference.conf | 5 + .../com/kakao/s2graph/core/utils/Logger.scala | 1 - .../kakao/s2graph/core/Integrate/CrudTest.scala | 1 - .../core/Integrate/IntegrateCommon.scala | 2 +- .../core/Integrate/VertexTestHelper.scala | 71 ++ s2rest_play/build.sbt | 3 +- .../test/benchmark/JsonBenchmarkSpec.scala | 14 +- .../benchmark/OrderingUtilBenchmarkSpec.scala | 16 +- .../benchmark/PostProcessBenchmarkSpec.scala | 367 +++++----- .../test/benchmark/SamplingBenchmarkSpec.scala | 2 +- .../test/controllers/AdminControllerSpec.scala | 30 +- s2rest_play/test/controllers/SpecCommon.scala | 668 +++++++++---------- s2rest_play/test/controllers/VertexSpec.scala | 106 +-- 15 files changed, 700 insertions(+), 620 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/5c0af72a/build.sbt ---------------------------------------------------------------------- diff --git a/build.sbt b/build.sbt index ad08bdb..c4035e3 100755 --- a/build.sbt +++ b/build.sbt @@ -5,7 +5,7 @@ lazy val commonSettings = Seq( scalaVersion := "2.11.7", version := "0.12.1-SNAPSHOT", scalacOptions := Seq("-language:postfixOps", "-unchecked", "-deprecation", "-feature", "-Xlint"), - javaOptions ++= collection.JavaConversions.propertiesAsScalaMap(System.getProperties).map{ case (key, value) => "-D" + key + "=" + value }.toSeq, + javaOptions ++= collection.JavaConversions.propertiesAsScalaMap(System.getProperties).map { case (key, value) => "-D" + key + "=" + value }.toSeq, testOptions in Test += Tests.Argument("-oDF"), parallelExecution in Test := false, resolvers ++= Seq( @@ -24,6 +24,7 @@ Revolver.settings lazy val s2rest_play = project.enablePlugins(PlayScala) .dependsOn(s2core, s2counter_core) .settings(commonSettings: _*) + .settings(testOptions in Test += Tests.Argument("sequential")) lazy val s2rest_netty = project .dependsOn(s2core) @@ -44,5 +45,6 @@ lazy val s2counter_loader = project.dependsOn(s2counter_core, spark) lazy val s2ml = project.settings(commonSettings: _*) -lazy val root = (project in file(".")). - aggregate(s2core, s2rest_play) +lazy val root = (project in file(".")) + .aggregate(s2core, s2rest_play) + .settings(commonSettings: _*) http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/5c0af72a/s2core/src/main/resources/logback.xml ---------------------------------------------------------------------- diff --git a/s2core/src/main/resources/logback.xml b/s2core/src/main/resources/logback.xml index 94f4920..428a70f 100644 --- a/s2core/src/main/resources/logback.xml +++ b/s2core/src/main/resources/logback.xml @@ -1,15 +1,19 @@ <?xml version="1.0" encoding="UTF-8"?> <configuration> - <jmxConfigurator/> - <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> - <encoder> - <pattern> - %d{ISO8601} %-5level [%thread] %logger{0}: %msg%n - </pattern> - </encoder> - </appender> + <jmxConfigurator/> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern> + %d{ISO8601} %-5level [%thread] %logger{0}: %msg%n + </pattern> + </encoder> + </appender> - <root level="info"> - <appender-ref ref="STDOUT"/> - </root> + <root name="error" level="error"> + <appender-ref ref="STDOUT"/> + </root> + + <root name="application" level="info"> + <appender-ref ref="STDOUT"/> + </root> </configuration> http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/5c0af72a/s2core/src/main/resources/reference.conf ---------------------------------------------------------------------- diff --git a/s2core/src/main/resources/reference.conf b/s2core/src/main/resources/reference.conf index b527f7f..5727b28 100644 --- a/s2core/src/main/resources/reference.conf +++ b/s2core/src/main/resources/reference.conf @@ -1,7 +1,12 @@ # APP PHASE phase=dev + host=localhost +logger.root=DEBUG + +logger.application=DEBUG + hbase.zookeeper.quorum=${host} # DB http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/5c0af72a/s2core/src/main/scala/com/kakao/s2graph/core/utils/Logger.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/com/kakao/s2graph/core/utils/Logger.scala b/s2core/src/main/scala/com/kakao/s2graph/core/utils/Logger.scala index cb4514d..609300a 100644 --- a/s2core/src/main/scala/com/kakao/s2graph/core/utils/Logger.scala +++ b/s2core/src/main/scala/com/kakao/s2graph/core/utils/Logger.scala @@ -1,6 +1,5 @@ package com.kakao.s2graph.core.utils -//import play.api.Logger import org.slf4j.LoggerFactory import play.api.libs.json.JsValue http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/5c0af72a/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 f3bbdd9..1c09778 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 @@ -4,7 +4,6 @@ import com.kakao.s2graph.core.mysqls._ import play.api.libs.json.{JsObject, Json} class CrudTest extends IntegrateCommon { - import CrudHelper._ import TestUtil._ http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/5c0af72a/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 230fa9c..6f73f11 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 @@ -143,7 +143,7 @@ trait IntegrateCommon extends FunSuite with Matchers with BeforeAndAfterAll { val index2 = "idx_2" val NumOfEachTest = 30 - val HttpRequestWaitingTime = Duration("Inf") + val HttpRequestWaitingTime = Duration("60 seconds") val createService = s"""{"serviceName" : "$testServiceName"}""" http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/5c0af72a/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/VertexTestHelper.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/VertexTestHelper.scala b/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/VertexTestHelper.scala new file mode 100644 index 0000000..ffbec11 --- /dev/null +++ b/s2core/src/test/scala/com/kakao/s2graph/core/Integrate/VertexTestHelper.scala @@ -0,0 +1,71 @@ +package com.kakao.s2graph.core.Integrate + +import com.kakao.s2graph.core.PostProcess +import play.api.libs.json.{JsValue, Json} + +import scala.concurrent.Await +import scala.util.Random + + +class VertexTestHelper extends IntegrateCommon { + + import TestUtil._ + import VertexTestHelper._ + + test("vertex") { + val ids = (7 until 20).map(tcNum => tcNum * 1000 + 0) + val (serviceName, columnName) = (testServiceName, testColumnName) + + val data = vertexInsertsPayload(serviceName, columnName, ids) + val payload = Json.parse(Json.toJson(data).toString) + println(payload) + + val vertices = parser.toVertices(payload, "insert", Option(serviceName), Option(columnName)) + Await.result(graph.mutateVertices(vertices, withWait = true), HttpRequestWaitingTime) + + val res = graph.getVertices(vertices).map { vertices => + PostProcess.verticesToJson(vertices) + } + + val ret = Await.result(res, HttpRequestWaitingTime) + val fetched = ret.as[Seq[JsValue]] + for { + (d, f) <- data.zip(fetched) + } yield { + (d \ "id") should be(f \ "id") + ((d \ "props") \ "age") should be((f \ "props") \ "age") + } + } + + object VertexTestHelper { + def vertexQueryJson(serviceName: String, columnName: String, ids: Seq[Int]) = { + Json.parse( + s""" + |[ + |{"serviceName": "$serviceName", "columnName": "$columnName", "ids": [${ids.mkString(",")} + ]} + |] + """.stripMargin) + } + + def vertexInsertsPayload(serviceName: String, columnName: String, ids: Seq[Int]): Seq[JsValue] = { + ids.map { id => + Json.obj("id" -> id, "props" -> randomProps, "timestamp" -> System.currentTimeMillis()) + } + } + + val vertexPropsKeys = List( + ("age", "int") + ) + + def randomProps() = { + (for { + (propKey, propType) <- vertexPropsKeys + } yield { + propKey -> Random.nextInt(100) + }).toMap + } + } +} + + http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/5c0af72a/s2rest_play/build.sbt ---------------------------------------------------------------------- diff --git a/s2rest_play/build.sbt b/s2rest_play/build.sbt index 09da78c..09216a1 100644 --- a/s2rest_play/build.sbt +++ b/s2rest_play/build.sbt @@ -10,8 +10,7 @@ libraryDependencies ++= Seq( ws, filters, "xalan" % "serializer" % "2.7.2", // Download in Intelli J(Download Source/Document) - "com.github.danielwegener" % "logback-kafka-appender" % "0.0.3", - "org.json4s" %% "json4s-native" % "3.2.11" % Test + "com.github.danielwegener" % "logback-kafka-appender" % "0.0.3" ) enablePlugins(JavaServerAppPackaging) http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/5c0af72a/s2rest_play/test/benchmark/JsonBenchmarkSpec.scala ---------------------------------------------------------------------- diff --git a/s2rest_play/test/benchmark/JsonBenchmarkSpec.scala b/s2rest_play/test/benchmark/JsonBenchmarkSpec.scala index 7f0ef83..1f7c1ef 100644 --- a/s2rest_play/test/benchmark/JsonBenchmarkSpec.scala +++ b/s2rest_play/test/benchmark/JsonBenchmarkSpec.scala @@ -8,32 +8,32 @@ class JsonBenchmarkSpec extends BenchmarkCommon { "json benchmark" >> { duration("map to json") { - (0 to 100) foreach { n => + (0 to 10) foreach { n => val numberMaps = (0 to 100).map { n => (n.toString -> JsNumber(n * n)) }.toMap Json.toJson(numberMaps) } } duration("directMakeJson") { - (0 to 100) foreach { n => + (0 to 10) foreach { n => var jsObj = play.api.libs.json.Json.obj() - (0 to 100).foreach { n => + (0 to 10).foreach { n => jsObj += (n.toString -> JsNumber(n * n)) } } } duration("map to json 2") { - (0 to 500) foreach { n => - val numberMaps = (0 to 100).map { n => (n.toString -> JsNumber(n * n)) }.toMap + (0 to 50) foreach { n => + val numberMaps = (0 to 10).map { n => (n.toString -> JsNumber(n * n)) }.toMap Json.toJson(numberMaps) } } duration("directMakeJson 2") { - (0 to 500) foreach { n => + (0 to 50) foreach { n => var jsObj = play.api.libs.json.Json.obj() - (0 to 100).foreach { n => + (0 to 10).foreach { n => jsObj += (n.toString -> JsNumber(n * n)) } } http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/5c0af72a/s2rest_play/test/benchmark/OrderingUtilBenchmarkSpec.scala ---------------------------------------------------------------------- diff --git a/s2rest_play/test/benchmark/OrderingUtilBenchmarkSpec.scala b/s2rest_play/test/benchmark/OrderingUtilBenchmarkSpec.scala index 053eb23..d2d3624 100644 --- a/s2rest_play/test/benchmark/OrderingUtilBenchmarkSpec.scala +++ b/s2rest_play/test/benchmark/OrderingUtilBenchmarkSpec.scala @@ -21,7 +21,7 @@ class OrderingUtilBenchmarkSpec extends BenchmarkCommon { } val sorted1 = duration("TupleOrdering double,long") { - (0 until 10000) foreach { _ => + (0 until 1000) foreach { _ => tupLs.sortBy { case (x, y) => -x -> -y } @@ -32,7 +32,7 @@ class OrderingUtilBenchmarkSpec extends BenchmarkCommon { }.map { x => x._1 } val sorted2 = duration("MultiOrdering double,long") { - (0 until 10000) foreach { _ => + (0 until 1000) foreach { _ => seqLs.sorted(new SeqMultiOrdering[Any](Seq(false, false))) } seqLs.sorted(new SeqMultiOrdering[Any](Seq(false, false))) @@ -42,7 +42,7 @@ class OrderingUtilBenchmarkSpec extends BenchmarkCommon { } "performance MultiOrdering double" >> { - val tupLs = (0 until 500) map { i => + val tupLs = (0 until 50) map { i => Random.nextDouble() -> Random.nextDouble() } @@ -51,13 +51,13 @@ class OrderingUtilBenchmarkSpec extends BenchmarkCommon { } duration("MultiOrdering double") { - (0 until 10000) foreach { _ => + (0 until 1000) foreach { _ => seqLs.sorted(new SeqMultiOrdering[Double](Seq(false, false))) } } duration("TupleOrdering double") { - (0 until 10000) foreach { _ => + (0 until 1000) foreach { _ => tupLs.sortBy { case (x, y) => -x -> -y } @@ -68,7 +68,7 @@ class OrderingUtilBenchmarkSpec extends BenchmarkCommon { } "performance MultiOrdering jsvalue" >> { - val tupLs = (0 until 500) map { i => + val tupLs = (0 until 50) map { i => Random.nextDouble() -> Random.nextLong() } @@ -77,7 +77,7 @@ class OrderingUtilBenchmarkSpec extends BenchmarkCommon { } val sorted1 = duration("TupleOrdering double,long") { - (0 until 10000) foreach { _ => + (0 until 1000) foreach { _ => tupLs.sortBy { case (x, y) => -x -> -y } @@ -88,7 +88,7 @@ class OrderingUtilBenchmarkSpec extends BenchmarkCommon { } val sorted2 = duration("MultiOrdering jsvalue") { - (0 until 10000) foreach { _ => + (0 until 1000) foreach { _ => seqLs.sorted(new SeqMultiOrdering[JsValue](Seq(false, false))) } seqLs.sorted(new SeqMultiOrdering[JsValue](Seq(false, false))) http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/5c0af72a/s2rest_play/test/benchmark/PostProcessBenchmarkSpec.scala ---------------------------------------------------------------------- diff --git a/s2rest_play/test/benchmark/PostProcessBenchmarkSpec.scala b/s2rest_play/test/benchmark/PostProcessBenchmarkSpec.scala index 3ae08e2..6de3dd5 100644 --- a/s2rest_play/test/benchmark/PostProcessBenchmarkSpec.scala +++ b/s2rest_play/test/benchmark/PostProcessBenchmarkSpec.scala @@ -1,184 +1,130 @@ -package benchmark - -import com.kakao.s2graph.core.mysqls.Label -import com.kakao.s2graph.core.rest.RequestParser -import com.kakao.s2graph.core.{PostProcess, Graph, Management} -import com.typesafe.config.ConfigFactory -import controllers._ -import play.api.libs.json.{JsValue, Json} -import play.api.test.{FakeApplication, FakeRequest, PlaySpecification} - -import scala.concurrent.Await -import scala.concurrent.duration._ - -/** - * Created by hsleep([email protected]) on 2015. 11. 6.. - */ -class PostProcessBenchmarkSpec extends SpecCommon with BenchmarkCommon with PlaySpecification { - init() - - override def init() = { - running(FakeApplication()) { - println("[init start]: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") - Management.deleteService(testServiceName) - - // 1. createService - val result = AdminController.createServiceInner(Json.parse(createService)) - println(s">> Service created : $createService, $result") - - val labelNames = Map( - testLabelNameWeak -> testLabelNameWeakCreate - ) - - for { - (labelName, create) <- labelNames - } { - Management.deleteLabel(labelName) - Label.findByName(labelName, useCache = false) match { - case None => - AdminController.createLabelInner(Json.parse(create)) - case Some(label) => - println(s">> Label already exist: $create, $label") - } - } - - // create edges - val bulkEdges: String = (0 until 500).map { i => - Seq(System.currentTimeMillis(), "insert", "e", "0", i, testLabelNameWeak, Json.obj("weight" -> i)).mkString("\t") - }.mkString("\n") - - val jsResult = contentAsJson(EdgeController.mutateAndPublish(bulkEdges, withWait = true)) - - println("[init end]: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") - } - } - - def getEdges(queryJson: JsValue): JsValue = { - val ret = route(FakeRequest(POST, "/graphs/getEdges").withJsonBody(queryJson)).get - contentAsJson(ret) - } - - val s2: Graph = com.kakao.s2graph.rest.Global.s2graph - -// "test performance of getEdges orderBy" >> { -// running(FakeApplication()) { -// val strJs = -// s""" -// |{ -// | "orderBy": [ -// | {"score": "DESC"}, -// | {"timestamp": "DESC"} -// | ], -// | "srcVertices": [ -// | { -// | "serviceName": "$testServiceName", -// | "columnName": "$testColumnName", -// | "ids": [0] -// | } -// | ], -// | "steps": [ -// | { -// | "step": [ -// | { -// | "cacheTTL": 60000, -// | "label": "$testLabelNameWeak", -// | "offset": 0, -// | "limit": -1, -// | "direction": "out", -// | "scoring": [ -// | {"weight": 1} -// | ] -// | } -// | ] -// | } -// | ] -// |} -// """.stripMargin -// -// object Parser extends RequestParser +//package benchmark // -// val js = Json.parse(strJs) -// -// val q = Parser.toQuery(js) +//import com.kakao.s2graph.core.mysqls.Label +//import com.kakao.s2graph.core.rest.RequestParser +//import com.kakao.s2graph.core.{PostProcess, Graph, Management} +//import com.typesafe.config.ConfigFactory +//import controllers._ +//import play.api.libs.json.{JsValue, Json} +//import play.api.test.{FakeApplication, FakeRequest, PlaySpecification} // -// val queryResultLs = Await.result(s2.getEdges(q), 1 seconds) +//import scala.concurrent.Await +//import scala.concurrent.duration._ // -// val resultJs = PostProcess.toSimpleVertexArrJson(queryResultLs) +///** +// * Created by hsleep([email protected]) on 2015. 11. 6.. +// */ +//class PostProcessBenchmarkSpec extends SpecCommon with BenchmarkCommon with PlaySpecification { // -// (resultJs \ "size").as[Int] must_== 500 +// init() // -// (0 to 5) foreach { _ => -// duration("toSimpleVertexArrJson new orderBy") { -// (0 to 1000) foreach { _ => -// PostProcess.toSimpleVertexArrJson(queryResultLs, Nil) -// } +// override def init() = { +// running(FakeApplication()) { +// println("[init start]: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") +// Management.deleteService(testServiceName) +// +// // 1. createService +// val result = AdminController.createServiceInner(Json.parse(createService)) +// println(s">> Service created : $createService, $result") +// +// val labelNames = Map( +// testLabelNameWeak -> testLabelNameWeakCreate +// ) +// +// for { +// (labelName, create) <- labelNames +// } { +// Management.deleteLabel(labelName) +// Label.findByName(labelName, useCache = false) match { +// case None => +// AdminController.createLabelInner(Json.parse(create)) +// case Some(label) => +// println(s">> Label already exist: $create, $label") // } // } // -// (resultJs \ "size").as[Int] must_== 500 +// // create edges +// val bulkEdges: String = (0 until 50).map { i => +// Seq(System.currentTimeMillis(), "insert", "e", "0", i, testLabelNameWeak, Json.obj("weight" -> i)).mkString("\t") +// }.mkString("\n") +// +// val jsResult = contentAsJson(EdgeController.mutateAndPublish(bulkEdges, withWait = true)) +// +// println("[init end]: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") // } // } - - "test performance of getEdges" >> { - running(FakeApplication()) { - val strJs = - s""" - |{ - | "srcVertices": [ - | { - | "serviceName": "$testServiceName", - | "columnName": "$testColumnName", - | "ids": [0] - | } - | ], - | "steps": [ - | { - | "step": [ - | { - | "cacheTTL": 60000, - | "label": "$testLabelNameWeak", - | "offset": 0, - | "limit": -1, - | "direction": "out", - | "scoring": [ - | {"weight": 1} - | ] - | } - | ] - | } - | ] - |} - """.stripMargin - - val config = ConfigFactory.load() - val s2graph = new Graph(config)(scala.concurrent.ExecutionContext.Implicits.global) - val s2parser = new RequestParser(s2graph.config) - val js = Json.parse(strJs) - - val q = s2parser.toQuery(js) - - val queryResultLs = Await.result(s2.getEdges(q), 1 seconds) - - val resultJs = PostProcess.toSimpleVertexArrJson(queryResultLs, Nil) - - (0 to 5) foreach { _ => - duration("toSimpleVertexArrJson new") { - (0 to 1000) foreach { _ => - PostProcess.toSimpleVertexArrJson(queryResultLs, Nil) - } - } - } - - (resultJs \ "size").as[Int] must_== 500 - } - } - -// "test performance of getEdges withScore=false" >> { +// +// def getEdges(queryJson: JsValue): JsValue = { +// val ret = route(FakeRequest(POST, "/graphs/getEdges").withJsonBody(queryJson)).get +// contentAsJson(ret) +// } +// +// val s2: Graph = com.kakao.s2graph.rest.Global.s2graph +// +//// "test performance of getEdges orderBy" >> { +//// running(FakeApplication()) { +//// val strJs = +//// s""" +//// |{ +//// | "orderBy": [ +//// | {"score": "DESC"}, +//// | {"timestamp": "DESC"} +//// | ], +//// | "srcVertices": [ +//// | { +//// | "serviceName": "$testServiceName", +//// | "columnName": "$testColumnName", +//// | "ids": [0] +//// | } +//// | ], +//// | "steps": [ +//// | { +//// | "step": [ +//// | { +//// | "cacheTTL": 60000, +//// | "label": "$testLabelNameWeak", +//// | "offset": 0, +//// | "limit": -1, +//// | "direction": "out", +//// | "scoring": [ +//// | {"weight": 1} +//// | ] +//// | } +//// | ] +//// | } +//// | ] +//// |} +//// """.stripMargin +//// +//// object Parser extends RequestParser +//// +//// val js = Json.parse(strJs) +//// +//// val q = Parser.toQuery(js) +//// +//// val queryResultLs = Await.result(s2.getEdges(q), 1 seconds) +//// +//// val resultJs = PostProcess.toSimpleVertexArrJson(queryResultLs) +//// +//// (resultJs \ "size").as[Int] must_== 500 +//// +//// (0 to 5) foreach { _ => +//// duration("toSimpleVertexArrJson new orderBy") { +//// (0 to 1000) foreach { _ => +//// PostProcess.toSimpleVertexArrJson(queryResultLs, Nil) +//// } +//// } +//// } +//// +//// (resultJs \ "size").as[Int] must_== 500 +//// } +//// } +// +// "test performance of getEdges" >> { // running(FakeApplication()) { // val strJs = // s""" // |{ -// | "withScore": false, // | "srcVertices": [ // | { // | "serviceName": "$testServiceName", @@ -205,33 +151,88 @@ class PostProcessBenchmarkSpec extends SpecCommon with BenchmarkCommon with Play // |} // """.stripMargin // -// object Parser extends RequestParser -// +// val config = ConfigFactory.load() +// val s2graph = new Graph(config)(scala.concurrent.ExecutionContext.Implicits.global) +// val s2parser = new RequestParser(s2graph.config) // val js = Json.parse(strJs) // -// val q = Parser.toQuery(js) +// val q = s2parser.toQuery(js) // // val queryResultLs = Await.result(s2.getEdges(q), 1 seconds) // -// val resultJs = PostProcess.toSimpleVertexArrJson(queryResultLs) -// -// (resultJs \ "size").as[Int] must_== 500 +// val resultJs = PostProcess.toSimpleVertexArrJson(queryResultLs, Nil) // // (0 to 5) foreach { _ => -// duration("toSimpleVertexArrJson withScore=false org") { -// (0 to 1000) foreach { _ => -// PostProcess.toSimpleVertexArrJsonOrg(queryResultLs, Nil) -// } -// } -// -// duration("toSimpleVertexArrJson withScore=false new") { -// (0 to 1000) foreach { _ => +// duration("toSimpleVertexArrJson new") { +// (0 to 100) foreach { _ => // PostProcess.toSimpleVertexArrJson(queryResultLs, Nil) // } // } // } // -// (resultJs \ "size").as[Int] must_== 500 +// (resultJs \ "size").as[Int] must_== 50 // } // } -} +// +//// "test performance of getEdges withScore=false" >> { +//// running(FakeApplication()) { +//// val strJs = +//// s""" +//// |{ +//// | "withScore": false, +//// | "srcVertices": [ +//// | { +//// | "serviceName": "$testServiceName", +//// | "columnName": "$testColumnName", +//// | "ids": [0] +//// | } +//// | ], +//// | "steps": [ +//// | { +//// | "step": [ +//// | { +//// | "cacheTTL": 60000, +//// | "label": "$testLabelNameWeak", +//// | "offset": 0, +//// | "limit": -1, +//// | "direction": "out", +//// | "scoring": [ +//// | {"weight": 1} +//// | ] +//// | } +//// | ] +//// | } +//// | ] +//// |} +//// """.stripMargin +//// +//// object Parser extends RequestParser +//// +//// val js = Json.parse(strJs) +//// +//// val q = Parser.toQuery(js) +//// +//// val queryResultLs = Await.result(s2.getEdges(q), 1 seconds) +//// +//// val resultJs = PostProcess.toSimpleVertexArrJson(queryResultLs) +//// +//// (resultJs \ "size").as[Int] must_== 500 +//// +//// (0 to 5) foreach { _ => +//// duration("toSimpleVertexArrJson withScore=false org") { +//// (0 to 1000) foreach { _ => +//// PostProcess.toSimpleVertexArrJsonOrg(queryResultLs, Nil) +//// } +//// } +//// +//// duration("toSimpleVertexArrJson withScore=false new") { +//// (0 to 1000) foreach { _ => +//// PostProcess.toSimpleVertexArrJson(queryResultLs, Nil) +//// } +//// } +//// } +//// +//// (resultJs \ "size").as[Int] must_== 500 +//// } +//// } +//} http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/5c0af72a/s2rest_play/test/benchmark/SamplingBenchmarkSpec.scala ---------------------------------------------------------------------- diff --git a/s2rest_play/test/benchmark/SamplingBenchmarkSpec.scala b/s2rest_play/test/benchmark/SamplingBenchmarkSpec.scala index 7e442e4..6f7f4fc 100644 --- a/s2rest_play/test/benchmark/SamplingBenchmarkSpec.scala +++ b/s2rest_play/test/benchmark/SamplingBenchmarkSpec.scala @@ -47,7 +47,7 @@ class SamplingBenchmarkSpec extends BenchmarkCommon { } // test data - val testLimit = 100000 + val testLimit = 1000 val testNum = 10 val testData = (0 to 1000).toList http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/5c0af72a/s2rest_play/test/controllers/AdminControllerSpec.scala ---------------------------------------------------------------------- diff --git a/s2rest_play/test/controllers/AdminControllerSpec.scala b/s2rest_play/test/controllers/AdminControllerSpec.scala index e41fccb..1d92ed2 100644 --- a/s2rest_play/test/controllers/AdminControllerSpec.scala +++ b/s2rest_play/test/controllers/AdminControllerSpec.scala @@ -10,18 +10,18 @@ import scala.concurrent.Await /** * Created by mojo22jojo([email protected]) on 15. 10. 13.. */ -class AdminControllerSpec extends SpecCommon { - init() - "EdgeControllerSpec" should { - "update htable" in { - running(FakeApplication()) { - val insertUrl = s"/graphs/updateHTable/$testLabelName/$newHTableName" - - val req = FakeRequest("POST", insertUrl).withBody("").withHeaders(HeaderNames.CONTENT_TYPE -> "text/plain") - - Await.result(route(req).get, HTTP_REQ_WAITING_TIME) - Label.findByName(testLabelName, useCache = true).get.hTableName mustEqual newHTableName - } - } - } -} +//class AdminControllerSpec extends SpecCommon { +// init() +// "EdgeControllerSpec" should { +// "update htable" in { +// running(FakeApplication()) { +// val insertUrl = s"/graphs/updateHTable/$testLabelName/$newHTableName" +// +// val req = FakeRequest("POST", insertUrl).withBody("").withHeaders(HeaderNames.CONTENT_TYPE -> "text/plain") +// +// Await.result(route(req).get, HTTP_REQ_WAITING_TIME) +// Label.findByName(testLabelName, useCache = true).get.hTableName mustEqual newHTableName +// } +// } +// } +//} http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/5c0af72a/s2rest_play/test/controllers/SpecCommon.scala ---------------------------------------------------------------------- diff --git a/s2rest_play/test/controllers/SpecCommon.scala b/s2rest_play/test/controllers/SpecCommon.scala index 28c4c23..5fec7ea 100644 --- a/s2rest_play/test/controllers/SpecCommon.scala +++ b/s2rest_play/test/controllers/SpecCommon.scala @@ -1,334 +1,334 @@ -package controllers - -import com.kakao.s2graph.core._ -import com.kakao.s2graph.core.mysqls._ -import org.specs2.mutable.Specification -import play.api.libs.json._ -import play.api.test.FakeApplication -import play.api.test.Helpers._ - -import scala.concurrent.Future -import scala.concurrent.duration._ -import scala.util.Random - -trait SpecCommon extends Specification { - val curTime = System.currentTimeMillis - - val t1 = curTime + 0 - val t2 = curTime + 1 - val t3 = curTime + 2 - val t4 = curTime + 3 - val t5 = curTime + 4 - - protected val testServiceName = "s2graph" - protected val testLabelName = "s2graph_label_test" - protected val testLabelName2 = "s2graph_label_test_2" - protected val testLabelNameV1 = "s2graph_label_test_v1" - protected val testLabelNameWeak = "s2graph_label_test_weak" - protected val testColumnName = "user_id_test" - protected val testColumnType = "long" - protected val testTgtColumnName = "item_id_test" - protected val testHTableName = "test-htable" - protected val newHTableName = "new-htable" - protected val index1 = "idx_1" - protected val index2 = "idx_2" - - val NUM_OF_EACH_TEST = 100 - val HTTP_REQ_WAITING_TIME = Duration(300, SECONDS) - val asyncFlushInterval = 100 - - val createService = s"""{"serviceName" : "$testServiceName"}""" - val testLabelNameCreate = - s""" - { - "label": "$testLabelName", - "srcServiceName": "$testServiceName", - "srcColumnName": "$testColumnName", - "srcColumnType": "long", - "tgtServiceName": "$testServiceName", - "tgtColumnName": "$testColumnName", - "tgtColumnType": "long", - "indices": [ - {"name": "$index1", "propNames": ["weight", "time", "is_hidden", "is_blocked"]}, - {"name": "$index2", "propNames": ["_timestamp"]} - ], - "props": [ - { - "name": "time", - "dataType": "long", - "defaultValue": 0 - }, - { - "name": "weight", - "dataType": "long", - "defaultValue": 0 - }, - { - "name": "is_hidden", - "dataType": "boolean", - "defaultValue": false - }, - { - "name": "is_blocked", - "dataType": "boolean", - "defaultValue": false - } - ], - "consistencyLevel": "strong", - "schemaVersion": "v2", - "compressionAlgorithm": "gz", - "hTableName": "$testHTableName" - }""" - - val testLabelName2Create = - s""" - { - "label": "$testLabelName2", - "srcServiceName": "$testServiceName", - "srcColumnName": "$testColumnName", - "srcColumnType": "long", - "tgtServiceName": "$testServiceName", - "tgtColumnName": "$testTgtColumnName", - "tgtColumnType": "string", - "indices": [{"name": "$index1", "propNames": ["time", "weight", "is_hidden", "is_blocked"]}], - "props": [ - { - "name": "time", - "dataType": "long", - "defaultValue": 0 - }, - { - "name": "weight", - "dataType": "long", - "defaultValue": 0 - }, - { - "name": "is_hidden", - "dataType": "boolean", - "defaultValue": false - }, - { - "name": "is_blocked", - "dataType": "boolean", - "defaultValue": false - } - ], - "consistencyLevel": "strong", - "isDirected": false, - "schemaVersion": "v3", - "compressionAlgorithm": "gz" - }""" - - val testLabelNameV1Create = - s""" - { - "label": "$testLabelNameV1", - "srcServiceName": "$testServiceName", - "srcColumnName": "$testColumnName", - "srcColumnType": "long", - "tgtServiceName": "$testServiceName", - "tgtColumnName": "${testTgtColumnName}_v1", - "tgtColumnType": "string", - "indices": [{"name": "$index1", "propNames": ["time", "weight", "is_hidden", "is_blocked"]}], - "props": [ - { - "name": "time", - "dataType": "long", - "defaultValue": 0 - }, - { - "name": "weight", - "dataType": "long", - "defaultValue": 0 - }, - { - "name": "is_hidden", - "dataType": "boolean", - "defaultValue": false - }, - { - "name": "is_blocked", - "dataType": "boolean", - "defaultValue": false - } - ], - "consistencyLevel": "strong", - "isDirected": true, - "schemaVersion": "v1", - "compressionAlgorithm": "gz" - }""" - val testLabelNameWeakCreate = - s""" - { - "label": "$testLabelNameWeak", - "srcServiceName": "$testServiceName", - "srcColumnName": "$testColumnName", - "srcColumnType": "long", - "tgtServiceName": "$testServiceName", - "tgtColumnName": "$testTgtColumnName", - "tgtColumnType": "string", - "indices": [{"name": "$index1", "propNames": ["time", "weight", "is_hidden", "is_blocked"]}], - "props": [ - { - "name": "time", - "dataType": "long", - "defaultValue": 0 - }, - { - "name": "weight", - "dataType": "long", - "defaultValue": 0 - }, - { - "name": "is_hidden", - "dataType": "boolean", - "defaultValue": false - }, - { - "name": "is_blocked", - "dataType": "boolean", - "defaultValue": false - } - ], - "consistencyLevel": "weak", - "isDirected": true, - "compressionAlgorithm": "gz" - }""" - - val vertexPropsKeys = List( - ("age", "int") - ) - - val createVertex = - s"""{ - "serviceName": "$testServiceName", - "columnName": "$testColumnName", - "columnType": "$testColumnType", - "props": [ - {"name": "is_active", "dataType": "boolean", "defaultValue": true}, - {"name": "phone_number", "dataType": "string", "defaultValue": "-"}, - {"name": "nickname", "dataType": "string", "defaultValue": ".."}, - {"name": "activity_score", "dataType": "float", "defaultValue": 0.0}, - {"name": "age", "dataType": "integer", "defaultValue": 0} - ] - }""" - - - val TS = System.currentTimeMillis() - - def queryJson(serviceName: String, columnName: String, labelName: String, id: String, dir: String, cacheTTL: Long = -1L) = { - val s = - s"""{ - "srcVertices": [ - { - "serviceName": "$serviceName", - "columnName": "$columnName", - "id": $id - } - ], - "steps": [ - [ - { - "label": "$labelName", - "direction": "$dir", - "offset": 0, - "limit": 10, - "cacheTTL": $cacheTTL - } - ] - ] - }""" - println(s) - Json.parse(s) - } - - 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) - println(s) - s - } - - def vertexQueryJson(serviceName: String, columnName: String, ids: Seq[Int]) = { - Json.parse( - s""" - |[ - |{"serviceName": "$serviceName", "columnName": "$columnName", "ids": [${ids.mkString(",")} - ]} - |] - """.stripMargin) - } - - def randomProps() = { - (for { - (propKey, propType) <- vertexPropsKeys - } yield { - propKey -> Random.nextInt(100) - }).toMap - } - - def vertexInsertsPayload(serviceName: String, columnName: String, ids: Seq[Int]): Seq[JsValue] = { - ids.map { id => - Json.obj("id" -> id, "props" -> randomProps, "timestamp" -> System.currentTimeMillis()) - } - } - - def commonCheck(rslt: Future[play.api.mvc.Result]): JsValue = { - status(rslt) must equalTo(OK) - contentType(rslt) must beSome.which(_ == "application/json") - val jsRslt = contentAsJson(rslt) - println("======") - println(jsRslt) - println("======") - jsRslt.as[JsObject].keys.contains("size") must equalTo(true) - (jsRslt \ "size").as[Int] must greaterThan(0) - jsRslt.as[JsObject].keys.contains("results") must equalTo(true) - val jsRsltsObj = jsRslt \ "results" - jsRsltsObj.as[JsArray].value(0).as[JsObject].keys.contains("from") must equalTo(true) - jsRsltsObj.as[JsArray].value(0).as[JsObject].keys.contains("to") must equalTo(true) - jsRsltsObj.as[JsArray].value(0).as[JsObject].keys.contains("_timestamp") must equalTo(true) - jsRsltsObj.as[JsArray].value(0).as[JsObject].keys.contains("props") must equalTo(true) - jsRslt - } - - def init() = { - running(FakeApplication()) { - println("[init start]: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") - Management.deleteService(testServiceName) - - // 1. createService - val result = AdminController.createServiceInner(Json.parse(createService)) - println(s">> Service created : $createService, $result") - - val labelNames = Map(testLabelName -> testLabelNameCreate, - testLabelName2 -> testLabelName2Create, - testLabelNameV1 -> testLabelNameV1Create, - testLabelNameWeak -> testLabelNameWeakCreate) - - for { - (labelName, create) <- labelNames - } { - Management.deleteLabel(labelName) - Label.findByName(labelName, useCache = false) match { - case None => - AdminController.createLabelInner(Json.parse(create)) - case Some(label) => - println(s">> Label already exist: $create, $label") - } - } - - // 5. create vertex - vertexPropsKeys.map { case (key, keyType) => - Management.addVertexProp(testServiceName, testColumnName, key, keyType) - } - - println("[init end]: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") - } - } -} - +//package controllers +// +//import com.kakao.s2graph.core._ +//import com.kakao.s2graph.core.mysqls._ +//import org.specs2.mutable.Specification +//import play.api.libs.json._ +//import play.api.test.FakeApplication +//import play.api.test.Helpers._ +// +//import scala.concurrent.Future +//import scala.concurrent.duration._ +//import scala.util.Random +// +//trait SpecCommon extends Specification { +// val curTime = System.currentTimeMillis +// +// val t1 = curTime + 0 +// val t2 = curTime + 1 +// val t3 = curTime + 2 +// val t4 = curTime + 3 +// val t5 = curTime + 4 +// +// protected val testServiceName = "s2graph" +// protected val testLabelName = "s2graph_label_test" +// protected val testLabelName2 = "s2graph_label_test_2" +// protected val testLabelNameV1 = "s2graph_label_test_v1" +// protected val testLabelNameWeak = "s2graph_label_test_weak" +// protected val testColumnName = "user_id_test" +// protected val testColumnType = "long" +// protected val testTgtColumnName = "item_id_test" +// protected val testHTableName = "test-htable" +// protected val newHTableName = "new-htable" +// protected val index1 = "idx_1" +// protected val index2 = "idx_2" +// +// val NUM_OF_EACH_TEST = 100 +// val HTTP_REQ_WAITING_TIME = Duration(300, SECONDS) +// val asyncFlushInterval = 100 +// +// val createService = s"""{"serviceName" : "$testServiceName"}""" +// val testLabelNameCreate = +// s""" +// { +// "label": "$testLabelName", +// "srcServiceName": "$testServiceName", +// "srcColumnName": "$testColumnName", +// "srcColumnType": "long", +// "tgtServiceName": "$testServiceName", +// "tgtColumnName": "$testColumnName", +// "tgtColumnType": "long", +// "indices": [ +// {"name": "$index1", "propNames": ["weight", "time", "is_hidden", "is_blocked"]}, +// {"name": "$index2", "propNames": ["_timestamp"]} +// ], +// "props": [ +// { +// "name": "time", +// "dataType": "long", +// "defaultValue": 0 +// }, +// { +// "name": "weight", +// "dataType": "long", +// "defaultValue": 0 +// }, +// { +// "name": "is_hidden", +// "dataType": "boolean", +// "defaultValue": false +// }, +// { +// "name": "is_blocked", +// "dataType": "boolean", +// "defaultValue": false +// } +// ], +// "consistencyLevel": "strong", +// "schemaVersion": "v2", +// "compressionAlgorithm": "gz", +// "hTableName": "$testHTableName" +// }""" +// +// val testLabelName2Create = +// s""" +// { +// "label": "$testLabelName2", +// "srcServiceName": "$testServiceName", +// "srcColumnName": "$testColumnName", +// "srcColumnType": "long", +// "tgtServiceName": "$testServiceName", +// "tgtColumnName": "$testTgtColumnName", +// "tgtColumnType": "string", +// "indices": [{"name": "$index1", "propNames": ["time", "weight", "is_hidden", "is_blocked"]}], +// "props": [ +// { +// "name": "time", +// "dataType": "long", +// "defaultValue": 0 +// }, +// { +// "name": "weight", +// "dataType": "long", +// "defaultValue": 0 +// }, +// { +// "name": "is_hidden", +// "dataType": "boolean", +// "defaultValue": false +// }, +// { +// "name": "is_blocked", +// "dataType": "boolean", +// "defaultValue": false +// } +// ], +// "consistencyLevel": "strong", +// "isDirected": false, +// "schemaVersion": "v3", +// "compressionAlgorithm": "gz" +// }""" +// +// val testLabelNameV1Create = +// s""" +// { +// "label": "$testLabelNameV1", +// "srcServiceName": "$testServiceName", +// "srcColumnName": "$testColumnName", +// "srcColumnType": "long", +// "tgtServiceName": "$testServiceName", +// "tgtColumnName": "${testTgtColumnName}_v1", +// "tgtColumnType": "string", +// "indices": [{"name": "$index1", "propNames": ["time", "weight", "is_hidden", "is_blocked"]}], +// "props": [ +// { +// "name": "time", +// "dataType": "long", +// "defaultValue": 0 +// }, +// { +// "name": "weight", +// "dataType": "long", +// "defaultValue": 0 +// }, +// { +// "name": "is_hidden", +// "dataType": "boolean", +// "defaultValue": false +// }, +// { +// "name": "is_blocked", +// "dataType": "boolean", +// "defaultValue": false +// } +// ], +// "consistencyLevel": "strong", +// "isDirected": true, +// "schemaVersion": "v1", +// "compressionAlgorithm": "gz" +// }""" +// val testLabelNameWeakCreate = +// s""" +// { +// "label": "$testLabelNameWeak", +// "srcServiceName": "$testServiceName", +// "srcColumnName": "$testColumnName", +// "srcColumnType": "long", +// "tgtServiceName": "$testServiceName", +// "tgtColumnName": "$testTgtColumnName", +// "tgtColumnType": "string", +// "indices": [{"name": "$index1", "propNames": ["time", "weight", "is_hidden", "is_blocked"]}], +// "props": [ +// { +// "name": "time", +// "dataType": "long", +// "defaultValue": 0 +// }, +// { +// "name": "weight", +// "dataType": "long", +// "defaultValue": 0 +// }, +// { +// "name": "is_hidden", +// "dataType": "boolean", +// "defaultValue": false +// }, +// { +// "name": "is_blocked", +// "dataType": "boolean", +// "defaultValue": false +// } +// ], +// "consistencyLevel": "weak", +// "isDirected": true, +// "compressionAlgorithm": "gz" +// }""" +// +// val vertexPropsKeys = List( +// ("age", "int") +// ) +// +// val createVertex = +// s"""{ +// "serviceName": "$testServiceName", +// "columnName": "$testColumnName", +// "columnType": "$testColumnType", +// "props": [ +// {"name": "is_active", "dataType": "boolean", "defaultValue": true}, +// {"name": "phone_number", "dataType": "string", "defaultValue": "-"}, +// {"name": "nickname", "dataType": "string", "defaultValue": ".."}, +// {"name": "activity_score", "dataType": "float", "defaultValue": 0.0}, +// {"name": "age", "dataType": "integer", "defaultValue": 0} +// ] +// }""" +// +// +// val TS = System.currentTimeMillis() +// +// def queryJson(serviceName: String, columnName: String, labelName: String, id: String, dir: String, cacheTTL: Long = -1L) = { +// val s = +// s"""{ +// "srcVertices": [ +// { +// "serviceName": "$serviceName", +// "columnName": "$columnName", +// "id": $id +// } +// ], +// "steps": [ +// [ +// { +// "label": "$labelName", +// "direction": "$dir", +// "offset": 0, +// "limit": 10, +// "cacheTTL": $cacheTTL +// } +// ] +// ] +// }""" +// println(s) +// Json.parse(s) +// } +// +// 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) +// println(s) +// s +// } +// +// def vertexQueryJson(serviceName: String, columnName: String, ids: Seq[Int]) = { +// Json.parse( +// s""" +// |[ +// |{"serviceName": "$serviceName", "columnName": "$columnName", "ids": [${ids.mkString(",")} +// ]} +// |] +// """.stripMargin) +// } +// +// def randomProps() = { +// (for { +// (propKey, propType) <- vertexPropsKeys +// } yield { +// propKey -> Random.nextInt(100) +// }).toMap +// } +// +// def vertexInsertsPayload(serviceName: String, columnName: String, ids: Seq[Int]): Seq[JsValue] = { +// ids.map { id => +// Json.obj("id" -> id, "props" -> randomProps, "timestamp" -> System.currentTimeMillis()) +// } +// } +// +// def commonCheck(rslt: Future[play.api.mvc.Result]): JsValue = { +// status(rslt) must equalTo(OK) +// contentType(rslt) must beSome.which(_ == "application/json") +// val jsRslt = contentAsJson(rslt) +// println("======") +// println(jsRslt) +// println("======") +// jsRslt.as[JsObject].keys.contains("size") must equalTo(true) +// (jsRslt \ "size").as[Int] must greaterThan(0) +// jsRslt.as[JsObject].keys.contains("results") must equalTo(true) +// val jsRsltsObj = jsRslt \ "results" +// jsRsltsObj.as[JsArray].value(0).as[JsObject].keys.contains("from") must equalTo(true) +// jsRsltsObj.as[JsArray].value(0).as[JsObject].keys.contains("to") must equalTo(true) +// jsRsltsObj.as[JsArray].value(0).as[JsObject].keys.contains("_timestamp") must equalTo(true) +// jsRsltsObj.as[JsArray].value(0).as[JsObject].keys.contains("props") must equalTo(true) +// jsRslt +// } +// +// def init() = { +// running(FakeApplication()) { +// println("[init start]: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") +// Management.deleteService(testServiceName) +// +// // 1. createService +// val result = AdminController.createServiceInner(Json.parse(createService)) +// println(s">> Service created : $createService, $result") +// +// val labelNames = Map(testLabelName -> testLabelNameCreate, +// testLabelName2 -> testLabelName2Create, +// testLabelNameV1 -> testLabelNameV1Create, +// testLabelNameWeak -> testLabelNameWeakCreate) +// +// for { +// (labelName, create) <- labelNames +// } { +// Management.deleteLabel(labelName) +// Label.findByName(labelName, useCache = false) match { +// case None => +// AdminController.createLabelInner(Json.parse(create)) +// case Some(label) => +// println(s">> Label already exist: $create, $label") +// } +// } +// +// // 5. create vertex +// vertexPropsKeys.map { case (key, keyType) => +// Management.addVertexProp(testServiceName, testColumnName, key, keyType) +// } +// +// println("[init end]: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") +// } +// } +//} +// http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/5c0af72a/s2rest_play/test/controllers/VertexSpec.scala ---------------------------------------------------------------------- diff --git a/s2rest_play/test/controllers/VertexSpec.scala b/s2rest_play/test/controllers/VertexSpec.scala index 46461ea..1999213 100644 --- a/s2rest_play/test/controllers/VertexSpec.scala +++ b/s2rest_play/test/controllers/VertexSpec.scala @@ -1,53 +1,53 @@ -package controllers - -import com.kakao.s2graph.core.Graph -import com.kakao.s2graph.core.rest.RestCaller -import com.typesafe.config.ConfigFactory -import play.api.libs.json._ -import play.api.test.FakeApplication -import play.api.test.Helpers._ - -import scala.concurrent.Await -import scala.concurrent.duration.Duration - -class VertexSpec extends SpecCommon { - // init() - - "vetex tc" should { - "tc1" in { - - running(FakeApplication()) { - val config = ConfigFactory.load() - val graph = new Graph(config) - val rest = new RestCaller(graph) - - val ids = (7 until 20).map(tcNum => tcNum * 1000 + 0) - - val (serviceName, columnName) = (testServiceName, testColumnName) - - val data = vertexInsertsPayload(serviceName, columnName, ids) - val payload = Json.parse(Json.toJson(data).toString) - println(payload) - - val jsResult = contentAsString(VertexController.tryMutates(payload, "insert", - Option(serviceName), Option(columnName), withWait = true)) - - val query = vertexQueryJson(serviceName, columnName, ids) - val res = rest.uriMatch("/graphs/getVertices", query) - - - val ret = Await.result(res, Duration("30 seconds")) - - println(">>>", ret) - val fetched = ret.as[Seq[JsValue]] - for { - (d, f) <- data.zip(fetched) - } yield { - (d \ "id") must beEqualTo((f \ "id")) - ((d \ "props") \ "age") must beEqualTo(((f \ "props") \ "age")) - } - } - true - } - } -} +//package controllers +// +//import com.kakao.s2graph.core.Graph +//import com.kakao.s2graph.core.rest.RestCaller +//import com.typesafe.config.ConfigFactory +//import play.api.libs.json._ +//import play.api.test.FakeApplication +//import play.api.test.Helpers._ +// +//import scala.concurrent.Await +//import scala.concurrent.duration.Duration +// +//class VertexSpec extends SpecCommon { +// // init() +// +// "vetex tc" should { +// "tc1" in { +// +// running(FakeApplication()) { +// val config = ConfigFactory.load() +// val graph = new Graph(config) +// val rest = new RestCaller(graph) +// +// val ids = (7 until 20).map(tcNum => tcNum * 1000 + 0) +// +// val (serviceName, columnName) = (testServiceName, testColumnName) +// +// val data = vertexInsertsPayload(serviceName, columnName, ids) +// val payload = Json.parse(Json.toJson(data).toString) +// println(payload) +// +// val jsResult = contentAsString(VertexController.tryMutates(payload, "insert", +// Option(serviceName), Option(columnName), withWait = true)) +// +// val query = vertexQueryJson(serviceName, columnName, ids) +// val res = rest.uriMatch("/graphs/getVertices", query) +// +// +// val ret = Await.result(res, Duration("30 seconds")) +// +// println(">>>", ret) +// val fetched = ret.as[Seq[JsValue]] +// for { +// (d, f) <- data.zip(fetched) +// } yield { +// (d \ "id") must beEqualTo((f \ "id")) +// ((d \ "props") \ "age") must beEqualTo(((f \ "props") \ "age")) +// } +// } +// true +// } +// } +//}
