Skip to content

Commit

Permalink
Merge branch 'master' into rocksdb-configfile
Browse files Browse the repository at this point in the history
  • Loading branch information
fm3 authored May 22, 2018
2 parents bff1e92 + 20803a4 commit dc19df0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
5 changes: 3 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % "1.2.3",
"com.typesafe.scala-logging" %% "scala-logging" % "3.7.2",
"org.scalatest" % "scalatest_2.12" % "3.0.4" % "test",
"io.grpc" % "grpc-netty" % com.trueaccord.scalapb.compiler.Version.grpcJavaVersion,
"com.trueaccord.scalapb" %% "scalapb-runtime-grpc" % com.trueaccord.scalapb.compiler.Version.scalapbVersion,
"io.grpc" % "grpc-netty" % scalapb.compiler.Version.grpcJavaVersion,
"io.grpc" % "grpc-services" % scalapb.compiler.Version.grpcJavaVersion,
"com.thesamet.scalapb" %% "scalapb-runtime-grpc" % scalapb.compiler.Version.scalapbVersion,
"org.rocksdb" % "rocksdbjni" % "5.11.3",
"com.github.scopt" %% "scopt" % "3.7.0"
)
Expand Down
4 changes: 2 additions & 2 deletions project/scalapb.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.12")
addSbtPlugin("com.thesamet" % "sbt-protoc" % "0.99.18")

libraryDependencies += "com.trueaccord.scalapb" %% "compilerplugin" % "0.6.6"
libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.7.4"
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import com.typesafe.scalalogging.LazyLogging

import scala.concurrent.Future

class FossilDBGrpcImpl(storeManager: StoreManager) extends FossilDBGrpc.FossilDB with LazyLogging {
class FossilDBGrpcImpl(storeManager: StoreManager)
extends FossilDBGrpc.FossilDB
with LazyLogging {

override def health(req: HealthRequest) = withExceptionHandler(req) {
HealthReply(true)
Expand Down
11 changes: 10 additions & 1 deletion src/main/scala/com/scalableminds/fossildb/FossilDBServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,26 @@ package com.scalableminds.fossildb

import com.scalableminds.fossildb.db.StoreManager
import com.scalableminds.fossildb.proto.fossildbapi.FossilDBGrpc
import io.grpc.health.v1.HealthCheckResponse
import com.typesafe.scalalogging.LazyLogging
import io.grpc.Server
import io.grpc.netty.NettyServerBuilder
import io.grpc.services.HealthStatusManager

import scala.concurrent.ExecutionContext

class FossilDBServer(storeManager: StoreManager, port: Int, executionContext: ExecutionContext) extends LazyLogging
{ self =>
private[this] var server: Server = null
private[this] var healthStatusManager: HealthStatusManager = null

def start(): Unit = {
server = NettyServerBuilder.forPort(port).maxMessageSize(Int.MaxValue).addService(FossilDBGrpc.bindService(new FossilDBGrpcImpl(storeManager), executionContext)).build.start
healthStatusManager = new HealthStatusManager()
server = NettyServerBuilder.forPort(port).maxMessageSize(Int.MaxValue)
.addService(FossilDBGrpc.bindService(new FossilDBGrpcImpl(storeManager), executionContext))
.addService(healthStatusManager.getHealthService())
.build.start
healthStatusManager.setStatus("", HealthCheckResponse.ServingStatus.SERVING)
logger.info("Server started, listening on " + port)
sys.addShutdownHook {
logger.info("Shutting down gRPC server since JVM is shutting down")
Expand All @@ -29,6 +37,7 @@ class FossilDBServer(storeManager: StoreManager, port: Int, executionContext: Ex
if (server != null) {
server.shutdown()
storeManager.close
healthStatusManager.setStatus("", HealthCheckResponse.ServingStatus.NOT_SERVING)
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/test/scala/com/scalableminds/fossildb/FossilDBSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import java.nio.file.Paths
import com.google.protobuf.ByteString
import com.scalableminds.fossildb.db.StoreManager
import com.scalableminds.fossildb.proto.fossildbapi._
import io.grpc.health.v1._
import io.grpc.netty.NettyChannelBuilder
import org.scalatest.{BeforeAndAfterEach, FlatSpec}

Expand All @@ -21,7 +22,9 @@ class FossilDBSuite extends FlatSpec with BeforeAndAfterEach with TestHelpers {

val port = 21505
var serverOpt: Option[FossilDBServer] = None
val client = FossilDBGrpc.blockingStub(NettyChannelBuilder.forAddress("127.0.0.1", port).maxInboundMessageSize(Int.MaxValue).usePlaintext(true).build)
val channel = NettyChannelBuilder.forAddress("127.0.0.1", port).maxInboundMessageSize(Int.MaxValue).usePlaintext().build
val client = FossilDBGrpc.blockingStub(channel)
val healthClient = HealthGrpc.newBlockingStub(channel)

val collectionA = "collectionA"
val collectionB = "collectionB"
Expand Down Expand Up @@ -58,6 +61,11 @@ class FossilDBSuite extends FlatSpec with BeforeAndAfterEach with TestHelpers {
assert(reply.success)
}

"GRPC Standard Health Check" should "report SERVING" in {
val reply = healthClient.check(HealthCheckRequest.getDefaultInstance())
assert(reply.getStatus.toString == "SERVING")
}

"Put" should "overwrite old value" in {
client.put(PutRequest(collectionA, aKey, Some(0), testData1))
client.put(PutRequest(collectionA, aKey, Some(0), testData2))
Expand Down

0 comments on commit dc19df0

Please sign in to comment.