Skip to content

Commit

Permalink
remove get method prefix
Browse files Browse the repository at this point in the history
fix test
  • Loading branch information
jxnu-liguobin committed Sep 8, 2023
1 parent b3e6df7 commit 9ed9221
Show file tree
Hide file tree
Showing 19 changed files with 129 additions and 123 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
52 changes: 26 additions & 26 deletions core/src/main/scala/zio/nebula/NebulaResultSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,61 +15,61 @@ import com.vesoft.nebula.graph.PlanDescription
* 梦境迷离
* @version 1.0,2023/8/29
*/
final class NebulaResultSet(resultSet: ResultSet) {
final class NebulaResultSet(underlying: ResultSet) {

import NebulaResultSet._

def isSucceeded: Boolean = resultSet.isSucceeded
def isSucceeded: Boolean = underlying.isSucceeded

def isEmpty: Boolean = resultSet.isEmpty
def isEmpty: Boolean = underlying.isEmpty

def errorCode: Int = resultSet.getErrorCode
def errorCode: Int = underlying.getErrorCode

def spaceName: String = resultSet.getSpaceName
def spaceName: String = underlying.getSpaceName

def errorMessage: String = resultSet.getErrorMessage
def errorMessage: String = underlying.getErrorMessage

def comment: String = resultSet.getComment
def comment: String = underlying.getComment

def latency: Long = resultSet.getLatency
def latency: Long = underlying.getLatency

def planDesc: PlanDescription = resultSet.getPlanDesc
def planDesc: PlanDescription = underlying.getPlanDesc

def keys: List[String] = resultSet.getColumnNames.asScala.toList
def keys: List[String] = underlying.getColumnNames.asScala.toList

def columnNames: List[String] = resultSet.getColumnNames.asScala.toList
def columnNames: List[String] = underlying.getColumnNames.asScala.toList

def rowsSize: Int = resultSet.rowsSize()
def rowsSize: Int = underlying.rowsSize()

def rowValues(index: Int): NebulaRecord = new NebulaRecord(resultSet.rowValues(index))
def rowValues(index: Int): NebulaRecord = new NebulaRecord(underlying.rowValues(index))

def colValues(columnName: String): List[ValueWrapper] = resultSet.colValues(columnName).asScala.toList
def colValues(columnName: String): List[ValueWrapper] = underlying.colValues(columnName).asScala.toList

def rows: List[Row] = resultSet.getRows.asScala.toList
def rows: List[Row] = underlying.getRows.asScala.toList

override def toString: String = resultSet.toString
override def toString: String = underlying.toString
}

object NebulaResultSet {

final class NebulaRecord(record: Record) extends Iterable[ValueWrapper] {
final class NebulaRecord(private val underlying: Record) extends Iterable[ValueWrapper] {

override def iterator: Iterator[ValueWrapper] = record.iterator().asScala
override def iterator: Iterator[ValueWrapper] = underlying.iterator().asScala

override def foreach[U](f: ValueWrapper => U): Unit = record.forEach((t: ValueWrapper) => f.apply(t))
override def foreach[U](f: ValueWrapper => U): Unit = underlying.forEach((t: ValueWrapper) => f.apply(t))

override def toString(): String = record.toString
override def toString(): String = underlying.toString

def spliterator: Spliterator[ValueWrapper] = record.spliterator
def spliterator: Spliterator[ValueWrapper] = underlying.spliterator

def get(index: Int): ValueWrapper = record.get(index)
def get(index: Int): ValueWrapper = underlying.get(index)

def get(columnName: String): ValueWrapper = record.get(columnName)
def get(columnName: String): ValueWrapper = underlying.get(columnName)

def values: util.List[ValueWrapper] = record.values()
def values: util.List[ValueWrapper] = underlying.values()

override def size: Int = record.size()
override def size: Int = underlying.size()

def contains(columnName: String): Boolean = record.contains(columnName)
def contains(columnName: String): Boolean = underlying.contains(columnName)
}
}
4 changes: 2 additions & 2 deletions core/src/main/scala/zio/nebula/NebulaSessionClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ trait NebulaSessionClient {
/**
* get the number of all Session
*/
def getSessionNums: Task[Int]
def sessionNum: Task[Int]

/**
* get the number of idle Session
*/
def getIdleSessionNums: Task[Int]
def idleSessionNum: Task[Int]
}

object NebulaSessionClient {
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/zio/nebula/NebulaSessionClientLive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ private[nebula] final class NebulaSessionClientLive(underlying: SessionPool) ext
override def execute(stmt: String): Task[NebulaResultSet] =
ZIO.attempt(new NebulaResultSet(underlying.execute(stmt)))

override def getIdleSessionNums: Task[Int] = ZIO.attempt(underlying.getIdleSessionNums)
override def idleSessionNum: Task[Int] = ZIO.attempt(underlying.getIdleSessionNums)

override def getSessionNums: Task[Int] = ZIO.attempt(underlying.getSessionNums)
override def sessionNum: Task[Int] = ZIO.attempt(underlying.getSessionNums)

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

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

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())

}
16 changes: 8 additions & 8 deletions core/src/main/scala/zio/nebula/meta/NebulaMetaClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ trait NebulaMetaClient {

def close(): Task[Unit]

def getSpaceId(spaceName: String): Task[Int]
def spaceId(spaceName: String): Task[Int]

def getSpace(spaceName: String): Task[SpaceItem]
def space(spaceName: String): Task[SpaceItem]

def getTagId(spaceName: String, tagName: String): Task[Int]
def tagId(spaceName: String, tagName: String): Task[Int]

def getTag(spaceName: String, tagName: String): Task[TagItem]
def tag(spaceName: String, tagName: String): Task[TagItem]

def getEdgeType(spaceName: String, edgeName: String): Task[Int]
def edgeType(spaceName: String, edgeName: String): Task[Int]

def getLeader(spaceName: String, part: Int): Task[NebulaHostAddress]
def leader(spaceName: String, part: Int): Task[NebulaHostAddress]

def getSpaceParts(spaceName: String): Task[List[Int]]
def spaceParts(spaceName: String): Task[List[Int]]

def getPartsAlloc(spaceName: String): Task[Map[Int, List[NebulaHostAddress]]]
def partsAlloc(spaceName: String): Task[Map[Int, List[NebulaHostAddress]]]

def listHosts: Task[Set[NebulaHostAddress]]
}
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/scala/zio/nebula/meta/NebulaMetaClientLive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ private[nebula] final class NebulaMetaClientLive(underlying: MetaManager) extend

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

override def getSpaceId(spaceName: String): Task[Int] = ZIO.attempt(underlying.getSpaceId(spaceName))
override def spaceId(spaceName: String): Task[Int] = ZIO.attempt(underlying.getSpaceId(spaceName))

override def getSpace(spaceName: String): Task[SpaceItem] = ZIO.attempt(underlying.getSpace(spaceName))
override def space(spaceName: String): Task[SpaceItem] = ZIO.attempt(underlying.getSpace(spaceName))

override def getTagId(spaceName: String, tagName: String): Task[Int] =
override def tagId(spaceName: String, tagName: String): Task[Int] =
ZIO.attempt(underlying.getTagId(spaceName, tagName))

override def getTag(spaceName: String, tagName: String): Task[TagItem] =
override def tag(spaceName: String, tagName: String): Task[TagItem] =
ZIO.attempt(underlying.getTag(spaceName, tagName))

override def getEdgeType(spaceName: String, edgeName: String): Task[Int] =
override def edgeType(spaceName: String, edgeName: String): Task[Int] =
ZIO.attempt(underlying.getEdgeType(spaceName, edgeName))

override def getLeader(spaceName: String, part: Int): Task[NebulaHostAddress] =
override def leader(spaceName: String, part: Int): Task[NebulaHostAddress] =
ZIO.attempt(underlying.getLeader(spaceName, part)).map(h => NebulaHostAddress(h.getHost, h.getPort))

override def getSpaceParts(spaceName: String): Task[List[Int]] =
override def spaceParts(spaceName: String): Task[List[Int]] =
ZIO.attempt(
underlying
.getSpaceParts(spaceName)
Expand All @@ -44,7 +44,7 @@ private[nebula] final class NebulaMetaClientLive(underlying: MetaManager) extend
.toList
)

override def getPartsAlloc(spaceName: String): Task[Map[Int, List[NebulaHostAddress]]] =
override def partsAlloc(spaceName: String): Task[Map[Int, List[NebulaHostAddress]]] =
ZIO.attempt(
underlying
.getPartsAlloc(spaceName)
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/scala/zio/nebula/net/NebulaClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ trait NebulaClient {

def close(): Task[Unit]

def getSession: ZIO[Scope & NebulaSessionPoolConfig, Throwable, NebulaSession]
def openSession(): ZIO[Scope & NebulaSessionPoolConfig, Throwable, NebulaSession]

def getActiveConnNum: Task[Int]
def activeConnNum: Task[Int]

def getIdleConnNum: Task[Int]
def idleConnNum: Task[Int]

def getWaitersNum: Task[Int]
def waitersNum: Task[Int]

}

Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/zio/nebula/net/NebulaClientLive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ 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)
)
)
} yield status

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

