I recently migrated my gRPC client to Stream approach, and the previous mocking implementation with Camouflage does not work anymore.
My client(Java):
private final TestAdapterStub testAdapterStub;
private CompletableFuture<GetTestResponse> responseFuture;
public GetTestResponse getTest(String id) {
GetTestRequest request = GetTestRequest.newBuilder()
.setId(id)
.build();
responseFuture = new CompletableFuture<>();
StreamObserver<GetTestResponse> responseObserver = getResponseObserver();
var requestObserver = testAdapterStub.getTest(responseObserver);
requestObserver.onNext(request);
requestObserver.onCompleted();
try {
return responseFuture.join(); // here I am not getting response, failing by timeout
} catch (CompletionException exception) {
...
}
}
private StreamObserver<GetTestAdapter.GetTestResponse> getTestObserver() {
return new StreamObserver<>() {
@Override
public void onNext(GetTestResponse getTestResponse) {
responseFuture.complete(getTestResponse);
}
@Override
public void onError(Throwable exception) {
responseFuture.completeExceptionally(exception);
}
@Override
public void onCompleted() {
}
};
}
}
So, basically, instead of calling some other service, I want to mock the response using camouflage.
According to the documentation https://testinggospels.github.io/camouflage/mocking-gRPC/, I have created .proto file and .mock file under the correct directories, proto file was tested through the Postman and I am getting response from server and I know that directories are correct, because when I start camouflage container in Docker, I see in logs that those .mock file and .proto files are registered.
But no matter how I try to compose .mock file from the options in documentation, I am either getting error in camouflage logs that something is wrong with the file, or not getting any response and failing by timeout.
I tried:
Unary Or Client Side Streaming
mock file:
{
"testResponse": {
}
}
Getting camouflage error: Cannot read properties of undefined (reading 'delay')
I have tried adding "delay": {{num_between lower=500 upper=600}}
option to the file, but apparently it is not the problem, and I can’t determine what does this log mean.
Server Side Streaming
mock file:
{
"testResponse": {
}
}
====
{
"testResponse": {
}
}
Getting camouflage error: Unexpected non-whitespace character after JSON at position 28
. In this case, despite what documentation says, camouflage does not see ‘====’ symbols as a separator.
Bidi Streaming
mock file:
{
"data": {
"testResponse": {
}
}
}
This is the method that does not produce camouflage errors, I see in logs that it should be returned, but in the client itself I am waiting in a debug and not getting the response, failing by timeout.
Obviously, I have tried all these options with real responses from server as well, added delays to each of the .mock files, but still did not get a positive result.
Would be very grateful for any advise to what is wrong with my implementation and how can I fix it.