Skip to content

Commit

Permalink
interop-testing: Support syncing protos from grpc-proto
Browse files Browse the repository at this point in the history
Two main incompatibilities existed in the copy of protos in grpc-proto:
no SimpleContext and an Empty method argument was replaced with a
message. "Context" is a very old word for "Metadata" back from the days
before the current gRPC protocol. We don't need that message in
particular, and well-known protos actually works in Protobuf Lite these
days, so we can swap to wrappers.proto's StringValue and don't need to
upstream a change to grpc-proto. The argument problem is fixed just by
changing the type in the Java code.

With the incompatibilities fixed, do a sync from grpc-proto and include
interop-testing.
  • Loading branch information
ejona86 committed May 18, 2022
1 parent 9cb3c6e commit 5bb721e
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ private ReconnectServiceGrpc() {}
public static final String SERVICE_NAME = "grpc.testing.ReconnectService";

// Static method descriptors that strictly reflect the proto.
private static volatile io.grpc.MethodDescriptor<io.grpc.testing.integration.EmptyProtos.Empty,
private static volatile io.grpc.MethodDescriptor<io.grpc.testing.integration.Messages.ReconnectParams,
io.grpc.testing.integration.EmptyProtos.Empty> getStartMethod;

@io.grpc.stub.annotations.RpcMethod(
fullMethodName = SERVICE_NAME + '/' + "Start",
requestType = io.grpc.testing.integration.EmptyProtos.Empty.class,
requestType = io.grpc.testing.integration.Messages.ReconnectParams.class,
responseType = io.grpc.testing.integration.EmptyProtos.Empty.class,
methodType = io.grpc.MethodDescriptor.MethodType.UNARY)
public static io.grpc.MethodDescriptor<io.grpc.testing.integration.EmptyProtos.Empty,
public static io.grpc.MethodDescriptor<io.grpc.testing.integration.Messages.ReconnectParams,
io.grpc.testing.integration.EmptyProtos.Empty> getStartMethod() {
io.grpc.MethodDescriptor<io.grpc.testing.integration.EmptyProtos.Empty, io.grpc.testing.integration.EmptyProtos.Empty> getStartMethod;
io.grpc.MethodDescriptor<io.grpc.testing.integration.Messages.ReconnectParams, io.grpc.testing.integration.EmptyProtos.Empty> getStartMethod;
if ((getStartMethod = ReconnectServiceGrpc.getStartMethod) == null) {
synchronized (ReconnectServiceGrpc.class) {
if ((getStartMethod = ReconnectServiceGrpc.getStartMethod) == null) {
ReconnectServiceGrpc.getStartMethod = getStartMethod =
io.grpc.MethodDescriptor.<io.grpc.testing.integration.EmptyProtos.Empty, io.grpc.testing.integration.EmptyProtos.Empty>newBuilder()
io.grpc.MethodDescriptor.<io.grpc.testing.integration.Messages.ReconnectParams, io.grpc.testing.integration.EmptyProtos.Empty>newBuilder()
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "Start"))
.setSampledToLocalTracing(true)
.setRequestMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(
io.grpc.testing.integration.EmptyProtos.Empty.getDefaultInstance()))
io.grpc.testing.integration.Messages.ReconnectParams.getDefaultInstance()))
.setResponseMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(
io.grpc.testing.integration.EmptyProtos.Empty.getDefaultInstance()))
.build();
Expand Down Expand Up @@ -131,7 +131,7 @@ public static abstract class ReconnectServiceImplBase implements io.grpc.Bindabl

