Skip to content

Commit

Permalink
update README.md, bump to scala 3.3.1
Browse files Browse the repository at this point in the history
fix test
  • Loading branch information
jxnu-liguobin committed Sep 8, 2023
1 parent 1886b32 commit df17098
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ target/
data/
logs/
.idea/
.bsp/
.bsp/
sdap.sbt
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ Support Scala 3, Scala 2.13 and Scala 2.12:
libraryDependencies += "io.github.jxnu-liguobin" %% "zio-nebula" % <latest version>
```

## Environment
## Version


There are the version correspondence between zio-nebula and nebula-java:

| zio | zio-nebula | nebula-java |
|:-----:|:----------:|:-----------:|
| 2.0.x | 0.0.x | 3.6.0 |

- zio 2.0.13
- nebula-java 3.6.0

## Example

Expand Down
23 changes: 16 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ val zioVersion = "2.0.13"
val scala3_Version = "3.2.2"
val scala2_13Version = "2.13.10"
val scala2_12Version = "2.12.16"
val zioConfigVersion = "4.0.0-RC16"
val zioConfigVersion = "4.0.0-RC16" // 3.3.0+ not support
val nebulaClientVersion = "3.6.0"
val logbackVersion = "1.4.5"

Expand All @@ -29,20 +29,26 @@ inThisBuild(
addCommandAlias("fmt", "all scalafmtSbt scalafmt test:scalafmt")
addCommandAlias("check", "all scalafmtSbtCheck scalafmtCheck test:scalafmtCheck")

val _zioTests = Seq(
"dev.zio" %% "zio-test-magnolia" % zioVersion,
"dev.zio" %% "zio-test" % zioVersion,
"dev.zio" %% "zio-test-sbt" % zioVersion
)

lazy val core = project
.in(file("core"))
.settings(
name := "zio-nebula",
crossScalaVersions := supportCrossVersionList,
name := "zio-nebula",
crossScalaVersions := supportCrossVersionList,
libraryDependencies ++= Seq(
"com.vesoft" % "client" % nebulaClientVersion,
"dev.zio" %% "zio-config-typesafe" % zioConfigVersion,
"dev.zio" %% "zio-config-magnolia" % zioConfigVersion,
"dev.zio" %% "zio" % zioVersion,
"dev.zio" %% "zio-test" % zioVersion % Test,
"ch.qos.logback" % "logback-classic" % logbackVersion % Test
),
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
) ++ _zioTests.map(_ % Test),
Test / parallelExecution := false,
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")
)

lazy val examples = project
Expand All @@ -59,7 +65,10 @@ lazy val examples = project
lazy val `zio-nebula` = project
.in(file("."))
.settings(
publish / skip := true
crossScalaVersions := Nil,
publish / skip := true,
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"),
libraryDependencies ++= _zioTests.map(_ % Test)
)
.aggregate(
core,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ private[nebula] final class NebulaSessionClientLive(underlying: SessionPool) ext

override def close(): Task[Unit] = ZIO.attempt(underlying.close())

override def init(): Task[Boolean] = ZIO.attemptBlocking(underlying.init())
override def init(): Task[Boolean] = ZIO.attempt(underlying.init())

}
2 changes: 1 addition & 1 deletion core/src/main/scala/zio/nebula/net/NebulaClientLive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private[nebula] final class NebulaClientLive(underlying: NebulaPl) extends Nebul
config <- ZIO.service[NebulaPoolConfig]
status <-
ZIO.serviceWithZIO[NebulaSessionPoolConfig](sessionConfig =>
ZIO.attemptBlocking(
ZIO.attempt(
underlying.init(sessionConfig.address.map(d => new HostAddress(d.host, d.port)).asJava, config.toJava)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private[nebula] final class NebulaStorageClientLive(underlying: StorageClient) e

import NebulaStorageClientLive._

override def connect(): Task[Boolean] = ZIO.attemptBlocking(underlying.connect())
override def connect(): Task[Boolean] = ZIO.attempt(underlying.connect())

override def close(): Task[Unit] = ZIO.attempt(underlying.close())

Expand Down
37 changes: 11 additions & 26 deletions core/src/test/scala/zio/nebula/NebulaClientSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package zio.nebula

import zio.ZIO
import zio.nebula.meta.NebulaMetaClient
import zio.nebula.net.{ NebulaClient, Stmt, StringStmt }
import zio.nebula.net.{ NebulaClient, Stmt }
import zio.nebula.storage.{ NebulaStorageClient, ScanEdge }
import zio.test._

Expand All @@ -13,16 +13,6 @@ import zio.test._
*/
object NebulaClientSpec extends NebulaSpec {

private def init(space: String): StringStmt =
Stmt.str(
s"""
|CREATE SPACE IF NOT EXISTS $space(vid_type=fixed_string(20));
|USE $space;
|CREATE TAG IF NOT EXISTS person(name string, age int);
|CREATE EDGE IF NOT EXISTS like(likeness double)
|""".stripMargin
)

val insertVertexes =
"""
|INSERT VERTEX person(name, age) VALUES
Expand All @@ -42,7 +32,6 @@ object NebulaClientSpec extends NebulaSpec {

val query =
"""
|USE test;
|MATCH (p:person) RETURN p LIMIT 4;
|""".stripMargin

Expand All @@ -51,6 +40,8 @@ object NebulaClientSpec extends NebulaSpec {
suite("nebula session pool")(
test("create and query") {
for {
init <- ZIO.serviceWithZIO[NebulaSessionClient](_.init())
_ <- ZIO.logInfo(s"init session: $init")
res1 <- ZIO.serviceWithZIO[NebulaSessionClient](_.execute(insertVertexes))
_ <- ZIO.logInfo(s"exec insert vertex: ${res1.errorMessage}")
res2 <- ZIO.serviceWithZIO[NebulaSessionClient](_.execute(insertEdges))
Expand All @@ -63,29 +54,23 @@ object NebulaClientSpec extends NebulaSpec {
suite("nebula meta manager")(
test("query") {
for {
initStatus <- ZIO.serviceWithZIO[NebulaClient](_.openSession().flatMap(_.execute(init("test_meta"))))
_ <- ZIO.logInfo(s"init stmt: ${initStatus.errorMessage}")
spaceItem <- ZIO.serviceWithZIO[NebulaMetaClient](_.space("test_meta"))
_ <- ZIO.logInfo(s"get space: ${spaceItem.toString}")
spaceId <- ZIO.serviceWithZIO[NebulaMetaClient](_.spaceId("test_meta"))
_ <- ZIO.logInfo(s"get space id: ${spaceId.toString}")
spaceItem <- ZIO.serviceWithZIO[NebulaMetaClient](_.space("test"))
_ <- ZIO.logInfo(s"get space: ${spaceItem.toString}")
spaceId <- ZIO.serviceWithZIO[NebulaMetaClient](_.spaceId("test"))
_ <- ZIO.logInfo(s"get space id: ${spaceId.toString}")
} yield assertTrue(spaceItem != null && spaceId > 0)
}
),
suite("nebula storage client")(
test("query") {
for {
initStatus <- ZIO.serviceWithZIO[NebulaClient](_.openSession().flatMap(_.execute(init("test_storage"))))
_ <- ZIO.logInfo(s"init stmt: ${initStatus.errorMessage}")
status <- ZIO.serviceWithZIO[NebulaStorageClient](
_.connect()
)
status <- ZIO.serviceWithZIO[NebulaStorageClient](_.connect())
_ <- ZIO.logInfo(s"connect status: ${status.toString}")
scanResult <- ZIO.serviceWithZIO[NebulaStorageClient](
_.scan(ScanEdge("test_storage", None, "likeness", None))
_.scan(ScanEdge("test", None, "like", None))
)
_ <- ZIO.logInfo(s"scan result: ${scanResult.next().toString}")
} yield assertTrue(scanResult != null)
_ <- ZIO.logInfo(s"scan result: $scanResult")
} yield assertTrue(scanResult.hasNext)
}
)
)
Expand Down
15 changes: 11 additions & 4 deletions core/src/test/scala/zio/nebula/NebulaSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ trait NebulaSpec extends ZIOSpecDefault {

type Nebula = Client with SessionClient with Storage with Meta with Scope

override def aspects: Chunk[TestAspectAtLeastR[TestEnvironment]] =
Chunk(TestAspect.fibers, TestAspect.timeout(180.seconds))

override def spec =
(specLayered @@ beforeAll(
ZIO.serviceWithZIO[NebulaClient](_.init())
*> ZIO.serviceWithZIO[NebulaClient](
_.openSession().flatMap(_.execute(Stmt.str("CREATE SPACE IF NOT EXISTS test(vid_type=fixed_string(20));")))
) *>
ZIO.serviceWithZIO[NebulaSessionClient](_.init())
) @@ sequential)
_.openSession().flatMap(_.execute(Stmt.str("""
|CREATE SPACE IF NOT EXISTS test(vid_type=fixed_string(20));
|USE test;
|CREATE TAG IF NOT EXISTS person(name string, age int);
|CREATE EDGE IF NOT EXISTS like(likeness double)
|""".stripMargin)))
)
) @@ sequential @@ eventually)
.provideShared(
Scope.default,
MetaEnv,
Expand Down
3 changes: 1 addition & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10")

addDependencyTreePlugin
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.8")

0 comments on commit df17098

Please sign in to comment.