feat: getGrpcClient in integration TestKit, #568#606
Conversation
|
I haven't updated Scala samples yet because waiting for #592 to be merged first |
Now merged! |
|
thanks, then I'll continue |
| | * Use the generated gRPC client to call the service through the Akka Serverless proxy. | ||
| | */ | ||
| | private final ${serviceName}Client client; | ||
| | private final $serviceName client; |
There was a problem hiding this comment.
OK, so we lose the information that this is a client, which I think means we lose access to the 'power api' for the client - seems like a bit of a shame but perhaps was tricky to do otherwise?
There was a problem hiding this comment.
That is what we have for the client from the Context too. It was intentionally done like that because we thought too much "power" shouldn't leak to the users. If you see a use case where the client is needed you can create an issue about it (maybe we can support both and detect what kind of class that is passed in).
There was a problem hiding this comment.
One use case would be to pass metadata/headers I think.
| | public ${testClassName}() { | ||
| | client = ${serviceName}Client.create(testKit.getGrpcClientSettings(), testKit.getActorSystem()); | ||
| | public $testClassName() { | ||
| | client = testKit.getGrpcClient($serviceName.class, "$serviceName"); |
There was a problem hiding this comment.
Is it intentional to have both the class and the service name here? It looks like the 'serviceName' is passed in to find the 'right' implementation of this API from the config, which could be either an external (intra-service) one or the implementation in 'this' service. Since we always want to test the local implementation, perhaps it would be nice if we could have a getGrpcClient method that infers the 'local' service name, instead of requiring it here?
There was a problem hiding this comment.
While ${serviceName}Client.create(testKit.getGrpcClientSettings(), testKit.getActorSystem()); was rather verbose, I did like the "no tricks up our sleeve" aspect of it. What advantage does getGrpcClient have here? Caching the clients I think?
There was a problem hiding this comment.
The intention is to have the same API from integration tests as they are "used to" from the ActionContext.
For IntegrationTest the service name is not used. I can try to remove it from the testkit.
Since we always want to test the local implementation
Well, I was actually thinking that it could be possible to test a remote service in the same way (with different config), but that is maybe too advanced.
There was a problem hiding this comment.
I have removed the serviceName parameter, in TestKit
| private final CustomerService client; | ||
|
|
||
| public CustomerEntityIntegrationTest() { | ||
| client = CustomerServiceClient.create(testkit.getGrpcClientSettings(), testkit.getActorSystem()); | ||
| client = testKit.getGrpcClient(CustomerService.class, "CustomerService"); |
There was a problem hiding this comment.
I didn't think about this before, but since this method is not returning a client, but the service trait, maybe a more intuitive name would be: getService or serviceInstance.
The fact that is a gRPC client becomes irrelevant. I just want an implementation of CustomerService that will magically do the trick for me.
Sure, the users will get the sense that this is a client calling some remote API, but we may want to reserve that name (ie getGrpcClient) to use for the power API. In that case, we make it more explicitly that what is returned is an akka grpc client. WDYT?
There was a problem hiding this comment.
For the record: In the main sources it is called getGrpcClient since it is also a way to re-use/manage lifecycle of any gRPC client you'd want to use, also for a non akkasls service somewhere.
fb40195 to
b8eb5eb
Compare
| client.increase(IncreaseValue(counterId, 42)).flatMap { _ => | ||
| client.decrease(DecreaseValue(counterId, 32)) | ||
| )).futureValue | ||
| }.futureValue |
There was a problem hiding this comment.
@raboof I'm not sure we can guarantee the order from two such "current" client.increase calls (there could be many async boundaries on the way), so I change it to sequential
There was a problem hiding this comment.
I'm not sure we can guarantee the order from two such "current" client.increase calls
I agree we can't. I had assumed they'd end at 10 in whatever order they're applied though - though I'll admit I haven't checked, and perhaps that makes this a bad example :)
| @@ -16,8 +16,11 @@ | |||
|
|
|||
| package com.akkaserverless.scalasdk.testkit | |||
There was a problem hiding this comment.
@raboof this is the scalasdk AkkaServerlessTestKit changes if you would like to take a second look
59fb21f to
37d2b05
Compare
|
|
||
| override def materializer(): Materializer = Materializer(system) | ||
| override def materializer(): Materializer = | ||
| SystemMaterializer(system).materializer |
There was a problem hiding this comment.
@johanandren note this change. If I'm not mistaken Materializer.apply(system) creates a new Materializer?
There was a problem hiding this comment.
Ah, indeed, this is what was intended.
| javaClient.closed().asScala | ||
| case scalaClient: AkkaGrpcScalaClient => scalaClient.close() | ||
| case scalaClient: AkkaGrpcScalaClient => | ||
| scalaClient.closed |
johanandren
left a comment
There was a problem hiding this comment.
LGTM but I wonder about all those empty unit tests
| // ActionResult<Empty> result = testKit.decrease(CounterTopicApi.Decreased.newBuilder()...build()); | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Should we really check in the stub unit tests? It sort of makes it look like something actually is tested in the samples in the CI pr validation and also if we change how the code is generated we'll need to delete and re-check in for it to get up to date with codegen.
There was a problem hiding this comment.
ok, I can remove, but it's difficult to "see" that it shouldn't be added when fiddling with the samples
There was a problem hiding this comment.
eh, we already have many many of those added
leaving that as a separate cleanup if your find it important
References #568