Skip to content

Commit 4fd8a8e

Browse files
committed
Minor docs
1 parent 4fea12b commit 4fd8a8e

File tree

9 files changed

+73
-90
lines changed

9 files changed

+73
-90
lines changed

vertx-grpc-docs/src/main/java/examples/GrpcServerExamples.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void requestResponse(GrpcServer server) {
5050

5151
public void streamingRequest(GrpcServer server) {
5252

53-
server.callHandler(StreamingGrpcService.Sink, request -> {
53+
server.callHandler(StreamingGrpcService.Proto.Sink, request -> {
5454
request.handler(item -> {
5555
// Process item
5656
});
@@ -256,7 +256,7 @@ public void messageLevelAPI(GrpcServer server) {
256256
}
257257

258258
public void unaryStub1(GrpcServer server) {
259-
GreeterService stub = new GreeterService() {
259+
GreeterService service = new GreeterService() {
260260
@Override
261261
public Future<HelloReply> sayHello(HelloRequest request) {
262262
return Future.succeededFuture(HelloReply.newBuilder().setMessage("Hello " + request.getName()).build());
@@ -265,24 +265,24 @@ public Future<HelloReply> sayHello(HelloRequest request) {
265265
}
266266

267267
public void unaryStub2(GrpcServer server) {
268-
GreeterService stub = new GreeterService() {
268+
GreeterService service = new GreeterService() {
269269
@Override
270270
public void sayHello(HelloRequest request, Completable<HelloReply> response) {
271271
response.succeed(HelloReply.newBuilder().setMessage("Hello " + request.getName()).build());
272272
}
273273
};
274274
}
275275

276-
public void unaryStub3(GreeterGrpcService stub, GrpcServer server) {
277-
server.addService(stub);
276+
public void unaryStub3(GreeterGrpcService service, GrpcServer server) {
277+
server.addService(service);
278278
}
279279

280-
public void unaryStub4(GreeterGrpcService stub, GrpcServer server) {
281-
server.addService(GreeterGrpcService.of(stub));
280+
public void unaryStub4(GreeterService service, GrpcServer server) {
281+
server.addService(GreeterGrpcService.Proto.of(service));
282282
}
283283

284284
public void streamingRequestStub(GrpcServer server) {
285-
StreamingGrpcService stub = new StreamingGrpcService() {
285+
StreamingGrpcService service = new StreamingGrpcService() {
286286
@Override
287287
public void sink(ReadStream<Item> stream, Completable<Empty> response) {
288288
stream.handler(item -> {
@@ -292,15 +292,15 @@ public void sink(ReadStream<Item> stream, Completable<Empty> response) {
292292
stream.endHandler(v -> response.succeed(Empty.getDefaultInstance()));
293293
}
294294
};
295-
server.addService(stub);
295+
server.addService(service);
296296
}
297297

298298
private Future<ReadStream<Item>> streamOfItems() {
299299
throw new UnsupportedOperationException();
300300
}
301301

302302
public void streamingResponseStub1() {
303-
StreamingService stub = new StreamingService() {
303+
StreamingService service = new StreamingService() {
304304
@Override
305305
public Future<ReadStream<Item>> source(Empty request) {
306306
return streamOfItems();
@@ -309,7 +309,7 @@ public Future<ReadStream<Item>> source(Empty request) {
309309
}
310310

311311
public void streamingResponseStub2() {
312-
StreamingService stub = new StreamingService() {
312+
StreamingService service = new StreamingService() {
313313
@Override
314314
public void source(Empty request, WriteStream<Item> response) {
315315
response.write(Item.newBuilder().setValue("value-1").build());

vertx-grpc-docs/src/main/java/examples/grpc/GreeterGrpcService.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ public void bind(GrpcServer server) {
5757
builder(this).bind(all()).build().bind(server);
5858
}
5959

60+
/**
61+
* @return a service binding all methods of the given {@code service}
62+
*/
63+
public static Service of(GreeterService service) {
64+
return builder(service).bind(all()).build();
65+
}
66+
6067
/**
6168
* SayHello protobuf RPC server service method.
6269
*/
@@ -115,13 +122,6 @@ public static Service of(GreeterService service) {
115122
}
116123
}
117124

118-
/**
119-
* @return a service binding all methods of the given {@code service}
120-
*/
121-
public static Service of(GreeterService service) {
122-
return builder(service).bind(all()).build();
123-
}
124-
125125
/**
126126
* @return a free form builder that gives the opportunity to bind only certain methods of a service
127127
*/
@@ -219,13 +219,13 @@ private void handle_sayHello(io.vertx.grpc.server.GrpcServerRequest<examples.grp
219219
if (err == null) {
220220
request.response().end(res);
221221
} else {
222-
request.response().status(GrpcStatus.INTERNAL).end();
222+
request.response().status(GrpcStatus.UNKNOWN).end();
223223
}
224224
});
225225
} catch (UnsupportedOperationException err) {
226226
request.response().status(GrpcStatus.UNIMPLEMENTED).end();
227227
} catch (RuntimeException err) {
228-
request.response().status(GrpcStatus.INTERNAL).end();
228+
request.response().status(GrpcStatus.UNKNOWN).end();
229229
}
230230
});
231231
}

vertx-grpc-docs/src/main/java/examples/grpc/StreamingGrpcService.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ public void bind(GrpcServer server) {
5959
builder(this).bind(all()).build().bind(server);
6060
}
6161

62+
/**
63+
* @return a service binding all methods of the given {@code service}
64+
*/
65+
public static Service of(StreamingService service) {
66+
return builder(service).bind(all()).build();
67+
}
68+
6269
/**
6370
* Source protobuf RPC server service method.
6471
*/
@@ -118,13 +125,6 @@ public static Service of(StreamingService service) {
118125
}
119126
}
120127

121-
/**
122-
* @return a service binding all methods of the given {@code service}
123-
*/
124-
public static Service of(StreamingService service) {
125-
return builder(service).bind(all()).build();
126-
}
127-
128128
/**
129129
* @return a free form builder that gives the opportunity to bind only certain methods of a service
130130
*/
@@ -232,7 +232,7 @@ private void handle_source(io.vertx.grpc.server.GrpcServerRequest<examples.grpc.
232232
} catch (UnsupportedOperationException e) {
233233
request.response().status(GrpcStatus.UNIMPLEMENTED).end();
234234
} catch (RuntimeException err) {
235-
request.response().status(GrpcStatus.INTERNAL).end();
235+
request.response().status(GrpcStatus.UNKNOWN).end();
236236
}
237237
});
238238
}
@@ -243,13 +243,13 @@ private void handle_sink(io.vertx.grpc.server.GrpcServerRequest<examples.grpc.It
243243
if (err == null) {
244244
request.response().end(res);
245245
} else {
246-
request.response().status(GrpcStatus.INTERNAL).end();
246+
request.response().status(GrpcStatus.UNKNOWN).end();
247247
}
248248
});
249249
} catch (UnsupportedOperationException err) {
250250
request.response().status(GrpcStatus.UNIMPLEMENTED).end();
251251
} catch (RuntimeException err) {
252-
request.response().status(GrpcStatus.INTERNAL).end();
252+
request.response().status(GrpcStatus.UNKNOWN).end();
253253
}
254254
}
255255

@@ -259,7 +259,7 @@ private void handle_pipe(io.vertx.grpc.server.GrpcServerRequest<examples.grpc.It
259259
} catch (UnsupportedOperationException err) {
260260
request.response().status(GrpcStatus.UNIMPLEMENTED).end();
261261
} catch (RuntimeException err) {
262-
request.response().status(GrpcStatus.INTERNAL).end();
262+
request.response().status(GrpcStatus.UNKNOWN).end();
263263
}
264264
}
265265
}

vertx-grpc-it/src/test/java/io/vertx/grpc/it/DeadlineTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030

3131
import java.util.concurrent.TimeUnit;
3232

33-
import static io.grpc.examples.helloworld.GreeterGrpcService.SayHello;
34-
3533
/**
3634
* @author <a href="mailto:[email protected]">Julien Viet</a>
3735
*/

vertx-grpc-it/src/test/java/io/vertx/grpc/it/ProtocPluginTest.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,12 @@
1010
*/
1111
package io.vertx.grpc.it;
1212

13-
import com.google.protobuf.ByteString;
1413
import io.grpc.examples.helloworld.*;
1514
import io.grpc.testing.integration.*;
16-
import io.vertx.core.Completable;
17-
import io.vertx.core.Future;
18-
import io.vertx.core.Promise;
19-
import io.vertx.core.http.HttpServer;
2015
import io.vertx.core.net.SocketAddress;
21-
import io.vertx.core.streams.ReadStream;
22-
import io.vertx.core.streams.WriteStream;
23-
import io.vertx.ext.unit.Async;
24-
import io.vertx.ext.unit.TestContext;
25-
import io.vertx.grpc.client.InvalidStatusException;
26-
import io.vertx.grpc.common.GrpcStatus;
2716
import io.vertx.grpc.server.GrpcServer;
2817
import io.vertx.grpc.client.GrpcClient;
2918
import io.vertx.grpc.server.Service;
30-
import org.junit.Test;
31-
32-
import java.nio.charset.StandardCharsets;
33-
import java.util.ArrayList;
34-
import java.util.List;
35-
import java.util.concurrent.TimeUnit;
3619

3720
public class ProtocPluginTest extends ProtocPluginTestBase {
3821

vertx-grpc-it/src/test/java/io/vertx/grpc/it/ProtocPluginTestBase.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void unaryCall(Messages.SimpleRequest request, Completable<Messages.Simpl
121121
public void testUnary_FutureReturn(TestContext should) throws Exception {
122122
// Create gRPC Server
123123
GrpcServer grpcServer = grpcServer();
124-
grpcServer.addService(TestServiceGrpcService.of(new TestServiceService() {
124+
grpcServer.addService(testService(new TestServiceService() {
125125
@Override
126126
public Future<Messages.SimpleResponse> unaryCall(Messages.SimpleRequest request) {
127127
return Future.succeededFuture(Messages.SimpleResponse.newBuilder()
@@ -152,7 +152,7 @@ public Future<Messages.SimpleResponse> unaryCall(Messages.SimpleRequest request)
152152
public void testUnary_FutureReturn_ErrorHandling(TestContext should) throws Exception {
153153
// Create gRPC Server
154154
GrpcServer grpcServer = grpcServer();
155-
grpcServer.addService(TestServiceGrpcService.of(new TestServiceService() {
155+
grpcServer.addService(testService(new TestServiceService() {
156156
@Override
157157
public Future<Messages.SimpleResponse> unaryCall(Messages.SimpleRequest request) {
158158
throw new RuntimeException("Simulated error");
@@ -173,7 +173,7 @@ public Future<Messages.SimpleResponse> unaryCall(Messages.SimpleRequest request)
173173
.onComplete(should.asyncAssertFailure(err -> {
174174
should.assertTrue(err instanceof InvalidStatusException);
175175
InvalidStatusException ise = (InvalidStatusException) err;
176-
should.assertEquals(GrpcStatus.INTERNAL, ise.actualStatus());
176+
should.assertEquals(GrpcStatus.UNKNOWN, ise.actualStatus());
177177
test.complete();
178178
}));
179179
test.awaitSuccess();
@@ -183,7 +183,7 @@ public Future<Messages.SimpleResponse> unaryCall(Messages.SimpleRequest request)
183183
public void testManyUnary_PromiseArg(TestContext should) throws Exception {
184184
// Create gRPC Server
185185
GrpcServer grpcServer = grpcServer();
186-
grpcServer.addService(TestServiceGrpcService.of(new TestServiceService() {
186+
grpcServer.addService(testService(new TestServiceService() {
187187
@Override
188188
public void streamingInputCall(ReadStream<Messages.StreamingInputCallRequest> request, Completable<Messages.StreamingInputCallResponse> response) {
189189
List<Messages.StreamingInputCallRequest> list = new ArrayList<>();
@@ -225,7 +225,7 @@ public void streamingInputCall(ReadStream<Messages.StreamingInputCallRequest> re
225225
public void testManyUnary_FutureReturn(TestContext should) throws Exception {
226226
// Create gRPC Server
227227
GrpcServer grpcServer = grpcServer();
228-
grpcServer.addService(TestServiceGrpcService.of(new TestServiceService() {
228+
grpcServer.addService(testService(new TestServiceService() {
229229
@Override
230230
public Future<Messages.StreamingInputCallResponse> streamingInputCall(ReadStream<Messages.StreamingInputCallRequest> request) {
231231
Promise<Messages.StreamingInputCallResponse> promise = Promise.promise();
@@ -269,7 +269,7 @@ public Future<Messages.StreamingInputCallResponse> streamingInputCall(ReadStream
269269
public void testManyUnary_FutureReturn_ErrorHandling(TestContext should) throws Exception {
270270
// Create gRPC Server
271271
GrpcServer grpcServer = grpcServer();
272-
grpcServer.addService(TestServiceGrpcService.of(new TestServiceService() {
272+
grpcServer.addService(testService(new TestServiceService() {
273273
@Override
274274
public Future<Messages.StreamingInputCallResponse> streamingInputCall(ReadStream<Messages.StreamingInputCallRequest> request) {
275275
throw new RuntimeException("Simulated error");
@@ -296,7 +296,7 @@ public Future<Messages.StreamingInputCallResponse> streamingInputCall(ReadStream
296296
.onComplete(should.asyncAssertFailure(err -> {
297297
should.assertTrue(err instanceof InvalidStatusException);
298298
InvalidStatusException ise = (InvalidStatusException) err;
299-
should.assertEquals(GrpcStatus.INTERNAL, ise.actualStatus());
299+
should.assertEquals(GrpcStatus.UNKNOWN, ise.actualStatus());
300300
test.complete();
301301
}));
302302
test.awaitSuccess();
@@ -306,7 +306,7 @@ public Future<Messages.StreamingInputCallResponse> streamingInputCall(ReadStream
306306
public void testUnaryMany_WriteStreamArg(TestContext should) throws Exception {
307307
// Create gRPC Server
308308
GrpcServer grpcServer = grpcServer();
309-
grpcServer.addService(TestServiceGrpcService.of(new TestServiceService() {
309+
grpcServer.addService(testService(new TestServiceService() {
310310
@Override
311311
public void streamingOutputCall(Messages.StreamingOutputCallRequest request, WriteStream<Messages.StreamingOutputCallResponse> response) {
312312
response.write(Messages.StreamingOutputCallResponse.newBuilder()
@@ -347,7 +347,7 @@ public void streamingOutputCall(Messages.StreamingOutputCallRequest request, Wri
347347
public void testUnaryMany_ReadStreamReturn(TestContext should) throws Exception {
348348
// Create gRPC Server
349349
GrpcServer grpcServer = grpcServer();
350-
grpcServer.addService(TestServiceGrpcService.of(new TestServiceService() {
350+
grpcServer.addService(testService(new TestServiceService() {
351351
@Override
352352
protected void streamingOutputCall(Messages.StreamingOutputCallRequest request, WriteStream<Messages.StreamingOutputCallResponse> response) {
353353
response.write(Messages.StreamingOutputCallResponse.newBuilder()
@@ -388,7 +388,7 @@ protected void streamingOutputCall(Messages.StreamingOutputCallRequest request,
388388
public void testUnaryMany_ReadStreamReturn_ErrorHandling(TestContext should) throws Exception {
389389
// Create gRPC Server
390390
GrpcServer grpcServer = grpcServer();
391-
grpcServer.addService(TestServiceGrpcService.of(new TestServiceService() {
391+
grpcServer.addService(testService(new TestServiceService() {
392392
@Override
393393
protected void streamingOutputCall(Messages.StreamingOutputCallRequest request, WriteStream<Messages.StreamingOutputCallResponse> response) {
394394
throw new RuntimeException("Simulated error");
@@ -408,7 +408,7 @@ protected void streamingOutputCall(Messages.StreamingOutputCallRequest request,
408408
.build();
409409
client.streamingOutputCall(request)
410410
.onComplete(should.asyncAssertFailure(err -> {
411-
should.assertEquals("Invalid status: actual:INTERNAL, expected:OK", err.getMessage());
411+
should.assertEquals("Invalid status: actual:UNKNOWN, expected:OK", err.getMessage());
412412
test.complete();
413413
}));
414414
test.awaitSuccess();
@@ -418,7 +418,7 @@ protected void streamingOutputCall(Messages.StreamingOutputCallRequest request,
418418
public void testmanyMany_WriteStreamArg(TestContext should) throws Exception {
419419
// Create gRPC Server
420420
GrpcServer grpcServer = grpcServer();
421-
grpcServer.addService(TestServiceGrpcService.of(new TestServiceService() {
421+
grpcServer.addService(testService(new TestServiceService() {
422422
@Override
423423
public void fullDuplexCall(ReadStream<Messages.StreamingOutputCallRequest> request, WriteStream<Messages.StreamingOutputCallResponse> response) {
424424
request.endHandler($ -> {
@@ -466,7 +466,7 @@ public void fullDuplexCall(ReadStream<Messages.StreamingOutputCallRequest> reque
466466
public void testmanyMany_ReadStreamReturn(TestContext should) throws Exception {
467467
// Create gRPC Server
468468
GrpcServer grpcServer = grpcServer();
469-
grpcServer.addService(TestServiceGrpcService.of(new TestServiceService() {
469+
grpcServer.addService(testService(new TestServiceService() {
470470
@Override
471471
protected void fullDuplexCall(ReadStream<Messages.StreamingOutputCallRequest> request, WriteStream<Messages.StreamingOutputCallResponse> response) {
472472
request.endHandler($ -> {
@@ -514,7 +514,7 @@ protected void fullDuplexCall(ReadStream<Messages.StreamingOutputCallRequest> re
514514
public void testmanyMany_ReadStreamReturn_ErrorHandling(TestContext should) throws Exception {
515515
// Create gRPC Server
516516
GrpcServer grpcServer = grpcServer();
517-
grpcServer.addService(TestServiceGrpcService.of(new TestServiceService() {
517+
grpcServer.addService(testService(new TestServiceService() {
518518
@Override
519519
protected void fullDuplexCall(ReadStream<Messages.StreamingOutputCallRequest> request, WriteStream<Messages.StreamingOutputCallResponse> response) {
520520
throw new RuntimeException("Simulated error");
@@ -539,7 +539,7 @@ protected void fullDuplexCall(ReadStream<Messages.StreamingOutputCallRequest> re
539539
req.end();
540540
})
541541
.onComplete(should.asyncAssertFailure(err -> {
542-
should.assertEquals("Invalid status: actual:INTERNAL, expected:OK", err.getMessage());
542+
should.assertEquals("Invalid status: actual:UNKNOWN, expected:OK", err.getMessage());
543543
test.complete();
544544
}));
545545
test.awaitSuccess();

0 commit comments

Comments
 (0)