Skip to content

Commit d3ae124

Browse files
authored
cleanup: use different import alias for services than messages (#4148)
1 parent 4cf4a98 commit d3ae124

File tree

17 files changed

+149
-119
lines changed

17 files changed

+149
-119
lines changed

benchmark/benchmain/main.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ import (
6565
"google.golang.org/grpc/benchmark/stats"
6666
"google.golang.org/grpc/grpclog"
6767
"google.golang.org/grpc/internal/channelz"
68-
testpb "google.golang.org/grpc/interop/grpc_testing"
6968
"google.golang.org/grpc/keepalive"
7069
"google.golang.org/grpc/metadata"
7170
"google.golang.org/grpc/test/bufconn"
71+
72+
testgrpc "google.golang.org/grpc/interop/grpc_testing"
73+
testpb "google.golang.org/grpc/interop/grpc_testing"
7274
)
7375

7476
var (
@@ -259,7 +261,7 @@ func unconstrainedStreamBenchmark(start startFunc, stop ucStopFunc, bf stats.Fea
259261
// service. The client is configured using the different options in the passed
260262
// 'bf'. Also returns a cleanup function to close the client and release
261263
// resources.
262-
func makeClient(bf stats.Features) (testpb.BenchmarkServiceClient, func()) {
264+
func makeClient(bf stats.Features) (testgrpc.BenchmarkServiceClient, func()) {
263265
nw := &latency.Network{Kbps: bf.Kbps, Latency: bf.Latency, MTU: bf.MTU}
264266
opts := []grpc.DialOption{}
265267
sopts := []grpc.ServerOption{}
@@ -327,7 +329,7 @@ func makeClient(bf stats.Features) (testpb.BenchmarkServiceClient, func()) {
327329
lis = nw.Listener(lis)
328330
stopper := bm.StartServer(bm.ServerInfo{Type: "protobuf", Listener: lis}, sopts...)
329331
conn := bm.NewClientConn("" /* target not used */, opts...)
330-
return testpb.NewBenchmarkServiceClient(conn), func() {
332+
return testgrpc.NewBenchmarkServiceClient(conn), func() {
331333
conn.Close()
332334
stopper()
333335
}
@@ -351,7 +353,7 @@ func makeFuncUnary(bf stats.Features) (rpcCallFunc, rpcCleanupFunc) {
351353
func makeFuncStream(bf stats.Features) (rpcCallFunc, rpcCleanupFunc) {
352354
tc, cleanup := makeClient(bf)
353355

354-
streams := make([]testpb.BenchmarkService_StreamingCallClient, bf.MaxConcurrentCalls)
356+
streams := make([]testgrpc.BenchmarkService_StreamingCallClient, bf.MaxConcurrentCalls)
355357
for i := 0; i < bf.MaxConcurrentCalls; i++ {
356358
stream, err := tc.StreamingCall(context.Background())
357359
if err != nil {
@@ -402,10 +404,10 @@ func makeFuncUnconstrainedStream(bf stats.Features) (rpcSendFunc, rpcRecvFunc, r
402404
}, cleanup
403405
}
404406

405-
func setupUnconstrainedStream(bf stats.Features) ([]testpb.BenchmarkService_StreamingCallClient, *testpb.SimpleRequest, rpcCleanupFunc) {
407+
func setupUnconstrainedStream(bf stats.Features) ([]testgrpc.BenchmarkService_StreamingCallClient, *testpb.SimpleRequest, rpcCleanupFunc) {
406408
tc, cleanup := makeClient(bf)
407409

408-
streams := make([]testpb.BenchmarkService_StreamingCallClient, bf.MaxConcurrentCalls)
410+
streams := make([]testgrpc.BenchmarkService_StreamingCallClient, bf.MaxConcurrentCalls)
409411
md := metadata.Pairs(benchmark.UnconstrainedStreamingHeader, "1")
410412
ctx := metadata.NewOutgoingContext(context.Background(), md)
411413
for i := 0; i < bf.MaxConcurrentCalls; i++ {
@@ -428,13 +430,13 @@ func setupUnconstrainedStream(bf stats.Features) ([]testpb.BenchmarkService_Stre
428430

429431
// Makes a UnaryCall gRPC request using the given BenchmarkServiceClient and
430432
// request and response sizes.
431-
func unaryCaller(client testpb.BenchmarkServiceClient, reqSize, respSize int) {
433+
func unaryCaller(client testgrpc.BenchmarkServiceClient, reqSize, respSize int) {
432434
if err := bm.DoUnaryCall(client, reqSize, respSize); err != nil {
433435
logger.Fatalf("DoUnaryCall failed: %v", err)
434436
}
435437
}
436438

437-
func streamCaller(stream testpb.BenchmarkService_StreamingCallClient, reqSize, respSize int) {
439+
func streamCaller(stream testgrpc.BenchmarkService_StreamingCallClient, reqSize, respSize int) {
438440
if err := bm.DoStreamingRoundTrip(stream, reqSize, respSize); err != nil {
439441
logger.Fatalf("DoStreamingRoundTrip failed: %v", err)
440442
}

benchmark/benchmark.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ import (
3131
"google.golang.org/grpc"
3232
"google.golang.org/grpc/codes"
3333
"google.golang.org/grpc/grpclog"
34-
testpb "google.golang.org/grpc/interop/grpc_testing"
3534
"google.golang.org/grpc/metadata"
3635
"google.golang.org/grpc/status"
36+
37+
testgrpc "google.golang.org/grpc/interop/grpc_testing"
38+
testpb "google.golang.org/grpc/interop/grpc_testing"
3739
)
3840

3941
var logger = grpclog.Component("benchmark")
@@ -61,7 +63,7 @@ func NewPayload(t testpb.PayloadType, size int) *testpb.Payload {
6163
}
6264

6365
type testServer struct {
64-
testpb.UnimplementedBenchmarkServiceServer
66+
testgrpc.UnimplementedBenchmarkServiceServer
6567
}
6668

6769
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) (*
7577
// of ping-pong.
7678
const UnconstrainedStreamingHeader = "unconstrained-streaming"
7779

78-
func (s *testServer) StreamingCall(stream testpb.BenchmarkService_StreamingCallServer) error {
80+
func (s *testServer) StreamingCall(stream testgrpc.BenchmarkService_StreamingCallServer) error {
7981
if md, ok := metadata.FromIncomingContext(stream.Context()); ok && len(md[UnconstrainedStreamingHeader]) != 0 {
8082
return s.UnconstrainedStreamingCall(stream)
8183
}
@@ -100,7 +102,7 @@ func (s *testServer) StreamingCall(stream testpb.BenchmarkService_StreamingCallS
100102
}
101103
}
102104

103-
func (s *testServer) UnconstrainedStreamingCall(stream testpb.BenchmarkService_StreamingCallServer) error {
105+
func (s *testServer) UnconstrainedStreamingCall(stream testgrpc.BenchmarkService_StreamingCallServer) error {
104106
in := new(testpb.SimpleRequest)
105107
// Receive a message to learn response type and size.
106108
err := stream.RecvMsg(in)
@@ -151,7 +153,7 @@ func (s *testServer) UnconstrainedStreamingCall(stream testpb.BenchmarkService_S
151153
// byteBufServer is a gRPC server that sends and receives byte buffer.
152154
// The purpose is to benchmark the gRPC performance without protobuf serialization/deserialization overhead.
153155
type byteBufServer struct {
154-
testpb.UnimplementedBenchmarkServiceServer
156+
testgrpc.UnimplementedBenchmarkServiceServer
155157
respSize int32
156158
}
157159

@@ -161,7 +163,7 @@ func (s *byteBufServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest)
161163
return &testpb.SimpleResponse{}, nil
162164
}
163165

164-
func (s *byteBufServer) StreamingCall(stream testpb.BenchmarkService_StreamingCallServer) error {
166+
func (s *byteBufServer) StreamingCall(stream testgrpc.BenchmarkService_StreamingCallServer) error {
165167
for {
166168
var in []byte
167169
err := stream.(grpc.ServerStream).RecvMsg(&in)
@@ -201,13 +203,13 @@ func StartServer(info ServerInfo, opts ...grpc.ServerOption) func() {
201203
s := grpc.NewServer(opts...)
202204
switch info.Type {
203205
case "protobuf":
204-
testpb.RegisterBenchmarkServiceServer(s, &testServer{})
206+
testgrpc.RegisterBenchmarkServiceServer(s, &testServer{})
205207
case "bytebuf":
206208
respSize, ok := info.Metadata.(int32)
207209
if !ok {
208210
logger.Fatalf("failed to StartServer, invalid metadata: %v, for Type: %v", info.Metadata, info.Type)
209211
}
210-
testpb.RegisterBenchmarkServiceServer(s, &byteBufServer{respSize: respSize})
212+
testgrpc.RegisterBenchmarkServiceServer(s, &byteBufServer{respSize: respSize})
211213
default:
212214
logger.Fatalf("failed to StartServer, unknown Type: %v", info.Type)
213215
}
@@ -218,7 +220,7 @@ func StartServer(info ServerInfo, opts ...grpc.ServerOption) func() {
218220
}
219221

220222
// 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 {
222224
pl := NewPayload(testpb.PayloadType_COMPRESSABLE, reqSize)
223225
req := &testpb.SimpleRequest{
224226
ResponseType: pl.Type,
@@ -232,7 +234,7 @@ func DoUnaryCall(tc testpb.BenchmarkServiceClient, reqSize, respSize int) error
232234
}
233235

234236
// 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 {
236238
pl := NewPayload(testpb.PayloadType_COMPRESSABLE, reqSize)
237239
req := &testpb.SimpleRequest{
238240
ResponseType: pl.Type,
@@ -253,7 +255,7 @@ func DoStreamingRoundTrip(stream testpb.BenchmarkService_StreamingCallClient, re
253255
}
254256

255257
// 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 {
257259
out := make([]byte, reqSize)
258260
if err := stream.(grpc.ClientStream).SendMsg(&out); err != nil {
259261
return fmt.Errorf("/BenchmarkService/StreamingCall.(ClientStream).SendMsg(_) = %v, want <nil>", err)

benchmark/client/main.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ import (
5353
"google.golang.org/grpc/benchmark/stats"
5454
"google.golang.org/grpc/grpclog"
5555
"google.golang.org/grpc/internal/syscall"
56+
57+
testgrpc "google.golang.org/grpc/interop/grpc_testing"
5658
testpb "google.golang.org/grpc/interop/grpc_testing"
5759
)
5860

@@ -164,7 +166,7 @@ func runWithConn(cc *grpc.ClientConn, req *testpb.SimpleRequest, warmDeadline, e
164166
}
165167

166168
func makeCaller(cc *grpc.ClientConn, req *testpb.SimpleRequest) func() {
167-
client := testpb.NewBenchmarkServiceClient(cc)
169+
client := testgrpc.NewBenchmarkServiceClient(cc)
168170
if *rpcType == "unary" {
169171
return func() {
170172
if _, err := client.UnaryCall(context.Background(), req); err != nil {

benchmark/worker/benchmark_client.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ import (
3232
"google.golang.org/grpc/codes"
3333
"google.golang.org/grpc/credentials"
3434
"google.golang.org/grpc/internal/syscall"
35-
testpb "google.golang.org/grpc/interop/grpc_testing"
3635
"google.golang.org/grpc/status"
3736
"google.golang.org/grpc/testdata"
37+
38+
testgrpc "google.golang.org/grpc/interop/grpc_testing"
39+
testpb "google.golang.org/grpc/interop/grpc_testing"
3840
)
3941

4042
var caFile = flag.String("ca_file", "", "The file containing the CA root cert file")
@@ -243,7 +245,7 @@ func startBenchmarkClient(config *testpb.ClientConfig) (*benchmarkClient, error)
243245

244246
func (bc *benchmarkClient) doCloseLoopUnary(conns []*grpc.ClientConn, rpcCountPerConn int, reqSize int, respSize int) {
245247
for ic, conn := range conns {
246-
client := testpb.NewBenchmarkServiceClient(conn)
248+
client := testgrpc.NewBenchmarkServiceClient(conn)
247249
// For each connection, create rpcCountPerConn goroutines to do rpc.
248250
for j := 0; j < rpcCountPerConn; j++ {
249251
// Create histogram for each goroutine.
@@ -285,7 +287,7 @@ func (bc *benchmarkClient) doCloseLoopUnary(conns []*grpc.ClientConn, rpcCountPe
285287
}
286288

287289
func (bc *benchmarkClient) doCloseLoopStreaming(conns []*grpc.ClientConn, rpcCountPerConn int, reqSize int, respSize int, payloadType string) {
288-
var doRPC func(testpb.BenchmarkService_StreamingCallClient, int, int) error
290+
var doRPC func(testgrpc.BenchmarkService_StreamingCallClient, int, int) error
289291
if payloadType == "bytebuf" {
290292
doRPC = benchmark.DoByteBufStreamingRoundTrip
291293
} else {
@@ -294,7 +296,7 @@ func (bc *benchmarkClient) doCloseLoopStreaming(conns []*grpc.ClientConn, rpcCou
294296
for ic, conn := range conns {
295297
// For each connection, create rpcCountPerConn goroutines to do rpc.
296298
for j := 0; j < rpcCountPerConn; j++ {
297-
c := testpb.NewBenchmarkServiceClient(conn)
299+
c := testgrpc.NewBenchmarkServiceClient(conn)
298300
stream, err := c.StreamingCall(context.Background())
299301
if err != nil {
300302
logger.Fatalf("%v.StreamingCall(_) = _, %v", c, err)

benchmark/worker/main.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ import (
3535
"google.golang.org/grpc"
3636
"google.golang.org/grpc/codes"
3737
"google.golang.org/grpc/grpclog"
38-
testpb "google.golang.org/grpc/interop/grpc_testing"
3938
"google.golang.org/grpc/status"
39+
40+
testgrpc "google.golang.org/grpc/interop/grpc_testing"
41+
testpb "google.golang.org/grpc/interop/grpc_testing"
4042
)
4143

4244
var (
@@ -75,12 +77,12 @@ func (byteBufCodec) String() string {
7577
// workerServer implements WorkerService rpc handlers.
7678
// It can create benchmarkServer or benchmarkClient on demand.
7779
type workerServer struct {
78-
testpb.UnimplementedWorkerServiceServer
80+
testgrpc.UnimplementedWorkerServiceServer
7981
stop chan<- bool
8082
serverPort int
8183
}
8284

83-
func (s *workerServer) RunServer(stream testpb.WorkerService_RunServerServer) error {
85+
func (s *workerServer) RunServer(stream testgrpc.WorkerService_RunServerServer) error {
8486
var bs *benchmarkServer
8587
defer func() {
8688
// Close benchmark server when stream ends.
@@ -135,7 +137,7 @@ func (s *workerServer) RunServer(stream testpb.WorkerService_RunServerServer) er
135137
}
136138
}
137139

138-
func (s *workerServer) RunClient(stream testpb.WorkerService_RunClientServer) error {
140+
func (s *workerServer) RunClient(stream testgrpc.WorkerService_RunClientServer) error {
139141
var bc *benchmarkClient
140142
defer func() {
141143
// Shut down benchmark client when stream ends.
@@ -209,7 +211,7 @@ func main() {
209211

210212
s := grpc.NewServer()
211213
stop := make(chan bool)
212-
testpb.RegisterWorkerServiceServer(s, &workerServer{
214+
testgrpc.RegisterWorkerServiceServer(s, &workerServer{
213215
stop: stop,
214216
serverPort: *serverPort,
215217
})

binarylog/binarylog_end2end_test.go

+15-13
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ import (
3131
"github.com/golang/protobuf/proto"
3232
"google.golang.org/grpc"
3333
"google.golang.org/grpc/binarylog"
34-
pb "google.golang.org/grpc/binarylog/grpc_binarylog_v1"
3534
"google.golang.org/grpc/grpclog"
3635
iblog "google.golang.org/grpc/internal/binarylog"
3736
"google.golang.org/grpc/internal/grpctest"
38-
testpb "google.golang.org/grpc/interop/grpc_testing"
3937
"google.golang.org/grpc/metadata"
4038
"google.golang.org/grpc/status"
39+
40+
pb "google.golang.org/grpc/binarylog/grpc_binarylog_v1"
41+
testgrpc "google.golang.org/grpc/interop/grpc_testing"
42+
testpb "google.golang.org/grpc/interop/grpc_testing"
4143
)
4244

4345
var grpclogLogger = grpclog.Component("binarylog")
@@ -126,7 +128,7 @@ func payloadToID(p *testpb.Payload) int32 {
126128
}
127129

128130
type testServer struct {
129-
testpb.UnimplementedTestServiceServer
131+
testgrpc.UnimplementedTestServiceServer
130132
te *test
131133
}
132134

@@ -148,7 +150,7 @@ func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*
148150
return &testpb.SimpleResponse{Payload: in.Payload}, nil
149151
}
150152

151-
func (s *testServer) FullDuplexCall(stream testpb.TestService_FullDuplexCallServer) error {
153+
func (s *testServer) FullDuplexCall(stream testgrpc.TestService_FullDuplexCallServer) error {
152154
md, ok := metadata.FromIncomingContext(stream.Context())
153155
if ok {
154156
if err := stream.SendHeader(md); err != nil {
@@ -176,7 +178,7 @@ func (s *testServer) FullDuplexCall(stream testpb.TestService_FullDuplexCallServ
176178
}
177179
}
178180

179-
func (s *testServer) StreamingInputCall(stream testpb.TestService_StreamingInputCallServer) error {
181+
func (s *testServer) StreamingInputCall(stream testgrpc.TestService_StreamingInputCallServer) error {
180182
md, ok := metadata.FromIncomingContext(stream.Context())
181183
if ok {
182184
if err := stream.SendHeader(md); err != nil {
@@ -200,7 +202,7 @@ func (s *testServer) StreamingInputCall(stream testpb.TestService_StreamingInput
200202
}
201203
}
202204

203-
func (s *testServer) StreamingOutputCall(in *testpb.StreamingOutputCallRequest, stream testpb.TestService_StreamingOutputCallServer) error {
205+
func (s *testServer) StreamingOutputCall(in *testpb.StreamingOutputCallRequest, stream testgrpc.TestService_StreamingOutputCallServer) error {
204206
md, ok := metadata.FromIncomingContext(stream.Context())
205207
if ok {
206208
if err := stream.SendHeader(md); err != nil {
@@ -227,7 +229,7 @@ func (s *testServer) StreamingOutputCall(in *testpb.StreamingOutputCallRequest,
227229
type test struct {
228230
t *testing.T
229231

230-
testService testpb.TestServiceServer // nil means none
232+
testService testgrpc.TestServiceServer // nil means none
231233
// srv and srvAddr are set once startServer is called.
232234
srv *grpc.Server
233235
srvAddr string // Server IP without port.
@@ -282,7 +284,7 @@ func (lw *listenerWrapper) Accept() (net.Conn, error) {
282284

283285
// startServer starts a gRPC server listening. Callers should defer a
284286
// call to te.tearDown to clean up.
285-
func (te *test) startServer(ts testpb.TestServiceServer) {
287+
func (te *test) startServer(ts testgrpc.TestServiceServer) {
286288
te.testService = ts
287289
lis, err := net.Listen("tcp", "localhost:0")
288290

@@ -298,7 +300,7 @@ func (te *test) startServer(ts testpb.TestServiceServer) {
298300
s := grpc.NewServer(opts...)
299301
te.srv = s
300302
if te.testService != nil {
301-
testpb.RegisterTestServiceServer(s, te.testService)
303+
testgrpc.RegisterTestServiceServer(s, te.testService)
302304
}
303305

304306
go s.Serve(lis)
@@ -343,7 +345,7 @@ func (te *test) doUnaryCall(c *rpcConfig) (*testpb.SimpleRequest, *testpb.Simple
343345
req *testpb.SimpleRequest
344346
err error
345347
)
346-
tc := testpb.NewTestServiceClient(te.clientConn())
348+
tc := testgrpc.NewTestServiceClient(te.clientConn())
347349
if c.success {
348350
req = &testpb.SimpleRequest{Payload: idToPayload(errorID + 1)}
349351
} else {
@@ -363,7 +365,7 @@ func (te *test) doFullDuplexCallRoundtrip(c *rpcConfig) ([]proto.Message, []prot
363365
resps []proto.Message
364366
err error
365367
)
366-
tc := testpb.NewTestServiceClient(te.clientConn())
368+
tc := testgrpc.NewTestServiceClient(te.clientConn())
367369
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
368370
defer cancel()
369371
ctx = metadata.NewOutgoingContext(ctx, testMetadata)
@@ -412,7 +414,7 @@ func (te *test) doClientStreamCall(c *rpcConfig) ([]proto.Message, proto.Message
412414
resp *testpb.StreamingInputCallResponse
413415
err error
414416
)
415-
tc := testpb.NewTestServiceClient(te.clientConn())
417+
tc := testgrpc.NewTestServiceClient(te.clientConn())
416418
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
417419
defer cancel()
418420
ctx = metadata.NewOutgoingContext(ctx, testMetadata)
@@ -445,7 +447,7 @@ func (te *test) doServerStreamCall(c *rpcConfig) (proto.Message, []proto.Message
445447
err error
446448
)
447449

448-
tc := testpb.NewTestServiceClient(te.clientConn())
450+
tc := testgrpc.NewTestServiceClient(te.clientConn())
449451
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
450452
defer cancel()
451453
ctx = metadata.NewOutgoingContext(ctx, testMetadata)

0 commit comments

Comments
 (0)