Created
February 26, 2020 15:39
-
-
Save unludo/299ddd977fb92699c233529877e97565 to your computer and use it in GitHub Desktop.
bidir stream example for gatling-grpc - below 0.8 version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def connect(productIdFieldName: String, token: String, checkLicenseUpdate:Boolean = false): GrpcCallActionBuilder[ProductConnectionReq, ProductStrmgMessage] = { | |
| val dT = Calendar.getInstance() | |
| grpc("connectReq") | |
| .service(ProductServiceGrpc.stub) | |
| .rpc(service => { req: ProductConnectionReq => | |
| val p = Promise[ProductStrmgMessage]() | |
| val requestObserver = service.connect( | |
| new ClientResponseObserver[ProductConnectionReq, ProductStrmgMessage] { | |
| var requestStream: ClientCallStreamObserver[ProductConnectionReq] = _ | |
| override def beforeStart(requestStream: ClientCallStreamObserver[ProductConnectionReq]): Unit = { | |
| this.requestStream = requestStream | |
| } | |
| override def onNext(value: ProductStrmgMessage): Unit = { | |
| println(s"[${dT.getTime()}]==================================================>Next " + value.data.isLicenseUpdate) | |
| if (!checkLicenseUpdate) { | |
| p.trySuccess(value) | |
| } | |
| if(checkLicenseUpdate && value.data.isLicenseUpdate){ | |
| p.trySuccess(value) | |
| } | |
| } | |
| override def onError(throwable: Throwable): Unit = { | |
| if (p != null) { | |
| p.tryFailure(throwable) | |
| } | |
| } | |
| override def onCompleted(): Unit = { | |
| println(s"[${dT.getTime()}]==================>Completed!") | |
| } | |
| }) | |
| requestObserver.onNext(req) | |
| p.future | |
| })(ProductConnectionReq.defaultInstance.withLastpublicip("192.168.1.9")) | |
| .header(Metadata.Key.of("authorization", Metadata.ASCII_STRING_MARSHALLER))(token) | |
| .header(Metadata.Key.of("productId", Metadata.ASCII_STRING_MARSHALLER))($(productIdFieldName)) | |
| // called with this | |
| val hwIdFeeder = (1 to nbProducts).toStream.map(i => Map("hwid" -> ("perf" + i.toString))).toIterator | |
| val productsScenario = scenario("Products connect and disconnect after 1 minute") | |
| .feed(hwIdFeeder) | |
| .exec(ProductsServiceGrpc.connect("hwid", token)) | |
| // the grpc proto rpc method looks like this | |
| // rpc connect (stream ProductConnectionReq) returns (stream ProductStrmgMessage); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
verified server logs as well, seeing issue in gatling/client end only when "no data" received from serverStream
Below is the normal flow when everything goes okay