http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/JsonParserTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/JsonParserTest.scala b/s2core/src/test/scala/com/kakao/s2graph/core/JsonParserTest.scala deleted file mode 100644 index 127f2fe..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/JsonParserTest.scala +++ /dev/null @@ -1,66 +0,0 @@ -package com.kakao.s2graph.core - -import com.kakao.s2graph.core.types.{InnerValLike, InnerVal} -import org.scalatest.{Matchers, FunSuite} - -class JsonParserTest extends FunSuite with Matchers with TestCommon with JSONParser { - - import types.HBaseType._ - import InnerVal._ - - val innerValsPerVersion = for { - version <- List(VERSION2, VERSION1) - } yield { - val innerVals = List( - (InnerVal.withStr("ABC123", version), STRING), - (InnerVal.withNumber(23, version), BYTE), - (InnerVal.withNumber(23, version), INT), - (InnerVal.withNumber(Int.MaxValue, version), INT), - (InnerVal.withNumber(Int.MinValue, version), INT), - (InnerVal.withNumber(Long.MaxValue, version), LONG), - (InnerVal.withNumber(Long.MinValue, version), LONG), - (InnerVal.withBoolean(true, version), BOOLEAN) - ) - val doubleVals = if (version == VERSION2) { - List( - (InnerVal.withDouble(Double.MaxValue, version), DOUBLE), - (InnerVal.withDouble(Double.MinValue, version), DOUBLE), - (InnerVal.withDouble(0.1, version), DOUBLE), - (InnerVal.withFloat(Float.MinValue, version), FLOAT), - (InnerVal.withFloat(Float.MaxValue, version), FLOAT), - (InnerVal.withFloat(0.9f, version), FLOAT) - ) - } else { - List.empty[(InnerValLike, String)] - } - (innerVals ++ doubleVals, version) - } - - def testInnerValToJsValue(innerValWithDataTypes: Seq[(InnerValLike, String)], - version: String) = { - for { - (innerVal, dataType) <- innerValWithDataTypes - } { - val jsValueOpt = innerValToJsValue(innerVal, dataType) - val decodedOpt = jsValueOpt.flatMap { jsValue => - jsValueToInnerVal(jsValue, dataType, version) - } - println(s"jsValue: $jsValueOpt") - println(s"innerVal: $decodedOpt") - (decodedOpt.isDefined && innerVal == decodedOpt.get) shouldBe true - } - } - - test("aa") { - val innerVal = InnerVal.withStr("abc", VERSION2) - val tmp = innerValToJsValue(innerVal, "string") - println(tmp) - } - test("JsValue <-> InnerVal with dataType") { - for { - (innerValWithDataTypes, version) <- innerValsPerVersion - } { - testInnerValToJsValue(innerValWithDataTypes, version) - } - } -}
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/OrderingUtilTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/OrderingUtilTest.scala b/s2core/src/test/scala/com/kakao/s2graph/core/OrderingUtilTest.scala deleted file mode 100644 index 61818fc..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/OrderingUtilTest.scala +++ /dev/null @@ -1,130 +0,0 @@ -package com.kakao.s2graph.core - -import com.kakao.s2graph.core.OrderingUtil._ -import org.scalatest.{FunSuite, Matchers} -import play.api.libs.json.JsString - -class OrderingUtilTest extends FunSuite with Matchers { - test("test SeqMultiOrdering") { - val jsLs: Seq[Seq[Any]] = Seq( - Seq(0, "a"), - Seq(0, "b"), - Seq(1, "a"), - Seq(1, "b"), - Seq(2, "c") - ) - - // number descending, string ascending - val sortedJsLs: Seq[Seq[Any]] = Seq( - Seq(2, "c"), - Seq(1, "a"), - Seq(1, "b"), - Seq(0, "a"), - Seq(0, "b") - ) - - val ascendingLs: Seq[Boolean] = Seq(false, true) - val resultJsLs = jsLs.sorted(new SeqMultiOrdering[Any](ascendingLs)) - - resultJsLs.toString() should equal(sortedJsLs.toString()) - } - - test("test tuple 1 TupleMultiOrdering") { - val jsLs: Seq[(Any, Any, Any, Any)] = Seq( - (0, None, None, None), - (0, None, None, None), - (1, None, None, None), - (1, None, None, None), - (2, None, None, None) - ) - - val sortedJsLs: Seq[(Any, Any, Any, Any)] = Seq( - (2, None, None, None), - (1, None, None, None), - (1, None, None, None), - (0, None, None, None), - (0, None, None, None) - ) - - val ascendingLs: Seq[Boolean] = Seq(false) - val resultJsLs = jsLs.sorted(TupleMultiOrdering[Any](ascendingLs)) - - resultJsLs.toString() should equal(sortedJsLs.toString()) - } - - test("test tuple 2 TupleMultiOrdering") { - val jsLs: Seq[(Any, Any, Any, Any)] = Seq( - (0, "a", None, None), - (0, "b", None, None), - (1, "a", None, None), - (1, "b", None, None), - (2, "c", None, None) - ) - - // number descending, string ascending - val sortedJsLs: Seq[(Any, Any, Any, Any)] = Seq( - (2, "c", None, None), - (1, "a", None, None), - (1, "b", None, None), - (0, "a", None, None), - (0, "b", None, None) - ) - - val ascendingLs: Seq[Boolean] = Seq(false, true) - val resultJsLs = jsLs.sorted(TupleMultiOrdering[Any](ascendingLs)) - - resultJsLs.toString() should equal(sortedJsLs.toString()) - } - - test("test tuple 3 TupleMultiOrdering") { - val jsLs: Seq[(Any, Any, Any, Any)] = Seq( - (0, "a", 0l, None), - (0, "a", 1l, None), - (0, "b", 0l, None), - (1, "a", 0l, None), - (1, "b", 0l, None), - (2, "c", 0l, None) - ) - - val sortedJsLs: Seq[(Any, Any, Any, Any)] = Seq( - (0, "a", 1l, None), - (0, "a", 0l, None), - (0, "b", 0l, None), - (1, "a", 0l, None), - (1, "b", 0l, None), - (2, "c", 0l, None) - ) - - val ascendingLs: Seq[Boolean] = Seq(true, true, false) - val resultJsLs = jsLs.sorted(TupleMultiOrdering[Any](ascendingLs)) - - resultJsLs.toString() should equal(sortedJsLs.toString()) - } - - test("test tuple 4 TupleMultiOrdering") { - val jsLs: Seq[(Any, Any, Any, Any)] = Seq( - (0, "a", 0l, JsString("a")), - (0, "a", 0l, JsString("b")), - (0, "a", 1l, JsString("a")), - (0, "b", 0l, JsString("b")), - (1, "a", 0l, JsString("b")), - (1, "b", 0l, JsString("b")), - (2, "c", 0l, JsString("b")) - ) - - val sortedJsLs: Seq[(Any, Any, Any, Any)] = Seq( - (0, "a", 0l, JsString("b")), - (0, "a", 0l, JsString("a")), - (0, "a", 1l, JsString("a")), - (0, "b", 0l, JsString("b")), - (1, "a", 0l, JsString("b")), - (1, "b", 0l, JsString("b")), - (2, "c", 0l, JsString("b")) - ) - - val ascendingLs: Seq[Boolean] = Seq(true, true, true, false) - val resultJsLs = jsLs.sorted(TupleMultiOrdering[Any](ascendingLs)) - - resultJsLs.toString() should equal(sortedJsLs.toString()) - } -} http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/QueryParamTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/QueryParamTest.scala b/s2core/src/test/scala/com/kakao/s2graph/core/QueryParamTest.scala deleted file mode 100644 index 544c17c..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/QueryParamTest.scala +++ /dev/null @@ -1,86 +0,0 @@ -package com.kakao.s2graph.core - -import com.kakao.s2graph.core.types.LabelWithDirection -import org.apache.hadoop.hbase.util.Bytes -import org.scalatest.{FunSuite, Matchers} - -class QueryParamTest extends FunSuite with Matchers with TestCommon { -// val version = HBaseType.VERSION2 -// val testEdge = Management.toEdge(ts, "insert", "1", "10", labelNameV2, "out", Json.obj("is_blocked" -> true, "phone_number" -> "xxxx", "age" -> 20).toString) -// test("EdgeTransformer toInnerValOpt") { -// -// /** only labelNameV2 has string type output */ -// val jsVal = Json.arr(Json.arr("_to"), Json.arr("phone_number.$", "phone_number"), Json.arr("age.$", "age")) -// val transformer = EdgeTransformer(queryParamV2, jsVal) -// val convertedLs = transformer.transform(testEdge, None) -// -// convertedLs(0).tgtVertex.innerId.toString == "10" shouldBe true -// convertedLs(1).tgtVertex.innerId.toString == "phone_number.xxxx" shouldBe true -// convertedLs(2).tgtVertex.innerId.toString == "age.20" shouldBe true -// true -// } - - val dummyRequests = { - for { - id <- 0 until 1000 - } yield { - Bytes.toBytes(id) - } - } - - test("QueryParam toCacheKey bytes") { - val startedAt = System.nanoTime() - val queryParam = QueryParam(LabelWithDirection(1, 0)) - - for { - i <- dummyRequests.indices - x = queryParam.toCacheKey(dummyRequests(i)) - } { - for { - j <- dummyRequests.indices if i != j - y = queryParam.toCacheKey(dummyRequests(j)) - } { - x should not equal y - } - } - - dummyRequests.zip(dummyRequests).foreach { case (x, y) => - val xHash = queryParam.toCacheKey(x) - val yHash = queryParam.toCacheKey(y) -// println(xHash, yHash) - xHash should be(yHash) - } - val duration = System.nanoTime() - startedAt - - println(s">> bytes: $duration") - } - - test("QueryParam toCacheKey with variable params") { - val startedAt = System.nanoTime() - val queryParam = QueryParam(LabelWithDirection(1, 0)) - - dummyRequests.zip(dummyRequests).foreach { case (x, y) => - x shouldBe y - queryParam.limit(0, 10) - var xHash = queryParam.toCacheKey(x) - xHash shouldBe queryParam.toCacheKey(y) - queryParam.limit(1, 10) - var yHash = queryParam.toCacheKey(y) - queryParam.toCacheKey(x) shouldBe yHash -// println(xHash, yHash) - xHash should not be yHash - - queryParam.limit(0, 10) - xHash = queryParam.toCacheKey(x) - queryParam.limit(0, 11) - yHash = queryParam.toCacheKey(y) - - xHash should not be yHash - } - - val duration = System.nanoTime() - startedAt - - println(s">> diff: $duration") - } - -} http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/TestCommon.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/TestCommon.scala b/s2core/src/test/scala/com/kakao/s2graph/core/TestCommon.scala deleted file mode 100644 index ed9aaa5..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/TestCommon.scala +++ /dev/null @@ -1,192 +0,0 @@ -package com.kakao.s2graph.core - -import com.kakao.s2graph.core.mysqls._ -//import com.kakao.s2graph.core.models._ - - -import com.kakao.s2graph.core.types._ -import org.apache.hadoop.hbase.util.Bytes -import org.hbase.async.{PutRequest, KeyValue} - - -trait TestCommon { - val ts = System.currentTimeMillis() - val testServiceId = 1 - val testColumnId = 1 - val testLabelId = 1 - val testDir = GraphUtil.directions("out") - val testOp = GraphUtil.operations("insert") - val testLabelOrderSeq = LabelIndex.DefaultSeq - val testLabelWithDir = LabelWithDirection(testLabelId, testDir) - val labelMeta = LabelMeta - - def equalsTo(x: Array[Byte], y: Array[Byte]) = Bytes.compareTo(x, y) == 0 - - def largerThan(x: Array[Byte], y: Array[Byte]) = Bytes.compareTo(x, y) > 0 - - def lessThan(x: Array[Byte], y: Array[Byte]) = Bytes.compareTo(x, y) < 0 - - def lessThanEqual(x: Array[Byte], y: Array[Byte]) = Bytes.compareTo(x, y) <= 0 - - /** */ - import HBaseType.{VERSION2, VERSION1} - private val tsValSmall = InnerVal.withLong(ts, VERSION1) - private val tsValLarge = InnerVal.withLong(ts + 1, VERSION1) - private val boolValSmall = InnerVal.withBoolean(false, VERSION1) - private val boolValLarge = InnerVal.withBoolean(true, VERSION1) - private val doubleValSmall = InnerVal.withDouble(-0.1, VERSION1) - private val doubleValLarge = InnerVal.withDouble(0.1, VERSION1) - private val toSeq = LabelMeta.toSeq.toInt - private val toVal = InnerVal.withLong(Long.MinValue, VERSION1) - - - private val tsValSmallV2 = InnerVal.withLong(ts, VERSION2) - private val tsValLargeV2 = InnerVal.withLong(ts + 1, VERSION2) - private val boolValSmallV2 = InnerVal.withBoolean(false, VERSION2) - private val boolValLargeV2 = InnerVal.withBoolean(true, VERSION2) - private val doubleValSmallV2 = InnerVal.withDouble(-0.1, VERSION2) - private val doubleValLargeV2 = InnerVal.withDouble(0.1, VERSION2) - private val toValV2 = InnerVal.withLong(Long.MinValue, VERSION2) - - val intVals = (Int.MinValue until Int.MinValue + 10) ++ (-129 to -126) ++ (-1 to 1) ++ (126 to 129) ++ - (Int.MaxValue - 10 until Int.MaxValue) - val intInnerVals = intVals.map { v => InnerVal.withNumber(BigDecimal(v), VERSION1) } - - val intInnerValsV2 = intVals.map { v => InnerVal.withNumber(BigDecimal(v), VERSION2) } - - val stringVals = List("abc", "abd", "ac", "aca", "b") - val stringInnerVals = stringVals.map { s => InnerVal.withStr(s, VERSION1)} - val stringInnerValsV2 = stringVals.map { s => InnerVal.withStr(s, VERSION2)} - - val numVals = (Long.MinValue until Long.MinValue + 10).map(BigDecimal(_)) ++ - (Int.MinValue until Int.MinValue + 10).map(BigDecimal(_)) ++ - (Int.MaxValue - 10 until Int.MaxValue).map(BigDecimal(_)) ++ - (Long.MaxValue - 10 until Long.MaxValue).map(BigDecimal(_)) - val numInnerVals = numVals.map { n => InnerVal.withLong(n.toLong, VERSION1)} - val numInnerValsV2 = numVals.map { n => InnerVal.withNumber(n, VERSION2)} - - val doubleStep = Double.MaxValue / 5 - val doubleVals = (Double.MinValue until 0 by doubleStep).map(BigDecimal(_)) ++ - (-9999.9 until -9994.1 by 1.1).map(BigDecimal(_)) ++ - (-128.0 until 128.0 by 1.2).map(BigDecimal(_)) ++ - (129.0 until 142.0 by 1.1).map(BigDecimal(_)) ++ - (doubleStep until Double.MaxValue by doubleStep).map(BigDecimal(_)) - val doubleInnerVals = doubleVals.map { d => InnerVal.withDouble(d.toDouble, VERSION1)} - val doubleInnerValsV2 = doubleVals.map { d => InnerVal.withDouble(d.toDouble, VERSION2)} - - /** version 1 string order is broken */ - val idxPropsLs = Seq( - Seq((0 -> tsValSmall), (1 -> boolValSmall), (2 -> InnerVal.withStr("ac", VERSION1)),(toSeq -> toVal)), - Seq((0 -> tsValSmall), (1 -> boolValSmall), (2 -> InnerVal.withStr("ab", VERSION1)), (toSeq -> toVal)), - Seq((0 -> tsValSmall), (1 -> boolValSmall), (2-> InnerVal.withStr("b", VERSION1)), (toSeq -> toVal)), - Seq((0 -> tsValSmall), (1 -> boolValLarge), (2 -> InnerVal.withStr("b", VERSION1)), (toSeq -> toVal)), - Seq((0 -> tsValLarge), (1 -> boolValSmall), (2 -> InnerVal.withStr("a", VERSION1)), (toSeq -> toVal)) - ).map(seq => seq.map(t => t._1.toByte -> t._2 )) - - val idxPropsLsV2 = Seq( - Seq((0 -> tsValSmallV2), (1 -> boolValSmallV2), (2 -> InnerVal.withStr("a", VERSION2)), (3 -> doubleValSmallV2), (toSeq -> toValV2)), - Seq((0 -> tsValSmallV2), (1 -> boolValSmallV2), (2 -> InnerVal.withStr("a", VERSION2)), (3 -> doubleValLargeV2), (toSeq -> toValV2)), - Seq((0 -> tsValSmallV2), (1 -> boolValSmallV2), (2 -> InnerVal.withStr("ab", VERSION2)), (3 -> doubleValLargeV2), (toSeq -> toValV2)), - Seq((0 -> tsValSmallV2), (1 -> boolValSmallV2), (2-> InnerVal.withStr("b", VERSION2)), (3 ->doubleValLargeV2), (toSeq -> toValV2)), - Seq((0 -> tsValSmallV2), (1 -> boolValLargeV2), (2 -> InnerVal.withStr("a", VERSION2)), (3 ->doubleValLargeV2), (toSeq -> toValV2)), - Seq((0 -> tsValLargeV2), (1 -> boolValSmallV2), (2 -> InnerVal.withStr("a", VERSION2)), (3 ->doubleValLargeV2), (toSeq -> toValV2)) - ).map(seq => seq.map(t => t._1.toByte -> t._2 ) ) - - val idxPropsWithTsLs = idxPropsLs.map { idxProps => - idxProps.map { case (k, v) => k -> InnerValLikeWithTs(v, ts) } - } - val idxPropsWithTsLsV2 = idxPropsLsV2.map { idxProps => - idxProps.map { case (k, v) => k -> InnerValLikeWithTs(v, ts) } - } - // - // def testOrder(idxPropsLs: Seq[Seq[(Byte, InnerValLike)]], - // innerVals: Iterable[InnerValLike], skipHashBytes: Boolean = false) - // (createFunc: (Seq[(Byte, InnerValLike)], InnerValLike) => HBaseSerializable, - // fromBytesFunc: Array[Byte] => HBaseSerializable) = { - // /** check if increasing target vertex id is ordered properly with same indexProps */ - // val rets = for { - // idxProps <- idxPropsLs - // } yield { - // val head = createFunc(idxProps, innerVals.head) - // val start = head - // var prev = head - // val rets = for { - // innerVal <- innerVals.tail - // } yield { - // val current = createFunc(idxProps, innerVal) - // val bytes = current.bytes - // val decoded = fromBytesFunc(bytes) - // println(s"current: $current") - // println(s"decoded: $decoded") - // - // val prevBytes = if (skipHashBytes) prev.bytes.drop(GraphUtil.bytesForMurMurHash) else prev.bytes - // val currentBytes = if (skipHashBytes) bytes.drop(GraphUtil.bytesForMurMurHash) else bytes - // val (isSame, orderPreserved) = (current, decoded) match { - // case (c: v2.EdgeQualifier, d: v2.EdgeQualifier) if (idxProps.map(_._1).contains(toSeq)) => - // /** _to is used in indexProps */ - // (c.props.map(_._2) == d.props.map(_._2) && c.op == d.op, Bytes.compareTo(currentBytes, prevBytes) <= 0) - // case _ => - // (current == decoded, lessThan(currentBytes, prevBytes)) - // } - // - // println(s"$current ${bytes.toList}") - // println(s"$prev ${prev.bytes.toList}") - // println(s"SerDe[$isSame], Order[$orderPreserved]") - // prev = current - // isSame && orderPreserved - // } - // rets.forall(x => x) - // } - // rets.forall(x => x) - // } - // def testOrderReverse(idxPropsLs: Seq[Seq[(Byte, InnerValLike)]], innerVals: Iterable[InnerValLike], - // skipHashBytes: Boolean = false) - // (createFunc: (Seq[(Byte, InnerValLike)], InnerValLike) => HBaseSerializable, - // fromBytesFunc: Array[Byte] => HBaseSerializable) = { - // /** check if increasing target vertex id is ordered properly with same indexProps */ - // val rets = for { - // innerVal <- innerVals - // } yield { - // val head = createFunc(idxPropsLs.head, innerVal) - // val start = head - // var prev = head - // val rets = for { - // idxProps <- idxPropsLs.tail - // } yield { - // val current = createFunc(idxProps, innerVal) - // val bytes = current.bytes - // val decoded = fromBytesFunc(bytes) - // println(s"current: $current") - // println(s"decoded: $decoded") - // - // val prevBytes = if (skipHashBytes) prev.bytes.drop(GraphUtil.bytesForMurMurHash) else prev.bytes - // val currentBytes = if (skipHashBytes) bytes.drop(GraphUtil.bytesForMurMurHash) else bytes - // val (isSame, orderPreserved) = (current, decoded) match { - // case (c: v2.EdgeQualifier, d: v2.EdgeQualifier) if (idxProps.map(_._1).contains(toSeq)) => - // /** _to is used in indexProps */ - // (c.props.map(_._2) == d.props.map(_._2) && c.op == d.op, Bytes.compareTo(currentBytes, prevBytes) <= 0) - // case _ => - // (current == decoded, lessThan(currentBytes, prevBytes)) - // } - // - // println(s"$current ${bytes.toList}") - // println(s"$prev ${prev.bytes.toList}") - // println(s"SerDe[$isSame], Order[$orderPreserved]") - // prev = current - // isSame && orderPreserved - // } - // - // rets.forall(x => x) - // } - // - // rets.forall(x => x) - // } - // - // - // def putToKeyValues(put: PutRequest) = { - // val ts = put.timestamp() - // for ((q, v) <- put.qualifiers().zip(put.values)) yield { - // new KeyValue(put.key(), put.family(), q, ts, v) - // } - // } -} http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/TestCommonWithModels.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/TestCommonWithModels.scala b/s2core/src/test/scala/com/kakao/s2graph/core/TestCommonWithModels.scala deleted file mode 100644 index f7c4bc1..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/TestCommonWithModels.scala +++ /dev/null @@ -1,197 +0,0 @@ -package com.kakao.s2graph.core - -import com.kakao.s2graph.core.Management.JsonModel.{Index, Prop} -import com.kakao.s2graph.core.mysqls._ -import scalikejdbc.AutoSession - -//import com.kakao.s2graph.core.models._ - -import com.kakao.s2graph.core.types.{InnerVal, LabelWithDirection} -import com.typesafe.config.{Config, ConfigFactory} - -import scala.concurrent.ExecutionContext - -trait TestCommonWithModels { - - import InnerVal._ - import types.HBaseType._ - - var graph: Graph = _ - var config: Config = _ - var management: Management = _ - - def initTests() = { - config = ConfigFactory.load() - graph = new Graph(config)(ExecutionContext.Implicits.global) - management = new Management(graph) - - implicit val session = AutoSession - - deleteTestLabel() - deleteTestService() - - createTestService() - createTestLabel() - } - - def zkQuorum = config.getString("hbase.zookeeper.quorum") - - def cluster = config.getString("hbase.zookeeper.quorum") - - implicit val session = AutoSession - - val serviceName = "_test_service" - val serviceNameV2 = "_test_service_v2" - val serviceNameV3 = "_test_service_v3" - val serviceNameV4 = "_test_service_v4" - - val columnName = "user_id" - val columnNameV2 = "user_id_v2" - val columnNameV3 = "user_id_v3" - val columnNameV4 = "user_id_v4" - - val columnType = "long" - val columnTypeV2 = "long" - val columnTypeV3 = "long" - val columnTypeV4 = "long" - - val tgtColumnName = "itme_id" - val tgtColumnNameV2 = "item_id_v2" - val tgtColumnNameV3 = "item_id_v3" - val tgtColumnNameV4 = "item_id_v4" - - val tgtColumnType = "string" - val tgtColumnTypeV2 = "string" - val tgtColumnTypeV3 = "string" - val tgtColumnTypeV4 = "string" - - val hTableName = "_test_cases" - val preSplitSize = 0 - - val labelName = "_test_label" - val labelNameV2 = "_test_label_v2" - val labelNameV3 = "_test_label_v3" - val labelNameV4 = "_test_label_v4" - - val undirectedLabelName = "_test_label_undirected" - val undirectedLabelNameV2 = "_test_label_undirected_v2" - - val testProps = Seq( - Prop("affinity_score", "0.0", DOUBLE), - Prop("is_blocked", "false", BOOLEAN), - Prop("time", "0", INT), - Prop("weight", "0", INT), - Prop("is_hidden", "true", BOOLEAN), - Prop("phone_number", "xxx-xxx-xxxx", STRING), - Prop("score", "0.1", FLOAT), - Prop("age", "10", INT) - ) - val testIdxProps = Seq(Index("_PK", Seq("_timestamp", "affinity_score"))) - val consistencyLevel = "strong" - val hTableTTL = None - - - def createTestService() = { - implicit val session = AutoSession - management.createService(serviceName, cluster, hTableName, preSplitSize, hTableTTL = None, "gz") - management.createService(serviceNameV2, cluster, hTableName, preSplitSize, hTableTTL = None, "gz") - management.createService(serviceNameV3, cluster, hTableName, preSplitSize, hTableTTL = None, "gz") - management.createService(serviceNameV4, cluster, hTableName, preSplitSize, hTableTTL = None, "gz") - } - - def deleteTestService() = { - implicit val session = AutoSession - Management.deleteService(serviceName) - Management.deleteService(serviceNameV2) - Management.deleteService(serviceNameV3) - Management.deleteService(serviceNameV4) - } - - def deleteTestLabel() = { - implicit val session = AutoSession - Management.deleteLabel(labelName) - Management.deleteLabel(labelNameV2) - Management.deleteLabel(undirectedLabelName) - Management.deleteLabel(undirectedLabelNameV2) - } - - def createTestLabel() = { - implicit val session = AutoSession - management.createLabel(labelName, serviceName, columnName, columnType, serviceName, columnName, columnType, - isDirected = true, serviceName, testIdxProps, testProps, consistencyLevel, Some(hTableName), hTableTTL, VERSION1, false, "lg4") - - management.createLabel(labelNameV2, serviceNameV2, columnNameV2, columnTypeV2, serviceNameV2, tgtColumnNameV2, tgtColumnTypeV2, - isDirected = true, serviceNameV2, testIdxProps, testProps, consistencyLevel, Some(hTableName), hTableTTL, VERSION2, false, "lg4") - - management.createLabel(labelNameV3, serviceNameV3, columnNameV3, columnTypeV3, serviceNameV3, tgtColumnNameV3, tgtColumnTypeV3, - isDirected = true, serviceNameV3, testIdxProps, testProps, consistencyLevel, Some(hTableName), hTableTTL, VERSION3, false, "lg4") - - management.createLabel(labelNameV4, serviceNameV4, columnNameV4, columnTypeV4, serviceNameV4, tgtColumnNameV4, tgtColumnTypeV4, - isDirected = true, serviceNameV4, testIdxProps, testProps, consistencyLevel, Some(hTableName), hTableTTL, VERSION4, false, "lg4") - - management.createLabel(undirectedLabelName, serviceName, columnName, columnType, serviceName, tgtColumnName, tgtColumnType, - isDirected = false, serviceName, testIdxProps, testProps, consistencyLevel, Some(hTableName), hTableTTL, VERSION3, false, "lg4") - - management.createLabel(undirectedLabelNameV2, serviceNameV2, columnNameV2, columnTypeV2, serviceNameV2, tgtColumnNameV2, tgtColumnTypeV2, - isDirected = false, serviceName, testIdxProps, testProps, consistencyLevel, Some(hTableName), hTableTTL, VERSION2, false, "lg4") - } - - def service = Service.findByName(serviceName, useCache = false).get - - def serviceV2 = Service.findByName(serviceNameV2, useCache = false).get - - def serviceV3 = Service.findByName(serviceNameV3, useCache = false).get - - def serviceV4 = Service.findByName(serviceNameV4, useCache = false).get - - def column = ServiceColumn.find(service.id.get, columnName, useCache = false).get - - def columnV2 = ServiceColumn.find(serviceV2.id.get, columnNameV2, useCache = false).get - - def columnV3 = ServiceColumn.find(serviceV3.id.get, columnNameV3, useCache = false).get - - def columnV4 = ServiceColumn.find(serviceV4.id.get, columnNameV4, useCache = false).get - - def tgtColumn = ServiceColumn.find(service.id.get, tgtColumnName, useCache = false).get - - def tgtColumnV2 = ServiceColumn.find(serviceV2.id.get, tgtColumnNameV2, useCache = false).get - - def tgtColumnV3 = ServiceColumn.find(serviceV3.id.get, tgtColumnNameV3, useCache = false).get - - def tgtColumnV4 = ServiceColumn.find(serviceV4.id.get, tgtColumnNameV4, useCache = false).get - - def label = Label.findByName(labelName, useCache = false).get - - def labelV2 = Label.findByName(labelNameV2, useCache = false).get - - def labelV3 = Label.findByName(labelNameV3, useCache = false).get - - def labelV4 = Label.findByName(labelNameV4, useCache = false).get - - def undirectedLabel = Label.findByName(undirectedLabelName, useCache = false).get - - def undirectedLabelV2 = Label.findByName(undirectedLabelNameV2, useCache = false).get - - def dir = GraphUtil.directions("out") - - def op = GraphUtil.operations("insert") - - def labelOrderSeq = LabelIndex.DefaultSeq - - def labelWithDir = LabelWithDirection(label.id.get, dir) - - def labelWithDirV2 = LabelWithDirection(labelV2.id.get, dir) - - def labelWithDirV3 = LabelWithDirection(labelV3.id.get, dir) - - def labelWithDirV4 = LabelWithDirection(labelV4.id.get, dir) - - def queryParam = QueryParam(labelWithDir) - - def queryParamV2 = QueryParam(labelWithDirV2) - - def queryParamV3 = QueryParam(labelWithDirV3) - - def queryParamV4 = QueryParam(labelWithDirV4) - -} http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/VertexTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/VertexTest.scala b/s2core/src/test/scala/com/kakao/s2graph/core/VertexTest.scala deleted file mode 100644 index 62b98b5..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/VertexTest.scala +++ /dev/null @@ -1,79 +0,0 @@ -//package com.kakao.s2graph.core -// -//import com.kakao.s2graph.core.types.{VertexId, InnerVal, InnerValLike} -//import org.scalatest.{Matchers, FunSuite} -// -// -///** -// * Created by shon on 5/29/15. -// */ -//class VertexTest extends FunSuite with Matchers with TestCommonWithModels with TestCommon { -// -// import types.HBaseType.{VERSION1, VERSION2} -// val idxPropsList = idxPropsLs.map { seq => seq.map { kv => kv._1.toInt -> kv._2 }} -// val idxPropsListV2 = idxPropsLsV2.map { seq => seq.map { kv => kv._1.toInt -> kv._2 }} -// def equalsExact(left: Vertex, right: Vertex) = { -// left.id == right.id && left.ts == right.ts && -// left.props == right.props && left.op == right.op -// } -// def vertexId(innerVal: InnerValLike)(version: String) = { -// val colId = if (version == VERSION2) columnV2.id.get else column.id.get -// VertexId(colId, innerVal) -// } -// -// /** assumes innerVal is sorted */ -// def testVertexEncodeDecode(innerVals: Seq[InnerValLike], -// propsLs: Seq[Seq[(Int, InnerValLike)]], version: String) = { -// for { -// props <- propsLs -// } { -// val currentTs = BigDecimal(props.toMap.get(0.toByte).get.toString).toLong -// val head = Vertex(vertexId(innerVals.head)(version), currentTs, props.toMap, op) -// val start = head -// var prev = head -// for { -// innerVal <- innerVals.tail -// } { -// var current = Vertex(vertexId(innerVal)(version), currentTs, props.toMap, op) -// val puts = current.buildPutsAsync() -// val kvs = for {put <- puts; kv <- putToKeyValues(put)} yield kv -// val decodedOpt = Vertex(kvs, version) -// val prevBytes = prev.rowKey.bytes.drop(GraphUtil.bytesForMurMurHash) -// val currentBytes = current.rowKey.bytes.drop(GraphUtil.bytesForMurMurHash) -// decodedOpt.isDefined shouldBe true -// val isSame = equalsExact(decodedOpt.get, current) -// val comp = lessThan(currentBytes, prevBytes) -// -// println(s"current: $current") -// println(s"decoded: ${decodedOpt.get}") -// println(s"$isSame, $comp") -// prev = current -// isSame && comp shouldBe true -// } -// } -// } -// -// test("test with int innerVals as id version 1") { -// testVertexEncodeDecode(intInnerVals, idxPropsList, VERSION1) -// } -// test("test with int innerVals as id version 2") { -// testVertexEncodeDecode(intInnerValsV2, idxPropsListV2, VERSION2) -// } -// test("test with string stringVals as id versoin 2") { -// testVertexEncodeDecode(stringInnerValsV2, idxPropsListV2, VERSION2) -// } -// // test("test vertex encoding/decoding") { -// // val innerVal1 = new InnerVal(BigDecimal(10)) -// // val innerVal2 = new InnerValV1(Some(10L), None, None) -// // println(s"${innerVal1.bytes.toList}") -// // println(s"${innerVal2.bytes.toList}") -// // val id1 = new CompositeId(0, innerVal1, isEdge = false, useHash = true) -// // val id2 = new CompositeIdV1(0, innerVal2, isEdge = false, useHash = true) -// // val ts = System.currentTimeMillis() -// // val v1 = Vertex(id1, ts) -// // val v2 = Vertex(id2, ts) -// // -// // println(s"${v1.rowKey.bytes.toList}") -// // println(s"${v2.rowKey.bytes.toList}") -// // } -//} http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/models/ModelTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/models/ModelTest.scala b/s2core/src/test/scala/com/kakao/s2graph/core/models/ModelTest.scala deleted file mode 100644 index f66eabf..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/models/ModelTest.scala +++ /dev/null @@ -1,135 +0,0 @@ -package com.kakao.s2graph.core.models - -import java.util.concurrent.ExecutorService - -import com.kakao.s2graph.core.mysqls.{Label, Model} -import com.kakao.s2graph.core.{TestCommonWithModels, TestCommon, Graph} -import com.typesafe.config.ConfigFactory -import org.scalatest.{BeforeAndAfterAll, Sequential, FunSuite, Matchers} - -import scala.concurrent.ExecutionContext - -class ModelTest extends FunSuite with Matchers with TestCommonWithModels with BeforeAndAfterAll { - override def beforeAll(): Unit = { - initTests() - } - - override def afterAll(): Unit = { - graph.shutdown() - } - - // val serviceName = "testService" - // val newServiceName = "newTestService" - // val cluster = "localhost" - // val hbaseTableName = "s2graph-dev" - // val columnName = "user_id" - // val columnType = "long" - // val labelName = "model_test_label" - // val newLabelName = "new_model_test_label" - // val columnMetaName = "is_valid_user" - // val labelMetaName = "is_hidden" - // val hbaseTableTTL = -1 - // val id = 1 - // - // val service = HService(Map("id" -> id, "serviceName" -> serviceName, "cluster" -> cluster, - // "hbaseTableName" -> hbaseTableName, "preSplitSize" -> 0, "hbaseTableTTL" -> -1)) - // val serviceColumn = HServiceColumn(Map("id" -> id, "serviceId" -> service.id.get, - // "columnName" -> columnName, "columnType" -> columnType)) - // val columnMeta = HColumnMeta(Map("id" -> id, "columnId" -> serviceColumn.id.get, "name" -> columnMetaName, "seq" -> 1.toByte)) - // val label = HLabel(Map("id" -> id, "label" -> labelName, - // "srcServiceId" -> service.id.get, "srcColumnName" -> columnName, "srcColumnType" -> columnType, - // "tgtServiceId" -> service.id.get, "tgtColumnName" -> columnName, "tgtColumnType" -> columnType, - // "isDirected" -> true, "serviceName" -> service.serviceName, "serviceId" -> service.id.get, - // "consistencyLevel" -> "weak", "hTableName" -> hbaseTableName, "hTableTTL" -> -1 - // )) - // val labelMeta = HLabelMeta(Map("id" -> id, "labelId" -> label.id.get, "name" -> labelMetaName, "seq" -> 1.toByte, - // "defaultValue" -> false, "dataType" -> "boolean", "usedInIndex" -> false)) - // val labelIndex = HLabelIndex(Map("id" -> id, "labelId" -> label.id.get, "seq" -> 1.toByte, - // "metaSeqs" -> "0", "formular" -> "none")) - test("test Label.findByName") { - val labelOpt = Label.findByName(labelName, useCache = false) - println(labelOpt) - labelOpt.isDefined shouldBe true - val indices = labelOpt.get.indices - indices.size > 0 shouldBe true - println(indices) - val defaultIndexOpt = labelOpt.get.defaultIndex - println(defaultIndexOpt) - defaultIndexOpt.isDefined shouldBe true - val metas = labelOpt.get.metaProps - println(metas) - metas.size > 0 shouldBe true - val srcService = labelOpt.get.srcService - println(srcService) - val tgtService = labelOpt.get.tgtService - println(tgtService) - val service = labelOpt.get.service - println(service) - val srcColumn = labelOpt.get.srcService - println(srcColumn) - val tgtColumn = labelOpt.get.tgtService - println(tgtColumn) - } - // test("test create") { - // service.create() - // HService.findByName(serviceName, useCache = false) == Some(service) - // - // serviceColumn.create() - // HServiceColumn.findsByServiceId(service.id.get, useCache = false).headOption == Some(serviceColumn) - // - // columnMeta.create() - // HColumnMeta.findByName(serviceColumn.id.get, columnMetaName, useCache = false) == Some(columnMeta) - // - // label.create() - // HLabel.findByName(labelName, useCache = false) == Some(label) - // - // labelMeta.create() - // HLabelMeta.findByName(label.id.get, labelMetaName, useCache = false) == Some(labelMeta) - // - // labelIndex.create() - // HLabelIndex.findByLabelIdAll(label.id.get, useCache = false).headOption == Some(labelIndex) - // } - // - // test("test update") { - // service.update("cluster", "...") - // HService.findById(service.id.get, useCache = false).cluster == "..." - // - // service.update("serviceName", newServiceName) - // assert(HService.findByName(serviceName, useCache = false) == None) - // HService.findByName(newServiceName, useCache = false).map { service => service.id.get == service.id.get} - // - // label.update("label", newLabelName) - // HLabel.findById(label.id.get, useCache = false).label == "newLabelName" - // - // label.update("consistencyLevel", "strong") - // HLabel.findById(label.id.get, useCache = false).consistencyLevel == "strong" && - // HLabel.findByName(newLabelName).isDefined && - // HLabel.findByName(labelName) == None - // - // } - // test("test read by index") { - // val labels = HLabel.findBySrcServiceId(service.id.get, useCache = false) - // val idxs = HLabelIndex.findByLabelIdAll(label.id.get, useCache = false) - // labels.length == 1 && - // labels.head == label - // idxs.length == 1 && - // idxs.head == labelIndex - // } - // test("test delete") { - //// HLabel.findByName(labelName).foreach { label => - //// label.deleteAll() - //// } - // HLabel.findByName(newLabelName).foreach { label => - // label.deleteAll() - // } - // HLabelMeta.findAllByLabelId(label.id.get, useCache = false).isEmpty && - // HLabelIndex.findByLabelIdAll(label.id.get, useCache = false).isEmpty - // - // service.deleteAll() - // } - - // test("test labelIndex") { - // println(HLabelIndex.findByLabelIdAll(1)) - // } - -} http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/mysqls/ExperimentSpec.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/mysqls/ExperimentSpec.scala b/s2core/src/test/scala/com/kakao/s2graph/core/mysqls/ExperimentSpec.scala deleted file mode 100644 index 078b5a9..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/mysqls/ExperimentSpec.scala +++ /dev/null @@ -1,64 +0,0 @@ -package com.kakao.s2graph.core.mysqls - -import java.util.Properties - -import com.typesafe.config.ConfigFactory -import org.scalatest.{BeforeAndAfterAll, FlatSpec, Matchers} -import scalikejdbc._ - -class ExperimentSpec extends FlatSpec with Matchers with BeforeAndAfterAll { - val Ttl = 2 - override def beforeAll(): Unit = { - /* - maxSize = config.getInt("cache.max.size") - ttl = config.getInt("cache.ttl.seconds") - */ - val props = new Properties() - props.setProperty("cache.ttl.seconds", Ttl.toString) - Model.apply(ConfigFactory.load(ConfigFactory.parseProperties(props))) - - implicit val session = AutoSession - sql"""DELETE FROM buckets""".update().apply() - sql"""DELETE FROM experiments""".update().apply() - - val expId = sql"""INSERT INTO experiments(service_id, service_name, `name`, description) VALUES(1, "s1", "exp1", "")""".updateAndReturnGeneratedKey().apply() - sql"""INSERT INTO - buckets(experiment_id, modular, http_verb, api_path, request_body, impression_id) - VALUES($expId, "1~100", "POST", "/a/b/c", "None", "imp1")""".update().apply() - - } - - "Experiment" should "find bucket list" in { - Experiment.findBy(1, "exp1") should not be empty - - Experiment.findBy(1, "exp1").foreach { exp => - val bucket = exp.buckets.head - bucket.impressionId should equal("imp1") - } - } - - it should "update bucket list after cache ttl time" in { - Experiment.findBy(1, "exp1").foreach { exp => - val bucket = exp.buckets.head - bucket.impressionId should equal("imp1") - - implicit val session = AutoSession - - sql"""UPDATE buckets SET impression_id = "imp2" WHERE id = ${bucket.id}""".update().apply() - } - - // sleep ttl time - Thread.sleep((Ttl + 1) * 1000) - - // update experiment and bucket - Experiment.findBy(1, "exp1").foreach(exp => exp.buckets) - - // wait for cache updating - Thread.sleep(1 * 1000) - - // should be updated - Experiment.findBy(1, "exp1").foreach { exp => - exp.buckets.head.impressionId should equal("imp2") - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/parsers/WhereParserTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/parsers/WhereParserTest.scala b/s2core/src/test/scala/com/kakao/s2graph/core/parsers/WhereParserTest.scala deleted file mode 100644 index febad3d..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/parsers/WhereParserTest.scala +++ /dev/null @@ -1,234 +0,0 @@ -package com.kakao.s2graph.core.parsers - -import com.kakao.s2graph.core._ -import com.kakao.s2graph.core.mysqls.{Experiment, Label, LabelMeta} -import com.kakao.s2graph.core.types._ -import com.kakao.s2graph.core.utils.logger -import org.scalatest.{FunSuite, Matchers} -import play.api.libs.json.Json - -class WhereParserTest extends FunSuite with Matchers with TestCommonWithModels { - initTests() - - // dummy data for dummy edge - initTests() - - import HBaseType.{VERSION1, VERSION2} - - val ts = System.currentTimeMillis() - val dummyTs = (LabelMeta.timeStampSeq -> InnerValLikeWithTs.withLong(ts, ts, label.schemaVersion)) - - def ids(version: String) = { - val colId = if (version == VERSION2) columnV2.id.get else column.id.get - val srcId = SourceVertexId(colId, InnerVal.withLong(1, version)) - val tgtId = TargetVertexId(colId, InnerVal.withLong(2, version)) - - val srcIdStr = SourceVertexId(colId, InnerVal.withStr("abc", version)) - val tgtIdStr = TargetVertexId(colId, InnerVal.withStr("def", version)) - - val srcVertex = Vertex(srcId, ts) - val tgtVertex = Vertex(tgtId, ts) - val srcVertexStr = Vertex(srcIdStr, ts) - val tgtVertexStr = Vertex(tgtIdStr, ts) - (srcId, tgtId, srcIdStr, tgtIdStr, srcVertex, tgtVertex, srcVertexStr, tgtVertexStr, version) - } - - - def validate(label: Label)(edge: Edge)(sql: String)(expected: Boolean) = { - val whereOpt = WhereParser(label).parse(sql) - whereOpt.isSuccess shouldBe true - - println("=================================================================") - println(sql) - println(whereOpt.get) - - val ret = whereOpt.get.filter(edge) - if (ret != expected) { - println("==================") - println(s"$whereOpt") - println(s"$edge") - println("==================") - } - ret shouldBe expected - } - - test("check where clause not nested") { - for { - (srcId, tgtId, srcIdStr, tgtIdStr, srcVertex, tgtVertex, srcVertexStr, tgtVertexStr, schemaVer) <- List(ids(VERSION1), ids(VERSION2)) - } { - /** test for each version */ - val js = Json.obj("is_hidden" -> true, "is_blocked" -> false, "weight" -> 10, "time" -> 3, "name" -> "abc") - val propsInner = Management.toProps(label, js.fields).map { case (k, v) => k -> InnerValLikeWithTs(v, ts) }.toMap + dummyTs - val edge = Edge(srcVertex, tgtVertex, labelWithDir, 0.toByte, ts, propsInner) - val f = validate(label)(edge) _ - - /** labelName label is long-long relation */ - f(s"_to=${tgtVertex.innerId.toString}")(true) - - // currently this throw exception since label`s _to is long type. - f(s"_to=19230495")(false) - f(s"_to!=19230495")(true) - } - } - - test("check where clause nested") { - for { - (srcId, tgtId, srcIdStr, tgtIdStr, srcVertex, tgtVertex, srcVertexStr, tgtVertexStr, schemaVer) <- List(ids(VERSION1), ids(VERSION2)) - } { - /** test for each version */ - val js = Json.obj("is_hidden" -> true, "is_blocked" -> false, "weight" -> 10, "time" -> 3, "name" -> "abc") - val propsInner = Management.toProps(label, js.fields).map { case (k, v) => k -> InnerValLikeWithTs(v, ts) }.toMap + dummyTs - val edge = Edge(srcVertex, tgtVertex, labelWithDir, 0.toByte, ts, propsInner) - - val f = validate(label)(edge) _ - - // time == 3 - f("time >= 3")(true) - f("time > 2")(true) - f("time <= 3")(true) - f("time < 2")(false) - - f("(time in (1, 2, 3) and is_blocked = true) or is_hidden = false")(false) - f("(time in (1, 2, 3) or is_blocked = true) or is_hidden = false")(true) - f("(time in (1, 2, 3) and is_blocked = true) or is_hidden = true")(true) - f("(time in (1, 2, 3) or is_blocked = true) and is_hidden = true")(true) - - f("((time in ( 1, 2, 3) and weight between 1 and 10) or is_hidden=false)")(true) - f("(time in (1, 2, 4 ) or weight between 1 and 9) or (is_hidden = false)")(false) - f("(time in ( 1,2,4 ) or weight between 1 and 9) or is_hidden= true")(true) - f("(time in (1,2,3) or weight between 1 and 10) and is_hidden =false")(false) - } - } - - test("check where clause with from/to long") { - for { - (srcId, tgtId, srcIdStr, tgtIdStr, srcVertex, tgtVertex, srcVertexStr, tgtVertexStr, schemaVer) <- List(ids(VERSION1), ids(VERSION2)) - } { - /** test for each version */ - val js = Json.obj("is_hidden" -> true, "is_blocked" -> false, "weight" -> 10, "time" -> 3, "name" -> "abc") - val propsInner = Management.toProps(label, js.fields).map { case (k, v) => k -> InnerValLikeWithTs(v, ts) }.toMap + dummyTs - val labelWithDirection = if (schemaVer == VERSION2) labelWithDirV2 else labelWithDir - val edge = Edge(srcVertex, tgtVertex, labelWithDirection, 0.toByte, ts, propsInner) - val lname = if (schemaVer == VERSION2) labelNameV2 else labelName - val f = validate(label)(edge) _ - - f(s"_from = -1 or _to = ${tgtVertex.innerId.value}")(true) - f(s"_from = ${srcVertex.innerId.value} and _to = ${tgtVertex.innerId.value}")(true) - f(s"_from = ${tgtVertex.innerId.value} and _to = 102934")(false) - f(s"_from = -1")(false) - f(s"_from in (-1, -0.1)")(false) - } - } - - - test("check where clause with parent") { - for { - (srcId, tgtId, srcIdStr, tgtIdStr, srcVertex, tgtVertex, srcVertexStr, tgtVertexStr, schemaVer) <- List(ids(VERSION1), ids(VERSION2)) - } { - /** test for each version */ - val js = Json.obj("is_hidden" -> true, "is_blocked" -> false, "weight" -> 10, "time" -> 1, "name" -> "abc") - val parentJs = Json.obj("is_hidden" -> false, "is_blocked" -> false, "weight" -> 20, "time" -> 3, "name" -> "a") - - val propsInner = Management.toProps(label, js.fields).map { case (k, v) => k -> InnerValLikeWithTs(v, ts) }.toMap + dummyTs - val parentPropsInner = Management.toProps(label, parentJs.fields).map { case (k, v) => k -> InnerValLikeWithTs(v, ts) }.toMap + dummyTs - - val grandParentEdge = Edge(srcVertex, tgtVertex, labelWithDir, 0.toByte, ts, parentPropsInner) - val parentEdge = Edge(srcVertex, tgtVertex, labelWithDir, 0.toByte, ts, parentPropsInner, - parentEdges = Seq(EdgeWithScore(grandParentEdge, 1.0))) - val edge = Edge(srcVertex, tgtVertex, labelWithDir, 0.toByte, ts, propsInner, - parentEdges = Seq(EdgeWithScore(parentEdge, 1.0))) - - println(edge.toString) - println(parentEdge.toString) - println(grandParentEdge.toString) - - val f = validate(label)(edge) _ - - // Compare edge's prop(`_from`) with edge's prop(`name`) - f("_from = 1")(true) - f("_to = 2")(true) - f("_from = 123")(false) - f("_from = time")(true) - - // Compare edge's prop(`weight`) with edge's prop(`time`) - f("weight = time")(false) - f("weight = is_blocked")(false) - - // Compare edge's prop(`weight`) with parent edge's prop(`weight`) - f("_parent.is_blocked = is_blocked")(true) - f("is_hidden = _parent.is_hidden")(false) - f("_parent.weight = weight")(false) - - // Compare edge's prop(`is_hidden`) with parent of parent edge's prop(`is_hidden`) - f("_parent._parent.is_hidden = is_hidden")(false) - f("_parent._parent.is_blocked = is_blocked")(true) - f("_parent._parent.weight = weight")(false) - f("_parent._parent.weight = _parent.weight")(true) - } - } - - test("replace reserved") { - val ts = 0 - import com.kakao.s2graph.core.rest.TemplateHelper._ - - calculate(ts, 1, "hour") should be(hour + ts) - calculate(ts, 1, "day") should be(day + ts) - - calculate(ts + 10, 1, "HOUR") should be(hour + ts + 10) - calculate(ts + 10, 1, "DAY") should be(day + ts + 10) - - val body = """{ - "day": ${1day}, - "hour": ${1hour}, - "-day": "${-10 day}", - "-hour": ${-10 hour}, - "now": "${now}" - } - """ - - val parsed = replaceVariable(ts, body) - val json = Json.parse(parsed) - - (json \ "day").as[Long] should be (1 * day + ts) - (json \ "hour").as[Long] should be (1 * hour + ts) - - (json \ "-day").as[Long] should be (-10 * day + ts) - (json \ "-hour").as[Long] should be (-10 * hour + ts) - - (json \ "now").as[Long] should be (ts) - - val otherBody = """{ - "nextday": "${next_day}", - "3dayago": "${next_day - 3 day}", - "nexthour": "${next_hour}" - }""" - - val currentTs = System.currentTimeMillis() - val expectedDayTs = currentTs / day * day + day - val expectedHourTs = currentTs / hour * hour + hour - val threeDayAgo = expectedDayTs - 3 * day - val currentTsLs = (1 until 1000).map(currentTs + _) - - currentTsLs.foreach { ts => - val parsed = replaceVariable(ts, otherBody) - val json = Json.parse(parsed) - - (json \ "nextday").as[Long] should be(expectedDayTs) - (json \ "nexthour").as[Long] should be(expectedHourTs) - (json \ "3dayago").as[Long] should be(threeDayAgo) - } - } - - // test("time decay") { - // val ts = System.currentTimeMillis() - // - // for { - // i <- (0 until 10) - // } { - // val timeUnit = 60 * 60 - // val diff = i * timeUnit - // val x = TimeDecay(1.0, 0.05, timeUnit) - // println(x.decay(diff)) - // } - // } -} http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/storage/hbase/AsynchbaseQueryBuilderTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/storage/hbase/AsynchbaseQueryBuilderTest.scala b/s2core/src/test/scala/com/kakao/s2graph/core/storage/hbase/AsynchbaseQueryBuilderTest.scala deleted file mode 100644 index 128f2d7..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/storage/hbase/AsynchbaseQueryBuilderTest.scala +++ /dev/null @@ -1,53 +0,0 @@ -//package com.kakao.s2graph.core.storage.hbase -// -//import com.kakao.s2graph.core.Graph -//import com.typesafe.config.ConfigFactory -// -//import org.apache.hadoop.hbase.util.Bytes -//import org.hbase.async.GetRequest -//import org.scalatest.{FunSuite, Matchers} -// -//import scala.concurrent.ExecutionContext -// -//class AsynchbaseQueryBuilderTest extends FunSuite with Matchers { -// -// val dummyRequests = { -// for { -// id <- 0 until 1000 -// } yield { -// new GetRequest("a", Bytes.toBytes(id)) -// } -// } -// -// implicit val ec = ExecutionContext.Implicits.global -// val config = ConfigFactory.load() -// val graph = new Graph(config) -// -// val qb = new AsynchbaseQueryBuilder(graph.storage.asInstanceOf[AsynchbaseStorage]) -// -// test("test toCacheKeyBytes") { -// val startedAt = System.nanoTime() -// -// for { -// i <- dummyRequests.indices -// x = qb.toCacheKeyBytes(dummyRequests(i)) -// } { -// for { -// j <- dummyRequests.indices if i != j -// y = qb.toCacheKeyBytes(dummyRequests(j)) -// } { -// x should not equal y -// } -// } -// -// dummyRequests.zip(dummyRequests).foreach { case (x, y) => -// val xHash = qb.toCacheKeyBytes(x) -// val yHash = qb.toCacheKeyBytes(y) -// // println(xHash, yHash) -// xHash should be(yHash) -// } -// val duration = System.nanoTime() - startedAt -// -// println(s">> bytes: $duration") -// } -//} http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/storage/hbase/AsynchbaseStorageTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/storage/hbase/AsynchbaseStorageTest.scala b/s2core/src/test/scala/com/kakao/s2graph/core/storage/hbase/AsynchbaseStorageTest.scala deleted file mode 100644 index 87a0dcb..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/storage/hbase/AsynchbaseStorageTest.scala +++ /dev/null @@ -1,36 +0,0 @@ -package com.kakao.s2graph.core.storage.hbase - -import com.typesafe.config.ConfigFactory -import org.hbase.async.{GetRequest, PutRequest} -import org.scalatest.{Matchers, FunSuite} -import scala.collection.JavaConversions._ - -class AsynchbaseStorageTest extends FunSuite with Matchers { - - /** need secured cluster */ -// test("test secure cluster connection") { -// val config = ConfigFactory.parseMap( -// Map( -// "hbase.zookeeper.quorum" -> "localhost", -// "hbase.security.auth.enable" -> "true", -// "hbase.security.authentication" -> "kerberos", -// "hbase.kerberos.regionserver.principal" -> "hbase/[email protected]", -// "hbase.sasl.clientconfig" -> "Client", -// "java.security.krb5.conf" -> "krb5.conf", -// "java.security.auth.login.config" -> "async-client.jaas.conf") -// ) -// -// val client = AsynchbaseStorage.makeClient(config) -// val table = "test".getBytes() -// -// val putRequest = new PutRequest(table, "a".getBytes(), "e".getBytes, "a".getBytes, "a".getBytes) -// val getRequest = new GetRequest(table, "a".getBytes(), "e".getBytes) -// val ret = client.put(putRequest).join() -// val kvs = client.get(getRequest).join() -// for { -// kv <- kvs -// } { -// println(kv.toString) -// } -// } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/storage/hbase/IndexEdgeTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/storage/hbase/IndexEdgeTest.scala b/s2core/src/test/scala/com/kakao/s2graph/core/storage/hbase/IndexEdgeTest.scala deleted file mode 100644 index e68fc20..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/storage/hbase/IndexEdgeTest.scala +++ /dev/null @@ -1,81 +0,0 @@ -package com.kakao.s2graph.core.storage.hbase - -import com.kakao.s2graph.core.mysqls.{Label, LabelMeta, LabelIndex} -import com.kakao.s2graph.core.{IndexEdge, Vertex, TestCommonWithModels} -import com.kakao.s2graph.core.types._ -import org.scalatest.{FunSuite, Matchers} - - -class IndexEdgeTest extends FunSuite with Matchers with TestCommonWithModels { - initTests() - - /** - * check if storage serializer/deserializer can translate from/to bytes array. - * @param l: label for edge. - * @param ts: timestamp for edge. - * @param to: to VertexId for edge. - * @param props: expected props of edge. - */ - def check(l: Label, ts: Long, to: InnerValLike, props: Map[Byte, InnerValLike]): Unit = { - val from = InnerVal.withLong(1, l.schemaVersion) - val vertexId = SourceVertexId(HBaseType.DEFAULT_COL_ID, from) - val tgtVertexId = TargetVertexId(HBaseType.DEFAULT_COL_ID, to) - val vertex = Vertex(vertexId, ts) - val tgtVertex = Vertex(tgtVertexId, ts) - val labelWithDir = LabelWithDirection(l.id.get, 0) - - val indexEdge = IndexEdge(vertex, tgtVertex, labelWithDir, 0, ts, LabelIndex.DefaultSeq, props) - val _indexEdgeOpt = graph.storage.indexEdgeDeserializer(l.schemaVersion).fromKeyValues(queryParam, - graph.storage.indexEdgeSerializer(indexEdge).toKeyValues, l.schemaVersion, None) - - _indexEdgeOpt should not be empty - indexEdge should be(_indexEdgeOpt.get) - } - - - /** note that props have to be properly set up for equals */ - test("test serializer/deserializer for index edge.") { - val ts = System.currentTimeMillis() - for { - l <- Seq(label, labelV2, labelV3, labelV4) - } { - val to = InnerVal.withLong(101, l.schemaVersion) - val tsInnerVal = InnerVal.withLong(ts, l.schemaVersion) - val props = Map(LabelMeta.timeStampSeq -> tsInnerVal, - 1.toByte -> InnerVal.withDouble(2.1, l.schemaVersion)) - - check(l, ts, to, props) - } - } - - test("test serializer/deserializer for degree edge.") { - val ts = System.currentTimeMillis() - for { - l <- Seq(label, labelV2, labelV3, labelV4) - } { - val to = InnerVal.withStr("0", l.schemaVersion) - val tsInnerVal = InnerVal.withLong(ts, l.schemaVersion) - val props = Map( - LabelMeta.degreeSeq -> InnerVal.withLong(10, l.schemaVersion), - LabelMeta.timeStampSeq -> tsInnerVal) - - check(l, ts, to, props) - } - } - - test("test serializer/deserializer for incrementCount index edge.") { - val ts = System.currentTimeMillis() - for { - l <- Seq(label, labelV2, labelV3, labelV4) - } { - val to = InnerVal.withLong(101, l.schemaVersion) - - val tsInnerVal = InnerVal.withLong(ts, l.schemaVersion) - val props = Map(LabelMeta.timeStampSeq -> tsInnerVal, - 1.toByte -> InnerVal.withDouble(2.1, l.schemaVersion), - LabelMeta.countSeq -> InnerVal.withLong(10, l.schemaVersion)) - - check(l, ts, to, props) - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/types/CompositeIdTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/types/CompositeIdTest.scala b/s2core/src/test/scala/com/kakao/s2graph/core/types/CompositeIdTest.scala deleted file mode 100644 index d014208..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/types/CompositeIdTest.scala +++ /dev/null @@ -1,109 +0,0 @@ -//package com.kakao.s2graph.core.types -// -//import com.kakao.s2graph.core.{TestCommonWithModels, GraphUtil, TestCommon} -//import com.kakao.s2graph.core.types2._ -//import org.apache.hadoop.hbase.util.Bytes -//import org.scalatest.{Matchers, FunSuite} -// -///** -// * Created by shon on 5/29/15. -// */ -//class CompositeIdTest extends FunSuite with Matchers with TestCommon with TestCommonWithModels { -// /** these constants need to be sorted asc order for test to run */ -// import InnerVal.{VERSION1, VERSION2} -// -// -// val functions = for { -// isEdge <- List(true, false) -// useHash <- List(false) -// } yield { -// val serializer = (idxProps: Seq[(Byte, InnerValLike)], innerVal: InnerValLike) => -// CompositeId(testColumnId, innerVal, isEdge, useHash) -// val deserializer = (bytes: Array[Byte]) => CompositeId.fromBytes(bytes, 0, isEdge, useHash) -// (serializer, deserializer) -// } -// -// def testOrder(innerVals: Iterable[InnerValLike], isEdge: Boolean, useHash: Boolean, version: String) = { -// /** check if increasing target vertex id is ordered properly with same indexProps */ -// import InnerVal.{VERSION1, VERSION2} -// val colId = version match { -// case VERSION2 => columnV2.id.get -// case VERSION1 => column.id.get -// case _ => throw new RuntimeException("!") -// } -// val head = CompositeId(colId, innerVals.head, isEdge = isEdge, useHash = useHash) -// var prev = head -// -// for { -// innerVal <- innerVals.tail -// } { -// val current = CompositeId(colId, innerVal, isEdge = isEdge, useHash = useHash) -// val bytes = current.bytes -// val decoded = CompositeId.fromBytes(bytes, 0, isEdge, useHash, version) -// -// println(s"current: $current") -// println(s"decoded: $decoded") -// -// val prevBytes = if (useHash) prev.bytes.drop(GraphUtil.bytesForMurMurHash) else prev.bytes -// val currentBytes = if (useHash) bytes.drop(GraphUtil.bytesForMurMurHash) else bytes -// println(s"prev: $prev, ${Bytes.compareTo(currentBytes, prevBytes)}") -// val comp = lessThan(currentBytes, prevBytes) && current == decoded -// prev = current -// comp shouldBe true -// } -// } -// /** version 1 */ -// test("order of compositeId numeric v1") { -// for { -// isEdge <- List(true, false) -// useHash <- List(true, false) -// } { -// testOrder(numInnerVals, isEdge, useHash, VERSION1) -// } -// } -// /** string order in v1 is not actually descending. it depends on string length */ -//// test("order of compositeId string v1") { -//// for { -//// isEdge <- List(true, false) -//// useHash <- List(true, false) -//// } { -//// testOrder(stringInnerVals, isEdge, useHash, VERSION1) -//// } -//// } -//// test("order of compositeId double v1") { -//// for { -//// isEdge <- List(true, false) -//// useHash <- List(true, false) -//// } { -//// testOrder(doubleInnerVals, isEdge, useHash, VERSION1) -//// } -//// } -// /** version 2 */ -// test("order of compositeId numeric v2") { -// for { -// isEdge <- List(true, false) -// useHash <- List(true, false) -// } { -// testOrder(numInnerValsV2, isEdge, useHash, VERSION2) -// } -// } -// test("order of compositeId string v2") { -// for { -// isEdge <- List(true, false) -// useHash <- List(true, false) -// } { -// testOrder(stringInnerValsV2, isEdge, useHash, VERSION2) -// } -// } -// test("order of compositeId double v2") { -// for { -// isEdge <- List(true, false) -// useHash <- List(true, false) -// } { -// testOrder(doubleInnerValsV2, isEdge, useHash, VERSION2) -// } -// } -// -// -// -//} http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/types/EdgeTypeTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/types/EdgeTypeTest.scala b/s2core/src/test/scala/com/kakao/s2graph/core/types/EdgeTypeTest.scala deleted file mode 100644 index cfcedd1..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/types/EdgeTypeTest.scala +++ /dev/null @@ -1,69 +0,0 @@ -//package com.kakao.s2graph.core.types -// -//import com.kakao.s2graph.core.types2._ -//import com.kakao.s2graph.core.{TestCommonWithModels, TestCommon} -//import org.scalatest.{Matchers, FunSuite} -// -///** -// * Created by shon on 5/29/15. -// */ -//class EdgeTypeTest extends FunSuite with Matchers with TestCommon { -// -// import HBaseType.{VERSION1, VERSION2} -// def vertexId(innerVal: InnerValLike) = VertexId(testColumnId, innerVal) -// def sourceVertexId(innerVal: InnerValLike) = SourceVertexId(testColumnId, innerVal) -// def targetVertexId(innerVal: InnerValLike) = TargetVertexId(testColumnId, innerVal) -// val skipHashBytes = true -// -// test("test edge row key order with int source vertex id version 1") { -// val version = VERSION1 -// val serializer = (idxProps: Seq[(Byte, InnerValLike)], innerVal: InnerValLike) => -// EdgeRowKey(sourceVertexId(innerVal), testLabelWithDir, testLabelOrderSeq, isInverted = false)(version) -// val deserializer = (bytes: Array[Byte]) => EdgeRowKey.fromBytes(bytes, 0, bytes.length, version) -// testOrder(idxPropsLs, intInnerVals, skipHashBytes)(serializer, deserializer) shouldBe true -// } -// test("test edge row key order with int source vertex id version 2") { -// val version = VERSION2 -// val serializer = (idxProps: Seq[(Byte, InnerValLike)], innerVal: InnerValLike) => -// EdgeRowKey(sourceVertexId(innerVal), testLabelWithDir, testLabelOrderSeq, isInverted = false)(version) -// val deserializer = (bytes: Array[Byte]) => EdgeRowKey.fromBytes(bytes, 0, bytes.length, version) -// testOrder(idxPropsLsV2, intInnerValsV2, skipHashBytes)(serializer, deserializer) shouldBe true -// } -// -// test("test edge row qualifier with int target vertex id version 1") { -// val version = VERSION1 -// val serializer = (idxProps: Seq[(Byte, InnerValLike)], innerVal: InnerValLike) => -// EdgeQualifier(idxProps, targetVertexId(innerVal), testOp)(version) -// val deserializer = (bytes: Array[Byte]) => EdgeQualifier.fromBytes(bytes, 0, bytes.length, version) -// -// testOrder(idxPropsLs, intInnerVals, !skipHashBytes)(serializer, deserializer) shouldBe true -// testOrderReverse(idxPropsLs, intInnerVals, !skipHashBytes)(serializer, deserializer) shouldBe true -// } -// test("test edge row qualifier with int target vertex id version 2") { -// val version = VERSION2 -// val serializer = (idxProps: Seq[(Byte, InnerValLike)], innerVal: InnerValLike) => -// EdgeQualifier(idxProps, targetVertexId(innerVal), testOp)(version) -// val deserializer = (bytes: Array[Byte]) => EdgeQualifier.fromBytes(bytes, 0, bytes.length, version) -// -// testOrder(idxPropsLsV2, intInnerValsV2, !skipHashBytes)(serializer, deserializer) shouldBe true -// testOrderReverse(idxPropsLsV2, intInnerValsV2, !skipHashBytes)(serializer, deserializer) shouldBe true -// } -// -// test("test edge row qualifier inverted with int target vertex id version 1") { -// val version = VERSION1 -// val serializer = (idxProps: Seq[(Byte, InnerValLike)], innerVal: InnerValLike) => -// EdgeQualifierInverted(targetVertexId(innerVal))(version) -// val deserializer = (bytes: Array[Byte]) => EdgeQualifierInverted.fromBytes(bytes, 0, bytes.length, version) -// -// testOrder(idxPropsLs, intInnerVals, !skipHashBytes)(serializer, deserializer) shouldBe true -// } -// test("test edge row qualifier inverted with int target vertex id version 2") { -// val version = VERSION2 -// val serializer = (idxProps: Seq[(Byte, InnerValLike)], innerVal: InnerValLike) => -// EdgeQualifierInverted(targetVertexId(innerVal))(version) -// val deserializer = (bytes: Array[Byte]) => EdgeQualifierInverted.fromBytes(bytes, 0, bytes.length, version) -// -// testOrder(idxPropsLsV2, intInnerValsV2, !skipHashBytes)(serializer, deserializer) shouldBe true -// } -// -//} http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/types/InnerValTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/types/InnerValTest.scala b/s2core/src/test/scala/com/kakao/s2graph/core/types/InnerValTest.scala deleted file mode 100644 index 69a299d..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/types/InnerValTest.scala +++ /dev/null @@ -1,130 +0,0 @@ -package com.kakao.s2graph.core.types - -import com.kakao.s2graph.core.TestCommonWithModels -import com.kakao.s2graph.core.types._ -import org.apache.hadoop.hbase.util.{Bytes, OrderedBytes, SimplePositionedByteRange} -import org.scalatest.{Matchers, FunSuite} -import play.api.libs.json.Json - -class InnerValTest extends FunSuite with Matchers with TestCommonWithModels { - initTests() - - import HBaseType.{VERSION2, VERSION1} - val decimals = List( - BigDecimal(Long.MinValue), - BigDecimal(Int.MinValue), - BigDecimal(Double.MinValue), - BigDecimal(Float.MinValue), - BigDecimal(Short.MinValue), - BigDecimal(Byte.MinValue), - - BigDecimal(-1), - BigDecimal(0), - BigDecimal(1), - BigDecimal(Long.MaxValue), - BigDecimal(Int.MaxValue), - BigDecimal(Double.MaxValue), - BigDecimal(Float.MaxValue), - BigDecimal(Short.MaxValue), - BigDecimal(Byte.MaxValue) - ) - val booleans = List( - false, true - ) - val strings = List( - "abc", "abd", "ac", "aca" - ) - val texts = List( - (0 until 1000).map(x => "a").mkString - ) - val blobs = List( - (0 until 1000).map(x => Byte.MaxValue).toArray - ) - def testEncodeDecode(ranges: List[InnerValLike], version: String) = { - for { - innerVal <- ranges - } { - val bytes = innerVal.bytes - val (decoded, numOfBytesUsed) = InnerVal.fromBytes(bytes, 0, bytes.length, version) - innerVal == decoded shouldBe true - bytes.length == numOfBytesUsed shouldBe true - } - } - // test("big decimal") { - // for { - // version <- List(VERSION2, VERSION1) - // } { - // val innerVals = decimals.map { num => InnerVal.withNumber(num, version)} - // testEncodeDecode(innerVals, version) - // } - // } - // test("text") { - // for { - // version <- List(VERSION2) - // } { - // val innerVals = texts.map { t => InnerVal.withStr(t, version) } - // testEncodeDecode(innerVals, version) - // } - // } - // test("string") { - // for { - // version <- List(VERSION2, VERSION1) - // } { - // val innerVals = strings.map { t => InnerVal.withStr(t, version) } - // testEncodeDecode(innerVals, version) - // } - // } - // test("blob") { - // for { - // version <- List(VERSION2) - // } { - // val innerVals = blobs.map { t => InnerVal.withBlob(t, version) } - // testEncodeDecode(innerVals, version) - // } - // } - // test("boolean") { - // for { - // version <- List(VERSION2, VERSION1) - // } { - // val innerVals = booleans.map { t => InnerVal.withBoolean(t, version) } - // testEncodeDecode(innerVals, version) - // } - // } - test("korean") { - val small = InnerVal.withStr("ê°", VERSION2) - val large = InnerVal.withStr("ë", VERSION2) - val smallBytes = small.bytes - val largeBytes = large.bytes - - println (Bytes.compareTo(smallBytes, largeBytes)) - true - } - // test("innerVal") { - // val srcVal = InnerVal.withLong(44391298, VERSION2) - // val srcValV1 = InnerVal.withLong(44391298, VERSION1) - // val tgtVal = InnerVal.withLong(7295564, VERSION2) - // - // val a = VertexId(0, srcVal) - // val b = SourceVertexId(0, srcVal) - // val c = TargetVertexId(0, srcVal) - // val aa = VertexId(0, srcValV1) - // val bb = SourceVertexId(0, srcValV1) - // val cc = TargetVertexId(0, srcValV1) - // println(a.bytes.toList) - // println(b.bytes.toList) - // println(c.bytes.toList) - // - // println(aa.bytes.toList) - // println(bb.bytes.toList) - // println(cc.bytes.toList) - // } - // test("aa") { - // val bytes = InnerVal.withLong(Int.MaxValue, VERSION2).bytes - // val pbr = new SimplePositionedByteRange(bytes) - // pbr.setOffset(1) - // println(pbr.getPosition) - // val num = OrderedBytes.decodeNumericAsBigDecimal(pbr) - // println(pbr.getPosition) - // true - // } -} http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/types/SourceVertexIdTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/types/SourceVertexIdTest.scala b/s2core/src/test/scala/com/kakao/s2graph/core/types/SourceVertexIdTest.scala deleted file mode 100644 index b77e27b..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/types/SourceVertexIdTest.scala +++ /dev/null @@ -1,52 +0,0 @@ -//package com.kakao.s2graph.core.types -// -//import com.kakao.s2graph.core.types2._ -//import com.kakao.s2graph.core.{TestCommonWithModels, TestCommon} -//import org.scalatest.{Matchers, FunSuite} -// -///** -// * Created by shon on 6/10/15. -// */ -//class SourceVertexIdTest extends FunSuite with Matchers with TestCommon with TestCommonWithModels{ -// import HBaseType.{VERSION1, VERSION2} -// -// val serializer = (idxProps: Seq[(Byte, InnerValLike)], innerVal: InnerValLike) => SourceVertexId(testColumnId, innerVal) -// def deserializer(version: String) = (bytes: Array[Byte]) => SourceVertexId.fromBytes(bytes, 0, bytes.length, version) -// def skipHashBytes = true -// val emptyIndexPropsLs = Seq(Seq.empty[(Byte, InnerValLike)]) -// /** version 1 */ -// test("order of compositeId numeric v1") { -// val version = VERSION1 -// testOrder(emptyIndexPropsLs, numInnerVals, skipHashBytes)(serializer, deserializer(version)) shouldBe true -// } -// /** string order in v1 is not actually descending. it depends on string length */ -// // test("order of compositeId string v1") { -// // for { -// // isEdge <- List(true, false) -// // useHash <- List(true, false) -// // } { -// // testOrder(stringInnerVals, isEdge, useHash, VERSION1) -// // } -// // } -// // test("order of compositeId double v1") { -// // for { -// // isEdge <- List(true, false) -// // useHash <- List(true, false) -// // } { -// // testOrder(doubleInnerVals, isEdge, useHash, VERSION1) -// // } -// // } -// /** version 2 */ -// test("order of compositeId numeric v2") { -// val version = VERSION2 -// testOrder(emptyIndexPropsLs, numInnerValsV2, skipHashBytes)(serializer, deserializer(version)) shouldBe true -// } -// test("order of compositeId string v2") { -// val version = VERSION2 -// testOrder(emptyIndexPropsLs, stringInnerValsV2, skipHashBytes)(serializer, deserializer(version)) shouldBe true -// } -// test("order of compositeId double v2") { -// val version = VERSION2 -// testOrder(emptyIndexPropsLs, doubleInnerValsV2, skipHashBytes)(serializer, deserializer(version)) shouldBe true -// } -//} http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/types/TargetVertexIdTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/types/TargetVertexIdTest.scala b/s2core/src/test/scala/com/kakao/s2graph/core/types/TargetVertexIdTest.scala deleted file mode 100644 index 845de95..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/types/TargetVertexIdTest.scala +++ /dev/null @@ -1,53 +0,0 @@ -//package com.kakao.s2graph.core.types -// -//import com.kakao.s2graph.core.types2._ -//import com.kakao.s2graph.core.{TestCommonWithModels, TestCommon} -//import org.scalatest.{Matchers, FunSuite} -// -///** -// * Created by shon on 6/10/15. -// */ -//class TargetVertexIdTest extends FunSuite with Matchers with TestCommon with TestCommonWithModels{ -// import HBaseType.{VERSION1, VERSION2} -// -// val serializer = (idxProps: Seq[(Byte, InnerValLike)], innerVal: InnerValLike) => TargetVertexId(testColumnId, innerVal) -// def deserializer(version: String) = (bytes: Array[Byte]) => TargetVertexId.fromBytes(bytes, 0, bytes.length, version) -// def skipHashBytes = false -// -// val emptyIndexPropsLs = Seq(Seq.empty[(Byte, InnerValLike)]) -// /** version 1 */ -// test("order of compositeId numeric v1") { -// val version = VERSION1 -// testOrder(emptyIndexPropsLs, numInnerVals, skipHashBytes)(serializer, deserializer(version)) shouldBe true -// } -// /** string order in v1 is not actually descending. it depends on string length */ -// // test("order of compositeId string v1") { -// // for { -// // isEdge <- List(true, false) -// // useHash <- List(true, false) -// // } { -// // testOrder(stringInnerVals, isEdge, useHash, VERSION1) -// // } -// // } -// // test("order of compositeId double v1") { -// // for { -// // isEdge <- List(true, false) -// // useHash <- List(true, false) -// // } { -// // testOrder(doubleInnerVals, isEdge, useHash, VERSION1) -// // } -// // } -// /** version 2 */ -// test("order of compositeId numeric v2") { -// val version = VERSION2 -// testOrder(emptyIndexPropsLs, numInnerValsV2, skipHashBytes)(serializer, deserializer(version)) shouldBe true -// } -// test("order of compositeId string v2") { -// val version = VERSION2 -// testOrder(emptyIndexPropsLs, stringInnerValsV2, skipHashBytes)(serializer, deserializer(version)) shouldBe true -// } -// test("order of compositeId double v2") { -// val version = VERSION2 -// testOrder(emptyIndexPropsLs, doubleInnerValsV2, skipHashBytes)(serializer, deserializer(version)) shouldBe true -// } -//} http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/types/VertexIdTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/types/VertexIdTest.scala b/s2core/src/test/scala/com/kakao/s2graph/core/types/VertexIdTest.scala deleted file mode 100644 index c0d1e59..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/types/VertexIdTest.scala +++ /dev/null @@ -1,52 +0,0 @@ -//package com.kakao.s2graph.core.types -// -//import com.kakao.s2graph.core.types2.{HBaseType, VertexId, InnerValLike, InnerVal} -//import com.kakao.s2graph.core.{GraphUtil, TestCommonWithModels, TestCommon} -//import org.scalatest.{Matchers, FunSuite} -// -///** -// * Created by shon on 6/10/15. -// */ -//class VertexIdTest extends FunSuite with Matchers with TestCommon with TestCommonWithModels { -// import HBaseType.{VERSION1, VERSION2} -// -// val serializer = (idxProps: Seq[(Byte, InnerValLike)], innerVal: InnerValLike) => VertexId(testColumnId, innerVal) -// def deserializer(version: String) = (bytes: Array[Byte]) => VertexId.fromBytes(bytes, 0, bytes.length, version) -// val skipHashBytes = true -// val emptyIndexPropsLs = Seq(Seq.empty[(Byte, InnerValLike)]) -// /** version 1 */ -// test("order of compositeId numeric v1") { -// val version = VERSION1 -// testOrder(emptyIndexPropsLs, numInnerVals, skipHashBytes)(serializer, deserializer(version)) shouldBe true -// } -// /** string order in v1 is not actually descending. it depends on string length */ -// // test("order of compositeId string v1") { -// // for { -// // isEdge <- List(true, false) -// // useHash <- List(true, false) -// // } { -// // testOrder(stringInnerVals, isEdge, useHash, VERSION1) -// // } -// // } -// // test("order of compositeId double v1") { -// // for { -// // isEdge <- List(true, false) -// // useHash <- List(true, false) -// // } { -// // testOrder(doubleInnerVals, isEdge, useHash, VERSION1) -// // } -// // } -// /** version 2 */ -// test("order of compositeId numeric v2") { -// val version = VERSION2 -// testOrder(emptyIndexPropsLs, numInnerValsV2, skipHashBytes)(serializer, deserializer(version)) shouldBe true -// } -// test("order of compositeId string v2") { -// val version = VERSION2 -// testOrder(emptyIndexPropsLs, stringInnerValsV2, skipHashBytes)(serializer, deserializer(version)) shouldBe true -// } -// test("order of compositeId double v2") { -// val version = VERSION2 -// testOrder(emptyIndexPropsLs, doubleInnerValsV2, skipHashBytes)(serializer, deserializer(version)) shouldBe true -// } -//} http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/b8a15217/s2core/src/test/scala/com/kakao/s2graph/core/types/VertexTypeTest.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/com/kakao/s2graph/core/types/VertexTypeTest.scala b/s2core/src/test/scala/com/kakao/s2graph/core/types/VertexTypeTest.scala deleted file mode 100644 index 284601b..0000000 --- a/s2core/src/test/scala/com/kakao/s2graph/core/types/VertexTypeTest.scala +++ /dev/null @@ -1,42 +0,0 @@ -//package com.kakao.s2graph.core.types -// -//import com.kakao.s2graph.core.TestCommon -//import com.kakao.s2graph.core.types2._ -//import org.apache.hadoop.hbase.util.Bytes -//import org.scalatest.{Matchers, FunSuite} -// -///** -// * Created by shon on 5/29/15. -// */ -//class VertexTypeTest extends FunSuite with Matchers with TestCommon { -// -// -// import HBaseType.{VERSION2, VERSION1} -// val skipHashBytes = true -//// -//// def functions = { -//// for { -//// version <- List(VERSION1, VERSION2) -//// } yield { -//// val serializer = (idxProps: Seq[(Byte, InnerValLike)], innerVal: InnerValLike) => -//// VertexRowKey(VertexId(testColumnId, innerVal))(version) -//// val deserializer = (bytes: Array[Byte]) => VertexRowKey.fromBytes(bytes, 0, bytes.length, version) -//// (serializer, deserializer, version) -//// } -//// } -// -// test("test vertex row key order with int id type version 1") { -// val serializer = (idxProps: Seq[(Byte, InnerValLike)], innerVal: InnerValLike) => -// VertexRowKey(VertexId(testColumnId, innerVal))(VERSION1) -// val deserializer = (bytes: Array[Byte]) => VertexRowKey.fromBytes(bytes, 0, bytes.length, VERSION1) -// testOrder(idxPropsLs, intInnerVals, skipHashBytes)(serializer, deserializer) -// } -// test("test vertex row key order with int id type version 2") { -// val serializer = (idxProps: Seq[(Byte, InnerValLike)], innerVal: InnerValLike) => -// VertexRowKey(VertexId(testColumnId, innerVal))(VERSION2) -// val deserializer = (bytes: Array[Byte]) => VertexRowKey.fromBytes(bytes, 0, bytes.length, VERSION2) -// testOrder(idxPropsLsV2, intInnerValsV2, skipHashBytes)(serializer, deserializer) -// } -// -// -//}
