added protection for grpc head and grpc received blocks metric (#184)
This commit is contained in:
@@ -134,20 +134,23 @@ class EthereumGrpcUpstreamSpec extends Specification {
|
||||
|
||||
@Override
|
||||
void subscribeHead(Common.Chain request, StreamObserver<BlockchainOuterClass.ChainHead> responseObserver) {
|
||||
responseObserver.onNext(
|
||||
BlockchainOuterClass.ChainHead.newBuilder()
|
||||
.setBlockId(block1.hash.toHex().substring(2))
|
||||
.setHeight(block1.number)
|
||||
.setWeight(ByteString.copyFrom(block1.totalDifficulty.toByteArray()))
|
||||
.build()
|
||||
)
|
||||
responseObserver.onNext(
|
||||
BlockchainOuterClass.ChainHead.newBuilder()
|
||||
.setBlockId(block2.hash.toHex().substring(2))
|
||||
.setHeight(block2.number)
|
||||
.setWeight(ByteString.copyFrom(block2.totalDifficulty.toByteArray()))
|
||||
.build()
|
||||
)
|
||||
new Thread({
|
||||
responseObserver.onNext(
|
||||
BlockchainOuterClass.ChainHead.newBuilder()
|
||||
.setBlockId(block1.hash.toHex().substring(2))
|
||||
.setHeight(block1.number)
|
||||
.setWeight(ByteString.copyFrom(block1.totalDifficulty.toByteArray()))
|
||||
.build()
|
||||
)
|
||||
Thread.sleep(100)
|
||||
responseObserver.onNext(
|
||||
BlockchainOuterClass.ChainHead.newBuilder()
|
||||
.setBlockId(block2.hash.toHex().substring(2))
|
||||
.setHeight(block2.number)
|
||||
.setWeight(ByteString.copyFrom(block2.totalDifficulty.toByteArray()))
|
||||
.build()
|
||||
)
|
||||
}).start()
|
||||
}
|
||||
})
|
||||
def upstream = new EthereumGrpcUpstream("test", hash, UpstreamsConfig.UpstreamRole.PRIMARY, Chain.ETHEREUM, client, new JsonRpcGrpcClient(client, Chain.ETHEREUM, metrics), null, ChainsConfig.ChainConfig.default())
|
||||
|
||||
@@ -42,16 +42,20 @@ class GrpcHeadSpec extends Specification {
|
||||
responseObserver.onError(new IllegalStateException("Unsupported chain"))
|
||||
return
|
||||
}
|
||||
[10, 11, 12, 14].forEach { height ->
|
||||
new Thread({ [10, 11, 12, 14].forEach { height ->
|
||||
println("next: $height")
|
||||
responseObserver.onNext(
|
||||
BlockchainOuterClass.ChainHead.newBuilder()
|
||||
.setChain(request.type)
|
||||
.setBlockId(height.toString())
|
||||
.setHeight(height)
|
||||
.build()
|
||||
)
|
||||
Thread.sleep(100)
|
||||
Thread.sleep(500)
|
||||
}
|
||||
responseObserver.onCompleted()
|
||||
responseObserver.onCompleted()
|
||||
}).start()
|
||||
|
||||
}
|
||||
})
|
||||
def convert = { BlockchainOuterClass.ChainHead head ->
|
||||
@@ -88,32 +92,34 @@ class GrpcHeadSpec extends Specification {
|
||||
responseObserver.onError(new IllegalStateException("Unsupported chain"))
|
||||
return
|
||||
}
|
||||
phase++
|
||||
if (phase == 1) {
|
||||
responseObserver.onError(new RuntimeException("Phase 1 error"))
|
||||
} else if (phase == 2) {
|
||||
[10, 11].forEach { height ->
|
||||
responseObserver.onNext(
|
||||
BlockchainOuterClass.ChainHead.newBuilder()
|
||||
.setChain(request.type)
|
||||
.setHeight(height)
|
||||
.build()
|
||||
)
|
||||
Thread.sleep(100)
|
||||
new Thread({
|
||||
phase++
|
||||
if (phase == 1) {
|
||||
responseObserver.onError(new RuntimeException("Phase 1 error"))
|
||||
} else if (phase == 2) {
|
||||
[10, 11].forEach { height ->
|
||||
responseObserver.onNext(
|
||||
BlockchainOuterClass.ChainHead.newBuilder()
|
||||
.setChain(request.type)
|
||||
.setHeight(height)
|
||||
.build()
|
||||
)
|
||||
Thread.sleep(100)
|
||||
}
|
||||
responseObserver.onError(new RuntimeException("Phase 2 error"))
|
||||
} else if (phase == 3) {
|
||||
[11, 12, 13].forEach { height ->
|
||||
responseObserver.onNext(
|
||||
BlockchainOuterClass.ChainHead.newBuilder()
|
||||
.setChain(request.type)
|
||||
.setHeight(height)
|
||||
.build()
|
||||
)
|
||||
Thread.sleep(100)
|
||||
}
|
||||
responseObserver.onCompleted()
|
||||
}
|
||||
responseObserver.onError(new RuntimeException("Phase 2 error"))
|
||||
} else if (phase == 3) {
|
||||
[11, 12, 13].forEach { height ->
|
||||
responseObserver.onNext(
|
||||
BlockchainOuterClass.ChainHead.newBuilder()
|
||||
.setChain(request.type)
|
||||
.setHeight(height)
|
||||
.build()
|
||||
)
|
||||
Thread.sleep(100)
|
||||
}
|
||||
responseObserver.onCompleted()
|
||||
}
|
||||
}).start()
|
||||
}
|
||||
})
|
||||
def convert = { BlockchainOuterClass.ChainHead head ->
|
||||
|
||||
Reference in New Issue
Block a user