def getSession: ZIO[Scope & NebulaSessionPoolConfig, Throwable, NebulaSession] =
def openSession(): ZIO[Scope & NebulaSessionPoolConfig, Throwable, NebulaSession] =
for {
sessionConfig <- ZIO.service[NebulaSessionPoolConfig]
session <-
Expand All @@ -47,10 +47,10 @@ private[nebula] final class NebulaClientLive(underlying: NebulaPl) extends Nebul
)(_.close().onError(e => ZIO.logErrorCause(e)).ignoreLogged)
} yield session

def getActiveConnNum: Task[Int] = ZIO.attempt(underlying.getActiveConnNum)
def activeConnNum: Task[Int] = ZIO.attempt(underlying.getActiveConnNum)

def getIdleConnNum: Task[Int] = ZIO.attempt(underlying.getIdleConnNum)
def idleConnNum: Task[Int] = ZIO.attempt(underlying.getIdleConnNum)

def getWaitersNum: Task[Int] = ZIO.attempt(underlying.getWaitersNum)
def waitersNum: Task[Int] = ZIO.attempt(underlying.getWaitersNum)

}
8 changes: 4 additions & 4 deletions core/src/main/scala/zio/nebula/net/NebulaSession.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ final class NebulaSession(private val underlying: Session) {
}
}

def ping: Task[Boolean] = ZIO.attempt(underlying.ping())
def ping(): Task[Boolean] = ZIO.attempt(underlying.ping())

def pingSession: Task[Boolean] = ZIO.attempt(underlying.pingSession())
def pingSession(): Task[Boolean] = ZIO.attempt(underlying.pingSession())

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

def getGraphHost: Task[HostAddress] = ZIO.attempt(underlying.getGraphHost)
def graphHost: Task[HostAddress] = ZIO.attempt(underlying.getGraphHost)

def getSessionID: Task[Long] = ZIO.attempt(underlying.getSessionID)
def sessionID: Task[Long] = ZIO.attempt(underlying.getSessionID)

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

Expand Down
Loading

0 comments on commit 9ed9221

Please sign in to comment.