@@ -31,9 +31,11 @@ import (
31
31
"google.golang.org/grpc"
32
32
"google.golang.org/grpc/codes"
33
33
"google.golang.org/grpc/grpclog"
34
- testpb "google.golang.org/grpc/interop/grpc_testing"
35
34
"google.golang.org/grpc/metadata"
36
35
"google.golang.org/grpc/status"
36
+
37
+ testgrpc "google.golang.org/grpc/interop/grpc_testing"
38
+ testpb "google.golang.org/grpc/interop/grpc_testing"
37
39
)
38
40
39
41
var logger = grpclog .Component ("benchmark" )
@@ -61,7 +63,7 @@ func NewPayload(t testpb.PayloadType, size int) *testpb.Payload {
61
63
}
62
64
63
65
type testServer struct {
64
- testpb .UnimplementedBenchmarkServiceServer
66
+ testgrpc .UnimplementedBenchmarkServiceServer
65
67
}
66
68
67
69
func (s * testServer ) UnaryCall (ctx context.Context , in * testpb.SimpleRequest ) (* testpb.SimpleResponse , error ) {
@@ -75,7 +77,7 @@ func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*
75
77
// of ping-pong.
76
78
const UnconstrainedStreamingHeader = "unconstrained-streaming"
77
79
78
- func (s * testServer ) StreamingCall (stream testpb .BenchmarkService_StreamingCallServer ) error {
80
+ func (s * testServer ) StreamingCall (stream testgrpc .BenchmarkService_StreamingCallServer ) error {
79
81
if md , ok := metadata .FromIncomingContext (stream .Context ()); ok && len (md [UnconstrainedStreamingHeader ]) != 0 {
80
82
return s .UnconstrainedStreamingCall (stream )
81
83
}
@@ -100,7 +102,7 @@ func (s *testServer) StreamingCall(stream testpb.BenchmarkService_StreamingCallS
100
102
}
101
103
}
102
104
103
- func (s * testServer ) UnconstrainedStreamingCall (stream testpb .BenchmarkService_StreamingCallServer ) error {
105
+ func (s * testServer ) UnconstrainedStreamingCall (stream testgrpc .BenchmarkService_StreamingCallServer ) error {
104
106
in := new (testpb.SimpleRequest )
105
107
// Receive a message to learn response type and size.
106
108
err := stream .RecvMsg (in )
@@ -151,7 +153,7 @@ func (s *testServer) UnconstrainedStreamingCall(stream testpb.BenchmarkService_S
151
153
// byteBufServer is a gRPC server that sends and receives byte buffer.
152
154
// The purpose is to benchmark the gRPC performance without protobuf serialization/deserialization overhead.
153
155
type byteBufServer struct {
154
- testpb .UnimplementedBenchmarkServiceServer
156
+ testgrpc .UnimplementedBenchmarkServiceServer
155
157
respSize int32
156
158
}
157
159
@@ -161,7 +163,7 @@ func (s *byteBufServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest)
161
163
return & testpb.SimpleResponse {}, nil
162
164
}
163
165
164
- func (s * byteBufServer ) StreamingCall (stream testpb .BenchmarkService_StreamingCallServer ) error {
166
+ func (s * byteBufServer ) StreamingCall (stream testgrpc .BenchmarkService_StreamingCallServer ) error {
165
167
for {
166
168
var in []byte
167
169
err := stream .(grpc.ServerStream ).RecvMsg (& in )
@@ -201,13 +203,13 @@ func StartServer(info ServerInfo, opts ...grpc.ServerOption) func() {
201
203
s := grpc .NewServer (opts ... )
202
204
switch info .Type {
203
205
case "protobuf" :
204
- testpb .RegisterBenchmarkServiceServer (s , & testServer {})
206
+ testgrpc .RegisterBenchmarkServiceServer (s , & testServer {})
205
207
case "bytebuf" :
206
208
respSize , ok := info .Metadata .(int32 )
207
209
if ! ok {
208
210
logger .Fatalf ("failed to StartServer, invalid metadata: %v, for Type: %v" , info .Metadata , info .Type )
209
211
}
210
- testpb .RegisterBenchmarkServiceServer (s , & byteBufServer {respSize : respSize })
212
+ testgrpc .RegisterBenchmarkServiceServer (s , & byteBufServer {respSize : respSize })
211
213
default :
212
214
logger .Fatalf ("failed to StartServer, unknown Type: %v" , info .Type )
213
215
}
@@ -218,7 +220,7 @@ func StartServer(info ServerInfo, opts ...grpc.ServerOption) func() {
218
220
}
219
221
220
222
// DoUnaryCall performs an unary RPC with given stub and request and response sizes.
221
- func DoUnaryCall (tc testpb .BenchmarkServiceClient , reqSize , respSize int ) error {
223
+ func DoUnaryCall (tc testgrpc .BenchmarkServiceClient , reqSize , respSize int ) error {
222
224
pl := NewPayload (testpb .PayloadType_COMPRESSABLE , reqSize )
223
225
req := & testpb.SimpleRequest {
224
226
ResponseType : pl .Type ,
@@ -232,7 +234,7 @@ func DoUnaryCall(tc testpb.BenchmarkServiceClient, reqSize, respSize int) error
232
234
}
233
235
234
236
// DoStreamingRoundTrip performs a round trip for a single streaming rpc.
235
- func DoStreamingRoundTrip (stream testpb .BenchmarkService_StreamingCallClient , reqSize , respSize int ) error {
237
+ func DoStreamingRoundTrip (stream testgrpc .BenchmarkService_StreamingCallClient , reqSize , respSize int ) error {
236
238
pl := NewPayload (testpb .PayloadType_COMPRESSABLE , reqSize )
237
239
req := & testpb.SimpleRequest {
238
240
ResponseType : pl .Type ,
@@ -253,7 +255,7 @@ func DoStreamingRoundTrip(stream testpb.BenchmarkService_StreamingCallClient, re
253
255
}
254
256
255
257
// DoByteBufStreamingRoundTrip performs a round trip for a single streaming rpc, using a custom codec for byte buffer.
256
- func DoByteBufStreamingRoundTrip (stream testpb .BenchmarkService_StreamingCallClient , reqSize , respSize int ) error {
258
+ func DoByteBufStreamingRoundTrip (stream testgrpc .BenchmarkService_StreamingCallClient , reqSize , respSize int ) error {
257
259
out := make ([]byte , reqSize )
258
260
if err := stream .(grpc.ClientStream ).SendMsg (& out ); err != nil {
259
261
return fmt .Errorf ("/BenchmarkService/StreamingCall.(ClientStream).SendMsg(_) = %v, want <nil>" , err )
0 commit comments