/**
*/
public void start(io.grpc.testing.integration.EmptyProtos.Empty request,
public void start(io.grpc.testing.integration.Messages.ReconnectParams request,
io.grpc.stub.StreamObserver<io.grpc.testing.integration.EmptyProtos.Empty> responseObserver) {
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getStartMethod(), responseObserver);
}
Expand All @@ -149,7 +149,7 @@ public void stop(io.grpc.testing.integration.EmptyProtos.Empty request,
getStartMethod(),
io.grpc.stub.ServerCalls.asyncUnaryCall(
new MethodHandlers<
io.grpc.testing.integration.EmptyProtos.Empty,
io.grpc.testing.integration.Messages.ReconnectParams,
io.grpc.testing.integration.EmptyProtos.Empty>(
this, METHODID_START)))
.addMethod(
Expand Down Expand Up @@ -182,7 +182,7 @@ protected ReconnectServiceStub build(

/**
*/
public void start(io.grpc.testing.integration.EmptyProtos.Empty request,
public void start(io.grpc.testing.integration.Messages.ReconnectParams request,
io.grpc.stub.StreamObserver<io.grpc.testing.integration.EmptyProtos.Empty> responseObserver) {
io.grpc.stub.ClientCalls.asyncUnaryCall(
getChannel().newCall(getStartMethod(), getCallOptions()), request, responseObserver);
Expand Down Expand Up @@ -216,7 +216,7 @@ protected ReconnectServiceBlockingStub build(

/**
*/
public io.grpc.testing.integration.EmptyProtos.Empty start(io.grpc.testing.integration.EmptyProtos.Empty request) {
public io.grpc.testing.integration.EmptyProtos.Empty start(io.grpc.testing.integration.Messages.ReconnectParams request) {
return io.grpc.stub.ClientCalls.blockingUnaryCall(
getChannel(), getStartMethod(), getCallOptions(), request);
}
Expand Down Expand Up @@ -249,7 +249,7 @@ protected ReconnectServiceFutureStub build(
/**
*/
public com.google.common.util.concurrent.ListenableFuture<io.grpc.testing.integration.EmptyProtos.Empty> start(
io.grpc.testing.integration.EmptyProtos.Empty request) {
io.grpc.testing.integration.Messages.ReconnectParams request) {
return io.grpc.stub.ClientCalls.futureUnaryCall(
getChannel().newCall(getStartMethod(), getCallOptions()), request);
}
Expand Down Expand Up @@ -284,7 +284,7 @@ private static final class MethodHandlers<Req, Resp> implements
public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
switch (methodId) {
case METHODID_START:
serviceImpl.start((io.grpc.testing.integration.EmptyProtos.Empty) request,
serviceImpl.start((io.grpc.testing.integration.Messages.ReconnectParams) request,
(io.grpc.stub.StreamObserver<io.grpc.testing.integration.EmptyProtos.Empty>) responseObserver);
break;
case METHODID_STOP:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ private ReconnectServiceGrpc() {}
public static final String SERVICE_NAME = "grpc.testing.ReconnectService";

// Static method descriptors that strictly reflect the proto.
private static volatile io.grpc.MethodDescriptor<io.grpc.testing.integration.EmptyProtos.Empty,
private static volatile io.grpc.MethodDescriptor<io.grpc.testing.integration.Messages.ReconnectParams,
io.grpc.testing.integration.EmptyProtos.Empty> getStartMethod;

@io.grpc.stub.annotations.RpcMethod(
fullMethodName = SERVICE_NAME + '/' + "Start",
requestType = io.grpc.testing.integration.EmptyProtos.Empty.class,
requestType = io.grpc.testing.integration.Messages.ReconnectParams.class,
responseType = io.grpc.testing.integration.EmptyProtos.Empty.class,
methodType = io.grpc.MethodDescriptor.MethodType.UNARY)
public static io.grpc.MethodDescriptor<io.grpc.testing.integration.EmptyProtos.Empty,
public static io.grpc.MethodDescriptor<io.grpc.testing.integration.Messages.ReconnectParams,
io.grpc.testing.integration.EmptyProtos.Empty> getStartMethod() {
io.grpc.MethodDescriptor<io.grpc.testing.integration.EmptyProtos.Empty, io.grpc.testing.integration.EmptyProtos.Empty> getStartMethod;
io.grpc.MethodDescriptor<io.grpc.testing.integration.Messages.ReconnectParams, io.grpc.testing.integration.EmptyProtos.Empty> getStartMethod;
if ((getStartMethod = ReconnectServiceGrpc.getStartMethod) == null) {
synchronized (ReconnectServiceGrpc.class) {
if ((getStartMethod = ReconnectServiceGrpc.getStartMethod) == null) {
ReconnectServiceGrpc.getStartMethod = getStartMethod =
io.grpc.MethodDescriptor.<io.grpc.testing.integration.EmptyProtos.Empty, io.grpc.testing.integration.EmptyProtos.Empty>newBuilder()
io.grpc.MethodDescriptor.<io.grpc.testing.integration.Messages.ReconnectParams, io.grpc.testing.integration.EmptyProtos.Empty>newBuilder()
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "Start"))
.setSampledToLocalTracing(true)
.setRequestMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(
io.grpc.testing.integration.EmptyProtos.Empty.getDefaultInstance()))
io.grpc.testing.integration.Messages.ReconnectParams.getDefaultInstance()))
.setResponseMarshaller(io.grpc.protobuf.lite.ProtoLiteUtils.marshaller(
io.grpc.testing.integration.EmptyProtos.Empty.getDefaultInstance()))
.build();
Expand Down Expand Up @@ -131,7 +131,7 @@ public static abstract class ReconnectServiceImplBase implements io.grpc.Bindabl

/**
*/
public void start(io.grpc.testing.integration.EmptyProtos.Empty request,
public void start(io.grpc.testing.integration.Messages.ReconnectParams request,
io.grpc.stub.StreamObserver<io.grpc.testing.integration.EmptyProtos.Empty> responseObserver) {
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getStartMethod(), responseObserver);
}
Expand All @@ -149,7 +149,7 @@ public void stop(io.grpc.testing.integration.EmptyProtos.Empty request,
getStartMethod(),
io.grpc.stub.ServerCalls.asyncUnaryCall(
new MethodHandlers<
io.grpc.testing.integration.EmptyProtos.Empty,
io.grpc.testing.integration.Messages.ReconnectParams,
io.grpc.testing.integration.EmptyProtos.Empty>(
this, METHODID_START)))
.addMethod(
Expand Down Expand Up @@ -182,7 +182,7 @@ protected ReconnectServiceStub build(

/**
*/
public void start(io.grpc.testing.integration.EmptyProtos.Empty request,
public void start(io.grpc.testing.integration.Messages.ReconnectParams request,
io.grpc.stub.StreamObserver<io.grpc.testing.integration.EmptyProtos.Empty> responseObserver) {
io.grpc.stub.ClientCalls.asyncUnaryCall(
getChannel().newCall(getStartMethod(), getCallOptions()), request, responseObserver);
Expand Down Expand Up @@ -216,7 +216,7 @@ protected ReconnectServiceBlockingStub build(

/**
*/
public io.grpc.testing.integration.EmptyProtos.Empty start(io.grpc.testing.integration.EmptyProtos.Empty request) {
public io.grpc.testing.integration.EmptyProtos.Empty start(io.grpc.testing.integration.Messages.ReconnectParams request) {
return io.grpc.stub.ClientCalls.blockingUnaryCall(
getChannel(), getStartMethod(), getCallOptions(), request);
}
Expand Down Expand Up @@ -249,7 +249,7 @@ protected ReconnectServiceFutureStub build(
/**
*/
public com.google.common.util.concurrent.ListenableFuture<io.grpc.testing.integration.EmptyProtos.Empty> start(
io.grpc.testing.integration.EmptyProtos.Empty request) {
io.grpc.testing.integration.Messages.ReconnectParams request) {
return io.grpc.stub.ClientCalls.futureUnaryCall(
getChannel().newCall(getStartMethod(), getCallOptions()), request);
}
Expand Down Expand Up @@ -284,7 +284,7 @@ private static final class MethodHandlers<Req, Resp> implements
public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
switch (methodId) {
case METHODID_START:
serviceImpl.start((io.grpc.testing.integration.EmptyProtos.Empty) request,
serviceImpl.start((io.grpc.testing.integration.Messages.ReconnectParams) request,
(io.grpc.stub.StreamObserver<io.grpc.testing.integration.EmptyProtos.Empty>) responseObserver);
break;
case METHODID_STOP:
Expand Down
2 changes: 1 addition & 1 deletion buildscripts/sync-protos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ curl -Ls https://github.com/grpc/grpc-proto/archive/master.tar.gz | tar xz -C "$
base="$tmpdir/grpc-proto-master"

# Copy protos in 'src/main/proto' from grpc-proto for these projects
for project in alts grpclb services rls; do
for project in alts grpclb services rls interop-testing; do
while read -r proto; do
[ -f "$base/$proto" ] && cp "$base/$proto" "$project/src/main/proto/$proto"
echo "$proto"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ private ReconnectServiceGrpc() {}
public static final String SERVICE_NAME = "grpc.testing.ReconnectService";

// Static method descriptors that strictly reflect the proto.
private static volatile io.grpc.MethodDescriptor<io.grpc.testing.integration.EmptyProtos.Empty,
private static volatile io.grpc.MethodDescriptor<io.grpc.testing.integration.Messages.ReconnectParams,
io.grpc.testing.integration.EmptyProtos.Empty> getStartMethod;

@io.grpc.stub.annotations.RpcMethod(
fullMethodName = SERVICE_NAME + '/' + "Start",
requestType = io.grpc.testing.integration.EmptyProtos.Empty.class,
requestType = io.grpc.testing.integration.Messages.ReconnectParams.class,
responseType = io.grpc.testing.integration.EmptyProtos.Empty.class,
methodType = io.grpc.MethodDescriptor.MethodType.UNARY)
public static io.grpc.MethodDescriptor<io.grpc.testing.integration.EmptyProtos.Empty,
public static io.grpc.MethodDescriptor<io.grpc.testing.integration.Messages.ReconnectParams,
io.grpc.testing.integration.EmptyProtos.Empty> getStartMethod() {
io.grpc.MethodDescriptor<io.grpc.testing.integration.EmptyProtos.Empty, io.grpc.testing.integration.EmptyProtos.Empty> getStartMethod;
io.grpc.MethodDescriptor<io.grpc.testing.integration.Messages.ReconnectParams, io.grpc.testing.integration.EmptyProtos.Empty> getStartMethod;
if ((getStartMethod = ReconnectServiceGrpc.getStartMethod) == null) {
synchronized (ReconnectServiceGrpc.class) {
if ((getStartMethod = ReconnectServiceGrpc.getStartMethod) == null) {
ReconnectServiceGrpc.getStartMethod = getStartMethod =
io.grpc.MethodDescriptor.<io.grpc.testing.integration.EmptyProtos.Empty, io.grpc.testing.integration.EmptyProtos.Empty>newBuilder()
io.grpc.MethodDescriptor.<io.grpc.testing.integration.Messages.ReconnectParams, io.grpc.testing.integration.EmptyProtos.Empty>newBuilder()
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
.setFullMethodName(generateFullMethodName(SERVICE_NAME, "Start"))
.setSampledToLocalTracing(true)
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
io.grpc.testing.integration.EmptyProtos.Empty.getDefaultInstance()))
io.grpc.testing.integration.Messages.ReconnectParams.getDefaultInstance()))
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
io.grpc.testing.integration.EmptyProtos.Empty.getDefaultInstance()))
.setSchemaDescriptor(new ReconnectServiceMethodDescriptorSupplier("Start"))
Expand Down Expand Up @@ -133,7 +133,7 @@ public static abstract class ReconnectServiceImplBase implements io.grpc.Bindabl

/**
*/
public void start(io.grpc.testing.integration.EmptyProtos.Empty request,
public void start(io.grpc.testing.integration.Messages.ReconnectParams request,
io.grpc.stub.StreamObserver<io.grpc.testing.integration.EmptyProtos.Empty> responseObserver) {
io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall(getStartMethod(), responseObserver);
}
Expand All @@ -151,7 +151,7 @@ public void stop(io.grpc.testing.integration.EmptyProtos.Empty request,
getStartMethod(),
io.grpc.stub.ServerCalls.asyncUnaryCall(
new MethodHandlers<
io.grpc.testing.integration.EmptyProtos.Empty,
io.grpc.testing.integration.Messages.ReconnectParams,
io.grpc.testing.integration.EmptyProtos.Empty>(
this, METHODID_START)))
.addMethod(
Expand Down Expand Up @@ -184,7 +184,7 @@ protected ReconnectServiceStub build(

/**
*/
public void start(io.grpc.testing.integration.EmptyProtos.Empty request,
public void start(io.grpc.testing.integration.Messages.ReconnectParams request,
io.grpc.stub.StreamObserver<io.grpc.testing.integration.EmptyProtos.Empty> responseObserver) {
io.grpc.stub.ClientCalls.asyncUnaryCall(
getChannel().newCall(getStartMethod(), getCallOptions()), request, responseObserver);
Expand Down Expand Up @@ -218,7 +218,7 @@ protected ReconnectServiceBlockingStub build(

/**
*/
public io.grpc.testing.integration.EmptyProtos.Empty start(io.grpc.testing.integration.EmptyProtos.Empty request) {
public io.grpc.testing.integration.EmptyProtos.Empty start(io.grpc.testing.integration.Messages.ReconnectParams request) {
return io.grpc.stub.ClientCalls.blockingUnaryCall(
getChannel(), getStartMethod(), getCallOptions(), request);
}
Expand Down Expand Up @@ -251,7 +251,7 @@ protected ReconnectServiceFutureStub build(
/**
*/
public com.google.common.util.concurrent.ListenableFuture<io.grpc.testing.integration.EmptyProtos.Empty> start(
io.grpc.testing.integration.EmptyProtos.Empty request) {
io.grpc.testing.integration.Messages.ReconnectParams request) {
return io.grpc.stub.ClientCalls.futureUnaryCall(
getChannel().newCall(getStartMethod(), getCallOptions()), request);
}
Expand Down Expand Up @@ -286,7 +286,7 @@ private static final class MethodHandlers<Req, Resp> implements
public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
switch (methodId) {
case METHODID_START:
serviceImpl.start((io.grpc.testing.integration.EmptyProtos.Empty) request,
serviceImpl.start((io.grpc.testing.integration.Messages.ReconnectParams) request,
(io.grpc.stub.StreamObserver<io.grpc.testing.integration.EmptyProtos.Empty>) responseObserver);
break;
case METHODID_STOP:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.google.common.util.concurrent.SettableFuture;
import com.google.protobuf.ByteString;
import com.google.protobuf.MessageLite;
import com.google.protobuf.StringValue;
import io.grpc.CallOptions;
import io.grpc.Channel;
import io.grpc.ClientCall;
Expand Down Expand Up @@ -1058,10 +1059,9 @@ public void veryLargeResponse() throws Exception {
public void exchangeMetadataUnaryCall() throws Exception {
// Capture the metadata exchange
Metadata fixedHeaders = new Metadata();
// Send a context proto (as it's in the default extension registry)
Messages.SimpleContext contextValue =
Messages.SimpleContext.newBuilder().setValue("dog").build();
fixedHeaders.put(Util.METADATA_KEY, contextValue);
// Send a metadata proto
StringValue metadataValue = StringValue.newBuilder().setValue("dog").build();
fixedHeaders.put(Util.METADATA_KEY, metadataValue);
// .. and expect it to be echoed back in trailers
AtomicReference<Metadata> trailersCapture = new AtomicReference<>();
AtomicReference<Metadata> headersCapture = new AtomicReference<>();
Expand All @@ -1072,18 +1072,17 @@ public void exchangeMetadataUnaryCall() throws Exception {
assertNotNull(stub.emptyCall(EMPTY));

// Assert that our side channel object is echoed back in both headers and trailers
Assert.assertEquals(contextValue, headersCapture.get().get(Util.METADATA_KEY));
Assert.assertEquals(contextValue, trailersCapture.get().get(Util.METADATA_KEY));
Assert.assertEquals(metadataValue, headersCapture.get().get(Util.METADATA_KEY));
Assert.assertEquals(metadataValue, trailersCapture.get().get(Util.METADATA_KEY));
}

@Test
public void exchangeMetadataStreamingCall() throws Exception {
// Capture the metadata exchange
Metadata fixedHeaders = new Metadata();
// Send a context proto (as it's in the default extension registry)
Messages.SimpleContext contextValue =
Messages.SimpleContext.newBuilder().setValue("dog").build();
fixedHeaders.put(Util.METADATA_KEY, contextValue);
// Send a metadata proto
StringValue metadataValue = StringValue.newBuilder().setValue("dog").build();
fixedHeaders.put(Util.METADATA_KEY, metadataValue);
// .. and expect it to be echoed back in trailers
AtomicReference<Metadata> trailersCapture = new AtomicReference<>();
AtomicReference<Metadata> headersCapture = new AtomicReference<>();
Expand Down Expand Up @@ -1114,8 +1113,8 @@ public void exchangeMetadataStreamingCall() throws Exception {
org.junit.Assert.assertEquals(responseSizes.size() * numRequests, recorder.getValues().size());

// Assert that our side channel object is echoed back in both headers and trailers
Assert.assertEquals(contextValue, headersCapture.get().get(Util.METADATA_KEY));
Assert.assertEquals(contextValue, trailersCapture.get().get(Util.METADATA_KEY));
Assert.assertEquals(metadataValue, headersCapture.get().get(Util.METADATA_KEY));
Assert.assertEquals(metadataValue, trailersCapture.get().get(Util.METADATA_KEY));
}

@Test
Expand Down

0 comments on commit 5bb721e

Please sign in to comment.