Skip to content

Commit 10521e4

Browse files
committed
set status of grpc health status manager
1 parent 04d65b5 commit 10521e4

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/main/scala/com/scalableminds/fossildb/FossilDBServer.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package com.scalableminds.fossildb
55

66
import com.scalableminds.fossildb.db.StoreManager
77
import com.scalableminds.fossildb.proto.fossildbapi.FossilDBGrpc
8-
import io.grpc.health.v1.HealthGrpc
8+
import io.grpc.health.v1.{HealthCheckResponse, HealthGrpc}
99
import com.typesafe.scalalogging.LazyLogging
1010
import io.grpc.Server
1111
import io.grpc.netty.NettyServerBuilder
@@ -24,6 +24,7 @@ class FossilDBServer(storeManager: StoreManager, port: Int, executionContext: Ex
2424
.addService(FossilDBGrpc.bindService(new FossilDBGrpcImpl(storeManager), executionContext))
2525
.addService(healthStatusManager.getHealthService())
2626
.build.start
27+
healthStatusManager.setStatus("", HealthCheckResponse.ServingStatus.SERVING)
2728
logger.info("Server started, listening on " + port)
2829
sys.addShutdownHook {
2930
logger.info("Shutting down gRPC server since JVM is shutting down")
@@ -36,6 +37,7 @@ class FossilDBServer(storeManager: StoreManager, port: Int, executionContext: Ex
3637
if (server != null) {
3738
server.shutdown()
3839
storeManager.close
40+
healthStatusManager.setStatus("", HealthCheckResponse.ServingStatus.NOT_SERVING)
3941
}
4042
}
4143

src/test/scala/com/scalableminds/fossildb/FossilDBSuite.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import java.nio.file.Paths
99
import com.google.protobuf.ByteString
1010
import com.scalableminds.fossildb.db.StoreManager
1111
import com.scalableminds.fossildb.proto.fossildbapi._
12+
import io.grpc.health.v1._
1213
import io.grpc.netty.NettyChannelBuilder
1314
import org.scalatest.{BeforeAndAfterEach, FlatSpec}
1415

@@ -21,7 +22,9 @@ class FossilDBSuite extends FlatSpec with BeforeAndAfterEach {
2122

2223
val port = 21505
2324
var serverOpt: Option[FossilDBServer] = None
24-
val client = FossilDBGrpc.blockingStub(NettyChannelBuilder.forAddress("127.0.0.1", port).maxInboundMessageSize(Int.MaxValue).usePlaintext(true).build)
25+
val channel = NettyChannelBuilder.forAddress("127.0.0.1", port).maxInboundMessageSize(Int.MaxValue).usePlaintext().build
26+
val client = FossilDBGrpc.blockingStub(channel)
27+
val healthClient = HealthGrpc.newBlockingStub(channel)
2528

2629
val collectionA = "collectionA"
2730
val collectionB = "collectionB"
@@ -65,6 +68,11 @@ class FossilDBSuite extends FlatSpec with BeforeAndAfterEach {
6568
assert(reply.success)
6669
}
6770

71+
"GRPC Standard Health Check" should "report SERVING" in {
72+
val reply = healthClient.check(HealthCheckRequest.getDefaultInstance())
73+
assert(reply.getStatus.toString == "SERVING")
74+
}
75+
6876
"Put" should "overwrite old value" in {
6977
client.put(PutRequest(collectionA, aKey, Some(0), testData1))
7078
client.put(PutRequest(collectionA, aKey, Some(0), testData2))

0 commit comments

Comments
 (0)