Merge pull request #35 from iamqizhao/master

Replace end2end_test proto with the one for interop. The latter is better on testing error and corner cases.
This commit is contained in:
Qi Zhao
2015-02-11 19:09:53 -08:00
8 changed files with 1191 additions and 674 deletions

View File

@ -34,14 +34,11 @@
package grpc_test
import (
"fmt"
"io"
"log"
"math"
"net"
"reflect"
"strconv"
"strings"
"sync"
"testing"
"time"
@ -52,7 +49,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
testpb "google.golang.org/grpc/test/proto"
testpb "google.golang.org/grpc/test/grpc_testing"
)
var (
@ -62,10 +59,32 @@ var (
}
)
type mathServer struct {
type testServer struct {
}
func (s *mathServer) Div(ctx context.Context, in *testpb.DivArgs) (*testpb.DivReply, error) {
func (s *testServer) EmptyCall(ctx context.Context, in *testpb.Empty) (*testpb.Empty, error) {
return new(testpb.Empty), nil
}
func newPayload(t testpb.PayloadType, size int32) *testpb.Payload {
if size < 0 {
log.Fatalf("Requested a response with invalid length %d", size)
}
body := make([]byte, size)
switch t {
case testpb.PayloadType_COMPRESSABLE:
case testpb.PayloadType_UNCOMPRESSABLE:
log.Fatalf("PayloadType UNCOMPRESSABLE is not supported")
default:
log.Fatalf("Unsupported payload type: %d", t)
}
return &testpb.Payload{
Type: t.Enum(),
Body: body,
}
}
func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
md, ok := metadata.FromContext(ctx)
if ok {
if err := grpc.SendHeader(ctx, md); err != nil {
@ -73,19 +92,46 @@ func (s *mathServer) Div(ctx context.Context, in *testpb.DivArgs) (*testpb.DivRe
}
grpc.SetTrailer(ctx, md)
}
n, d := in.GetDividend(), in.GetDivisor()
if d == 0 {
return nil, fmt.Errorf("math: divide by 0")
}
out := new(testpb.DivReply)
out.Quotient = proto.Int64(n / d)
out.Remainder = proto.Int64(n % d)
// Simulate some service delay.
time.Sleep(2 * time.Millisecond)
return out, nil // no error
return &testpb.SimpleResponse{
Payload: newPayload(in.GetResponseType(), in.GetResponseSize()),
}, nil
}
func (s *mathServer) DivMany(stream testpb.Math_DivManyServer) error {
func (s *testServer) StreamingOutputCall(args *testpb.StreamingOutputCallRequest, stream testpb.TestService_StreamingOutputCallServer) error {
cs := args.GetResponseParameters()
for _, c := range cs {
if us := c.GetIntervalUs(); us > 0 {
time.Sleep(time.Duration(us) * time.Microsecond)
}
if err := stream.Send(&testpb.StreamingOutputCallResponse{
Payload: newPayload(args.GetResponseType(), c.GetSize()),
}); err != nil {
return err
}
}
return nil
}
func (s *testServer) StreamingInputCall(stream testpb.TestService_StreamingInputCallServer) error {
var sum int
for {
in, err := stream.Recv()
if err == io.EOF {
return stream.SendAndClose(&testpb.StreamingInputCallResponse{
AggregatedPayloadSize: proto.Int32(int32(sum)),
})
}
if err != nil {
return err
}
p := in.GetPayload().GetBody()
sum += len(p)
}
}
func (s *testServer) FullDuplexCall(stream testpb.TestService_FullDuplexCallServer) error {
md, ok := metadata.FromContext(stream.Context())
if ok {
if err := stream.SendHeader(md); err != nil {
@ -102,53 +148,52 @@ func (s *mathServer) DivMany(stream testpb.Math_DivManyServer) error {
if err != nil {
return err
}
n, d := in.GetDividend(), in.GetDivisor()
if d == 0 {
return fmt.Errorf("math: divide by 0")
}
err = stream.Send(&testpb.DivReply{
Quotient: proto.Int64(n / d),
Remainder: proto.Int64(n % d),
})
if err != nil {
return err
cs := in.GetResponseParameters()
for _, c := range cs {
if us := c.GetIntervalUs(); us > 0 {
time.Sleep(time.Duration(us) * time.Microsecond)
}
if err := stream.Send(&testpb.StreamingOutputCallResponse{
Payload: newPayload(in.GetResponseType(), c.GetSize()),
}); err != nil {
return err
}
}
}
}
func (s *mathServer) Fib(args *testpb.FibArgs, stream testpb.Math_FibServer) error {
var (
limit = args.GetLimit()
count int64
x, y int64 = 0, 1
)
for count = 0; limit == 0 || count < limit; count++ {
// Send the next number in the Fibonacci sequence.
stream.Send(&testpb.Num{
Num: proto.Int64(x),
})
x, y = y, x+y
}
return nil // The RPC library will call stream.CloseSend for us.
}
func (s *mathServer) Sum(stream testpb.Math_SumServer) error {
var sum int64
func (s *testServer) HalfDuplexCall(stream testpb.TestService_HalfDuplexCallServer) error {
msgBuf := make([]*testpb.StreamingOutputCallRequest, 0)
for {
m, err := stream.Recv()
in, err := stream.Recv()
if err == io.EOF {
return stream.SendAndClose(&testpb.Num{Num: &sum})
// read done.
break
}
if err != nil {
return err
}
sum += m.GetNum()
msgBuf = append(msgBuf, in)
}
for _, m := range msgBuf {
cs := m.GetResponseParameters()
for _, c := range cs {
if us := c.GetIntervalUs(); us > 0 {
time.Sleep(time.Duration(us) * time.Microsecond)
}
if err := stream.Send(&testpb.StreamingOutputCallResponse{
Payload: newPayload(m.GetResponseType(), c.GetSize()),
}); err != nil {
return err
}
}
}
return nil
}
const tlsDir = "testdata/"
func setUp(useTLS bool, maxStream uint32) (s *grpc.Server, mc testpb.MathClient) {
func setUp(useTLS bool, maxStream uint32) (s *grpc.Server, tc testpb.TestServiceClient) {
lis, err := net.Listen("tcp", ":0")
if err != nil {
log.Fatalf("Failed to listen: %v", err)
@ -158,8 +203,7 @@ func setUp(useTLS bool, maxStream uint32) (s *grpc.Server, mc testpb.MathClient)
log.Fatalf("Failed to parse listener address: %v", err)
}
s = grpc.NewServer(grpc.MaxConcurrentStreams(maxStream))
ms := &mathServer{}
testpb.RegisterService(s, ms)
testpb.RegisterService(s, &testServer{})
if useTLS {
creds, err := credentials.NewServerTLSFromFile(tlsDir+"server1.pem", tlsDir+"server1.key")
if err != nil {
@ -183,36 +227,55 @@ func setUp(useTLS bool, maxStream uint32) (s *grpc.Server, mc testpb.MathClient)
if err != nil {
log.Fatalf("Dial(%q) = %v", addr, err)
}
mc = testpb.NewMathClient(conn)
tc = testpb.NewTestServiceClient(conn)
return
}
func TestFailedRPC(t *testing.T) {
s, mc := setUp(false, math.MaxUint32)
func TestEmptyUnary(t *testing.T) {
s, tc := setUp(true, math.MaxUint32)
defer s.Stop()
args := &testpb.DivArgs{
Dividend: proto.Int64(8),
Divisor: proto.Int64(0),
reply, err := tc.EmptyCall(context.Background(), &testpb.Empty{})
if err != nil || !proto.Equal(&testpb.Empty{}, reply) {
t.Fatalf("TestService/EmptyCall(_, _) = _, %v, want %v, <nil>", reply, err, &testpb.Empty{})
}
expectedErr := grpc.Errorf(codes.Unknown, "math: divide by 0")
reply, rpcErr := mc.Div(context.Background(), args)
if fmt.Sprint(rpcErr) != fmt.Sprint(expectedErr) {
t.Fatalf(`mathClient.Div(_, _) = %v, %v; want <nil>, %v`, reply, rpcErr, expectedErr)
}
func TestLargeUnary(t *testing.T) {
s, tc := setUp(true, math.MaxUint32)
defer s.Stop()
argSize := 271828
respSize := 314159
req := &testpb.SimpleRequest{
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
ResponseSize: proto.Int32(int32(respSize)),
Payload: newPayload(testpb.PayloadType_COMPRESSABLE, int32(argSize)),
}
reply, err := tc.UnaryCall(context.Background(), req)
if err != nil {
t.Fatalf("TestService/UnaryCall(_, _) = _, %v, want _, <nil>", err)
}
pt := reply.GetPayload().GetType()
ps := len(reply.GetPayload().GetBody())
if pt != testpb.PayloadType_COMPRESSABLE || ps != respSize {
t.Fatalf("Got the reply with type %d len %d; want %d, %d", pt, ps, testpb.PayloadType_COMPRESSABLE, respSize)
}
}
func TestMetadataUnaryRPC(t *testing.T) {
s, mc := setUp(true, math.MaxUint32)
s, tc := setUp(true, math.MaxUint32)
defer s.Stop()
args := &testpb.DivArgs{
Dividend: proto.Int64(8),
Divisor: proto.Int64(2),
argSize := 2718
respSize := 314
req := &testpb.SimpleRequest{
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
ResponseSize: proto.Int32(int32(respSize)),
Payload: newPayload(testpb.PayloadType_COMPRESSABLE, int32(argSize)),
}
ctx := metadata.NewContext(context.Background(), testMetadata)
var header, trailer metadata.MD
_, err := mc.Div(ctx, args, grpc.Header(&header), grpc.Trailer(&trailer))
ctx := metadata.NewContext(context.Background(), testMetadata)
_, err := tc.UnaryCall(ctx, req, grpc.Header(&header), grpc.Trailer(&trailer))
if err != nil {
t.Fatalf("mathClient.Div(%v, _, _, _) = _, %v; want _, <nil>", ctx, err)
t.Fatalf("TestService.UnaryCall(%v, _, _, _) = _, %v; want _, <nil>", ctx, err)
}
if !reflect.DeepEqual(testMetadata, header) {
t.Fatalf("Received header metadata %v, want %v", header, testMetadata)
@ -222,18 +285,22 @@ func TestMetadataUnaryRPC(t *testing.T) {
}
}
func performOneRPC(t *testing.T, mc testpb.MathClient, wg *sync.WaitGroup) {
args := &testpb.DivArgs{
Dividend: proto.Int64(8),
Divisor: proto.Int64(3),
func performOneRPC(t *testing.T, tc testpb.TestServiceClient, wg *sync.WaitGroup) {
argSize := 2718
respSize := 314
req := &testpb.SimpleRequest{
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
ResponseSize: proto.Int32(int32(respSize)),
Payload: newPayload(testpb.PayloadType_COMPRESSABLE, int32(argSize)),
}
reply, err := mc.Div(context.Background(), args)
want := &testpb.DivReply{
Quotient: proto.Int64(2),
Remainder: proto.Int64(2),
reply, err := tc.UnaryCall(context.Background(), req)
if err != nil {
t.Fatalf("TestService/UnaryCall(_, _) = _, %v, want _, <nil>", err)
}
if err != nil || !proto.Equal(reply, want) {
t.Errorf(`mathClient.Div(_, _) = %v, %v; want %v, <nil>`, reply, err, want)
pt := reply.GetPayload().GetType()
ps := len(reply.GetPayload().GetBody())
if pt != testpb.PayloadType_COMPRESSABLE || ps != respSize {
t.Fatalf("Got the reply with type %d len %d; want %d, %d", pt, ps, testpb.PayloadType_COMPRESSABLE, respSize)
}
wg.Done()
}
@ -242,7 +309,7 @@ func performOneRPC(t *testing.T, mc testpb.MathClient, wg *sync.WaitGroup) {
// TODO(zhaoq): Refactor to make this clearer and add more cases to test racy
// and error-prone paths.
func TestRetry(t *testing.T) {
s, mc := setUp(true, math.MaxUint32)
s, tc := setUp(true, math.MaxUint32)
defer s.Stop()
var wg sync.WaitGroup
wg.Add(1)
@ -258,118 +325,110 @@ func TestRetry(t *testing.T) {
for i := 0; i < 1000; i++ {
time.Sleep(2 * time.Millisecond)
wg.Add(1)
go performOneRPC(t, mc, &wg)
go performOneRPC(t, tc, &wg)
}
wg.Wait()
}
// TODO(zhaoq): Have a better test coverage of timeout and cancellation mechanism.
func TestTimeout(t *testing.T) {
s, mc := setUp(true, math.MaxUint32)
s, tc := setUp(true, math.MaxUint32)
defer s.Stop()
args := &testpb.DivArgs{
Dividend: proto.Int64(8),
Divisor: proto.Int64(3),
argSize := 2718
respSize := 314
req := &testpb.SimpleRequest{
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
ResponseSize: proto.Int32(int32(respSize)),
Payload: newPayload(testpb.PayloadType_COMPRESSABLE, int32(argSize)),
}
// Performs 100 RPCs with various timeout values so that
// the RPCs could timeout on different stages of their lifetime. This
// is the best-effort to cover various cases when an rpc gets cancelled.
for i := 1; i <= 100; i++ {
ctx, _ := context.WithTimeout(context.Background(), time.Duration(i)*time.Microsecond)
reply, err := mc.Div(ctx, args)
reply, err := tc.UnaryCall(ctx, req)
if grpc.Code(err) != codes.DeadlineExceeded {
t.Fatalf(`mathClient.Div(_, _) = %v, %v; want <nil>, error code: %d`, reply, err, codes.DeadlineExceeded)
t.Fatalf(`TestService/UnaryCallv(_, _) = %v, %v; want <nil>, error code: %d`, reply, err, codes.DeadlineExceeded)
}
}
}
func TestCancel(t *testing.T) {
s, mc := setUp(true, math.MaxUint32)
s, tc := setUp(true, math.MaxUint32)
defer s.Stop()
args := &testpb.DivArgs{
Dividend: proto.Int64(8),
Divisor: proto.Int64(3),
argSize := 2718
respSize := 314
req := &testpb.SimpleRequest{
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
ResponseSize: proto.Int32(int32(respSize)),
Payload: newPayload(testpb.PayloadType_COMPRESSABLE, int32(argSize)),
}
ctx, cancel := context.WithCancel(context.Background())
time.AfterFunc(1*time.Millisecond, cancel)
reply, err := mc.Div(ctx, args)
reply, err := tc.UnaryCall(ctx, req)
if grpc.Code(err) != codes.Canceled {
t.Fatalf(`mathClient.Div(_, _) = %v, %v; want <nil>, error code: %d`, reply, err, codes.Canceled)
t.Fatalf(`TestService/UnaryCall(_, _) = %v, %v; want <nil>, error code: %d`, reply, err, codes.Canceled)
}
}
// The following tests the gRPC streaming RPC implementations.
// TODO(zhaoq): Have better coverage on error cases.
var (
reqSizes = []int{27182, 8, 1828, 45904}
respSizes = []int{31415, 9, 2653, 58979}
)
func TestBidiStreaming(t *testing.T) {
s, mc := setUp(true, math.MaxUint32)
func TestPingPong(t *testing.T) {
s, tc := setUp(true, math.MaxUint32)
defer s.Stop()
for _, test := range []struct {
// input
divs []string
// output
status error
}{
{[]string{"1/1", "3/2", "2/3", "1/2"}, io.EOF},
{[]string{"2/5", "2/3", "3/0", "5/4"}, grpc.Errorf(codes.Unknown, "math: divide by 0")},
} {
stream, err := mc.DivMany(context.Background())
if err != nil {
t.Fatalf("failed to create stream %v", err)
}
// Start a goroutine to parse and send the args.
go func() {
for _, args := range parseArgs(test.divs) {
if err := stream.Send(args); err != nil {
t.Errorf("Send failed: %v", err)
return
}
}
// Tell the server we're done sending args.
stream.CloseSend()
}()
var rpcStatus error
for {
_, err := stream.Recv()
if err != nil {
rpcStatus = err
break
}
}
if rpcStatus != test.status {
t.Fatalf(`mathClient.DivMany got %v ; want %v`, rpcStatus, test.status)
}
stream, err := tc.FullDuplexCall(context.Background())
if err != nil {
t.Fatalf("%v.FullDuplexCall(_) = _, %v, want <nil>", tc, err)
}
}
// parseArgs converts a list of "n/d" strings into DivArgs.
// parseArgs crashes the process on error.
func parseArgs(divs []string) (args []*testpb.DivArgs) {
for _, div := range divs {
parts := strings.Split(div, "/")
n, err := strconv.ParseInt(parts[0], 10, 64)
if err != nil {
log.Fatal(err)
var index int
for index < len(reqSizes) {
respParam := []*testpb.ResponseParameters{
&testpb.ResponseParameters{
Size: proto.Int32(int32(respSizes[index])),
},
}
d, err := strconv.ParseInt(parts[1], 10, 64)
if err != nil {
log.Fatal(err)
req := &testpb.StreamingOutputCallRequest{
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
ResponseParameters: respParam,
Payload: newPayload(testpb.PayloadType_COMPRESSABLE, int32(reqSizes[index])),
}
args = append(args, &testpb.DivArgs{
Dividend: &n,
Divisor: &d,
})
if err := stream.Send(req); err != nil {
t.Fatalf("%v.Send(%v) = %v, want <nil>", stream, req, err)
}
reply, err := stream.Recv()
if err != nil {
t.Fatalf("%v.Recv() = %v, want <nil>", stream, err)
}
pt := reply.GetPayload().GetType()
if pt != testpb.PayloadType_COMPRESSABLE {
t.Fatalf("Got the reply of type %d, want %d", pt, testpb.PayloadType_COMPRESSABLE)
}
size := len(reply.GetPayload().GetBody())
if size != int(respSizes[index]) {
t.Fatalf("Got reply body of length %d, want %d", size, respSizes[index])
}
index++
}
if err := stream.CloseSend(); err != nil {
t.Fatalf("%v.CloseSend() got %v, want %v", stream, err, nil)
}
if _, err := stream.Recv(); err != io.EOF {
t.Fatalf("%v failed to complele the ping pong test: %v", stream, err)
}
return
}
func TestMetadataStreamingRPC(t *testing.T) {
s, mc := setUp(true, math.MaxUint32)
s, tc := setUp(true, math.MaxUint32)
defer s.Stop()
ctx := metadata.NewContext(context.Background(), testMetadata)
stream, err := mc.DivMany(ctx)
stream, err := tc.FullDuplexCall(ctx)
if err != nil {
t.Fatalf("Failed to create stream %v", err)
t.Fatalf("%v.FullDuplexCall(_) = _, %v, want <nil>", tc, err)
}
go func() {
headerMD, err := stream.Header()
@ -381,11 +440,23 @@ func TestMetadataStreamingRPC(t *testing.T) {
if err != nil || !reflect.DeepEqual(testMetadata, headerMD) {
t.Errorf("#2 %v.Header() = %v, %v, want %v, <nil>", stream, headerMD, err, testMetadata)
}
for _, args := range parseArgs([]string{"1/1", "3/2", "2/3"}) {
if err := stream.Send(args); err != nil {
t.Errorf("%v.Send(_) failed: %v", stream, err)
var index int
for index < len(reqSizes) {
respParam := []*testpb.ResponseParameters{
&testpb.ResponseParameters{
Size: proto.Int32(int32(respSizes[index])),
},
}
req := &testpb.StreamingOutputCallRequest{
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
ResponseParameters: respParam,
Payload: newPayload(testpb.PayloadType_COMPRESSABLE, int32(reqSizes[index])),
}
if err := stream.Send(req); err != nil {
t.Errorf("%v.Send(%v) = %v, want <nil>", stream, req, err)
return
}
index++
}
// Tell the server we're done sending args.
stream.CloseSend()
@ -403,57 +474,85 @@ func TestMetadataStreamingRPC(t *testing.T) {
}
func TestServerStreaming(t *testing.T) {
s, mc := setUp(true, math.MaxUint32)
s, tc := setUp(true, math.MaxUint32)
defer s.Stop()
args := &testpb.FibArgs{}
// Requests the first 10 Fibonnaci numbers.
args.Limit = proto.Int64(10)
// Start the stream and send the args.
stream, err := mc.Fib(context.Background(), args)
respParam := make([]*testpb.ResponseParameters, len(respSizes))
for i, s := range respSizes {
respParam[i] = &testpb.ResponseParameters{
Size: proto.Int32(int32(s)),
}
}
req := &testpb.StreamingOutputCallRequest{
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),
ResponseParameters: respParam,
}
stream, err := tc.StreamingOutputCall(context.Background(), req)
if err != nil {
t.Fatalf("failed to create stream %v", err)
t.Fatalf("%v.StreamingOutputCall(_) = _, %v, want <nil>", tc, err)
}
var rpcStatus error
var respCnt int
var index int
for {
_, err := stream.Recv()
reply, err := stream.Recv()
if err != nil {
rpcStatus = err
break
}
pt := reply.GetPayload().GetType()
if pt != testpb.PayloadType_COMPRESSABLE {
t.Fatalf("Got the reply of type %d, want %d", pt, testpb.PayloadType_COMPRESSABLE)
}
size := len(reply.GetPayload().GetBody())
if size != int(respSizes[index]) {
t.Fatalf("Got reply body of length %d, want %d", size, respSizes[index])
}
index++
respCnt++
}
if rpcStatus != io.EOF {
t.Fatalf(`mathClient.Fib got %v ; want <EOF>`, rpcStatus)
t.Fatalf("Failed to finish the server streaming rpc: %v, want <EOF>", err)
}
if respCnt != len(respSizes) {
t.Fatalf("Got %d reply, want %d", len(respSizes), respCnt)
}
}
func TestClientStreaming(t *testing.T) {
s, mc := setUp(true, math.MaxUint32)
s, tc := setUp(true, math.MaxUint32)
defer s.Stop()
stream, err := mc.Sum(context.Background())
stream, err := tc.StreamingInputCall(context.Background())
if err != nil {
t.Fatalf("failed to create stream: %v", err)
t.Fatalf("%v.StreamingInputCall(_) = _, %v, want <nil>", tc, err)
}
for _, n := range []int64{1, -2, 0, 7} {
if err := stream.Send(&testpb.Num{Num: &n}); err != nil {
t.Fatalf("failed to send requests %v", err)
var sum int
for _, s := range reqSizes {
pl := newPayload(testpb.PayloadType_COMPRESSABLE, int32(s))
req := &testpb.StreamingInputCallRequest{
Payload: pl,
}
if err := stream.Send(req); err != nil {
t.Fatalf("%v.Send(%v) = %v, want <nil>", stream, req, err)
}
sum += s
}
if _, err := stream.CloseAndRecv(); err != io.EOF {
t.Fatalf("stream.CloseAndRecv() got %v; want <EOF>", err)
reply, err := stream.CloseAndRecv()
if err != io.EOF {
t.Fatalf("%v.CloseAndRecv() got error %v, want %v", stream, err, io.EOF)
}
if reply.GetAggregatedPayloadSize() != int32(sum) {
t.Fatalf("%v.CloseAndRecv().GetAggregatePayloadSize() = %v; want %v", stream, reply.GetAggregatedPayloadSize(), sum)
}
}
func TestExceedMaxStreamsLimit(t *testing.T) {
// Only allows 1 live stream per server transport.
s, mc := setUp(true, 1)
s, tc := setUp(true, 1)
defer s.Stop()
var err error
for {
time.Sleep(2 * time.Millisecond)
_, err = mc.Sum(context.Background())
_, err = tc.StreamingInputCall(context.Background())
// Loop until the settings of max concurrent streams is
// received by the client.
if err != nil {

View File

@ -0,0 +1,96 @@
// Message definitions to be used by integration test service definitions.
syntax = "proto2";
package grpc.testing;
message Empty {}
// The type of payload that should be returned.
enum PayloadType {
// Compressable text format.
COMPRESSABLE = 0;
// Uncompressable binary format.
UNCOMPRESSABLE = 1;
// Randomly chosen from all other formats defined in this enum.
RANDOM = 2;
}
// A block of data, to simply increase gRPC message size.
message Payload {
// The type of data in body.
optional PayloadType type = 1;
// Primary contents of payload.
optional bytes body = 2;
}
// 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.
optional PayloadType response_type = 1;
// Desired payload size in the response from the server.
// If response_type is COMPRESSABLE, this denotes the size before compression.
optional int32 response_size = 2;
// Optional input payload sent along with the request.
optional Payload payload = 3;
}
// Unary response, as configured by the request.
message SimpleResponse {
// Payload to increase message size.
optional Payload payload = 1;
// The user the request came from, for verifying authentication was
// successful when the client expected it.
optional int64 effective_gaia_user_id = 2;
}
// Client-streaming request.
message StreamingInputCallRequest {
// Optional input payload sent along with the request.
optional Payload payload = 1;
// Not expecting any payload from the response.
}
// Client-streaming response.
message StreamingInputCallResponse {
// Aggregated size of payloads received from the client.
optional int32 aggregated_payload_size = 1;
}
// Configuration for a particular response.
message ResponseParameters {
// Desired payload sizes in responses from the server.
// If response_type is COMPRESSABLE, this denotes the size before compression.
optional int32 size = 1;
// Desired interval between consecutive responses in the response stream in
// microseconds.
optional int32 interval_us = 2;
}
// 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.
optional PayloadType response_type = 1;
// Configuration for each expected response message.
repeated ResponseParameters response_parameters = 2;
// Optional input payload sent along with the request.
optional Payload payload = 3;
}
// Server-streaming response, as configured by the request and parameters.
message StreamingOutputCallResponse {
// Payload to increase response size.
optional Payload payload = 1;
}

View File

@ -0,0 +1,41 @@
// An integration test service that covers all the method signature permutations
// of unary/streaming requests/responses.
syntax = "proto2";
import "github.com/google/grpc_go/interop/testdata/messages.proto";
package grpc.testing;
// A simple service to test the various types of RPCs and experiment with
// performance with various types of payload.
service TestService {
// One empty request followed by one empty response.
rpc EmptyCall(Empty) returns (Empty);
// One request followed by one response.
// The server returns the client payload as-is.
rpc UnaryCall(SimpleRequest) returns (SimpleResponse);
// One request followed by a sequence of responses (streamed download).
// The server returns the payload with client desired type and sizes.
rpc StreamingOutputCall(StreamingOutputCallRequest)
returns (stream StreamingOutputCallResponse);
// A sequence of requests followed by one response (streamed upload).
// The server returns the aggregated size of client payload as the result.
rpc StreamingInputCall(stream StreamingInputCallRequest)
returns (StreamingInputCallResponse);
// 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.
rpc FullDuplexCall(stream StreamingOutputCallRequest)
returns (stream StreamingOutputCallResponse);
// 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.
rpc HalfDuplexCall(stream StreamingOutputCallRequest)
returns (stream StreamingOutputCallResponse);
}

View File

@ -0,0 +1,403 @@
/*
*
* Copyright 2014, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
// Code generated by protoc-gen-go.
// source: net/grpc/go/interop/test.proto
// DO NOT EDIT!
/*
Package grpc_testing is a generated protocol buffer package.
It is generated from these files:
net/grpc/go/interop/test.proto
It has these top-level messages:
Payload
SimpleRequest
SimpleResponse
SimpleContext
StreamingInputCallRequest
StreamingInputCallResponse
ResponseParameters
StreamingOutputCallRequest
StreamingOutputCallResponse
*/
package grpc_testing
import proto "github.com/golang/protobuf/proto"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = math.Inf
type Empty struct {
XXX_unrecognized []byte `json:"-"`
}
func (m *Empty) Reset() { *m = Empty{} }
func (m *Empty) String() string { return proto.CompactTextString(m) }
func (*Empty) ProtoMessage() {}
func (*Empty) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
// The type of payload that should be returned.
type PayloadType int32
const (
// Compressable text format.
PayloadType_COMPRESSABLE PayloadType = 0
// Uncompressable binary format.
PayloadType_UNCOMPRESSABLE PayloadType = 1
// Randomly chosen from all other formats defined in this enum.
PayloadType_RANDOM PayloadType = 2
)
var PayloadType_name = map[int32]string{
0: "COMPRESSABLE",
1: "UNCOMPRESSABLE",
2: "RANDOM",
}
var PayloadType_value = map[string]int32{
"COMPRESSABLE": 0,
"UNCOMPRESSABLE": 1,
"RANDOM": 2,
}
func (x PayloadType) Enum() *PayloadType {
p := new(PayloadType)
*p = x
return p
}
func (x PayloadType) String() string {
return proto.EnumName(PayloadType_name, int32(x))
}
func (x *PayloadType) UnmarshalJSON(data []byte) error {
value, err := proto.UnmarshalJSONEnum(PayloadType_value, data, "PayloadType")
if err != nil {
return err
}
*x = PayloadType(value)
return nil
}
func (PayloadType) EnumDescriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
// A block of data, to simply increase gRPC message size.
type Payload struct {
// The type of data in body.
Type *PayloadType `protobuf:"varint,1,opt,name=type,enum=grpc.testing.PayloadType" json:"type,omitempty"`
// Primary contents of payload.
Body []byte `protobuf:"bytes,2,opt,name=body" json:"body,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *Payload) Reset() { *m = Payload{} }
func (m *Payload) String() string { return proto.CompactTextString(m) }
func (*Payload) ProtoMessage() {}
func (*Payload) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
func (m *Payload) GetType() PayloadType {
if m != nil && m.Type != nil {
return *m.Type
}
return PayloadType_COMPRESSABLE
}
func (m *Payload) GetBody() []byte {
if m != nil {
return m.Body
}
return nil
}
// Unary request.
type SimpleRequest struct {
// Desired payload type in the response from the server.
// If response_type is RANDOM, server randomly chooses one from other formats.
ResponseType *PayloadType `protobuf:"varint,1,opt,name=response_type,enum=grpc.testing.PayloadType" json:"response_type,omitempty"`
// Desired payload size in the response from the server.
// If response_type is COMPRESSABLE, this denotes the size before compression.
ResponseSize *int32 `protobuf:"varint,2,opt,name=response_size" json:"response_size,omitempty"`
// Optional input payload sent along with the request.
Payload *Payload `protobuf:"bytes,3,opt,name=payload" json:"payload,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *SimpleRequest) Reset() { *m = SimpleRequest{} }
func (m *SimpleRequest) String() string { return proto.CompactTextString(m) }
func (*SimpleRequest) ProtoMessage() {}
func (*SimpleRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
func (m *SimpleRequest) GetResponseType() PayloadType {
if m != nil && m.ResponseType != nil {
return *m.ResponseType
}
return PayloadType_COMPRESSABLE
}
func (m *SimpleRequest) GetResponseSize() int32 {
if m != nil && m.ResponseSize != nil {
return *m.ResponseSize
}
return 0
}
func (m *SimpleRequest) GetPayload() *Payload {
if m != nil {
return m.Payload
}
return nil
}
// Unary response, as configured by the request.
type SimpleResponse struct {
// Payload to increase message size.
Payload *Payload `protobuf:"bytes,1,opt,name=payload" json:"payload,omitempty"`
// The user the request came from, for verifying authentication was
// successful when the client expected it.
EffectiveGaiaUserId *int64 `protobuf:"varint,2,opt,name=effective_gaia_user_id" json:"effective_gaia_user_id,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *SimpleResponse) Reset() { *m = SimpleResponse{} }
func (m *SimpleResponse) String() string { return proto.CompactTextString(m) }
func (*SimpleResponse) ProtoMessage() {}
func (*SimpleResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{2} }
func (m *SimpleResponse) GetPayload() *Payload {
if m != nil {
return m.Payload
}
return nil
}
func (m *SimpleResponse) GetEffectiveGaiaUserId() int64 {
if m != nil && m.EffectiveGaiaUserId != nil {
return *m.EffectiveGaiaUserId
}
return 0
}
type SimpleContext struct {
Value *string `protobuf:"bytes,1,opt,name=value" json:"value,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *SimpleContext) Reset() { *m = SimpleContext{} }
func (m *SimpleContext) String() string { return proto.CompactTextString(m) }
func (*SimpleContext) ProtoMessage() {}
func (*SimpleContext) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{3} }
func (m *SimpleContext) GetValue() string {
if m != nil && m.Value != nil {
return *m.Value
}
return ""
}
func init() {
}
// Client-streaming request.
type StreamingInputCallRequest struct {
// Optional input payload sent along with the request.
Payload *Payload `protobuf:"bytes,1,opt,name=payload" json:"payload,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *StreamingInputCallRequest) Reset() { *m = StreamingInputCallRequest{} }
func (m *StreamingInputCallRequest) String() string { return proto.CompactTextString(m) }
func (*StreamingInputCallRequest) ProtoMessage() {}
func (*StreamingInputCallRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{4} }
func (m *StreamingInputCallRequest) GetPayload() *Payload {
if m != nil {
return m.Payload
}
return nil
}
// Client-streaming response.
type StreamingInputCallResponse struct {
// Aggregated size of payloads received from the client.
AggregatedPayloadSize *int32 `protobuf:"varint,1,opt,name=aggregated_payload_size" json:"aggregated_payload_size,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *StreamingInputCallResponse) Reset() { *m = StreamingInputCallResponse{} }
func (m *StreamingInputCallResponse) String() string { return proto.CompactTextString(m) }
func (*StreamingInputCallResponse) ProtoMessage() {}
func (*StreamingInputCallResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{5} }
func (m *StreamingInputCallResponse) GetAggregatedPayloadSize() int32 {
if m != nil && m.AggregatedPayloadSize != nil {
return *m.AggregatedPayloadSize
}
return 0
}
// Configuration for a particular response.
type ResponseParameters struct {
// Desired payload sizes in responses from the server.
// If response_type is COMPRESSABLE, this denotes the size before compression.
Size *int32 `protobuf:"varint,1,opt,name=size" json:"size,omitempty"`
// Desired interval between consecutive responses in the response stream in
// microseconds.
IntervalUs *int32 `protobuf:"varint,2,opt,name=interval_us" json:"interval_us,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *ResponseParameters) Reset() { *m = ResponseParameters{} }
func (m *ResponseParameters) String() string { return proto.CompactTextString(m) }
func (*ResponseParameters) ProtoMessage() {}
func (*ResponseParameters) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{6} }
func (m *ResponseParameters) GetSize() int32 {
if m != nil && m.Size != nil {
return *m.Size
}
return 0
}
func (m *ResponseParameters) GetIntervalUs() int32 {
if m != nil && m.IntervalUs != nil {
return *m.IntervalUs
}
return 0
}
// Server-streaming request.
type StreamingOutputCallRequest struct {
// 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.
ResponseType *PayloadType `protobuf:"varint,1,opt,name=response_type,enum=grpc.testing.PayloadType" json:"response_type,omitempty"`
// Configuration for each expected response message.
ResponseParameters []*ResponseParameters `protobuf:"bytes,2,rep,name=response_parameters" json:"response_parameters,omitempty"`
// Optional input payload sent along with the request.
Payload *Payload `protobuf:"bytes,3,opt,name=payload" json:"payload,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *StreamingOutputCallRequest) Reset() { *m = StreamingOutputCallRequest{} }
func (m *StreamingOutputCallRequest) String() string { return proto.CompactTextString(m) }
func (*StreamingOutputCallRequest) ProtoMessage() {}
func (*StreamingOutputCallRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{7} }
func (m *StreamingOutputCallRequest) GetResponseType() PayloadType {
if m != nil && m.ResponseType != nil {
return *m.ResponseType
}
return PayloadType_COMPRESSABLE
}
func (m *StreamingOutputCallRequest) GetResponseParameters() []*ResponseParameters {
if m != nil {
return m.ResponseParameters
}
return nil
}
func (m *StreamingOutputCallRequest) GetPayload() *Payload {
if m != nil {
return m.Payload
}
return nil
}
// Server-streaming response, as configured by the request and parameters.
type StreamingOutputCallResponse struct {
// Payload to increase response size.
Payload *Payload `protobuf:"bytes,1,opt,name=payload" json:"payload,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *StreamingOutputCallResponse) Reset() { *m = StreamingOutputCallResponse{} }
func (m *StreamingOutputCallResponse) String() string { return proto.CompactTextString(m) }
func (*StreamingOutputCallResponse) ProtoMessage() {}
func (*StreamingOutputCallResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{8} }
func (m *StreamingOutputCallResponse) GetPayload() *Payload {
if m != nil {
return m.Payload
}
return nil
}
func init() {
proto.RegisterEnum("grpc.testing.PayloadType", PayloadType_name, PayloadType_value)
}
var fileDescriptor0 = []byte{
// 628 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xbc, 0x55, 0x4d, 0x6f, 0xd3, 0x40,
0x10, 0xc5, 0x49, 0x3f, 0xd4, 0xc9, 0x87, 0xa2, 0xad, 0x0a, 0xa9, 0x5b, 0x95, 0xe2, 0x03, 0x4d,
0x38, 0xd8, 0x28, 0x17, 0x4e, 0x15, 0xb4, 0x69, 0x2a, 0x90, 0xe8, 0x87, 0x9a, 0x56, 0xea, 0xcd,
0xda, 0x24, 0xd3, 0x95, 0x25, 0xdb, 0x6b, 0xec, 0x75, 0xd5, 0x70, 0x42, 0xfc, 0x11, 0x38, 0xf6,
0x0f, 0x70, 0xe4, 0x6f, 0x71, 0x66, 0x9d, 0xb5, 0x8b, 0x13, 0x5c, 0x48, 0x0f, 0x70, 0xf4, 0xee,
0x9b, 0xf7, 0xde, 0xbc, 0x99, 0x4d, 0x60, 0xcb, 0x47, 0x61, 0xb1, 0x30, 0x18, 0x5a, 0x8c, 0x5b,
0x8e, 0x2f, 0x30, 0xe4, 0x81, 0x25, 0x30, 0x12, 0x66, 0x10, 0x72, 0xc1, 0x49, 0x35, 0xb9, 0x33,
0x93, 0x03, 0xc7, 0x67, 0x7a, 0x3b, 0x41, 0x4f, 0x2e, 0x3a, 0xd6, 0x20, 0x74, 0x46, 0x0c, 0xd5,
0x97, 0xe5, 0x61, 0x14, 0x51, 0x86, 0x76, 0x84, 0x69, 0xa1, 0xbe, 0x99, 0x83, 0x2a, 0x0c, 0x7a,
0x81, 0x18, 0xab, 0x5b, 0xe3, 0x0d, 0x2c, 0x9f, 0xd2, 0xb1, 0xcb, 0xe9, 0x88, 0xec, 0xc0, 0x82,
0x18, 0x07, 0xd8, 0xd4, 0xb6, 0xb5, 0x56, 0xbd, 0xb3, 0x6e, 0xe6, 0x05, 0xcd, 0x14, 0x74, 0x2e,
0x01, 0xa4, 0x0a, 0x0b, 0x03, 0x3e, 0x1a, 0x37, 0x4b, 0x12, 0x58, 0x35, 0x3e, 0x69, 0x50, 0xeb,
0x3b, 0x5e, 0xe0, 0xe2, 0x19, 0x7e, 0x88, 0x25, 0x9c, 0xbc, 0x84, 0x5a, 0x88, 0x51, 0xc0, 0xfd,
0x08, 0xed, 0xf9, 0x18, 0xd7, 0x72, 0x15, 0x91, 0xf3, 0x11, 0x27, 0xd4, 0x8b, 0xe4, 0x39, 0x2c,
0x07, 0x0a, 0xd5, 0x2c, 0xcb, 0x83, 0x4a, 0x67, 0xad, 0x90, 0xc2, 0xb8, 0x84, 0x7a, 0xe6, 0x40,
0x91, 0xe4, 0x2b, 0xb5, 0x3f, 0x54, 0x92, 0x2d, 0x78, 0x8c, 0x57, 0x57, 0x38, 0x14, 0xce, 0x35,
0xda, 0x8c, 0x3a, 0xd4, 0x8e, 0x23, 0x0c, 0x6d, 0x67, 0x34, 0x71, 0x50, 0x36, 0x6e, 0xb2, 0xde,
0xba, 0x5c, 0x8e, 0xe4, 0x46, 0x90, 0x1a, 0x2c, 0x5e, 0x53, 0x37, 0x56, 0x3d, 0xad, 0x74, 0x2e,
0x61, 0x2d, 0x97, 0xb8, 0x2d, 0x11, 0xe8, 0x47, 0x0e, 0xf7, 0xc9, 0xba, 0xca, 0xb7, 0x63, 0xaa,
0xe9, 0x98, 0x47, 0x0a, 0xd5, 0x47, 0xd1, 0xfc, 0xf2, 0xf9, 0xc7, 0xb3, 0x89, 0xa7, 0x8d, 0x69,
0x4f, 0x53, 0x42, 0x46, 0x17, 0xd6, 0xfb, 0x22, 0x44, 0xea, 0xc9, 0xab, 0x77, 0x7e, 0x10, 0x8b,
0x2e, 0x75, 0xdd, 0x2c, 0xe1, 0x39, 0xdb, 0x33, 0x76, 0x41, 0x2f, 0x22, 0x49, 0x43, 0x7a, 0x0a,
0x4f, 0x28, 0x63, 0x21, 0x32, 0x2a, 0x70, 0x64, 0xa7, 0x84, 0x2a, 0xff, 0x84, 0x75, 0xd1, 0x78,
0x05, 0x24, 0x03, 0x9f, 0xd2, 0x90, 0x7a, 0x28, 0xb7, 0x32, 0x4a, 0xc6, 0xff, 0x0b, 0x43, 0x56,
0xa1, 0x32, 0xd9, 0x56, 0x99, 0x8a, 0xcc, 0x4e, 0x0d, 0xce, 0xf8, 0xa6, 0xe5, 0x84, 0x4f, 0x62,
0x31, 0x63, 0xff, 0xe1, 0x0b, 0xb2, 0x0b, 0xab, 0x77, 0x15, 0xc1, 0x9d, 0x15, 0xa9, 0x56, 0x96,
0xcd, 0x6f, 0x4f, 0xd7, 0x15, 0x58, 0x9e, 0x77, 0x91, 0x7a, 0xb0, 0x51, 0x68, 0xfb, 0x61, 0x5b,
0xf5, 0xe2, 0x35, 0x54, 0xf2, 0xe6, 0x1b, 0x50, 0xed, 0x9e, 0x1c, 0x9d, 0x9e, 0xf5, 0xfa, 0xfd,
0xbd, 0xfd, 0xf7, 0xbd, 0xc6, 0x23, 0x42, 0xa0, 0x7e, 0x71, 0x3c, 0x75, 0xa6, 0x11, 0x80, 0xa5,
0xb3, 0xbd, 0xe3, 0x83, 0x93, 0xa3, 0x46, 0xa9, 0xf3, 0x7d, 0x01, 0x2a, 0xe7, 0x92, 0xb4, 0x2f,
0x73, 0x75, 0x86, 0x48, 0xda, 0xb0, 0xd2, 0x4b, 0x1e, 0x6d, 0xe2, 0x86, 0xd4, 0xb2, 0xd5, 0x9a,
0x1c, 0xe9, 0xd3, 0x9f, 0xe4, 0x10, 0x56, 0x2e, 0x7c, 0x1a, 0x2a, 0x68, 0xe1, 0x86, 0xa5, 0x53,
0xd0, 0x37, 0x8b, 0x2f, 0xd3, 0x5e, 0x39, 0xac, 0x16, 0x44, 0x41, 0x5a, 0x33, 0x45, 0xf7, 0x0e,
0x59, 0x6f, 0xcf, 0x81, 0x54, 0x5a, 0x46, 0xf9, 0x56, 0xd3, 0x88, 0x0b, 0xe4, 0xf7, 0x5d, 0x25,
0x3b, 0xf7, 0xb0, 0xcc, 0x3e, 0x09, 0xbd, 0xf5, 0x77, 0x60, 0xa6, 0xf6, 0x55, 0xaa, 0x79, 0x50,
0x3f, 0x8c, 0x5d, 0xf7, 0x20, 0x96, 0x3d, 0xdf, 0xfc, 0xbb, 0xce, 0x96, 0xa4, 0xd6, 0xad, 0x92,
0x7b, 0x4b, 0xdd, 0xab, 0xff, 0x24, 0xb7, 0x6f, 0x41, 0x7b, 0xc8, 0x3d, 0x93, 0x71, 0xce, 0x5c,
0x34, 0xe5, 0x1f, 0x80, 0x19, 0x89, 0x78, 0x30, 0x18, 0xdf, 0x91, 0x24, 0x4f, 0x96, 0x85, 0x54,
0xc8, 0x9f, 0xaa, 0x46, 0xa9, 0x55, 0xfa, 0x19, 0x00, 0x00, 0xff, 0xff, 0x0b, 0xad, 0xee, 0x7c,
0x7e, 0x06, 0x00, 0x00,
}

View File

@ -0,0 +1,379 @@
/*
*
* Copyright 2014, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
package grpc_testing
import (
"fmt"
proto "github.com/golang/protobuf/proto"
context "golang.org/x/net/context"
"google.golang.org/grpc"
"io"
)
type TestServiceClient interface {
EmptyCall(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error)
UnaryCall(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (*SimpleResponse, error)
StreamingOutputCall(ctx context.Context, m *StreamingOutputCallRequest, opts ...grpc.CallOption) (TestService_StreamingOutputCallClient, error)
StreamingInputCall(ctx context.Context, opts ...grpc.CallOption) (TestService_StreamingInputCallClient, error)
FullDuplexCall(ctx context.Context, opts ...grpc.CallOption) (TestService_FullDuplexCallClient, error)
HalfDuplexCall(ctx context.Context, opts ...grpc.CallOption) (TestService_HalfDuplexCallClient, error)
}
type testServiceClient struct {
cc *grpc.ClientConn
}
func NewTestServiceClient(cc *grpc.ClientConn) TestServiceClient {
return &testServiceClient{cc}
}
func (c *testServiceClient) EmptyCall(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Empty, error) {
out := new(Empty)
err := grpc.Invoke(ctx, "/grpc.testing.TestService/EmptyCall", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *testServiceClient) UnaryCall(ctx context.Context, in *SimpleRequest, opts ...grpc.CallOption) (*SimpleResponse, error) {
out := new(SimpleResponse)
err := grpc.Invoke(ctx, "/grpc.testing.TestService/UnaryCall", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *testServiceClient) StreamingOutputCall(ctx context.Context, m *StreamingOutputCallRequest, opts ...grpc.CallOption) (TestService_StreamingOutputCallClient, error) {
stream, err := grpc.NewClientStream(ctx, c.cc, "/grpc.testing.TestService/StreamingOutputCall", opts...)
if err != nil {
return nil, err
}
x := &testServiceStreamingOutputCallClient{stream}
if err := x.ClientStream.SendProto(m); err != nil {
return nil, err
}
if err := x.ClientStream.CloseSend(); err != nil {
return nil, err
}
return x, nil
}
type TestService_StreamingOutputCallClient interface {
Recv() (*StreamingOutputCallResponse, error)
grpc.ClientStream
}
type testServiceStreamingOutputCallClient struct {
grpc.ClientStream
}
func (x *testServiceStreamingOutputCallClient) Recv() (*StreamingOutputCallResponse, error) {
m := new(StreamingOutputCallResponse)
if err := x.ClientStream.RecvProto(m); err != nil {
return nil, err
}
return m, nil
}
func (c *testServiceClient) StreamingInputCall(ctx context.Context, opts ...grpc.CallOption) (TestService_StreamingInputCallClient, error) {
stream, err := grpc.NewClientStream(ctx, c.cc, "/grpc.testing.TestService/StreamingInputCall", opts...)
if err != nil {
return nil, err
}
return &testServiceStreamingInputCallClient{stream}, nil
}
type TestService_StreamingInputCallClient interface {
Send(*StreamingInputCallRequest) error
CloseAndRecv() (*StreamingInputCallResponse, error)
grpc.ClientStream
}
type testServiceStreamingInputCallClient struct {
grpc.ClientStream
}
func (x *testServiceStreamingInputCallClient) Send(m *StreamingInputCallRequest) error {
return x.ClientStream.SendProto(m)
}
func (x *testServiceStreamingInputCallClient) CloseAndRecv() (*StreamingInputCallResponse, error) {
if err := x.ClientStream.CloseSend(); err != nil {
return nil, err
}
m := new(StreamingInputCallResponse)
if err := x.ClientStream.RecvProto(m); err != nil {
return nil, err
}
// Read EOF.
if err := x.ClientStream.RecvProto(m); err == io.EOF {
return m, io.EOF
}
// gRPC protocol violation.
return m, fmt.Errorf("Violate gRPC client streaming protocol: no EOF after the response.")
}
func (c *testServiceClient) FullDuplexCall(ctx context.Context, opts ...grpc.CallOption) (TestService_FullDuplexCallClient, error) {
stream, err := grpc.NewClientStream(ctx, c.cc, "/grpc.testing.TestService/FullDuplexCall", opts...)
if err != nil {
return nil, err
}
return &testServiceFullDuplexCallClient{stream}, nil
}
type TestService_FullDuplexCallClient interface {
Send(*StreamingOutputCallRequest) error
Recv() (*StreamingOutputCallResponse, error)
grpc.ClientStream
}
type testServiceFullDuplexCallClient struct {
grpc.ClientStream
}
func (x *testServiceFullDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
return x.ClientStream.SendProto(m)
}
func (x *testServiceFullDuplexCallClient) Recv() (*StreamingOutputCallResponse, error) {
m := new(StreamingOutputCallResponse)
if err := x.ClientStream.RecvProto(m); err != nil {
return nil, err
}
return m, nil
}
func (c *testServiceClient) HalfDuplexCall(ctx context.Context, opts ...grpc.CallOption) (TestService_HalfDuplexCallClient, error) {
stream, err := grpc.NewClientStream(ctx, c.cc, "/grpc.testing.TestService/HalfDuplexCall", opts...)
if err != nil {
return nil, err
}
return &testServiceHalfDuplexCallClient{stream}, nil
}
type TestService_HalfDuplexCallClient interface {
Send(*StreamingOutputCallRequest) error
Recv() (*StreamingOutputCallResponse, error)
grpc.ClientStream
}
type testServiceHalfDuplexCallClient struct {
grpc.ClientStream
}
func (x *testServiceHalfDuplexCallClient) Send(m *StreamingOutputCallRequest) error {
return x.ClientStream.SendProto(m)
}
func (x *testServiceHalfDuplexCallClient) Recv() (*StreamingOutputCallResponse, error) {
m := new(StreamingOutputCallResponse)
if err := x.ClientStream.RecvProto(m); err != nil {
return nil, err
}
return m, nil
}
type TestServiceServer interface {
EmptyCall(context.Context, *Empty) (*Empty, error)
UnaryCall(context.Context, *SimpleRequest) (*SimpleResponse, error)
StreamingOutputCall(*StreamingOutputCallRequest, TestService_StreamingOutputCallServer) error
StreamingInputCall(TestService_StreamingInputCallServer) error
FullDuplexCall(TestService_FullDuplexCallServer) error
HalfDuplexCall(TestService_HalfDuplexCallServer) error
}
func RegisterService(s *grpc.Server, srv TestServiceServer) {
s.RegisterService(&_TestService_serviceDesc, srv)
}
func _TestService_EmptyCall_Handler(srv interface{}, ctx context.Context, buf []byte) (proto.Message, error) {
in := new(Empty)
if err := proto.Unmarshal(buf, in); err != nil {
return nil, err
}
out, err := srv.(TestServiceServer).EmptyCall(ctx, in)
if err != nil {
return nil, err
}
return out, nil
}
func _TestService_UnaryCall_Handler(srv interface{}, ctx context.Context, buf []byte) (proto.Message, error) {
in := new(SimpleRequest)
if err := proto.Unmarshal(buf, in); err != nil {
return nil, err
}
out, err := srv.(TestServiceServer).UnaryCall(ctx, in)
if err != nil {
return nil, err
}
return out, nil
}
func _TestService_StreamingOutputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
m := new(StreamingOutputCallRequest)
if err := stream.RecvProto(m); err != nil {
return err
}
return srv.(TestServiceServer).StreamingOutputCall(m, &testServiceStreamingOutputCallServer{stream})
}
type TestService_StreamingOutputCallServer interface {
Send(*StreamingOutputCallResponse) error
grpc.ServerStream
}
type testServiceStreamingOutputCallServer struct {
grpc.ServerStream
}
func (x *testServiceStreamingOutputCallServer) Send(m *StreamingOutputCallResponse) error {
return x.ServerStream.SendProto(m)
}
func _TestService_StreamingInputCall_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(TestServiceServer).StreamingInputCall(&testServiceStreamingInputCallServer{stream})
}
type TestService_StreamingInputCallServer interface {
SendAndClose(*StreamingInputCallResponse) error
Recv() (*StreamingInputCallRequest, error)
grpc.ServerStream
}
type testServiceStreamingInputCallServer struct {
grpc.ServerStream
}
func (x *testServiceStreamingInputCallServer) SendAndClose(m *StreamingInputCallResponse) error {
if err := x.ServerStream.SendProto(m); err != nil {
return err
}
return nil
}
func (x *testServiceStreamingInputCallServer) Recv() (*StreamingInputCallRequest, error) {
m := new(StreamingInputCallRequest)
if err := x.ServerStream.RecvProto(m); err != nil {
return nil, err
}
return m, nil
}
func _TestService_FullDuplexCall_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(TestServiceServer).FullDuplexCall(&testServiceFullDuplexCallServer{stream})
}
type TestService_FullDuplexCallServer interface {
Send(*StreamingOutputCallResponse) error
Recv() (*StreamingOutputCallRequest, error)
grpc.ServerStream
}
type testServiceFullDuplexCallServer struct {
grpc.ServerStream
}
func (x *testServiceFullDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
return x.ServerStream.SendProto(m)
}
func (x *testServiceFullDuplexCallServer) Recv() (*StreamingOutputCallRequest, error) {
m := new(StreamingOutputCallRequest)
if err := x.ServerStream.RecvProto(m); err != nil {
return nil, err
}
return m, nil
}
func _TestService_HalfDuplexCall_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(TestServiceServer).HalfDuplexCall(&testServiceHalfDuplexCallServer{stream})
}
type TestService_HalfDuplexCallServer interface {
Send(*StreamingOutputCallResponse) error
Recv() (*StreamingOutputCallRequest, error)
grpc.ServerStream
}
type testServiceHalfDuplexCallServer struct {
grpc.ServerStream
}
func (x *testServiceHalfDuplexCallServer) Send(m *StreamingOutputCallResponse) error {
return x.ServerStream.SendProto(m)
}
func (x *testServiceHalfDuplexCallServer) Recv() (*StreamingOutputCallRequest, error) {
m := new(StreamingOutputCallRequest)
if err := x.ServerStream.RecvProto(m); err != nil {
return nil, err
}
return m, nil
}
var _TestService_serviceDesc = grpc.ServiceDesc{
ServiceName: "grpc.testing.TestService",
HandlerType: (*TestServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "EmptyCall",
Handler: _TestService_EmptyCall_Handler,
},
{
MethodName: "UnaryCall",
Handler: _TestService_UnaryCall_Handler,
},
},
Streams: []grpc.StreamDesc{
{
StreamName: "StreamingOutputCall",
Handler: _TestService_StreamingOutputCall_Handler,
},
{
StreamName: "StreamingInputCall",
Handler: _TestService_StreamingInputCall_Handler,
},
{
StreamName: "FullDuplexCall",
Handler: _TestService_FullDuplexCall_Handler,
},
{
StreamName: "HalfDuplexCall",
Handler: _TestService_HalfDuplexCall_Handler,
},
},
}

View File

@ -1,157 +0,0 @@
/*
*
* Copyright 2014, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
// Code generated by protoc-gen-go.
// source: src/google.golang.org/grpc/test/proto/test.proto
// DO NOT EDIT!
/*
Package proto is a generated protocol buffer package.
It is generated from these files:
src/google.golang.org/grpc/test/proto/test.proto
It has these top-level messages:
DivArgs
DivReply
FibArgs
Num
FibReply
*/
package proto
import proto1 "github.com/golang/protobuf/proto"
import math "math"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto1.Marshal
var _ = math.Inf
type DivArgs struct {
Dividend *int64 `protobuf:"varint,1,req,name=dividend" json:"dividend,omitempty"`
Divisor *int64 `protobuf:"varint,2,req,name=divisor" json:"divisor,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *DivArgs) Reset() { *m = DivArgs{} }
func (m *DivArgs) String() string { return proto1.CompactTextString(m) }
func (*DivArgs) ProtoMessage() {}
func (m *DivArgs) GetDividend() int64 {
if m != nil && m.Dividend != nil {
return *m.Dividend
}
return 0
}
func (m *DivArgs) GetDivisor() int64 {
if m != nil && m.Divisor != nil {
return *m.Divisor
}
return 0
}
type DivReply struct {
Quotient *int64 `protobuf:"varint,1,req,name=quotient" json:"quotient,omitempty"`
Remainder *int64 `protobuf:"varint,2,req,name=remainder" json:"remainder,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *DivReply) Reset() { *m = DivReply{} }
func (m *DivReply) String() string { return proto1.CompactTextString(m) }
func (*DivReply) ProtoMessage() {}
func (m *DivReply) GetQuotient() int64 {
if m != nil && m.Quotient != nil {
return *m.Quotient
}
return 0
}
func (m *DivReply) GetRemainder() int64 {
if m != nil && m.Remainder != nil {
return *m.Remainder
}
return 0
}
type FibArgs struct {
Limit *int64 `protobuf:"varint,1,opt,name=limit" json:"limit,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *FibArgs) Reset() { *m = FibArgs{} }
func (m *FibArgs) String() string { return proto1.CompactTextString(m) }
func (*FibArgs) ProtoMessage() {}
func (m *FibArgs) GetLimit() int64 {
if m != nil && m.Limit != nil {
return *m.Limit
}
return 0
}
type Num struct {
Num *int64 `protobuf:"varint,1,req,name=num" json:"num,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *Num) Reset() { *m = Num{} }
func (m *Num) String() string { return proto1.CompactTextString(m) }
func (*Num) ProtoMessage() {}
func (m *Num) GetNum() int64 {
if m != nil && m.Num != nil {
return *m.Num
}
return 0
}
type FibReply struct {
Count *int64 `protobuf:"varint,1,req,name=count" json:"count,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *FibReply) Reset() { *m = FibReply{} }
func (m *FibReply) String() string { return proto1.CompactTextString(m) }
func (*FibReply) ProtoMessage() {}
func (m *FibReply) GetCount() int64 {
if m != nil && m.Count != nil {
return *m.Count
}
return 0
}
func init() {
}

View File

@ -1,50 +0,0 @@
syntax = "proto2";
package proto;
message DivArgs {
required int64 dividend = 1;
required int64 divisor = 2;
}
message DivReply {
required int64 quotient = 1;
required int64 remainder = 2;
}
message FibArgs {
optional int64 limit = 1;
}
message Num {
required int64 num = 1;
}
message FibReply {
required int64 count = 1;
}
service Math { // This name leads to "MathServer" and "MathClient".
// Div divides args.dividend by args.divisor and returns the quotient and
// remainder.
rpc Div (DivArgs) returns (DivReply) {
}
// DivMany accepts an arbitrary number of division args from the client stream
// and sends back the results in the reply stream. The stream continues until
// the client closes its end; the server does the same after sending all the
// replies. The stream ends immediately if either end aborts.
rpc DivMany (stream DivArgs) returns (stream DivReply) {
}
// Fib generates numbers in the Fibonacci sequence. If args.limit > 0, Fib4
// generates up to limit numbers; otherwise it continues until the call is
// canceled. Unlike Fib above, Fib4 has no final FibReply.
rpc Fib (FibArgs) returns (stream Num) {
}
// Sum sums a stream of numbers, returning the final result once the stream
// is closed.
rpc Sum (stream Num) returns (Num) {
}
}

View File

@ -1,294 +0,0 @@
/*
*
* Copyright 2014, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
package proto
import (
"fmt"
"io"
"google.golang.org/grpc"
context "golang.org/x/net/context"
proto "github.com/golang/protobuf/proto"
)
type MathClient interface {
Div(ctx context.Context, in *DivArgs, opts ...grpc.CallOption) (*DivReply, error)
DivMany(ctx context.Context, opts ...grpc.CallOption) (Math_DivManyClient, error)
Fib(ctx context.Context, m *FibArgs, opts ...grpc.CallOption) (Math_FibClient, error)
Sum(ctx context.Context, opts ...grpc.CallOption) (Math_SumClient, error)
}
type mathClient struct {
cc *grpc.ClientConn
}
func NewMathClient(cc *grpc.ClientConn) MathClient {
return &mathClient{cc}
}
func (c *mathClient) Div(ctx context.Context, in *DivArgs, opts ...grpc.CallOption) (*DivReply, error) {
out := new(DivReply)
err := grpc.Invoke(ctx, "/proto.Math/Div", in, out, c.cc, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *mathClient) DivMany(ctx context.Context, opts ...grpc.CallOption) (Math_DivManyClient, error) {
stream, err := grpc.NewClientStream(ctx, c.cc, "/proto.Math/DivMany", opts...)
if err != nil {
return nil, err
}
return &mathDivManyClient{stream}, nil
}
type Math_DivManyClient interface {
Send(*DivArgs) error
Recv() (*DivReply, error)
grpc.ClientStream
}
type mathDivManyClient struct {
grpc.ClientStream
}
func (x *mathDivManyClient) Send(m *DivArgs) error {
return x.ClientStream.SendProto(m)
}
func (x *mathDivManyClient) Recv() (*DivReply, error) {
m := new(DivReply)
if err := x.ClientStream.RecvProto(m); err != nil {
return nil, err
}
return m, nil
}
func (c *mathClient) Fib(ctx context.Context, m *FibArgs, opts ...grpc.CallOption) (Math_FibClient, error) {
stream, err := grpc.NewClientStream(ctx, c.cc, "/proto.Math/Fib", opts...)
if err != nil {
return nil, err
}
x := &mathFibClient{stream}
if err := x.ClientStream.SendProto(m); err != nil {
return nil, err
}
if err := x.ClientStream.CloseSend(); err != nil {
return nil, err
}
return x, nil
}
type Math_FibClient interface {
Recv() (*Num, error)
grpc.ClientStream
}
type mathFibClient struct {
grpc.ClientStream
}
func (x *mathFibClient) Recv() (*Num, error) {
m := new(Num)
if err := x.ClientStream.RecvProto(m); err != nil {
return nil, err
}
return m, nil
}
func (c *mathClient) Sum(ctx context.Context, opts ...grpc.CallOption) (Math_SumClient, error) {
stream, err := grpc.NewClientStream(ctx, c.cc, "/proto.Math/Sum", opts...)
if err != nil {
return nil, err
}
return &mathSumClient{stream}, nil
}
type Math_SumClient interface {
Send(*Num) error
CloseAndRecv() (*Num, error)
grpc.ClientStream
}
type mathSumClient struct {
grpc.ClientStream
}
func (x *mathSumClient) Send(m *Num) error {
return x.ClientStream.SendProto(m)
}
func (x *mathSumClient) CloseAndRecv() (*Num, error) {
if err := x.ClientStream.CloseSend(); err != nil {
return nil, err
}
m := new(Num)
if err := x.ClientStream.RecvProto(m); err != nil {
return nil, err
}
// Read EOF.
if err := x.ClientStream.RecvProto(m); err == io.EOF {
return m, io.EOF
}
// gRPC protocol violation.
return m, fmt.Errorf("Violate gRPC client streaming protocol: no EOF after the response.")
}
type MathServer interface {
Div(context.Context, *DivArgs) (*DivReply, error)
DivMany(Math_DivManyServer) error
Fib(*FibArgs, Math_FibServer) error
Sum(Math_SumServer) error
}
func RegisterService(s *grpc.Server, srv MathServer) {
s.RegisterService(&_Math_serviceDesc, srv)
}
func _Math_Div_Handler(srv interface{}, ctx context.Context, buf []byte) (proto.Message, error) {
in := new(DivArgs)
if err := proto.Unmarshal(buf, in); err != nil {
return nil, err
}
out, err := srv.(MathServer).Div(ctx, in)
if err != nil {
return nil, err
}
return out, nil
}
func _Math_DivMany_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(MathServer).DivMany(&mathDivManyServer{stream})
}
type Math_DivManyServer interface {
Send(*DivReply) error
Recv() (*DivArgs, error)
grpc.ServerStream
}
type mathDivManyServer struct {
grpc.ServerStream
}
func (x *mathDivManyServer) Send(m *DivReply) error {
return x.ServerStream.SendProto(m)
}
func (x *mathDivManyServer) Recv() (*DivArgs, error) {
m := new(DivArgs)
if err := x.ServerStream.RecvProto(m); err != nil {
return nil, err
}
return m, nil
}
func _Math_Fib_Handler(srv interface{}, stream grpc.ServerStream) error {
m := new(FibArgs)
if err := stream.RecvProto(m); err != nil {
return err
}
return srv.(MathServer).Fib(m, &mathFibServer{stream})
}
type Math_FibServer interface {
Send(*Num) error
grpc.ServerStream
}
type mathFibServer struct {
grpc.ServerStream
}
func (x *mathFibServer) Send(m *Num) error {
return x.ServerStream.SendProto(m)
}
func _Math_Sum_Handler(srv interface{}, stream grpc.ServerStream) error {
return srv.(MathServer).Sum(&mathSumServer{stream})
}
type Math_SumServer interface {
SendAndClose(*Num) error
Recv() (*Num, error)
grpc.ServerStream
}
type mathSumServer struct {
grpc.ServerStream
}
func (x *mathSumServer) SendAndClose(m *Num) error {
if err := x.ServerStream.SendProto(m); err != nil {
return err
}
return nil
}
func (x *mathSumServer) Recv() (*Num, error) {
m := new(Num)
if err := x.ServerStream.RecvProto(m); err != nil {
return nil, err
}
return m, nil
}
var _Math_serviceDesc = grpc.ServiceDesc{
ServiceName: "proto.Math",
HandlerType: (*MathServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "Div",
Handler: _Math_Div_Handler,
},
},
Streams: []grpc.StreamDesc{
{
StreamName: "DivMany",
Handler: _Math_DivMany_Handler,
},
{
StreamName: "Fib",
Handler: _Math_Fib_Handler,
},
{
StreamName: "Sum",
Handler: _Math_Sum_Handler,
},
},
}