gRPC-Java missing interfaces

92 views
Skip to first unread message

Ryan Michela

unread,
Feb 15, 2017, 3:56:23 PM2/15/17
to grpc.io
When protoc generates java stubs, it doesn't create interfaces for stubs or services. Instead, the blocking/async stubs are final classes and the service is an abstract base class. Interfaces would make mocking, DI, and utility classes easier to implement. 

Is the absence of generated interfaces an explicit design decision, and if so, what is the rationale?

Penn (Dapeng) Zhang

unread,
Feb 15, 2017, 4:42:09 PM2/15/17
to grpc.io
The rationale is discussed in https://github.com/grpc/grpc/issues/5371

For server side, Mocking/DI works fine for abstract base class. 
For client side, you should never mock the stubs, because a mock/fake stub is totally inconsistent with how the gRPC library actually works. For testing, a real stub constructed with an InProcessChannelBuilder is recommended. (testing examples: https://github.com/grpc/grpc-java/tree/master/examples/src/test/java/io/grpc/examples)
Reply all
Reply to author
Forward
0 new messages