Fix MySql connection lost error
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/f249c3e0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/f249c3e0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/f249c3e0 Branch: refs/heads/feature/test_daewon Commit: f249c3e0bc1252be76c7e8852f1f44d4dbf4a9f1 Parents: e407707 Author: daewon <[email protected]> Authored: Mon Dec 28 12:05:24 2015 +0900 Committer: daewon <[email protected]> Committed: Mon Dec 28 12:05:24 2015 +0900 ---------------------------------------------------------------------- .../s2graph/core/TestCommonWithModels.scala | 81 +++++++++++--------- .../kakao/s2graph/core/models/ModelTest.scala | 14 ++-- .../s2graph/core/mysqls/ExperimentSpec.scala | 3 - .../hbase/AsynchbaseQueryBuilderTest.scala | 12 +-- 4 files changed, 60 insertions(+), 50 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/f249c3e0/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 index fca7dc0..d350ab4 100644 --- a/s2core/src/test/scala/com/kakao/s2graph/core/TestCommonWithModels.scala +++ b/s2core/src/test/scala/com/kakao/s2graph/core/TestCommonWithModels.scala @@ -2,23 +2,43 @@ package com.kakao.s2graph.core import com.kakao.s2graph.core.Management.JsonModel.{Index, Prop} import com.kakao.s2graph.core.mysqls._ +import org.scalatest.BeforeAndAfterAll +import scalikejdbc.AutoSession //import com.kakao.s2graph.core.models._ import com.kakao.s2graph.core.types.{InnerVal, LabelWithDirection} -import com.typesafe.config.ConfigFactory +import com.typesafe.config.{Config, ConfigFactory} import scala.concurrent.ExecutionContext -trait TestCommonWithModels { +trait TestCommonWithModels { import InnerVal._ import types.HBaseType._ - val config = ConfigFactory.load() + var graph: Graph = _ + var config: Config = _ + + def initTests() = { + config = ConfigFactory.load() + graph = new Graph(config)(ExecutionContext.Implicits.global) + + 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 zkQuorum = config.getString("hbase.zookeeper.quorum") val serviceName = "_test_service" val serviceNameV2 = "_test_service_v2" val columnName = "user_id" @@ -31,7 +51,6 @@ trait TestCommonWithModels { val tgtColumnType = "string" val tgtColumnTypeV2 = "string" - val cluster = config.getString("hbase.zookeeper.quorum") val hTableName = "_test_cases" val preSplitSize = 0 val labelName = "_test_label" @@ -54,29 +73,21 @@ trait TestCommonWithModels { val consistencyLevel = "strong" val hTableTTL = None - val graph = new Graph(config)(ExecutionContext.Implicits.global) - - def initTests() = { - deleteTestLabel() - deleteTestService() - - Thread.sleep(1000) - - createTestService() - createTestLabel() - } def createTestService() = { + implicit val session = AutoSession Management.createService(serviceName, cluster, hTableName, preSplitSize, hTableTTL = None, "gz") Management.createService(serviceNameV2, cluster, hTableName, preSplitSize, hTableTTL = None, "gz") } def deleteTestService() = { + implicit val session = AutoSession Management.deleteService(serviceName) Management.deleteService(serviceNameV2) } def deleteTestLabel() = { + implicit val session = AutoSession Management.deleteLabel(labelName) Management.deleteLabel(labelNameV2) Management.deleteLabel(undirectedLabelName) @@ -85,6 +96,7 @@ trait TestCommonWithModels { 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") @@ -98,31 +110,28 @@ trait TestCommonWithModels { isDirected = false, serviceName, testIdxProps, testProps, consistencyLevel, Some(hTableName), hTableTTL, VERSION2, false, "lg4") } - /** */ - initTests() - - lazy val service = Service.findByName(serviceName, useCache = false).get - lazy val serviceV2 = Service.findByName(serviceNameV2, useCache = false).get + def service = Service.findByName(serviceName, useCache = false).get + def serviceV2 = Service.findByName(serviceNameV2, useCache = false).get - lazy val column = ServiceColumn.find(service.id.get, columnName, useCache = false).get - lazy val columnV2 = ServiceColumn.find(serviceV2.id.get, columnNameV2, 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 - lazy val tgtColumn = ServiceColumn.find(service.id.get, tgtColumnName, useCache = false).get - lazy val tgtColumnV2 = ServiceColumn.find(serviceV2.id.get, tgtColumnNameV2, 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 - lazy val label = Label.findByName(labelName, useCache = false).get - lazy val labelV2 = Label.findByName(labelNameV2, useCache = false).get + def label = Label.findByName(labelName, useCache = false).get + def labelV2 = Label.findByName(labelNameV2, useCache = false).get - lazy val undirectedLabel = Label.findByName(undirectedLabelName, useCache = false).get - lazy val undirectedLabelV2 = Label.findByName(undirectedLabelNameV2, useCache = false).get + def undirectedLabel = Label.findByName(undirectedLabelName, useCache = false).get + def undirectedLabelV2 = Label.findByName(undirectedLabelNameV2, useCache = false).get - lazy val dir = GraphUtil.directions("out") - lazy val op = GraphUtil.operations("insert") - lazy val labelOrderSeq = LabelIndex.DefaultSeq + def dir = GraphUtil.directions("out") + def op = GraphUtil.operations("insert") + def labelOrderSeq = LabelIndex.DefaultSeq - lazy val labelWithDir = LabelWithDirection(label.id.get, dir) - lazy val labelWithDirV2 = LabelWithDirection(labelV2.id.get, dir) + def labelWithDir = LabelWithDirection(label.id.get, dir) + def labelWithDirV2 = LabelWithDirection(labelV2.id.get, dir) - lazy val queryParam = QueryParam(labelWithDir) - lazy val queryParamV2 = QueryParam(labelWithDirV2) + def queryParam = QueryParam(labelWithDir) + def queryParamV2 = QueryParam(labelWithDirV2) } http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/f249c3e0/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 index 478da12..7ca62e9 100644 --- a/s2core/src/test/scala/com/kakao/s2graph/core/models/ModelTest.scala +++ b/s2core/src/test/scala/com/kakao/s2graph/core/models/ModelTest.scala @@ -5,14 +5,18 @@ 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.{FunSuite, Matchers} +import org.scalatest.{BeforeAndAfterAll, Sequential, FunSuite, Matchers} import scala.concurrent.ExecutionContext -/** - * Created by shon on 5/12/15. - */ -class ModelTest extends FunSuite with Matchers with TestCommonWithModels { +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" http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/f249c3e0/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 index 2e8cb50..7a0b91c 100644 --- a/s2core/src/test/scala/com/kakao/s2graph/core/mysqls/ExperimentSpec.scala +++ b/s2core/src/test/scala/com/kakao/s2graph/core/mysqls/ExperimentSpec.scala @@ -6,9 +6,6 @@ import com.typesafe.config.ConfigFactory import org.scalatest.{BeforeAndAfterAll, FlatSpec, Matchers} import scalikejdbc._ -/** - * Created by hsleep on 2015. 11. 30.. - */ class ExperimentSpec extends FlatSpec with Matchers with BeforeAndAfterAll { val Ttl = 2 override def beforeAll(): Unit = { http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/f249c3e0/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 index b404559..9b876c0 100644 --- 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 @@ -1,14 +1,13 @@ 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.Implicits.global -/** - * Created by hsleep([email protected]) on 2015. 11. 9.. - */ +import scala.concurrent.ExecutionContext + class AsynchbaseQueryBuilderTest extends FunSuite with Matchers { val dummyRequests = { for { @@ -18,8 +17,9 @@ class AsynchbaseQueryBuilderTest extends FunSuite with Matchers { } } - val config = Graph.DefaultConfig - val graph = new Graph(config) + implicit val ec = ExecutionContext.Implicits.global + val config = ConfigFactory.load() + val graph = new Graph(config)(ec) val qb = new AsynchbaseQueryBuilder(graph.storage.asInstanceOf[AsynchbaseStorage])
