Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To add support for GRPC protocol #412

Closed
JuhiAgr opened this issue Jun 5, 2018 · 23 comments
Closed

To add support for GRPC protocol #412

JuhiAgr opened this issue Jun 5, 2018 · 23 comments
Assignees
Labels

Comments

@JuhiAgr
Copy link

JuhiAgr commented Jun 5, 2018

It will help us to automate the messaging services which are written on https://grpc.io/blog/pubsub

@ptrthomas ptrthomas self-assigned this Jun 5, 2018
@ptrthomas
Copy link
Member

I'll leave this open for a while - but in my opinion you can do this today. You need to write 2 utilities. One to convert payloads to JSON and vice-versa and another to listen for async messages, maybe using polling. you can use the netty example as a reference: https://github.com/intuit/karate/tree/master/karate-netty#consumer-provider-example

and then you will be up and running. I suggest you do that and report back and then if it makes sense we can roll the above utilities into Karate or make them a separate maven module

since you are the first who has asked for this, I don't consider this a priority just yet.

@avyasbms
Copy link

avyasbms commented Jun 6, 2018

I might also be in a position to test this and share findings.

Since majority of our APIs are using karate, I was quite Interested in covering few other systems to move towards internals verifications with

@ptrthomas
Copy link
Member

@avyasbms not sure if we are on the same page here. maybe you should read that number 398 a little more carefully.

@JuhiAgr I'm closing this issue. if anyone wants to submit a PR, you can refer to this.

@avyasbms
Copy link

avyasbms commented Jun 6, 2018

@ptrthomas I have gone through your comments on #398 , I am interested in having karate DSL extended to more underlying systems to verify other than APIs :) May be we will find a way.

As of now DB/APIs are straight forward and as per your example here I can now try gRPC as well.

@avyasbms
Copy link

A lot of our projects are going towards using gRPC and requests for gRPC is being requested more and more.
I am going to start experiment to check how karate can help here, any pointers would be appreciated.
Also since it is not a priority, I am checking on how can I contribute on this.
Can we reopen this?

@ptrthomas
Copy link
Member

it doesn't need to be re-opened. just submit a PR referencing this ticket. does that make sense ?

@avyasbms
Copy link

Okay!
Any initial thoughts on its implementation ?
Can Karate in its current state be used for gRPC in any manner ?

@ptrthomas
Copy link
Member

@avyasbms I made some comments above already hope that gets you started

@sauravkumar05
Copy link

@ptrthomas would appreciate an example for grpc if possible since our project is also going to use grpc now

@ptrthomas
Copy link
Member

@sauravkumar05 no I haven't used GRPC yet. and please read my first comment in this thread carefully.

@thinkerou
Copy link
Contributor

thinkerou commented Sep 12, 2018

Hi @ptrthomas I want to implement the topic, and my opinion like this:

Feature:
  Background:
  * url 'ip+port' # grpc ip and port
  Scenario:
  * def in = read('pb.json')
  * rpc 'rpc-service-name' # like path
  * request method grpc # like post/put
  * match response match {}

so, How should I extend karate or write middleware? (I should refer to what code?) thanks!

now I can solve the follow topic:

  • input json convert to pb
  • pb convert to output json (like response body)
  • method grpc like post or put
  • rpc like path

@ptrthomas
Copy link
Member

ptrthomas commented Sep 12, 2018

@thinkerou here is what I suggest you should do. there is no need to add a new keyword to karate. we want to keep it simple ! instead use Java and the code will look similar to what you have. which I think is fine. you can read my detailed comments here:
#398 (comment)

I was just seeing if it possible for me to add this demo to Karate but it is too complicated and needs some binary etc to be downloaded, sorry I don't have time. there are very few "hello world" samples. if you can create an example, I will be happy to add it to karate.

  1. write a Java helper to take JSON and call your gRPC end point e.g. AND return JSON Rpc.invoke('service-name', Map)

That's all ! Then you will use all of Karate EXCEPT the HTTP part. Which is fine. 90% of what you need Karate for is test data and assertions.

Feature:

Background:
* def Rpc = Java.type('com.mycompany.Rpc')
* def config = { host: 'myhost', port: 9000, extra: 'blah' }
# constructor takes a java Map
* def rpc = new Rpc(config)

  Scenario:
  * def payload = read('pb.json')
  * def response = rpc.invoke('rpc-service-name', payload)
  * match response == { expected: 'foo' }

@thinkerou
Copy link
Contributor

@ptrthomas thanks, I will write some code and if they run ok after I will post one helloworld example and commit one pull request.

@ptrthomas
Copy link
Member

@thinkerou sure. one more thing. not many people know that karate can convert JSON to a Java Bean and vice versa. so in case it it useful, please see this example: https://github.com/intuit/karate/blob/master/karate-junit4/src/test/java/com/intuit/karate/junit4/demos/type-conv.feature#L122

@thinkerou
Copy link
Contributor

thinkerou commented Sep 17, 2018

@ptrthomas thanks a lot, I have one helloworld example please see https://github.com/thinkerou/karate-grpc/tree/master/karate-grpc-demo/src/test/java/demo/helloworld
maybe you can add example. and it not need to pojo convert json.
Because I need to support more protobuf object so I create one repo.

@ptrthomas
Copy link
Member

@thinkerou excellent ! this is exactly what I had in mind. and I will refer other users to your example. I will also add a link in the documentation. please continue on the same lines.

one suggestion for improvement is if you try print to the log, it should appear in the HTML report. maybe this is not needed, but something to think about.

@avyasbms
Copy link

avyasbms commented Sep 17, 2018 via email

@thinkerou
Copy link
Contributor

@ptrthomas ok, thanks!

@ptrthomas
Copy link
Member

@thinkerou do you have a Twitter ID ?

@ptrthomas
Copy link
Member

sorry for the spam - if anyone on this thread is interested, this Quora question needs an answer ;)

https://www.quora.com/How-do-I-test-GRPC-services-I-am-looking-for-an-API-framework-to-use-for-testing-that-is-scalable

@thinkerou
Copy link
Contributor

@ptrthomas Twitter ID also is thinkerou. and I will reply the question later.

@ptrthomas
Copy link
Member

@thinkerou you are so gonna love this ! https://twitter.com/KarateDSL/status/1042055022052179968

I got the idea after seeing your example.

@thinkerou
Copy link
Contributor

thinkerou commented Sep 19, 2018

@ptrthomas this will very useful which will perfect to combine auto test with perf test. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants