Fix Java generator bug that ignores bidi streaming attribute (#5063)

* Fix Java generator bug that ignores streaming: bidi attribute
Tests

* Java gRPC client streaming test

* Java gRPC Bidi Streaming Test
This commit is contained in:
Sumant Tambe
2018-11-29 10:33:17 -08:00
committed by Wouter van Oortmerssen
parent 0143f4e364
commit 9635d494b3
8 changed files with 636 additions and 48 deletions

View File

@@ -128,6 +128,72 @@ public final class MonsterStorageGrpc {
return getRetrieveMethod;
}
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
@java.lang.Deprecated // Use {@link #getGetMaxHitPointMethod()} instead.
public static final io.grpc.MethodDescriptor<MyGame.Example.Monster,
MyGame.Example.Stat> METHOD_GET_MAX_HIT_POINT = getGetMaxHitPointMethod();
private static volatile io.grpc.MethodDescriptor<MyGame.Example.Monster,
MyGame.Example.Stat> getGetMaxHitPointMethod;
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
public static io.grpc.MethodDescriptor<MyGame.Example.Monster,
MyGame.Example.Stat> getGetMaxHitPointMethod() {
io.grpc.MethodDescriptor<MyGame.Example.Monster, MyGame.Example.Stat> getGetMaxHitPointMethod;
if ((getGetMaxHitPointMethod = MonsterStorageGrpc.getGetMaxHitPointMethod) == null) {
synchronized (MonsterStorageGrpc.class) {
if ((getGetMaxHitPointMethod = MonsterStorageGrpc.getGetMaxHitPointMethod) == null) {
MonsterStorageGrpc.getGetMaxHitPointMethod = getGetMaxHitPointMethod =
io.grpc.MethodDescriptor.<MyGame.Example.Monster, MyGame.Example.Stat>newBuilder()
.setType(io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING)
.setFullMethodName(generateFullMethodName(
"MyGame.Example.MonsterStorage", "GetMaxHitPoint"))
.setSampledToLocalTracing(true)
.setRequestMarshaller(FlatbuffersUtils.marshaller(
MyGame.Example.Monster.class, getExtractorOfMonster()))
.setResponseMarshaller(FlatbuffersUtils.marshaller(
MyGame.Example.Stat.class, getExtractorOfStat()))
.setSchemaDescriptor(null)
.build();
}
}
}
return getGetMaxHitPointMethod;
}
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
@java.lang.Deprecated // Use {@link #getGetMinMaxHitPointsMethod()} instead.
public static final io.grpc.MethodDescriptor<MyGame.Example.Monster,
MyGame.Example.Stat> METHOD_GET_MIN_MAX_HIT_POINTS = getGetMinMaxHitPointsMethod();
private static volatile io.grpc.MethodDescriptor<MyGame.Example.Monster,
MyGame.Example.Stat> getGetMinMaxHitPointsMethod;
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
public static io.grpc.MethodDescriptor<MyGame.Example.Monster,
MyGame.Example.Stat> getGetMinMaxHitPointsMethod() {
io.grpc.MethodDescriptor<MyGame.Example.Monster, MyGame.Example.Stat> getGetMinMaxHitPointsMethod;
if ((getGetMinMaxHitPointsMethod = MonsterStorageGrpc.getGetMinMaxHitPointsMethod) == null) {
synchronized (MonsterStorageGrpc.class) {
if ((getGetMinMaxHitPointsMethod = MonsterStorageGrpc.getGetMinMaxHitPointsMethod) == null) {
MonsterStorageGrpc.getGetMinMaxHitPointsMethod = getGetMinMaxHitPointsMethod =
io.grpc.MethodDescriptor.<MyGame.Example.Monster, MyGame.Example.Stat>newBuilder()
.setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING)
.setFullMethodName(generateFullMethodName(
"MyGame.Example.MonsterStorage", "GetMinMaxHitPoints"))
.setSampledToLocalTracing(true)
.setRequestMarshaller(FlatbuffersUtils.marshaller(
MyGame.Example.Monster.class, getExtractorOfMonster()))
.setResponseMarshaller(FlatbuffersUtils.marshaller(
MyGame.Example.Stat.class, getExtractorOfStat()))
.setSchemaDescriptor(null)
.build();
}
}
}
return getGetMinMaxHitPointsMethod;
}
/**
* Creates a new async stub that supports all call types for the service
*/
@@ -169,6 +235,20 @@ public final class MonsterStorageGrpc {
asyncUnimplementedUnaryCall(getRetrieveMethod(), responseObserver);
}
/**
*/
public io.grpc.stub.StreamObserver<MyGame.Example.Monster> getMaxHitPoint(
io.grpc.stub.StreamObserver<MyGame.Example.Stat> responseObserver) {
return asyncUnimplementedStreamingCall(getGetMaxHitPointMethod(), responseObserver);
}
/**
*/
public io.grpc.stub.StreamObserver<MyGame.Example.Monster> getMinMaxHitPoints(
io.grpc.stub.StreamObserver<MyGame.Example.Stat> responseObserver) {
return asyncUnimplementedStreamingCall(getGetMinMaxHitPointsMethod(), responseObserver);
}
@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
.addMethod(
@@ -185,6 +265,20 @@ public final class MonsterStorageGrpc {
MyGame.Example.Stat,
MyGame.Example.Monster>(
this, METHODID_RETRIEVE)))
.addMethod(
getGetMaxHitPointMethod(),
asyncClientStreamingCall(
new MethodHandlers<
MyGame.Example.Monster,
MyGame.Example.Stat>(
this, METHODID_GET_MAX_HIT_POINT)))
.addMethod(
getGetMinMaxHitPointsMethod(),
asyncBidiStreamingCall(
new MethodHandlers<
MyGame.Example.Monster,
MyGame.Example.Stat>(
this, METHODID_GET_MIN_MAX_HIT_POINTS)))
.build();
}
}
@@ -222,6 +316,22 @@ public final class MonsterStorageGrpc {
asyncServerStreamingCall(
getChannel().newCall(getRetrieveMethod(), getCallOptions()), request, responseObserver);
}
/**
*/
public io.grpc.stub.StreamObserver<MyGame.Example.Monster> getMaxHitPoint(
io.grpc.stub.StreamObserver<MyGame.Example.Stat> responseObserver) {
return asyncClientStreamingCall(
getChannel().newCall(getGetMaxHitPointMethod(), getCallOptions()), responseObserver);
}
/**
*/
public io.grpc.stub.StreamObserver<MyGame.Example.Monster> getMinMaxHitPoints(
io.grpc.stub.StreamObserver<MyGame.Example.Stat> responseObserver) {
return asyncBidiStreamingCall(
getChannel().newCall(getGetMinMaxHitPointsMethod(), getCallOptions()), responseObserver);
}
}
/**
@@ -287,6 +397,8 @@ public final class MonsterStorageGrpc {
private static final int METHODID_STORE = 0;
private static final int METHODID_RETRIEVE = 1;
private static final int METHODID_GET_MIN_MAX_HIT_POINTS = 2;
private static final int METHODID_GET_MAX_HIT_POINT = 3;
private static final class MethodHandlers<Req, Resp> implements
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
@@ -323,6 +435,12 @@ public final class MonsterStorageGrpc {
public io.grpc.stub.StreamObserver<Req> invoke(
io.grpc.stub.StreamObserver<Resp> responseObserver) {
switch (methodId) {
case METHODID_GET_MAX_HIT_POINT:
return (io.grpc.stub.StreamObserver<Req>) serviceImpl.getMaxHitPoint(
(io.grpc.stub.StreamObserver<MyGame.Example.Stat>) responseObserver);
case METHODID_GET_MIN_MAX_HIT_POINTS:
return (io.grpc.stub.StreamObserver<Req>) serviceImpl.getMinMaxHitPoints(
(io.grpc.stub.StreamObserver<MyGame.Example.Stat>) responseObserver);
default:
throw new AssertionError();
}
@@ -341,6 +459,8 @@ public final class MonsterStorageGrpc {
.setSchemaDescriptor(null)
.addMethod(getStoreMethod())
.addMethod(getRetrieveMethod())
.addMethod(getGetMaxHitPointMethod())
.addMethod(getGetMinMaxHitPointsMethod())
.build();
}
}

View File

@@ -17,6 +17,10 @@ type MonsterStorageClient interface{
opts... grpc.CallOption) (* Stat, error)
Retrieve(ctx context.Context, in *flatbuffers.Builder,
opts... grpc.CallOption) (MonsterStorage_RetrieveClient, error)
GetMaxHitPoint(ctx context.Context,
opts... grpc.CallOption) (MonsterStorage_GetMaxHitPointClient, error)
GetMinMaxHitPoints(ctx context.Context,
opts... grpc.CallOption) (MonsterStorage_GetMinMaxHitPointsClient, error)
}
type monsterStorageClient struct {
@@ -60,10 +64,69 @@ func (x *monsterStorageRetrieveClient) Recv() (*Monster, error) {
return m, nil
}
func (c *monsterStorageClient) GetMaxHitPoint(ctx context.Context,
opts... grpc.CallOption) (MonsterStorage_GetMaxHitPointClient, error) {
stream, err := grpc.NewClientStream(ctx, &_MonsterStorage_serviceDesc.Streams[1], c.cc, "/MyGame.Example.MonsterStorage/GetMaxHitPoint", opts...)
if err != nil { return nil, err }
x := &monsterStorageGetMaxHitPointClient{stream}
return x,nil
}
type MonsterStorage_GetMaxHitPointClient interface {
Send(*flatbuffers.Builder) error
CloseAndRecv() (*Stat, error)
grpc.ClientStream
}
type monsterStorageGetMaxHitPointClient struct{
grpc.ClientStream
}
func (x *monsterStorageGetMaxHitPointClient) Send(m *flatbuffers.Builder) error {
return x.ClientStream.SendMsg(m)
}
func (x *monsterStorageGetMaxHitPointClient) CloseAndRecv() (*Stat, error) {
if err := x.ClientStream.CloseSend(); err != nil { return nil, err }
m := new (Stat)
if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err }
return m, nil
}
func (c *monsterStorageClient) GetMinMaxHitPoints(ctx context.Context,
opts... grpc.CallOption) (MonsterStorage_GetMinMaxHitPointsClient, error) {
stream, err := grpc.NewClientStream(ctx, &_MonsterStorage_serviceDesc.Streams[2], c.cc, "/MyGame.Example.MonsterStorage/GetMinMaxHitPoints", opts...)
if err != nil { return nil, err }
x := &monsterStorageGetMinMaxHitPointsClient{stream}
return x,nil
}
type MonsterStorage_GetMinMaxHitPointsClient interface {
Send(*flatbuffers.Builder) error
Recv() (*Stat, error)
grpc.ClientStream
}
type monsterStorageGetMinMaxHitPointsClient struct{
grpc.ClientStream
}
func (x *monsterStorageGetMinMaxHitPointsClient) Send(m *flatbuffers.Builder) error {
return x.ClientStream.SendMsg(m)
}
func (x *monsterStorageGetMinMaxHitPointsClient) Recv() (*Stat, error) {
m := new(Stat)
if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err }
return m, nil
}
// Server API for MonsterStorage service
type MonsterStorageServer interface {
Store(context.Context, *Monster) (*flatbuffers.Builder, error)
Retrieve(*Stat, MonsterStorage_RetrieveServer) error
GetMaxHitPoint(MonsterStorage_GetMaxHitPointServer) error
GetMinMaxHitPoints(MonsterStorage_GetMinMaxHitPointsServer) error
}
func RegisterMonsterStorageServer(s *grpc.Server, srv MonsterStorageServer) {
@@ -107,6 +170,56 @@ func (x *monsterStorageRetrieveServer) Send(m *flatbuffers.Builder) error {
}
func _MonsterStorage_GetMaxHitPoint_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(MonsterStorageServer).GetMaxHitPoint(&monsterStorageGetMaxHitPointServer{stream})
}
type MonsterStorage_GetMaxHitPointServer interface {
Recv() (* Monster, error)
SendAndClose(* flatbuffers.Builder) error
grpc.ServerStream
}
type monsterStorageGetMaxHitPointServer struct {
grpc.ServerStream
}
func (x *monsterStorageGetMaxHitPointServer) Recv() (*Monster, error) {
m := new(Monster)
if err := x.ServerStream.RecvMsg(m); err != nil { return nil, err }
return m, nil
}
func (x *monsterStorageGetMaxHitPointServer) SendAndClose(m *flatbuffers.Builder) error {
return x.ServerStream.SendMsg(m)
}
func _MonsterStorage_GetMinMaxHitPoints_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(MonsterStorageServer).GetMinMaxHitPoints(&monsterStorageGetMinMaxHitPointsServer{stream})
}
type MonsterStorage_GetMinMaxHitPointsServer interface {
Send(* flatbuffers.Builder) error
Recv() (* Monster, error)
grpc.ServerStream
}
type monsterStorageGetMinMaxHitPointsServer struct {
grpc.ServerStream
}
func (x *monsterStorageGetMinMaxHitPointsServer) Send(m *flatbuffers.Builder) error {
return x.ServerStream.SendMsg(m)
}
func (x *monsterStorageGetMinMaxHitPointsServer) Recv() (*Monster, error) {
m := new(Monster)
if err := x.ServerStream.RecvMsg(m); err != nil { return nil, err }
return m, nil
}
var _MonsterStorage_serviceDesc = grpc.ServiceDesc{
ServiceName: "MyGame.Example.MonsterStorage",
HandlerType: (*MonsterStorageServer)(nil),
@@ -122,6 +235,17 @@ var _MonsterStorage_serviceDesc = grpc.ServiceDesc{
Handler: _MonsterStorage_Retrieve_Handler,
ServerStreams: true,
},
{
StreamName: "GetMaxHitPoint",
Handler: _MonsterStorage_GetMaxHitPoint_Handler,
ClientStreams: true,
},
{
StreamName: "GetMinMaxHitPoints",
Handler: _MonsterStorage_GetMinMaxHitPoints_Handler,
ServerStreams: true,
ClientStreams: true,
},
},
}