mirror of https://github.com/grpc/grpc-web.git
All interop tests work now.
This commit is contained in:
parent
569d92f528
commit
1fda10af5f
|
@ -3,12 +3,12 @@ Outline of the code at this point.
|
|||
|
||||
This is Work-in-Progress.
|
||||
|
||||
Current state of the code: Some interop-tests work now.
|
||||
Current state of the code: All interop-tests work
|
||||
(interop-tests are listed here
|
||||
https://github.com/stanley-cheung/grpc-web/blob/add-interop/test/interop/README.md
|
||||
|
||||
To ru nthe interop-tests with this code, do the following
|
||||
1. mvn test. This brings ip a Test Service + grpc-web in-process proxy
|
||||
To run the interop-tests with this code, do the following
|
||||
1. mvn package. This brings ip a Test Service + grpc-web in-process proxy
|
||||
2. Run the client as documented here:
|
||||
https://github.com/stanley-cheung/grpc-web/blob/add-interop/test/interop/README.md#run-the-grpc-web-browser-client
|
||||
|
||||
|
@ -17,6 +17,5 @@ Current state of the code: Some interop-tests work now.
|
|||
5. It should show the following:
|
||||
EmptyUnary: passed
|
||||
LargeUnary: passed
|
||||
(and then some errors on the other tests which are not yet implemented in
|
||||
this grpc-web java proxy code.. working on it)
|
||||
etc for all tests
|
||||
|
||||
|
|
|
@ -17,6 +17,16 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>27.0.1-jre</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
<version>3.11.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
|
@ -75,6 +85,24 @@
|
|||
</extension>
|
||||
</extensions>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.xolstice.maven.plugins</groupId>
|
||||
<artifactId>protobuf-maven-plugin</artifactId>
|
||||
<version>0.5.0</version>
|
||||
<configuration>
|
||||
<protocArtifact>com.google.protobuf:protoc:3.4.0:exe:${os.detected.classifier}</protocArtifact>
|
||||
<pluginId>grpc-java</pluginId>
|
||||
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.7.0:exe:${os.detected.classifier}</pluginArtifact>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>compile-custom</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
|
|
|
@ -7,8 +7,8 @@ package com.google.grpcweb;
|
|||
* This is primarily to make unittesting easier for callers of objects supplied by this factory.
|
||||
*/
|
||||
public class Factory {
|
||||
private final GrpcServiceConnectionManager mGrpcServiceConnectionManager;
|
||||
private static Factory mInstance;
|
||||
private int mGrpPortNum;
|
||||
|
||||
public synchronized static void createSingleton(int grpcPortNum) {
|
||||
if (mInstance == null) {
|
||||
|
@ -19,10 +19,10 @@ public class Factory {
|
|||
static Factory getInstance() { return mInstance;}
|
||||
|
||||
private Factory(int grpcPortNum) {
|
||||
mGrpcServiceConnectionManager = new GrpcServiceConnectionManager(grpcPortNum);
|
||||
mGrpPortNum = grpcPortNum;
|
||||
}
|
||||
|
||||
GrpcServiceConnectionManager getGrpcServiceConnectionManager() {
|
||||
return mGrpcServiceConnectionManager;
|
||||
return new GrpcServiceConnectionManager(mGrpPortNum);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package com.google.grpcweb;
|
||||
|
||||
import io.grpc.Channel;
|
||||
import io.grpc.ClientInterceptors;
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
|
||||
/**
|
||||
* Manages the connection pool to talk to the grpc-service
|
||||
* TODO: Manage the connection pool to talk to the grpc-service
|
||||
*/
|
||||
class GrpcServiceConnectionManager {
|
||||
private final int mGrpcPortNum;
|
||||
|
@ -13,10 +15,14 @@ class GrpcServiceConnectionManager {
|
|||
mGrpcPortNum = grpcPortNum;
|
||||
}
|
||||
|
||||
ManagedChannel getChannel() {
|
||||
private ManagedChannel getManagedChannel() {
|
||||
// TODO: Manage a connection pool.
|
||||
return ManagedChannelBuilder.forAddress("localhost", mGrpcPortNum)
|
||||
.usePlaintext()
|
||||
.build();
|
||||
}
|
||||
|
||||
Channel getChannelWithClientInterceptor(GrpcWebClientInterceptor interceptor) {
|
||||
return ClientInterceptors.intercept(getManagedChannel(), interceptor);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package com.google.grpcweb;
|
||||
|
||||
import io.grpc.CallOptions;
|
||||
import io.grpc.Channel;
|
||||
import io.grpc.ClientCall;
|
||||
import io.grpc.ClientCall.Listener;
|
||||
import io.grpc.ClientInterceptor;
|
||||
import io.grpc.ForwardingClientCall.SimpleForwardingClientCall;
|
||||
import io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener;
|
||||
import io.grpc.Metadata;
|
||||
import io.grpc.MethodDescriptor;
|
||||
import io.grpc.Status;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.logging.Logger;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
class GrpcWebClientInterceptor implements ClientInterceptor {
|
||||
private static final Logger LOG = Logger.getLogger(GrpcWebClientInterceptor.class.getName());
|
||||
private final CountDownLatch mLatch;
|
||||
private final HttpServletResponse mResp;
|
||||
private final SendResponse mSendResponse;
|
||||
|
||||
GrpcWebClientInterceptor(HttpServletResponse resp, CountDownLatch latch, SendResponse send) {
|
||||
mLatch = latch;
|
||||
mResp = resp;
|
||||
mSendResponse = send;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method,
|
||||
CallOptions callOptions, Channel channel) {
|
||||
return new SimpleForwardingClientCall<ReqT, RespT>(channel.newCall(method, callOptions)) {
|
||||
@Override
|
||||
public void start(Listener<RespT> responseListener, Metadata headers) {
|
||||
super.start(new MetadataResponseListener<RespT>(responseListener), headers);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
class MetadataResponseListener<T> extends SimpleForwardingClientCallListener<T> {
|
||||
private boolean headersSent = false;
|
||||
|
||||
MetadataResponseListener(Listener<T> responseListener) {
|
||||
super(responseListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHeaders(Metadata h) {
|
||||
mSendResponse.writeHeaders(h);
|
||||
headersSent = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(Status s, Metadata t) {
|
||||
if (!headersSent) {
|
||||
// seems, sometimes onHeaders() is not called before this method is called!
|
||||
// so far, they are the error cases. let onError() method in ClientListener
|
||||
// handle this call. Could ignore this.
|
||||
// TODO is this correct? what if onError() never gets called? maybe here it should
|
||||
// be handled: send headers first and then send the trailers.
|
||||
} else {
|
||||
mSendResponse.writeTrailer(s, t);
|
||||
mLatch.countDown();
|
||||
}
|
||||
super.onClose(s, t);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,5 @@
|
|||
package com.google.grpcweb;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import java.io.IOException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
@ -14,14 +11,12 @@ public class GrpcWebTrafficServlet extends HttpServlet {
|
|||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
|
||||
new RequestHandler(mFactory).handle(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) {
|
||||
doGet(request, response);
|
||||
}
|
||||
|
||||
|
@ -30,9 +25,4 @@ public class GrpcWebTrafficServlet extends HttpServlet {
|
|||
public GrpcWebTrafficServlet() {
|
||||
mFactory = Factory.getInstance();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
GrpcWebTrafficServlet(Factory factory) {
|
||||
mFactory = factory;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,9 @@ import java.lang.reflect.InvocationTargetException;
|
|||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
class MessageHandler {
|
||||
private static final Logger LOGGER = Logger.getLogger(MessageHandler.class.getName());
|
||||
|
||||
@VisibleForTesting
|
||||
enum ContentType {
|
||||
GRPC_WEB_BINARY,
|
||||
|
@ -48,7 +45,6 @@ class MessageHandler {
|
|||
Object getInputProtobufObj(Method rpcMethod, byte[] in) {
|
||||
Class[] inputArgs = rpcMethod.getParameterTypes();
|
||||
Class inputArgClass = inputArgs[0];
|
||||
LOGGER.fine("inputArgClass name: " + inputArgClass.getName());
|
||||
|
||||
// use the inputArg classtype to create a protobuf object
|
||||
Method parseFromObj;
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
package com.google.grpcweb;
|
||||
|
||||
import io.grpc.Metadata;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
class MetadataUtil {
|
||||
private static final String BINARY_HEADER_SUFFIX = "-bin";
|
||||
private static final String GRPC_HEADER_PREFIX = "x-grpc-";
|
||||
private static final List<String> EXCLUDED = Arrays.asList("x-grpc-web", "content-type",
|
||||
"grpc-accept-encoding", "grpc-encoding");
|
||||
|
||||
static Metadata getHtpHeaders(HttpServletRequest req) {
|
||||
Metadata httpHeaders = new Metadata();
|
||||
Enumeration<String> headerNames = req.getHeaderNames();
|
||||
if (headerNames == null) {
|
||||
return httpHeaders;
|
||||
}
|
||||
// copy all headers "x-grpc-*" into Metadata
|
||||
// TODO: do we need to copy all "x-*" headers instead?
|
||||
while (headerNames.hasMoreElements()) {
|
||||
String headerName = headerNames.nextElement();
|
||||
if (EXCLUDED.contains(headerName.toLowerCase())) {
|
||||
continue;
|
||||
}
|
||||
if (headerName.toLowerCase().startsWith(GRPC_HEADER_PREFIX)) {
|
||||
// Get all the values of this header.
|
||||
Enumeration<String> values = req.getHeaders(headerName);
|
||||
if (values != null) {
|
||||
// Java enumerations have klunky API. lets convert to a list.
|
||||
// this will be a short list usually.
|
||||
List<String> list = Collections.list(values);
|
||||
for (String s : list) {
|
||||
if (headerName.toLowerCase().endsWith(BINARY_HEADER_SUFFIX)) {
|
||||
// Binary header
|
||||
httpHeaders.put(
|
||||
Metadata.Key.of(headerName, Metadata.BINARY_BYTE_MARSHALLER), s.getBytes());
|
||||
} else {
|
||||
// String header
|
||||
httpHeaders.put(
|
||||
Metadata.Key.of(headerName, Metadata.ASCII_STRING_MARSHALLER), s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return httpHeaders;
|
||||
}
|
||||
|
||||
static Map<String, String> getHttpHeadersFromMetadata(Metadata trailer) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (String key : trailer.keys()) {
|
||||
if (EXCLUDED.contains(key.toLowerCase())) {
|
||||
continue;
|
||||
}
|
||||
if (key.endsWith(Metadata.BINARY_HEADER_SUFFIX)) {
|
||||
// TODO allow any object type here
|
||||
byte[] value = trailer.get(Metadata.Key.of(key, Metadata.BINARY_BYTE_MARSHALLER));
|
||||
map.put(key, new String(value));
|
||||
} else {
|
||||
String value = trailer.get(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER));
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
package com.google.grpcweb;
|
||||
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.Channel;
|
||||
import io.grpc.Metadata;
|
||||
import io.grpc.Status;
|
||||
import io.grpc.stub.MetadataUtils;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
@ -14,14 +16,14 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
|
|||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
class RequestHandler {
|
||||
private static final Logger LOGGER = Logger.getLogger(RequestHandler.class.getName());
|
||||
private static final Logger LOG = Logger.getLogger(RequestHandler.class.getName());
|
||||
|
||||
private final Factory mFactory;
|
||||
private final MessageHandler mMessageHandler;
|
||||
private final GrpcServiceConnectionManager mGrpcServiceConnectionManager;
|
||||
|
||||
RequestHandler(Factory factory) {
|
||||
mFactory = factory;
|
||||
mMessageHandler = new MessageHandler();
|
||||
mGrpcServiceConnectionManager = factory.getGrpcServiceConnectionManager();
|
||||
}
|
||||
|
||||
public void handle(final HttpServletRequest req, final HttpServletResponse resp) {
|
||||
|
@ -42,10 +44,19 @@ class RequestHandler {
|
|||
return;
|
||||
}
|
||||
|
||||
// get the stubs for the rpc call and the method to be called within the stubs
|
||||
Object asyncStub = getRpcStub(cls, "newStub");
|
||||
Method asyncStubCall = getRpcMethod(asyncStub, methodName);
|
||||
// Create a ClientInterceptor object
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
GrpcWebClientInterceptor interceptor =
|
||||
new GrpcWebClientInterceptor(resp, latch, sendResponse);
|
||||
Channel channel = mGrpcServiceConnectionManager.getChannelWithClientInterceptor(interceptor);
|
||||
|
||||
// get the stub for the rpc call and the method to be called within the stub
|
||||
io.grpc.stub.AbstractStub asyncStub = getRpcStub(channel, cls, "newStub");
|
||||
Metadata headers = MetadataUtil.getHtpHeaders(req);
|
||||
if (!headers.keys().isEmpty()) {
|
||||
asyncStub = MetadataUtils.attachHeaders(asyncStub, headers);
|
||||
}
|
||||
Method asyncStubCall = getRpcMethod(asyncStub, methodName);
|
||||
// Get the input object bytes
|
||||
ServletInputStream in = req.getInputStream();
|
||||
MessageDeframer deframer = new MessageDeframer();
|
||||
|
@ -55,12 +66,13 @@ class RequestHandler {
|
|||
}
|
||||
|
||||
// Invoke the rpc call
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
asyncStubCall.invoke(asyncStub, inObj,
|
||||
new GrpcCallResponseReceiver(sendResponse, latch));
|
||||
latch.await(500, TimeUnit.MILLISECONDS);
|
||||
if (!latch.await(500, TimeUnit.MILLISECONDS)) {
|
||||
LOG.warning("grpc call took too long!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.info(e.getMessage());
|
||||
LOG.info("Exception occurred: " + e.getMessage());
|
||||
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
@ -86,18 +98,17 @@ class RequestHandler {
|
|||
try {
|
||||
rpcClass = Class.forName(className + "Grpc");
|
||||
} catch (ClassNotFoundException e) {
|
||||
LOGGER.info("no such class " + className);
|
||||
LOG.info("no such class " + className);
|
||||
}
|
||||
return rpcClass;
|
||||
}
|
||||
|
||||
private Object getRpcStub(Class cls, String stubName) {
|
||||
private io.grpc.stub.AbstractStub getRpcStub(Channel ch, Class cls, String stubName) {
|
||||
try {
|
||||
Method m = cls.getDeclaredMethod(stubName, io.grpc.Channel.class);
|
||||
ManagedChannel channel = mFactory.getGrpcServiceConnectionManager().getChannel();
|
||||
return m.invoke(null, channel);
|
||||
return (io.grpc.stub.AbstractStub) m.invoke(null, ch);
|
||||
} catch (Exception e) {
|
||||
LOGGER.warning("Error when fetching " + stubName + " for: " + cls.getName());
|
||||
LOG.warning("Error when fetching " + stubName + " for: " + cls.getName());
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
@ -133,15 +144,13 @@ class RequestHandler {
|
|||
@Override
|
||||
public void onError(Throwable t) {
|
||||
Status s = Status.fromThrowable(t);
|
||||
LOGGER.info("status is " + s.toString());
|
||||
sendResponse.writeError(s);
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
sendResponse.writeGrpcStatusTrailer(Status.OK);
|
||||
sendResponse.writeOk();
|
||||
sendResponse.writeStatusTrailer(Status.OK);
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package com.google.grpcweb;
|
||||
|
||||
import com.google.grpcweb.MessageHandler.ContentType;
|
||||
import io.grpc.Metadata;
|
||||
import io.grpc.Status;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -14,48 +16,68 @@ class SendResponse {
|
|||
|
||||
private final String mContentType;
|
||||
private final HttpServletResponse mResp;
|
||||
private boolean isFinalResponseSent = false;
|
||||
|
||||
SendResponse(HttpServletRequest req, HttpServletResponse resp) {
|
||||
mContentType = req.getContentType();
|
||||
mResp = resp;
|
||||
}
|
||||
/**
|
||||
* Write response out.
|
||||
*/
|
||||
void writeResponse(byte[] out) {
|
||||
setHeaders();
|
||||
writeResponse(out, MessageFramer.Type.DATA);
|
||||
}
|
||||
|
||||
void returnUnimplementedStatusCode() {
|
||||
setHeaders();
|
||||
writeGrpcStatusTrailer(Status.UNIMPLEMENTED);
|
||||
writeOk();
|
||||
}
|
||||
|
||||
void writeOk() {
|
||||
mResp.setStatus(HttpServletResponse.SC_OK);
|
||||
}
|
||||
|
||||
private void setHeaders() {
|
||||
synchronized void writeHeaders(Metadata headers) {
|
||||
if (isFinalResponseSent) return;
|
||||
mResp.setContentType(mContentType);
|
||||
mResp.setHeader("transfer-encoding", "chunked");
|
||||
mResp.setHeader("trailer", "grpc-status,grpc-message");
|
||||
if (headers == null) return;
|
||||
Map<String, String> ht = MetadataUtil.getHttpHeadersFromMetadata(headers);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String key : ht.keySet()) {
|
||||
mResp.setHeader(key, ht.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
void writeError(Status s) {
|
||||
setHeaders();
|
||||
writeGrpcStatusTrailer(s);
|
||||
synchronized void returnUnimplementedStatusCode() {
|
||||
if (isFinalResponseSent) return;
|
||||
writeHeaders(null);
|
||||
writeStatusTrailer(Status.UNIMPLEMENTED);
|
||||
isFinalResponseSent = true;
|
||||
}
|
||||
|
||||
synchronized void writeError(Status s) {
|
||||
if (isFinalResponseSent) return;
|
||||
writeHeaders(null);
|
||||
writeStatusTrailer(s);
|
||||
isFinalResponseSent = true;
|
||||
}
|
||||
|
||||
synchronized void writeStatusTrailer(Status status) {
|
||||
writeTrailer(status, null);
|
||||
}
|
||||
|
||||
synchronized void writeTrailer(Status status, Metadata trailer) {
|
||||
if (isFinalResponseSent) return;
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if (trailer != null) {
|
||||
Map<String, String> ht = MetadataUtil.getHttpHeadersFromMetadata(trailer);
|
||||
for (String key : ht.keySet()) {
|
||||
sb.append(String.format("%s:%s\r\n", key, ht.get(key)));
|
||||
}
|
||||
}
|
||||
sb.append(String.format("grpc-status:%d\r\n", status.getCode().value()));
|
||||
if (status.getDescription() != null && !status.getDescription().isEmpty()) {
|
||||
sb.append(String.format("grpc-message:%s\r\n", status.getDescription()));
|
||||
}
|
||||
LOG.fine("writing trailer: " + sb.toString());
|
||||
writeResponse(sb.toString().getBytes(), MessageFramer.Type.TRAILER);
|
||||
writeOk();
|
||||
}
|
||||
|
||||
void writeGrpcStatusTrailer(Status status) {
|
||||
String trailer = String.format("grpc-status:%d\r\ngrpc-message:%s\r\n",
|
||||
status.getCode().value(), status.getDescription());
|
||||
writeResponse(trailer.getBytes(), MessageFramer.Type.TRAILER);
|
||||
synchronized void writeResponse(byte[] out) {
|
||||
writeResponse(out, MessageFramer.Type.DATA);
|
||||
}
|
||||
|
||||
private void writeResponse(byte[] out, MessageFramer.Type type) {
|
||||
if (isFinalResponseSent) return;
|
||||
try {
|
||||
// PUNT multiple frames not handled
|
||||
byte[] prefix = new MessageFramer().getPrefix(out, type);
|
||||
|
@ -72,11 +94,12 @@ class SendResponse {
|
|||
}
|
||||
} catch (IOException e) {
|
||||
// TODO what to do here?
|
||||
LOG.info("can't write?");
|
||||
LOG.warning("can't write?");
|
||||
}
|
||||
}
|
||||
|
||||
private void logPrefix(byte[] p) {
|
||||
LOG.info("LENGTH : " + p.length + ", " + p[0] + ", " + p[1] + ", " + p[2] + ", " + p[3] + ", " + p[4]);
|
||||
private void writeOk() {
|
||||
mResp.setStatus(HttpServletResponse.SC_OK);
|
||||
isFinalResponseSent = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,462 +0,0 @@
|
|||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: grpc/testing/empty.proto
|
||||
|
||||
package grpc.testing;
|
||||
|
||||
/**
|
||||
* ******* DO NOT EDIT *******
|
||||
* Generated by proto compiler from protos in the following dir
|
||||
* https://github.com/grpc/grpc/tree/master/src/proto/grpc/testing
|
||||
*/
|
||||
public final class EmptyOuterClass {
|
||||
private EmptyOuterClass() {}
|
||||
public static void registerAllExtensions(
|
||||
com.google.protobuf.ExtensionRegistryLite registry) {
|
||||
}
|
||||
|
||||
public static void registerAllExtensions(
|
||||
com.google.protobuf.ExtensionRegistry registry) {
|
||||
registerAllExtensions(
|
||||
(com.google.protobuf.ExtensionRegistryLite) registry);
|
||||
}
|
||||
public interface EmptyOrBuilder extends
|
||||
// @@protoc_insertion_point(interface_extends:grpc.testing.Empty)
|
||||
com.google.protobuf.MessageOrBuilder {
|
||||
}
|
||||
/**
|
||||
* <pre>
|
||||
* An empty message that you can re-use to avoid defining duplicated empty
|
||||
* messages in your project. A typical example is to use it as argument or the
|
||||
* return value of a service API. For instance:
|
||||
* service Foo {
|
||||
* rpc Bar (grpc.testing.Empty) returns (grpc.testing.Empty) { };
|
||||
* };
|
||||
* </pre>
|
||||
*
|
||||
* Protobuf type {@code grpc.testing.Empty}
|
||||
*/
|
||||
public static final class Empty extends
|
||||
com.google.protobuf.GeneratedMessageV3 implements
|
||||
// @@protoc_insertion_point(message_implements:grpc.testing.Empty)
|
||||
EmptyOrBuilder {
|
||||
private static final long serialVersionUID = 0L;
|
||||
// Use Empty.newBuilder() to construct.
|
||||
private Empty(com.google.protobuf.GeneratedMessageV3.Builder<?> builder) {
|
||||
super(builder);
|
||||
}
|
||||
private Empty() {
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public final com.google.protobuf.UnknownFieldSet
|
||||
getUnknownFields() {
|
||||
return this.unknownFields;
|
||||
}
|
||||
private Empty(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
this();
|
||||
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
|
||||
com.google.protobuf.UnknownFieldSet.newBuilder();
|
||||
try {
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
int tag = input.readTag();
|
||||
switch (tag) {
|
||||
case 0:
|
||||
done = true;
|
||||
break;
|
||||
default: {
|
||||
if (!parseUnknownFieldProto3(
|
||||
input, unknownFields, extensionRegistry, tag)) {
|
||||
done = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
throw e.setUnfinishedMessage(this);
|
||||
} catch (java.io.IOException e) {
|
||||
throw new com.google.protobuf.InvalidProtocolBufferException(
|
||||
e).setUnfinishedMessage(this);
|
||||
} finally {
|
||||
this.unknownFields = unknownFields.build();
|
||||
makeExtensionsImmutable();
|
||||
}
|
||||
}
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return grpc.testing.EmptyOuterClass.internal_static_grpc_testing_Empty_descriptor;
|
||||
}
|
||||
|
||||
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return grpc.testing.EmptyOuterClass.internal_static_grpc_testing_Empty_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
grpc.testing.EmptyOuterClass.Empty.class, grpc.testing.EmptyOuterClass.Empty.Builder.class);
|
||||
}
|
||||
|
||||
private byte memoizedIsInitialized = -1;
|
||||
public final boolean isInitialized() {
|
||||
byte isInitialized = memoizedIsInitialized;
|
||||
if (isInitialized == 1) return true;
|
||||
if (isInitialized == 0) return false;
|
||||
|
||||
memoizedIsInitialized = 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void writeTo(com.google.protobuf.CodedOutputStream output)
|
||||
throws java.io.IOException {
|
||||
unknownFields.writeTo(output);
|
||||
}
|
||||
|
||||
public int getSerializedSize() {
|
||||
int size = memoizedSize;
|
||||
if (size != -1) return size;
|
||||
|
||||
size = 0;
|
||||
size += unknownFields.getSerializedSize();
|
||||
memoizedSize = size;
|
||||
return size;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public boolean equals(final java.lang.Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof grpc.testing.EmptyOuterClass.Empty)) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
grpc.testing.EmptyOuterClass.Empty other = (grpc.testing.EmptyOuterClass.Empty) obj;
|
||||
|
||||
boolean result = true;
|
||||
result = result && unknownFields.equals(other.unknownFields);
|
||||
return result;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public int hashCode() {
|
||||
if (memoizedHashCode != 0) {
|
||||
return memoizedHashCode;
|
||||
}
|
||||
int hash = 41;
|
||||
hash = (19 * hash) + getDescriptor().hashCode();
|
||||
hash = (29 * hash) + unknownFields.hashCode();
|
||||
memoizedHashCode = hash;
|
||||
return hash;
|
||||
}
|
||||
|
||||
public static grpc.testing.EmptyOuterClass.Empty parseFrom(
|
||||
java.nio.ByteBuffer data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static grpc.testing.EmptyOuterClass.Empty parseFrom(
|
||||
java.nio.ByteBuffer data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static grpc.testing.EmptyOuterClass.Empty parseFrom(
|
||||
com.google.protobuf.ByteString data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static grpc.testing.EmptyOuterClass.Empty parseFrom(
|
||||
com.google.protobuf.ByteString data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static grpc.testing.EmptyOuterClass.Empty parseFrom(byte[] data)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data);
|
||||
}
|
||||
public static grpc.testing.EmptyOuterClass.Empty parseFrom(
|
||||
byte[] data,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return PARSER.parseFrom(data, extensionRegistry);
|
||||
}
|
||||
public static grpc.testing.EmptyOuterClass.Empty parseFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input);
|
||||
}
|
||||
public static grpc.testing.EmptyOuterClass.Empty parseFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
public static grpc.testing.EmptyOuterClass.Empty parseDelimitedFrom(java.io.InputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseDelimitedWithIOException(PARSER, input);
|
||||
}
|
||||
public static grpc.testing.EmptyOuterClass.Empty parseDelimitedFrom(
|
||||
java.io.InputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseDelimitedWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
public static grpc.testing.EmptyOuterClass.Empty parseFrom(
|
||||
com.google.protobuf.CodedInputStream input)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input);
|
||||
}
|
||||
public static grpc.testing.EmptyOuterClass.Empty parseFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
return com.google.protobuf.GeneratedMessageV3
|
||||
.parseWithIOException(PARSER, input, extensionRegistry);
|
||||
}
|
||||
|
||||
public Builder newBuilderForType() { return newBuilder(); }
|
||||
public static Builder newBuilder() {
|
||||
return DEFAULT_INSTANCE.toBuilder();
|
||||
}
|
||||
public static Builder newBuilder(grpc.testing.EmptyOuterClass.Empty prototype) {
|
||||
return DEFAULT_INSTANCE.toBuilder().mergeFrom(prototype);
|
||||
}
|
||||
public Builder toBuilder() {
|
||||
return this == DEFAULT_INSTANCE
|
||||
? new Builder() : new Builder().mergeFrom(this);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected Builder newBuilderForType(
|
||||
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
|
||||
Builder builder = new Builder(parent);
|
||||
return builder;
|
||||
}
|
||||
/**
|
||||
* <pre>
|
||||
* An empty message that you can re-use to avoid defining duplicated empty
|
||||
* messages in your project. A typical example is to use it as argument or the
|
||||
* return value of a service API. For instance:
|
||||
* service Foo {
|
||||
* rpc Bar (grpc.testing.Empty) returns (grpc.testing.Empty) { };
|
||||
* };
|
||||
* </pre>
|
||||
*
|
||||
* Protobuf type {@code grpc.testing.Empty}
|
||||
*/
|
||||
public static final class Builder extends
|
||||
com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
|
||||
// @@protoc_insertion_point(builder_implements:grpc.testing.Empty)
|
||||
grpc.testing.EmptyOuterClass.EmptyOrBuilder {
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return grpc.testing.EmptyOuterClass.internal_static_grpc_testing_Empty_descriptor;
|
||||
}
|
||||
|
||||
protected com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
internalGetFieldAccessorTable() {
|
||||
return grpc.testing.EmptyOuterClass.internal_static_grpc_testing_Empty_fieldAccessorTable
|
||||
.ensureFieldAccessorsInitialized(
|
||||
grpc.testing.EmptyOuterClass.Empty.class, grpc.testing.EmptyOuterClass.Empty.Builder.class);
|
||||
}
|
||||
|
||||
// Construct using grpc.testing.EmptyOuterClass.Empty.newBuilder()
|
||||
private Builder() {
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
|
||||
private Builder(
|
||||
com.google.protobuf.GeneratedMessageV3.BuilderParent parent) {
|
||||
super(parent);
|
||||
maybeForceBuilderInitialization();
|
||||
}
|
||||
private void maybeForceBuilderInitialization() {
|
||||
if (com.google.protobuf.GeneratedMessageV3
|
||||
.alwaysUseFieldBuilders) {
|
||||
}
|
||||
}
|
||||
public Builder clear() {
|
||||
super.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
public com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptorForType() {
|
||||
return grpc.testing.EmptyOuterClass.internal_static_grpc_testing_Empty_descriptor;
|
||||
}
|
||||
|
||||
public grpc.testing.EmptyOuterClass.Empty getDefaultInstanceForType() {
|
||||
return grpc.testing.EmptyOuterClass.Empty.getDefaultInstance();
|
||||
}
|
||||
|
||||
public grpc.testing.EmptyOuterClass.Empty build() {
|
||||
grpc.testing.EmptyOuterClass.Empty result = buildPartial();
|
||||
if (!result.isInitialized()) {
|
||||
throw newUninitializedMessageException(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public grpc.testing.EmptyOuterClass.Empty buildPartial() {
|
||||
grpc.testing.EmptyOuterClass.Empty result = new grpc.testing.EmptyOuterClass.Empty(this);
|
||||
onBuilt();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Builder clone() {
|
||||
return (Builder) super.clone();
|
||||
}
|
||||
public Builder setField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
java.lang.Object value) {
|
||||
return (Builder) super.setField(field, value);
|
||||
}
|
||||
public Builder clearField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field) {
|
||||
return (Builder) super.clearField(field);
|
||||
}
|
||||
public Builder clearOneof(
|
||||
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
|
||||
return (Builder) super.clearOneof(oneof);
|
||||
}
|
||||
public Builder setRepeatedField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
int index, java.lang.Object value) {
|
||||
return (Builder) super.setRepeatedField(field, index, value);
|
||||
}
|
||||
public Builder addRepeatedField(
|
||||
com.google.protobuf.Descriptors.FieldDescriptor field,
|
||||
java.lang.Object value) {
|
||||
return (Builder) super.addRepeatedField(field, value);
|
||||
}
|
||||
public Builder mergeFrom(com.google.protobuf.Message other) {
|
||||
if (other instanceof grpc.testing.EmptyOuterClass.Empty) {
|
||||
return mergeFrom((grpc.testing.EmptyOuterClass.Empty)other);
|
||||
} else {
|
||||
super.mergeFrom(other);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Builder mergeFrom(grpc.testing.EmptyOuterClass.Empty other) {
|
||||
if (other == grpc.testing.EmptyOuterClass.Empty.getDefaultInstance()) return this;
|
||||
this.mergeUnknownFields(other.unknownFields);
|
||||
onChanged();
|
||||
return this;
|
||||
}
|
||||
|
||||
public final boolean isInitialized() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Builder mergeFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws java.io.IOException {
|
||||
grpc.testing.EmptyOuterClass.Empty parsedMessage = null;
|
||||
try {
|
||||
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
|
||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||
parsedMessage = (grpc.testing.EmptyOuterClass.Empty) e.getUnfinishedMessage();
|
||||
throw e.unwrapIOException();
|
||||
} finally {
|
||||
if (parsedMessage != null) {
|
||||
mergeFrom(parsedMessage);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public final Builder setUnknownFields(
|
||||
final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
return super.setUnknownFieldsProto3(unknownFields);
|
||||
}
|
||||
|
||||
public final Builder mergeUnknownFields(
|
||||
final com.google.protobuf.UnknownFieldSet unknownFields) {
|
||||
return super.mergeUnknownFields(unknownFields);
|
||||
}
|
||||
|
||||
|
||||
// @@protoc_insertion_point(builder_scope:grpc.testing.Empty)
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(class_scope:grpc.testing.Empty)
|
||||
private static final grpc.testing.EmptyOuterClass.Empty DEFAULT_INSTANCE;
|
||||
static {
|
||||
DEFAULT_INSTANCE = new grpc.testing.EmptyOuterClass.Empty();
|
||||
}
|
||||
|
||||
public static grpc.testing.EmptyOuterClass.Empty getDefaultInstance() {
|
||||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
private static final com.google.protobuf.Parser<Empty>
|
||||
PARSER = new com.google.protobuf.AbstractParser<Empty>() {
|
||||
public Empty parsePartialFrom(
|
||||
com.google.protobuf.CodedInputStream input,
|
||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
||||
return new Empty(input, extensionRegistry);
|
||||
}
|
||||
};
|
||||
|
||||
public static com.google.protobuf.Parser<Empty> parser() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Parser<Empty> getParserForType() {
|
||||
return PARSER;
|
||||
}
|
||||
|
||||
public grpc.testing.EmptyOuterClass.Empty getDefaultInstanceForType() {
|
||||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final com.google.protobuf.Descriptors.Descriptor
|
||||
internal_static_grpc_testing_Empty_descriptor;
|
||||
private static final
|
||||
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable
|
||||
internal_static_grpc_testing_Empty_fieldAccessorTable;
|
||||
|
||||
public static com.google.protobuf.Descriptors.FileDescriptor
|
||||
getDescriptor() {
|
||||
return descriptor;
|
||||
}
|
||||
private static com.google.protobuf.Descriptors.FileDescriptor
|
||||
descriptor;
|
||||
static {
|
||||
java.lang.String[] descriptorData = {
|
||||
"\n\030grpc/testing/empty.proto\022\014grpc.testing" +
|
||||
"\"\007\n\005Emptyb\006proto3"
|
||||
};
|
||||
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
||||
new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
|
||||
public com.google.protobuf.ExtensionRegistry assignDescriptors(
|
||||
com.google.protobuf.Descriptors.FileDescriptor root) {
|
||||
descriptor = root;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
com.google.protobuf.Descriptors.FileDescriptor
|
||||
.internalBuildGeneratedFileFrom(descriptorData,
|
||||
new com.google.protobuf.Descriptors.FileDescriptor[] {
|
||||
}, assigner);
|
||||
internal_static_grpc_testing_Empty_descriptor =
|
||||
getDescriptor().getMessageTypes().get(0);
|
||||
internal_static_grpc_testing_Empty_fieldAccessorTable = new
|
||||
com.google.protobuf.GeneratedMessageV3.FieldAccessorTable(
|
||||
internal_static_grpc_testing_Empty_descriptor,
|
||||
new java.lang.String[] { });
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(outer_class_scope)
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,81 +0,0 @@
|
|||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: grpc/testing/test.proto
|
||||
|
||||
package grpc.testing;
|
||||
|
||||
/**
|
||||
* ******* DO NOT EDIT *******
|
||||
* Generated by proto compiler from protos in the following dir
|
||||
* https://github.com/grpc/grpc/tree/master/src/proto/grpc/testing
|
||||
*/
|
||||
public final class TestFromProto {
|
||||
private TestFromProto() {}
|
||||
public static void registerAllExtensions(
|
||||
com.google.protobuf.ExtensionRegistryLite registry) {
|
||||
}
|
||||
|
||||
public static void registerAllExtensions(
|
||||
com.google.protobuf.ExtensionRegistry registry) {
|
||||
registerAllExtensions(
|
||||
(com.google.protobuf.ExtensionRegistryLite) registry);
|
||||
}
|
||||
|
||||
public static com.google.protobuf.Descriptors.FileDescriptor
|
||||
getDescriptor() {
|
||||
return descriptor;
|
||||
}
|
||||
private static com.google.protobuf.Descriptors.FileDescriptor
|
||||
descriptor;
|
||||
static {
|
||||
java.lang.String[] descriptorData = {
|
||||
"\n\027grpc/testing/test.proto\022\014grpc.testing\032" +
|
||||
"\030grpc/testing/empty.proto\032\033grpc/testing/" +
|
||||
"messages.proto2\313\005\n\013TestService\0225\n\tEmptyC" +
|
||||
"all\022\023.grpc.testing.Empty\032\023.grpc.testing." +
|
||||
"Empty\022F\n\tUnaryCall\022\033.grpc.testing.Simple" +
|
||||
"Request\032\034.grpc.testing.SimpleResponse\022O\n" +
|
||||
"\022CacheableUnaryCall\022\033.grpc.testing.Simpl" +
|
||||
"eRequest\032\034.grpc.testing.SimpleResponse\022l" +
|
||||
"\n\023StreamingOutputCall\022(.grpc.testing.Str" +
|
||||
"eamingOutputCallRequest\032).grpc.testing.S",
|
||||
"treamingOutputCallResponse0\001\022i\n\022Streamin" +
|
||||
"gInputCall\022\'.grpc.testing.StreamingInput" +
|
||||
"CallRequest\032(.grpc.testing.StreamingInpu" +
|
||||
"tCallResponse(\001\022i\n\016FullDuplexCall\022(.grpc" +
|
||||
".testing.StreamingOutputCallRequest\032).gr" +
|
||||
"pc.testing.StreamingOutputCallResponse(\001" +
|
||||
"0\001\022i\n\016HalfDuplexCall\022(.grpc.testing.Stre" +
|
||||
"amingOutputCallRequest\032).grpc.testing.St" +
|
||||
"reamingOutputCallResponse(\0010\001\022=\n\021Unimple" +
|
||||
"mentedCall\022\023.grpc.testing.Empty\032\023.grpc.t",
|
||||
"esting.Empty2U\n\024UnimplementedService\022=\n\021" +
|
||||
"UnimplementedCall\022\023.grpc.testing.Empty\032\023" +
|
||||
".grpc.testing.Empty2\211\001\n\020ReconnectService" +
|
||||
"\022;\n\005Start\022\035.grpc.testing.ReconnectParams" +
|
||||
"\032\023.grpc.testing.Empty\0228\n\004Stop\022\023.grpc.tes" +
|
||||
"ting.Empty\032\033.grpc.testing.ReconnectInfo2" +
|
||||
"\177\n\030LoadBalancerStatsService\022c\n\016GetClient" +
|
||||
"Stats\022&.grpc.testing.LoadBalancerStatsRe" +
|
||||
"quest\032\'.grpc.testing.LoadBalancerStatsRe" +
|
||||
"sponse\"\000b\006proto3"
|
||||
};
|
||||
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
||||
new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
|
||||
public com.google.protobuf.ExtensionRegistry assignDescriptors(
|
||||
com.google.protobuf.Descriptors.FileDescriptor root) {
|
||||
descriptor = root;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
com.google.protobuf.Descriptors.FileDescriptor
|
||||
.internalBuildGeneratedFileFrom(descriptorData,
|
||||
new com.google.protobuf.Descriptors.FileDescriptor[] {
|
||||
grpc.testing.EmptyOuterClass.getDescriptor(),
|
||||
grpc.testing.Messages.getDescriptor(),
|
||||
}, assigner);
|
||||
grpc.testing.EmptyOuterClass.getDescriptor();
|
||||
grpc.testing.Messages.getDescriptor();
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(outer_class_scope)
|
||||
}
|
|
@ -1,730 +0,0 @@
|
|||
package grpc.testing;
|
||||
|
||||
import static io.grpc.stub.ClientCalls.asyncUnaryCall;
|
||||
import static io.grpc.stub.ClientCalls.asyncServerStreamingCall;
|
||||
import static io.grpc.stub.ClientCalls.asyncClientStreamingCall;
|
||||
import static io.grpc.stub.ClientCalls.asyncBidiStreamingCall;
|
||||
import static io.grpc.stub.ClientCalls.blockingUnaryCall;
|
||||
import static io.grpc.stub.ClientCalls.blockingServerStreamingCall;
|
||||
import static io.grpc.stub.ClientCalls.futureUnaryCall;
|
||||
import static io.grpc.MethodDescriptor.generateFullMethodName;
|
||||
import static io.grpc.stub.ServerCalls.asyncUnaryCall;
|
||||
import static io.grpc.stub.ServerCalls.asyncServerStreamingCall;
|
||||
import static io.grpc.stub.ServerCalls.asyncClientStreamingCall;
|
||||
import static io.grpc.stub.ServerCalls.asyncBidiStreamingCall;
|
||||
import static io.grpc.stub.ServerCalls.asyncUnimplementedUnaryCall;
|
||||
import static io.grpc.stub.ServerCalls.asyncUnimplementedStreamingCall;
|
||||
|
||||
import grpc.testing.Messages.SimpleRequest;
|
||||
import grpc.testing.Messages.SimpleResponse;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
|
||||
/**
|
||||
* ******* DO NOT EDIT *******
|
||||
* Generated by proto compiler from protos in the following dir
|
||||
* https://github.com/grpc/grpc/tree/master/src/proto/grpc/testing
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* A simple service to test the various types of RPCs and experiment with
|
||||
* performance with various types of payload.
|
||||
* </pre>
|
||||
*/
|
||||
@javax.annotation.Generated(
|
||||
value = "by gRPC proto compiler (version 1.7.0)",
|
||||
comments = "Source: grpc/testing/test.proto")
|
||||
public final class TestServiceGrpc {
|
||||
|
||||
private TestServiceGrpc() {}
|
||||
|
||||
public static final String SERVICE_NAME = "grpc.testing.TestService";
|
||||
|
||||
// Static method descriptors that strictly reflect the proto.
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<grpc.testing.EmptyOuterClass.Empty,
|
||||
grpc.testing.EmptyOuterClass.Empty> METHOD_EMPTY_CALL =
|
||||
io.grpc.MethodDescriptor.<grpc.testing.EmptyOuterClass.Empty, grpc.testing.EmptyOuterClass.Empty>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"grpc.testing.TestService", "EmptyCall"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
grpc.testing.EmptyOuterClass.Empty.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
grpc.testing.EmptyOuterClass.Empty.getDefaultInstance()))
|
||||
.setSchemaDescriptor(new TestServiceMethodDescriptorSupplier("EmptyCall"))
|
||||
.build();
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<grpc.testing.Messages.SimpleRequest,
|
||||
grpc.testing.Messages.SimpleResponse> METHOD_UNARY_CALL =
|
||||
io.grpc.MethodDescriptor.<grpc.testing.Messages.SimpleRequest, grpc.testing.Messages.SimpleResponse>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"grpc.testing.TestService", "UnaryCall"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
grpc.testing.Messages.SimpleRequest.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
grpc.testing.Messages.SimpleResponse.getDefaultInstance()))
|
||||
.setSchemaDescriptor(new TestServiceMethodDescriptorSupplier("UnaryCall"))
|
||||
.build();
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<grpc.testing.Messages.SimpleRequest,
|
||||
grpc.testing.Messages.SimpleResponse> METHOD_CACHEABLE_UNARY_CALL =
|
||||
io.grpc.MethodDescriptor.<grpc.testing.Messages.SimpleRequest, grpc.testing.Messages.SimpleResponse>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"grpc.testing.TestService", "CacheableUnaryCall"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
grpc.testing.Messages.SimpleRequest.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
grpc.testing.Messages.SimpleResponse.getDefaultInstance()))
|
||||
.setSchemaDescriptor(new TestServiceMethodDescriptorSupplier("CacheableUnaryCall"))
|
||||
.build();
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<grpc.testing.Messages.StreamingOutputCallRequest,
|
||||
grpc.testing.Messages.StreamingOutputCallResponse> METHOD_STREAMING_OUTPUT_CALL =
|
||||
io.grpc.MethodDescriptor.<grpc.testing.Messages.StreamingOutputCallRequest, grpc.testing.Messages.StreamingOutputCallResponse>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.SERVER_STREAMING)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"grpc.testing.TestService", "StreamingOutputCall"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
grpc.testing.Messages.StreamingOutputCallRequest.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
grpc.testing.Messages.StreamingOutputCallResponse.getDefaultInstance()))
|
||||
.setSchemaDescriptor(new TestServiceMethodDescriptorSupplier("StreamingOutputCall"))
|
||||
.build();
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<grpc.testing.Messages.StreamingInputCallRequest,
|
||||
grpc.testing.Messages.StreamingInputCallResponse> METHOD_STREAMING_INPUT_CALL =
|
||||
io.grpc.MethodDescriptor.<grpc.testing.Messages.StreamingInputCallRequest, grpc.testing.Messages.StreamingInputCallResponse>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.CLIENT_STREAMING)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"grpc.testing.TestService", "StreamingInputCall"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
grpc.testing.Messages.StreamingInputCallRequest.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
grpc.testing.Messages.StreamingInputCallResponse.getDefaultInstance()))
|
||||
.setSchemaDescriptor(new TestServiceMethodDescriptorSupplier("StreamingInputCall"))
|
||||
.build();
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<grpc.testing.Messages.StreamingOutputCallRequest,
|
||||
grpc.testing.Messages.StreamingOutputCallResponse> METHOD_FULL_DUPLEX_CALL =
|
||||
io.grpc.MethodDescriptor.<grpc.testing.Messages.StreamingOutputCallRequest, grpc.testing.Messages.StreamingOutputCallResponse>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"grpc.testing.TestService", "FullDuplexCall"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
grpc.testing.Messages.StreamingOutputCallRequest.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
grpc.testing.Messages.StreamingOutputCallResponse.getDefaultInstance()))
|
||||
.setSchemaDescriptor(new TestServiceMethodDescriptorSupplier("FullDuplexCall"))
|
||||
.build();
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<grpc.testing.Messages.StreamingOutputCallRequest,
|
||||
grpc.testing.Messages.StreamingOutputCallResponse> METHOD_HALF_DUPLEX_CALL =
|
||||
io.grpc.MethodDescriptor.<grpc.testing.Messages.StreamingOutputCallRequest, grpc.testing.Messages.StreamingOutputCallResponse>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.BIDI_STREAMING)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"grpc.testing.TestService", "HalfDuplexCall"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
grpc.testing.Messages.StreamingOutputCallRequest.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
grpc.testing.Messages.StreamingOutputCallResponse.getDefaultInstance()))
|
||||
.setSchemaDescriptor(new TestServiceMethodDescriptorSupplier("HalfDuplexCall"))
|
||||
.build();
|
||||
@io.grpc.ExperimentalApi("https://github.com/grpc/grpc-java/issues/1901")
|
||||
public static final io.grpc.MethodDescriptor<grpc.testing.EmptyOuterClass.Empty,
|
||||
grpc.testing.EmptyOuterClass.Empty> METHOD_UNIMPLEMENTED_CALL =
|
||||
io.grpc.MethodDescriptor.<grpc.testing.EmptyOuterClass.Empty, grpc.testing.EmptyOuterClass.Empty>newBuilder()
|
||||
.setType(io.grpc.MethodDescriptor.MethodType.UNARY)
|
||||
.setFullMethodName(generateFullMethodName(
|
||||
"grpc.testing.TestService", "UnimplementedCall"))
|
||||
.setRequestMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
grpc.testing.EmptyOuterClass.Empty.getDefaultInstance()))
|
||||
.setResponseMarshaller(io.grpc.protobuf.ProtoUtils.marshaller(
|
||||
grpc.testing.EmptyOuterClass.Empty.getDefaultInstance()))
|
||||
.setSchemaDescriptor(new TestServiceMethodDescriptorSupplier("UnimplementedCall"))
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Creates a new async stub that supports all call types for the service
|
||||
*/
|
||||
public static TestServiceStub newStub(io.grpc.Channel channel) {
|
||||
return new TestServiceStub(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new blocking-style stub that supports unary and streaming output calls on the service
|
||||
*/
|
||||
public static TestServiceBlockingStub newBlockingStub(
|
||||
io.grpc.Channel channel) {
|
||||
return new TestServiceBlockingStub(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ListenableFuture-style stub that supports unary calls on the service
|
||||
*/
|
||||
public static TestServiceFutureStub newFutureStub(
|
||||
io.grpc.Channel channel) {
|
||||
return new TestServiceFutureStub(channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* A simple service to test the various types of RPCs and experiment with
|
||||
* performance with various types of payload.
|
||||
* </pre>
|
||||
*/
|
||||
public static abstract class TestServiceImplBase implements io.grpc.BindableService {
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* One empty request followed by one empty response.
|
||||
* </pre>
|
||||
*/
|
||||
public void emptyCall(grpc.testing.EmptyOuterClass.Empty request,
|
||||
io.grpc.stub.StreamObserver<grpc.testing.EmptyOuterClass.Empty> responseObserver) {
|
||||
asyncUnimplementedUnaryCall(METHOD_EMPTY_CALL, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* One request followed by one response.
|
||||
* </pre>
|
||||
*/
|
||||
public void unaryCall(grpc.testing.Messages.SimpleRequest request,
|
||||
io.grpc.stub.StreamObserver<grpc.testing.Messages.SimpleResponse> responseObserver) {
|
||||
asyncUnimplementedUnaryCall(METHOD_UNARY_CALL, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* One request followed by one response. Response has cache control
|
||||
* headers set such that a caching HTTP proxy (such as GFE) can
|
||||
* satisfy subsequent requests.
|
||||
* </pre>
|
||||
*/
|
||||
public void cacheableUnaryCall(grpc.testing.Messages.SimpleRequest request,
|
||||
io.grpc.stub.StreamObserver<grpc.testing.Messages.SimpleResponse> responseObserver) {
|
||||
asyncUnimplementedUnaryCall(METHOD_CACHEABLE_UNARY_CALL, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* One request followed by a sequence of responses (streamed download).
|
||||
* The server returns the payload with client desired type and sizes.
|
||||
* </pre>
|
||||
*/
|
||||
public void streamingOutputCall(grpc.testing.Messages.StreamingOutputCallRequest request,
|
||||
io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingOutputCallResponse> responseObserver) {
|
||||
asyncUnimplementedUnaryCall(METHOD_STREAMING_OUTPUT_CALL, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* A sequence of requests followed by one response (streamed upload).
|
||||
* The server returns the aggregated size of client payload as the result.
|
||||
* </pre>
|
||||
*/
|
||||
public io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingInputCallRequest> streamingInputCall(
|
||||
io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingInputCallResponse> responseObserver) {
|
||||
return asyncUnimplementedStreamingCall(METHOD_STREAMING_INPUT_CALL, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* A sequence of requests with each request served by the server immediately.
|
||||
* As one request could lead to multiple responses, this interface
|
||||
* demonstrates the idea of full duplexing.
|
||||
* </pre>
|
||||
*/
|
||||
public io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingOutputCallRequest> fullDuplexCall(
|
||||
io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingOutputCallResponse> responseObserver) {
|
||||
return asyncUnimplementedStreamingCall(METHOD_FULL_DUPLEX_CALL, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* A sequence of requests followed by a sequence of responses.
|
||||
* The server buffers all the client requests and then serves them in order. A
|
||||
* stream of responses are returned to the client when the server starts with
|
||||
* first request.
|
||||
* </pre>
|
||||
*/
|
||||
public io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingOutputCallRequest> halfDuplexCall(
|
||||
io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingOutputCallResponse> responseObserver) {
|
||||
return asyncUnimplementedStreamingCall(METHOD_HALF_DUPLEX_CALL, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* The test server will not implement this method. It will be used
|
||||
* to test the behavior when clients call unimplemented methods.
|
||||
* </pre>
|
||||
*/
|
||||
public void unimplementedCall(grpc.testing.EmptyOuterClass.Empty request,
|
||||
io.grpc.stub.StreamObserver<grpc.testing.EmptyOuterClass.Empty> responseObserver) {
|
||||
asyncUnimplementedUnaryCall(METHOD_UNIMPLEMENTED_CALL, responseObserver);
|
||||
}
|
||||
|
||||
@java.lang.Override public final io.grpc.ServerServiceDefinition bindService() {
|
||||
return io.grpc.ServerServiceDefinition.builder(getServiceDescriptor())
|
||||
.addMethod(
|
||||
METHOD_EMPTY_CALL,
|
||||
asyncUnaryCall(
|
||||
new MethodHandlers<
|
||||
grpc.testing.EmptyOuterClass.Empty,
|
||||
grpc.testing.EmptyOuterClass.Empty>(
|
||||
this, METHODID_EMPTY_CALL)))
|
||||
.addMethod(
|
||||
METHOD_UNARY_CALL,
|
||||
asyncUnaryCall(
|
||||
new MethodHandlers<
|
||||
grpc.testing.Messages.SimpleRequest,
|
||||
grpc.testing.Messages.SimpleResponse>(
|
||||
this, METHODID_UNARY_CALL)))
|
||||
.addMethod(
|
||||
METHOD_CACHEABLE_UNARY_CALL,
|
||||
asyncUnaryCall(
|
||||
new MethodHandlers<
|
||||
grpc.testing.Messages.SimpleRequest,
|
||||
grpc.testing.Messages.SimpleResponse>(
|
||||
this, METHODID_CACHEABLE_UNARY_CALL)))
|
||||
.addMethod(
|
||||
METHOD_STREAMING_OUTPUT_CALL,
|
||||
asyncServerStreamingCall(
|
||||
new MethodHandlers<
|
||||
grpc.testing.Messages.StreamingOutputCallRequest,
|
||||
grpc.testing.Messages.StreamingOutputCallResponse>(
|
||||
this, METHODID_STREAMING_OUTPUT_CALL)))
|
||||
.addMethod(
|
||||
METHOD_STREAMING_INPUT_CALL,
|
||||
asyncClientStreamingCall(
|
||||
new MethodHandlers<
|
||||
grpc.testing.Messages.StreamingInputCallRequest,
|
||||
grpc.testing.Messages.StreamingInputCallResponse>(
|
||||
this, METHODID_STREAMING_INPUT_CALL)))
|
||||
.addMethod(
|
||||
METHOD_FULL_DUPLEX_CALL,
|
||||
asyncBidiStreamingCall(
|
||||
new MethodHandlers<
|
||||
grpc.testing.Messages.StreamingOutputCallRequest,
|
||||
grpc.testing.Messages.StreamingOutputCallResponse>(
|
||||
this, METHODID_FULL_DUPLEX_CALL)))
|
||||
.addMethod(
|
||||
METHOD_HALF_DUPLEX_CALL,
|
||||
asyncBidiStreamingCall(
|
||||
new MethodHandlers<
|
||||
grpc.testing.Messages.StreamingOutputCallRequest,
|
||||
grpc.testing.Messages.StreamingOutputCallResponse>(
|
||||
this, METHODID_HALF_DUPLEX_CALL)))
|
||||
.addMethod(
|
||||
METHOD_UNIMPLEMENTED_CALL,
|
||||
asyncUnaryCall(
|
||||
new MethodHandlers<
|
||||
grpc.testing.EmptyOuterClass.Empty,
|
||||
grpc.testing.EmptyOuterClass.Empty>(
|
||||
this, METHODID_UNIMPLEMENTED_CALL)))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* A simple service to test the various types of RPCs and experiment with
|
||||
* performance with various types of payload.
|
||||
* </pre>
|
||||
*/
|
||||
public static final class TestServiceStub extends io.grpc.stub.AbstractStub<TestServiceStub> {
|
||||
private TestServiceStub(io.grpc.Channel channel) {
|
||||
super(channel);
|
||||
}
|
||||
|
||||
private TestServiceStub(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
super(channel, callOptions);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected TestServiceStub build(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
return new TestServiceStub(channel, callOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* One empty request followed by one empty response.
|
||||
* </pre>
|
||||
*/
|
||||
public void emptyCall(grpc.testing.EmptyOuterClass.Empty request,
|
||||
io.grpc.stub.StreamObserver<grpc.testing.EmptyOuterClass.Empty> responseObserver) {
|
||||
asyncUnaryCall(
|
||||
getChannel().newCall(METHOD_EMPTY_CALL, getCallOptions()), request, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* One request followed by one response.
|
||||
* </pre>
|
||||
*/
|
||||
public void unaryCall(grpc.testing.Messages.SimpleRequest request,
|
||||
io.grpc.stub.StreamObserver<grpc.testing.Messages.SimpleResponse> responseObserver) {
|
||||
asyncUnaryCall(
|
||||
getChannel().newCall(METHOD_UNARY_CALL, getCallOptions()), request, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* One request followed by one response. Response has cache control
|
||||
* headers set such that a caching HTTP proxy (such as GFE) can
|
||||
* satisfy subsequent requests.
|
||||
* </pre>
|
||||
*/
|
||||
public void cacheableUnaryCall(grpc.testing.Messages.SimpleRequest request,
|
||||
io.grpc.stub.StreamObserver<grpc.testing.Messages.SimpleResponse> responseObserver) {
|
||||
asyncUnaryCall(
|
||||
getChannel().newCall(METHOD_CACHEABLE_UNARY_CALL, getCallOptions()), request, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* One request followed by a sequence of responses (streamed download).
|
||||
* The server returns the payload with client desired type and sizes.
|
||||
* </pre>
|
||||
*/
|
||||
public void streamingOutputCall(grpc.testing.Messages.StreamingOutputCallRequest request,
|
||||
io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingOutputCallResponse> responseObserver) {
|
||||
asyncServerStreamingCall(
|
||||
getChannel().newCall(METHOD_STREAMING_OUTPUT_CALL, getCallOptions()), request, responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* A sequence of requests followed by one response (streamed upload).
|
||||
* The server returns the aggregated size of client payload as the result.
|
||||
* </pre>
|
||||
*/
|
||||
public io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingInputCallRequest> streamingInputCall(
|
||||
io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingInputCallResponse> responseObserver) {
|
||||
return asyncClientStreamingCall(
|
||||
getChannel().newCall(METHOD_STREAMING_INPUT_CALL, getCallOptions()), responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* A sequence of requests with each request served by the server immediately.
|
||||
* As one request could lead to multiple responses, this interface
|
||||
* demonstrates the idea of full duplexing.
|
||||
* </pre>
|
||||
*/
|
||||
public io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingOutputCallRequest> fullDuplexCall(
|
||||
io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingOutputCallResponse> responseObserver) {
|
||||
return asyncBidiStreamingCall(
|
||||
getChannel().newCall(METHOD_FULL_DUPLEX_CALL, getCallOptions()), responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* A sequence of requests followed by a sequence of responses.
|
||||
* The server buffers all the client requests and then serves them in order. A
|
||||
* stream of responses are returned to the client when the server starts with
|
||||
* first request.
|
||||
* </pre>
|
||||
*/
|
||||
public io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingOutputCallRequest> halfDuplexCall(
|
||||
io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingOutputCallResponse> responseObserver) {
|
||||
return asyncBidiStreamingCall(
|
||||
getChannel().newCall(METHOD_HALF_DUPLEX_CALL, getCallOptions()), responseObserver);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* The test server will not implement this method. It will be used
|
||||
* to test the behavior when clients call unimplemented methods.
|
||||
* </pre>
|
||||
*/
|
||||
public void unimplementedCall(grpc.testing.EmptyOuterClass.Empty request,
|
||||
io.grpc.stub.StreamObserver<grpc.testing.EmptyOuterClass.Empty> responseObserver) {
|
||||
asyncUnaryCall(
|
||||
getChannel().newCall(METHOD_UNIMPLEMENTED_CALL, getCallOptions()), request, responseObserver);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* A simple service to test the various types of RPCs and experiment with
|
||||
* performance with various types of payload.
|
||||
* </pre>
|
||||
*/
|
||||
public static final class TestServiceBlockingStub extends io.grpc.stub.AbstractStub<TestServiceBlockingStub> {
|
||||
private TestServiceBlockingStub(io.grpc.Channel channel) {
|
||||
super(channel);
|
||||
}
|
||||
|
||||
private TestServiceBlockingStub(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
super(channel, callOptions);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected TestServiceBlockingStub build(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
return new TestServiceBlockingStub(channel, callOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* One empty request followed by one empty response.
|
||||
* </pre>
|
||||
*/
|
||||
public grpc.testing.EmptyOuterClass.Empty emptyCall(grpc.testing.EmptyOuterClass.Empty request) {
|
||||
return blockingUnaryCall(
|
||||
getChannel(), METHOD_EMPTY_CALL, getCallOptions(), request);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* One request followed by one response.
|
||||
* </pre>
|
||||
*/
|
||||
public grpc.testing.Messages.SimpleResponse unaryCall(grpc.testing.Messages.SimpleRequest request) {
|
||||
return blockingUnaryCall(
|
||||
getChannel(), METHOD_UNARY_CALL, getCallOptions(), request);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* One request followed by one response. Response has cache control
|
||||
* headers set such that a caching HTTP proxy (such as GFE) can
|
||||
* satisfy subsequent requests.
|
||||
* </pre>
|
||||
*/
|
||||
public grpc.testing.Messages.SimpleResponse cacheableUnaryCall(grpc.testing.Messages.SimpleRequest request) {
|
||||
return blockingUnaryCall(
|
||||
getChannel(), METHOD_CACHEABLE_UNARY_CALL, getCallOptions(), request);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* One request followed by a sequence of responses (streamed download).
|
||||
* The server returns the payload with client desired type and sizes.
|
||||
* </pre>
|
||||
*/
|
||||
public java.util.Iterator<grpc.testing.Messages.StreamingOutputCallResponse> streamingOutputCall(
|
||||
grpc.testing.Messages.StreamingOutputCallRequest request) {
|
||||
return blockingServerStreamingCall(
|
||||
getChannel(), METHOD_STREAMING_OUTPUT_CALL, getCallOptions(), request);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* The test server will not implement this method. It will be used
|
||||
* to test the behavior when clients call unimplemented methods.
|
||||
* </pre>
|
||||
*/
|
||||
public grpc.testing.EmptyOuterClass.Empty unimplementedCall(grpc.testing.EmptyOuterClass.Empty request) {
|
||||
return blockingUnaryCall(
|
||||
getChannel(), METHOD_UNIMPLEMENTED_CALL, getCallOptions(), request);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* A simple service to test the various types of RPCs and experiment with
|
||||
* performance with various types of payload.
|
||||
* </pre>
|
||||
*/
|
||||
public static final class TestServiceFutureStub extends io.grpc.stub.AbstractStub<TestServiceFutureStub> {
|
||||
private TestServiceFutureStub(io.grpc.Channel channel) {
|
||||
super(channel);
|
||||
}
|
||||
|
||||
private TestServiceFutureStub(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
super(channel, callOptions);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
protected TestServiceFutureStub build(io.grpc.Channel channel,
|
||||
io.grpc.CallOptions callOptions) {
|
||||
return new TestServiceFutureStub(channel, callOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* One empty request followed by one empty response.
|
||||
* </pre>
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<grpc.testing.EmptyOuterClass.Empty> emptyCall(
|
||||
grpc.testing.EmptyOuterClass.Empty request) {
|
||||
return futureUnaryCall(
|
||||
getChannel().newCall(METHOD_EMPTY_CALL, getCallOptions()), request);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* One request followed by one response.
|
||||
* </pre>
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<grpc.testing.Messages.SimpleResponse> unaryCall(
|
||||
grpc.testing.Messages.SimpleRequest request) {
|
||||
return futureUnaryCall(
|
||||
getChannel().newCall(METHOD_UNARY_CALL, getCallOptions()), request);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* One request followed by one response. Response has cache control
|
||||
* headers set such that a caching HTTP proxy (such as GFE) can
|
||||
* satisfy subsequent requests.
|
||||
* </pre>
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<grpc.testing.Messages.SimpleResponse> cacheableUnaryCall(
|
||||
grpc.testing.Messages.SimpleRequest request) {
|
||||
return futureUnaryCall(
|
||||
getChannel().newCall(METHOD_CACHEABLE_UNARY_CALL, getCallOptions()), request);
|
||||
}
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* The test server will not implement this method. It will be used
|
||||
* to test the behavior when clients call unimplemented methods.
|
||||
* </pre>
|
||||
*/
|
||||
public com.google.common.util.concurrent.ListenableFuture<grpc.testing.EmptyOuterClass.Empty> unimplementedCall(
|
||||
grpc.testing.EmptyOuterClass.Empty request) {
|
||||
return futureUnaryCall(
|
||||
getChannel().newCall(METHOD_UNIMPLEMENTED_CALL, getCallOptions()), request);
|
||||
}
|
||||
}
|
||||
|
||||
private static final int METHODID_EMPTY_CALL = 0;
|
||||
private static final int METHODID_UNARY_CALL = 1;
|
||||
private static final int METHODID_CACHEABLE_UNARY_CALL = 2;
|
||||
private static final int METHODID_STREAMING_OUTPUT_CALL = 3;
|
||||
private static final int METHODID_UNIMPLEMENTED_CALL = 4;
|
||||
private static final int METHODID_STREAMING_INPUT_CALL = 5;
|
||||
private static final int METHODID_FULL_DUPLEX_CALL = 6;
|
||||
private static final int METHODID_HALF_DUPLEX_CALL = 7;
|
||||
|
||||
private static final class MethodHandlers<Req, Resp> implements
|
||||
io.grpc.stub.ServerCalls.UnaryMethod<Req, Resp>,
|
||||
io.grpc.stub.ServerCalls.ServerStreamingMethod<Req, Resp>,
|
||||
io.grpc.stub.ServerCalls.ClientStreamingMethod<Req, Resp>,
|
||||
io.grpc.stub.ServerCalls.BidiStreamingMethod<Req, Resp> {
|
||||
private final TestServiceImplBase serviceImpl;
|
||||
private final int methodId;
|
||||
|
||||
MethodHandlers(TestServiceImplBase serviceImpl, int methodId) {
|
||||
this.serviceImpl = serviceImpl;
|
||||
this.methodId = methodId;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("unchecked")
|
||||
public void invoke(Req request, io.grpc.stub.StreamObserver<Resp> responseObserver) {
|
||||
switch (methodId) {
|
||||
case METHODID_EMPTY_CALL:
|
||||
serviceImpl.emptyCall((grpc.testing.EmptyOuterClass.Empty) request,
|
||||
(io.grpc.stub.StreamObserver<grpc.testing.EmptyOuterClass.Empty>) responseObserver);
|
||||
break;
|
||||
case METHODID_UNARY_CALL:
|
||||
serviceImpl.unaryCall((grpc.testing.Messages.SimpleRequest) request,
|
||||
(io.grpc.stub.StreamObserver<grpc.testing.Messages.SimpleResponse>) responseObserver);
|
||||
break;
|
||||
case METHODID_CACHEABLE_UNARY_CALL:
|
||||
serviceImpl.cacheableUnaryCall((grpc.testing.Messages.SimpleRequest) request,
|
||||
(io.grpc.stub.StreamObserver<grpc.testing.Messages.SimpleResponse>) responseObserver);
|
||||
break;
|
||||
case METHODID_STREAMING_OUTPUT_CALL:
|
||||
serviceImpl.streamingOutputCall((grpc.testing.Messages.StreamingOutputCallRequest) request,
|
||||
(io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingOutputCallResponse>) responseObserver);
|
||||
break;
|
||||
case METHODID_UNIMPLEMENTED_CALL:
|
||||
serviceImpl.unimplementedCall((grpc.testing.EmptyOuterClass.Empty) request,
|
||||
(io.grpc.stub.StreamObserver<grpc.testing.EmptyOuterClass.Empty>) responseObserver);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("unchecked")
|
||||
public io.grpc.stub.StreamObserver<Req> invoke(
|
||||
io.grpc.stub.StreamObserver<Resp> responseObserver) {
|
||||
switch (methodId) {
|
||||
case METHODID_STREAMING_INPUT_CALL:
|
||||
return (io.grpc.stub.StreamObserver<Req>) serviceImpl.streamingInputCall(
|
||||
(io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingInputCallResponse>) responseObserver);
|
||||
case METHODID_FULL_DUPLEX_CALL:
|
||||
return (io.grpc.stub.StreamObserver<Req>) serviceImpl.fullDuplexCall(
|
||||
(io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingOutputCallResponse>) responseObserver);
|
||||
case METHODID_HALF_DUPLEX_CALL:
|
||||
return (io.grpc.stub.StreamObserver<Req>) serviceImpl.halfDuplexCall(
|
||||
(io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingOutputCallResponse>) responseObserver);
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static abstract class TestServiceBaseDescriptorSupplier
|
||||
implements io.grpc.protobuf.ProtoFileDescriptorSupplier, io.grpc.protobuf.ProtoServiceDescriptorSupplier {
|
||||
TestServiceBaseDescriptorSupplier() {}
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Descriptors.FileDescriptor getFileDescriptor() {
|
||||
return TestFromProto.getDescriptor();
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Descriptors.ServiceDescriptor getServiceDescriptor() {
|
||||
return getFileDescriptor().findServiceByName("TestService");
|
||||
}
|
||||
}
|
||||
|
||||
private static final class TestServiceFileDescriptorSupplier
|
||||
extends TestServiceBaseDescriptorSupplier {
|
||||
TestServiceFileDescriptorSupplier() {}
|
||||
}
|
||||
|
||||
private static final class TestServiceMethodDescriptorSupplier
|
||||
extends TestServiceBaseDescriptorSupplier
|
||||
implements io.grpc.protobuf.ProtoMethodDescriptorSupplier {
|
||||
private final String methodName;
|
||||
|
||||
TestServiceMethodDescriptorSupplier(String methodName) {
|
||||
this.methodName = methodName;
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
public com.google.protobuf.Descriptors.MethodDescriptor getMethodDescriptor() {
|
||||
return getServiceDescriptor().findMethodByName(methodName);
|
||||
}
|
||||
}
|
||||
|
||||
private static volatile io.grpc.ServiceDescriptor serviceDescriptor;
|
||||
|
||||
public static io.grpc.ServiceDescriptor getServiceDescriptor() {
|
||||
io.grpc.ServiceDescriptor result = serviceDescriptor;
|
||||
if (result == null) {
|
||||
synchronized (TestServiceGrpc.class) {
|
||||
result = serviceDescriptor;
|
||||
if (result == null) {
|
||||
serviceDescriptor = result = io.grpc.ServiceDescriptor.newBuilder(SERVICE_NAME)
|
||||
.setSchemaDescriptor(new TestServiceFileDescriptorSupplier())
|
||||
.addMethod(METHOD_EMPTY_CALL)
|
||||
.addMethod(METHOD_UNARY_CALL)
|
||||
.addMethod(METHOD_CACHEABLE_UNARY_CALL)
|
||||
.addMethod(METHOD_STREAMING_OUTPUT_CALL)
|
||||
.addMethod(METHOD_STREAMING_INPUT_CALL)
|
||||
.addMethod(METHOD_FULL_DUPLEX_CALL)
|
||||
.addMethod(METHOD_HALF_DUPLEX_CALL)
|
||||
.addMethod(METHOD_UNIMPLEMENTED_CALL)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
package grpc.testing.main;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import grpc.testing.EmptyOuterClass.Empty;
|
||||
import grpc.testing.Messages.EchoStatus;
|
||||
import grpc.testing.Messages.Payload;
|
||||
import grpc.testing.Messages.ResponseParameters;
|
||||
import grpc.testing.Messages.SimpleRequest;
|
||||
import grpc.testing.Messages.SimpleResponse;
|
||||
import grpc.testing.Messages.StreamingOutputCallResponse;
|
||||
import grpc.testing.TestServiceGrpc.TestServiceImplBase;
|
||||
import io.grpc.Status;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import java.util.logging.Logger;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* Implements the service methods defined in test.proto
|
||||
*/
|
||||
public class TestService extends TestServiceImplBase {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(TestService.class.getName());
|
||||
|
||||
@Override
|
||||
public void unaryCall(SimpleRequest request, StreamObserver<SimpleResponse> responseObserver) {
|
||||
if (request.hasResponseStatus()) {
|
||||
EchoStatus echoStatus = request.getResponseStatus();
|
||||
Status status = Status.fromCodeValue(echoStatus.getCode());
|
||||
status = status.withDescription(echoStatus.getMessage());
|
||||
responseObserver.onError(status.asRuntimeException());
|
||||
return;
|
||||
}
|
||||
int responseSizeDesired = request.getResponseSize();
|
||||
String resp = StringUtils.repeat("0", responseSizeDesired);
|
||||
Payload out = Payload.newBuilder().setBody(ByteString.copyFromUtf8(resp)).build();
|
||||
SimpleResponse response = SimpleResponse.newBuilder().setPayload(out).build();
|
||||
responseObserver.onNext(response);
|
||||
responseObserver.onCompleted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emptyCall(Empty request, io.grpc.stub.StreamObserver<Empty> responseObserver) {
|
||||
responseObserver.onNext(Empty.newBuilder().build());
|
||||
responseObserver.onCompleted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void streamingOutputCall(grpc.testing.Messages.StreamingOutputCallRequest request,
|
||||
io.grpc.stub.StreamObserver<grpc.testing.Messages.StreamingOutputCallResponse> responseObserver) {
|
||||
for (ResponseParameters params: request.getResponseParametersList()) {
|
||||
String str = StringUtils.repeat("0", params.getSize());
|
||||
Payload out = Payload.newBuilder().setBody(ByteString.copyFromUtf8(str)).build();
|
||||
StreamingOutputCallResponse resp =
|
||||
StreamingOutputCallResponse.newBuilder().setPayload(out).build();
|
||||
responseObserver.onNext(resp);
|
||||
// do we need to sleep before sending next one out
|
||||
try {
|
||||
if (params.getIntervalUs() >= 1000) {
|
||||
Thread.sleep(params.getIntervalUs() / 1000);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
// TODO ignore?
|
||||
}
|
||||
}
|
||||
responseObserver.onCompleted();
|
||||
}
|
||||
}
|
|
@ -5,7 +5,9 @@ import com.google.grpcweb.Factory;
|
|||
import com.google.grpcweb.GrpcWebTrafficServlet;
|
||||
import io.grpc.Server;
|
||||
import io.grpc.ServerBuilder;
|
||||
import io.grpc.ServerInterceptors;
|
||||
import java.util.EnumSet;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.logging.Logger;
|
||||
import javax.servlet.DispatcherType;
|
||||
import org.eclipse.jetty.servlet.ServletHandler;
|
||||
|
@ -20,8 +22,12 @@ public class TestServiceAndProxy {
|
|||
private static final int GRPC_WEB_PORT = 8080;
|
||||
|
||||
private static Server startGrpcService(int port) throws Exception {
|
||||
|
||||
Server grpcServer = ServerBuilder.forPort(port)
|
||||
.addService(new TestService())
|
||||
.addService(
|
||||
ServerInterceptors.intercept(
|
||||
new TestServiceImpl(Executors.newSingleThreadScheduledExecutor()),
|
||||
TestServiceImpl.interceptors()))
|
||||
.build();
|
||||
grpcServer.start();
|
||||
LOGGER.info("**** started gRPC Service on port# " + port);
|
||||
|
|
|
@ -0,0 +1,535 @@
|
|||
/*
|
||||
* Copyright 2020 The gRPC Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// ******************* DO NOT EDIT
|
||||
// This is copy of the following:
|
||||
// github.com/grpc/grpc-java/blob/master/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceImpl.java
|
||||
|
||||
package grpc.testing.main;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Queues;
|
||||
import com.google.protobuf.ByteString;
|
||||
import io.grpc.ForwardingServerCall.SimpleForwardingServerCall;
|
||||
import io.grpc.Metadata;
|
||||
import io.grpc.ServerCall;
|
||||
import io.grpc.ServerCallHandler;
|
||||
import io.grpc.ServerInterceptor;
|
||||
import io.grpc.Status;
|
||||
import io.grpc.internal.LogExceptionRunnable;
|
||||
import io.grpc.stub.ServerCallStreamObserver;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import grpc.testing.EmptyProtos;
|
||||
import grpc.testing.Messages;
|
||||
import grpc.testing.Messages.Payload;
|
||||
import grpc.testing.Messages.ResponseParameters;
|
||||
import grpc.testing.Messages.SimpleRequest;
|
||||
import grpc.testing.Messages.SimpleResponse;
|
||||
import grpc.testing.Messages.StreamingInputCallRequest;
|
||||
import grpc.testing.Messages.StreamingInputCallResponse;
|
||||
import grpc.testing.Messages.StreamingOutputCallRequest;
|
||||
import grpc.testing.Messages.StreamingOutputCallResponse;
|
||||
import grpc.testing.TestServiceGrpc;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.annotation.concurrent.GuardedBy;
|
||||
|
||||
/**
|
||||
* Implementation of the business logic for the TestService. Uses an executor to schedule chunks
|
||||
* sent in response streams.
|
||||
*/
|
||||
public class TestServiceImpl extends TestServiceGrpc.TestServiceImplBase {
|
||||
private final Random random = new Random();
|
||||
|
||||
private final ScheduledExecutorService executor;
|
||||
private final ByteString compressableBuffer;
|
||||
|
||||
/**
|
||||
* Constructs a controller using the given executor for scheduling response stream chunks.
|
||||
*/
|
||||
public TestServiceImpl(ScheduledExecutorService executor) {
|
||||
this.executor = executor;
|
||||
this.compressableBuffer = ByteString.copyFrom(new byte[1024]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emptyCall(EmptyProtos.Empty request,
|
||||
StreamObserver<EmptyProtos.Empty> responseObserver) {
|
||||
responseObserver.onNext(EmptyProtos.Empty.getDefaultInstance());
|
||||
responseObserver.onCompleted();
|
||||
}
|
||||
|
||||
/**
|
||||
* Immediately responds with a payload of the type and size specified in the request.
|
||||
*/
|
||||
@Override
|
||||
public void unaryCall(SimpleRequest req, StreamObserver<SimpleResponse> responseObserver) {
|
||||
ServerCallStreamObserver<SimpleResponse> obs =
|
||||
(ServerCallStreamObserver<SimpleResponse>) responseObserver;
|
||||
SimpleResponse.Builder responseBuilder = SimpleResponse.newBuilder();
|
||||
try {
|
||||
if (req.hasResponseCompressed() && req.getResponseCompressed().getValue()) {
|
||||
obs.setCompression("gzip");
|
||||
} else {
|
||||
obs.setCompression("identity");
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println("sending error");
|
||||
obs.onError(Status.UNIMPLEMENTED
|
||||
.withDescription("compression not supported.")
|
||||
.withCause(e)
|
||||
.asRuntimeException());
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.getResponseSize() != 0) {
|
||||
// For consistency with the c++ TestServiceImpl, use a random offset for unary calls.
|
||||
// TODO(wonderfly): whether or not this is a good approach needs further discussion.
|
||||
int offset = random.nextInt(compressableBuffer.size());
|
||||
ByteString payload = generatePayload(compressableBuffer, offset, req.getResponseSize());
|
||||
responseBuilder.setPayload(
|
||||
Payload.newBuilder()
|
||||
.setBody(payload));
|
||||
}
|
||||
|
||||
if (req.hasResponseStatus()) {
|
||||
obs.onError(Status.fromCodeValue(req.getResponseStatus().getCode())
|
||||
.withDescription(req.getResponseStatus().getMessage())
|
||||
.asRuntimeException());
|
||||
return;
|
||||
}
|
||||
|
||||
responseObserver.onNext(responseBuilder.build());
|
||||
responseObserver.onCompleted();
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a request that specifies chunk size and interval between responses, creates and schedules
|
||||
* the response stream.
|
||||
*/
|
||||
@Override
|
||||
public void streamingOutputCall(StreamingOutputCallRequest request,
|
||||
StreamObserver<StreamingOutputCallResponse> responseObserver) {
|
||||
// Create and start the response dispatcher.
|
||||
new ResponseDispatcher(responseObserver).enqueue(toChunkQueue(request)).completeInput();
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits until we have received all of the request messages and then returns the aggregate payload
|
||||
* size for all of the received requests.
|
||||
*/
|
||||
@Override
|
||||
public StreamObserver<Messages.StreamingInputCallRequest> streamingInputCall(
|
||||
final StreamObserver<Messages.StreamingInputCallResponse> responseObserver) {
|
||||
return new StreamObserver<StreamingInputCallRequest>() {
|
||||
private int totalPayloadSize;
|
||||
|
||||
@Override
|
||||
public void onNext(StreamingInputCallRequest message) {
|
||||
totalPayloadSize += message.getPayload().getBody().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
responseObserver.onNext(StreamingInputCallResponse.newBuilder()
|
||||
.setAggregatedPayloadSize(totalPayloadSize).build());
|
||||
responseObserver.onCompleted();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable cause) {
|
||||
responseObserver.onError(cause);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* True bi-directional streaming. Processes requests as they come in. Begins streaming results
|
||||
* immediately.
|
||||
*/
|
||||
@Override
|
||||
public StreamObserver<Messages.StreamingOutputCallRequest> fullDuplexCall(
|
||||
final StreamObserver<Messages.StreamingOutputCallResponse> responseObserver) {
|
||||
final ResponseDispatcher dispatcher = new ResponseDispatcher(responseObserver);
|
||||
return new StreamObserver<StreamingOutputCallRequest>() {
|
||||
@Override
|
||||
public void onNext(StreamingOutputCallRequest request) {
|
||||
if (request.hasResponseStatus()) {
|
||||
dispatcher.cancel();
|
||||
dispatcher.onError(Status.fromCodeValue(request.getResponseStatus().getCode())
|
||||
.withDescription(request.getResponseStatus().getMessage())
|
||||
.asRuntimeException());
|
||||
return;
|
||||
}
|
||||
dispatcher.enqueue(toChunkQueue(request));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
if (!dispatcher.isCancelled()) {
|
||||
// Tell the dispatcher that all input has been received.
|
||||
dispatcher.completeInput();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable cause) {
|
||||
dispatcher.onError(cause);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to {@link #fullDuplexCall}, except that it waits for all streaming requests to be
|
||||
* received before starting the streaming responses.
|
||||
*/
|
||||
@Override
|
||||
public StreamObserver<Messages.StreamingOutputCallRequest> halfDuplexCall(
|
||||
final StreamObserver<Messages.StreamingOutputCallResponse> responseObserver) {
|
||||
final ResponseDispatcher dispatcher = new ResponseDispatcher(responseObserver);
|
||||
final Queue<Chunk> chunks = new ArrayDeque<>();
|
||||
return new StreamObserver<StreamingOutputCallRequest>() {
|
||||
@Override
|
||||
public void onNext(StreamingOutputCallRequest request) {
|
||||
chunks.addAll(toChunkQueue(request));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
// Dispatch all of the chunks in one shot.
|
||||
dispatcher.enqueue(chunks).completeInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable cause) {
|
||||
dispatcher.onError(cause);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules the dispatch of a queue of chunks. Whenever chunks are added or input is completed,
|
||||
* the next response chunk is scheduled for delivery to the client. When no more chunks are
|
||||
* available, the stream is half-closed.
|
||||
*/
|
||||
private class ResponseDispatcher {
|
||||
private final Chunk completionChunk = new Chunk(0, 0, 0);
|
||||
private final Queue<Chunk> chunks;
|
||||
private final StreamObserver<StreamingOutputCallResponse> responseStream;
|
||||
private boolean scheduled;
|
||||
@GuardedBy("this") private boolean cancelled;
|
||||
private Throwable failure;
|
||||
private Runnable dispatchTask = new Runnable() {
|
||||
@Override
|
||||
@SuppressWarnings("CatchAndPrintStackTrace")
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
// Dispatch the current chunk to the client.
|
||||
try {
|
||||
dispatchChunk();
|
||||
} catch (RuntimeException e) {
|
||||
// Indicate that nothing is scheduled and re-throw.
|
||||
synchronized (ResponseDispatcher.this) {
|
||||
scheduled = false;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
// Schedule the next chunk if there is one.
|
||||
synchronized (ResponseDispatcher.this) {
|
||||
// Indicate that nothing is scheduled.
|
||||
scheduled = false;
|
||||
scheduleNextChunk();
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The {@link StreamObserver} will be used to send the queue of response chunks. Since calls to
|
||||
* {@link StreamObserver} must be synchronized across threads, no further calls should be made
|
||||
* directly on {@code responseStream} after it is provided to the {@link ResponseDispatcher}.
|
||||
*/
|
||||
public ResponseDispatcher(StreamObserver<StreamingOutputCallResponse> responseStream) {
|
||||
this.chunks = Queues.newLinkedBlockingQueue();
|
||||
this.responseStream = responseStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given chunks to the response stream and schedules the next chunk to be delivered if
|
||||
* needed.
|
||||
*/
|
||||
public synchronized ResponseDispatcher enqueue(Queue<Chunk> moreChunks) {
|
||||
assertNotFailed();
|
||||
chunks.addAll(moreChunks);
|
||||
scheduleNextChunk();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates that the input is completed and the currently enqueued response chunks are all that
|
||||
* remain to be scheduled for dispatch to the client.
|
||||
*/
|
||||
public ResponseDispatcher completeInput() {
|
||||
assertNotFailed();
|
||||
chunks.add(completionChunk);
|
||||
scheduleNextChunk();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the service to cancel the remaining responses.
|
||||
*/
|
||||
public synchronized void cancel() {
|
||||
Preconditions.checkState(!cancelled, "Dispatcher already cancelled");
|
||||
chunks.clear();
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
public synchronized boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
private synchronized void onError(Throwable cause) {
|
||||
responseStream.onError(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches the current response chunk to the client. This is only called by the executor. At
|
||||
* any time, a given dispatch task should only be registered with the executor once.
|
||||
*/
|
||||
private synchronized void dispatchChunk() {
|
||||
if (cancelled) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// Pop off the next chunk and send it to the client.
|
||||
Chunk chunk = chunks.remove();
|
||||
if (chunk == completionChunk) {
|
||||
responseStream.onCompleted();
|
||||
} else {
|
||||
responseStream.onNext(chunk.toResponse());
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
failure = e;
|
||||
if (Status.fromThrowable(e).getCode() == Status.CANCELLED.getCode()) {
|
||||
// Stream was cancelled by client, responseStream.onError() might be called already or
|
||||
// will be called soon by inbounding StreamObserver.
|
||||
chunks.clear();
|
||||
} else {
|
||||
responseStream.onError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules the next response chunk to be dispatched. If all input has been received and there
|
||||
* are no more chunks in the queue, the stream is closed.
|
||||
*/
|
||||
private void scheduleNextChunk() {
|
||||
synchronized (this) {
|
||||
if (scheduled) {
|
||||
// Dispatch task is already scheduled.
|
||||
return;
|
||||
}
|
||||
|
||||
// Schedule the next response chunk if there is one.
|
||||
Chunk nextChunk = chunks.peek();
|
||||
if (nextChunk != null) {
|
||||
scheduled = true;
|
||||
// TODO(ejona): cancel future if RPC is cancelled
|
||||
Future<?> unused = executor.schedule(new LogExceptionRunnable(dispatchTask),
|
||||
nextChunk.delayMicroseconds, TimeUnit.MICROSECONDS);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void assertNotFailed() {
|
||||
if (failure != null) {
|
||||
throw new IllegalStateException("Stream already failed", failure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Breaks down the request and creates a queue of response chunks for the given request.
|
||||
*/
|
||||
public Queue<Chunk> toChunkQueue(StreamingOutputCallRequest request) {
|
||||
Queue<Chunk> chunkQueue = new ArrayDeque<>();
|
||||
int offset = 0;
|
||||
for (ResponseParameters params : request.getResponseParametersList()) {
|
||||
chunkQueue.add(new Chunk(params.getIntervalUs(), offset, params.getSize()));
|
||||
|
||||
// Increment the offset past this chunk. Buffer need to be circular.
|
||||
offset = (offset + params.getSize()) % compressableBuffer.size();
|
||||
}
|
||||
return chunkQueue;
|
||||
}
|
||||
|
||||
/**
|
||||
* A single chunk of a response stream. Contains delivery information for the dispatcher and can
|
||||
* be converted to a streaming response proto. A chunk just references it's payload in the
|
||||
* {@link #compressableBuffer} array. The payload isn't actually created until {@link
|
||||
* #toResponse()} is called.
|
||||
*/
|
||||
private class Chunk {
|
||||
private final int delayMicroseconds;
|
||||
private final int offset;
|
||||
private final int length;
|
||||
|
||||
public Chunk(int delayMicroseconds, int offset, int length) {
|
||||
this.delayMicroseconds = delayMicroseconds;
|
||||
this.offset = offset;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert this chunk into a streaming response proto.
|
||||
*/
|
||||
private StreamingOutputCallResponse toResponse() {
|
||||
StreamingOutputCallResponse.Builder responseBuilder =
|
||||
StreamingOutputCallResponse.newBuilder();
|
||||
ByteString payload = generatePayload(compressableBuffer, offset, length);
|
||||
responseBuilder.setPayload(
|
||||
Payload.newBuilder()
|
||||
.setBody(payload));
|
||||
return responseBuilder.build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a payload of desired type and size. Reads compressableBuffer or
|
||||
* uncompressableBuffer as a circular buffer.
|
||||
*/
|
||||
private ByteString generatePayload(ByteString dataBuffer, int offset, int size) {
|
||||
ByteString payload = ByteString.EMPTY;
|
||||
// This offset would never pass the array boundary.
|
||||
int begin = offset;
|
||||
int end = 0;
|
||||
int bytesLeft = size;
|
||||
while (bytesLeft > 0) {
|
||||
end = Math.min(begin + bytesLeft, dataBuffer.size());
|
||||
// ByteString.substring returns the substring from begin, inclusive, to end, exclusive.
|
||||
payload = payload.concat(dataBuffer.substring(begin, end));
|
||||
bytesLeft -= (end - begin);
|
||||
begin = end % dataBuffer.size();
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
/** Returns interceptors necessary for full service implementation. */
|
||||
public static List<ServerInterceptor> interceptors() {
|
||||
return Arrays.asList(
|
||||
echoRequestHeadersInterceptor(Util.METADATA_KEY),
|
||||
echoRequestMetadataInHeaders(Util.ECHO_INITIAL_METADATA_KEY),
|
||||
echoRequestMetadataInTrailers(Util.ECHO_TRAILING_METADATA_KEY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Echo the request headers from a client into response headers and trailers. Useful for
|
||||
* testing end-to-end metadata propagation.
|
||||
*/
|
||||
private static ServerInterceptor echoRequestHeadersInterceptor(final Metadata.Key<?>... keys) {
|
||||
final Set<Metadata.Key<?>> keySet = new HashSet<>(Arrays.asList(keys));
|
||||
return new ServerInterceptor() {
|
||||
@Override
|
||||
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
|
||||
ServerCall<ReqT, RespT> call,
|
||||
final Metadata requestHeaders,
|
||||
ServerCallHandler<ReqT, RespT> next) {
|
||||
return next.startCall(new SimpleForwardingServerCall<ReqT, RespT>(call) {
|
||||
@Override
|
||||
public void sendHeaders(Metadata responseHeaders) {
|
||||
responseHeaders.merge(requestHeaders, keySet);
|
||||
super.sendHeaders(responseHeaders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(Status status, Metadata trailers) {
|
||||
trailers.merge(requestHeaders, keySet);
|
||||
super.close(status, trailers);
|
||||
}
|
||||
}, requestHeaders);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Echoes request headers with the specified key(s) from a client into response headers only.
|
||||
*/
|
||||
private static ServerInterceptor echoRequestMetadataInHeaders(final Metadata.Key<?>... keys) {
|
||||
final Set<Metadata.Key<?>> keySet = new HashSet<>(Arrays.asList(keys));
|
||||
return new ServerInterceptor() {
|
||||
@Override
|
||||
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
|
||||
ServerCall<ReqT, RespT> call,
|
||||
final Metadata requestHeaders,
|
||||
ServerCallHandler<ReqT, RespT> next) {
|
||||
return next.startCall(new SimpleForwardingServerCall<ReqT, RespT>(call) {
|
||||
@Override
|
||||
public void sendHeaders(Metadata responseHeaders) {
|
||||
responseHeaders.merge(requestHeaders, keySet);
|
||||
super.sendHeaders(responseHeaders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(Status status, Metadata trailers) {
|
||||
super.close(status, trailers);
|
||||
}
|
||||
}, requestHeaders);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Echoes request headers with the specified key(s) from a client into response trailers only.
|
||||
*/
|
||||
private static ServerInterceptor echoRequestMetadataInTrailers(final Metadata.Key<?>... keys) {
|
||||
final Set<Metadata.Key<?>> keySet = new HashSet<>(Arrays.asList(keys));
|
||||
return new ServerInterceptor() {
|
||||
@Override
|
||||
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
|
||||
ServerCall<ReqT, RespT> call,
|
||||
final Metadata requestHeaders,
|
||||
ServerCallHandler<ReqT, RespT> next) {
|
||||
return next.startCall(new SimpleForwardingServerCall<ReqT, RespT>(call) {
|
||||
@Override
|
||||
public void sendHeaders(Metadata responseHeaders) {
|
||||
super.sendHeaders(responseHeaders);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close(Status status, Metadata trailers) {
|
||||
trailers.merge(requestHeaders, keySet);
|
||||
super.close(status, trailers);
|
||||
}
|
||||
}, requestHeaders);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright 2020 The gRPC Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// ******************* DO NOT EDIT
|
||||
// This is copy of the following:
|
||||
// github.com/grpc/grpc-java/blob/master/interop-testing/src/main/java/io/grpc/testing/integration/Util.java
|
||||
|
||||
package grpc.testing.main;
|
||||
|
||||
import io.grpc.Metadata;
|
||||
import io.grpc.protobuf.lite.ProtoLiteUtils;
|
||||
import grpc.testing.Messages;
|
||||
|
||||
/**
|
||||
* Utility methods to support integration testing.
|
||||
*/
|
||||
public class Util {
|
||||
|
||||
public static final Metadata.Key<Messages.SimpleContext> METADATA_KEY =
|
||||
Metadata.Key.of(
|
||||
"grpc.testing.SimpleContext" + Metadata.BINARY_HEADER_SUFFIX,
|
||||
ProtoLiteUtils.metadataMarshaller(Messages.SimpleContext.getDefaultInstance()));
|
||||
public static final Metadata.Key<String> ECHO_INITIAL_METADATA_KEY
|
||||
= Metadata.Key.of("x-grpc-test-echo-initial", Metadata.ASCII_STRING_MARSHALLER);
|
||||
public static final Metadata.Key<byte[]> ECHO_TRAILING_METADATA_KEY
|
||||
= Metadata.Key.of("x-grpc-test-echo-trailing-bin", Metadata.BINARY_BYTE_MARSHALLER);
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
// Copyright 2015 gRPC authors.
|
||||
// Copyright 2015 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
|
@ -13,10 +12,17 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
syntax = "proto3";
|
||||
// ******************* DO NOT EDIT
|
||||
// This is copy of the following:
|
||||
// github.com/grpc/grpc-java/blob/master/interop-testing/src/main/proto/grpc/testing/empty.proto
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
package grpc.testing;
|
||||
|
||||
option java_package = "grpc.testing";
|
||||
option java_outer_classname = "EmptyProtos";
|
||||
|
||||
// An empty message that you can re-use to avoid defining duplicated empty
|
||||
// messages in your project. A typical example is to use it as argument or the
|
||||
// return value of a service API. For instance:
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
// Copyright 2015-2016 gRPC authors.
|
||||
// Copyright 2015 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
|
@ -15,28 +14,26 @@
|
|||
|
||||
// Message definitions to be used by integration test service definitions.
|
||||
|
||||
// ******************* DO NOT EDIT
|
||||
// This is copy of the following:
|
||||
// github.com/grpc/grpc-java/blob/master/interop-testing/src/main/proto/grpc/testing/messages.proto
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package grpc.testing;
|
||||
|
||||
// TODO(dgq): Go back to using well-known types once
|
||||
// https://github.com/grpc/grpc/issues/6980 has been fixed.
|
||||
// import "google/protobuf/wrappers.proto";
|
||||
option java_package = "grpc.testing";
|
||||
|
||||
// TODO(jihuncho): Use well-known types once all languages are synced.
|
||||
message BoolValue {
|
||||
// The bool value.
|
||||
bool value = 1;
|
||||
}
|
||||
|
||||
// The type of payload that should be returned.
|
||||
enum PayloadType {
|
||||
// Compressable text format.
|
||||
COMPRESSABLE = 0;
|
||||
}
|
||||
|
||||
// A block of data, to simply increase gRPC message size.
|
||||
message Payload {
|
||||
// The type of data in body.
|
||||
PayloadType type = 1;
|
||||
reserved 1;
|
||||
|
||||
// Primary contents of payload.
|
||||
bytes body = 2;
|
||||
}
|
||||
|
@ -65,9 +62,7 @@ enum GrpclbRouteType {
|
|||
|
||||
// Unary request.
|
||||
message SimpleRequest {
|
||||
// Desired payload type in the response from the server.
|
||||
// If response_type is RANDOM, server randomly chooses one from other formats.
|
||||
PayloadType response_type = 1;
|
||||
reserved 1;
|
||||
|
||||
// Desired payload size in the response from the server.
|
||||
int32 response_size = 2;
|
||||
|
@ -95,9 +90,6 @@ message SimpleRequest {
|
|||
|
||||
// Whether SimpleResponse should include server_id.
|
||||
bool fill_server_id = 9;
|
||||
|
||||
// Whether SimpleResponse should include grpclb_route_type.
|
||||
bool fill_grpclb_route_type = 10;
|
||||
}
|
||||
|
||||
// Unary response, as configured by the request.
|
||||
|
@ -109,17 +101,19 @@ message SimpleResponse {
|
|||
string username = 2;
|
||||
// OAuth scope.
|
||||
string oauth_scope = 3;
|
||||
|
||||
// Server ID. This must be unique among different server instances,
|
||||
// but the same across all RPC's made to a particular server instance.
|
||||
string server_id = 4;
|
||||
// gRPCLB Path.
|
||||
GrpclbRouteType grpclb_route_type = 5;
|
||||
|
||||
// Server hostname.
|
||||
string hostname = 6;
|
||||
}
|
||||
|
||||
message SimpleContext {
|
||||
string value = 1;
|
||||
}
|
||||
|
||||
// Client-streaming request.
|
||||
message StreamingInputCallRequest {
|
||||
// Optional input payload sent along with the request.
|
||||
|
@ -158,11 +152,7 @@ message ResponseParameters {
|
|||
|
||||
// Server-streaming request.
|
||||
message StreamingOutputCallRequest {
|
||||
// Desired payload type in the response from the server.
|
||||
// If response_type is RANDOM, the payload from each response in the stream
|
||||
// might be of different types. This is to simulate a mixed type of payload
|
||||
// stream.
|
||||
PayloadType response_type = 1;
|
||||
reserved 1;
|
||||
|
||||
// Configuration for each expected response message.
|
||||
repeated ResponseParameters response_parameters = 2;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
// Copyright 2015-2016 gRPC authors.
|
||||
// Copyright 2015 The gRPC Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
|
@ -12,9 +11,11 @@
|
|||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// An integration test service that covers all the method signature permutations
|
||||
// of unary/streaming requests/responses.
|
||||
// ******************* DO NOT EDIT
|
||||
// This is copy of the following:
|
||||
// github.com/grpc/grpc-java/blob/master/interop-testing/src/main/proto/grpc/testing/test.proto
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
|
@ -23,6 +24,8 @@ import "grpc/testing/messages.proto";
|
|||
|
||||
package grpc.testing;
|
||||
|
||||
option java_package = "grpc.testing";
|
||||
|
||||
// A simple service to test the various types of RPCs and experiment with
|
||||
// performance with various types of payload.
|
||||
service TestService {
|
||||
|
@ -74,7 +77,7 @@ service UnimplementedService {
|
|||
|
||||
// A service used to control reconnect server.
|
||||
service ReconnectService {
|
||||
rpc Start(grpc.testing.ReconnectParams) returns (grpc.testing.Empty);
|
||||
rpc Start(grpc.testing.Empty) returns (grpc.testing.Empty);
|
||||
rpc Stop(grpc.testing.Empty) returns (grpc.testing.ReconnectInfo);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue