diff --git a/docs/src/main/paradox/server/details.md b/docs/src/main/paradox/server/details.md index f3f47342..1863efae 100644 --- a/docs/src/main/paradox/server/details.md +++ b/docs/src/main/paradox/server/details.md @@ -16,10 +16,10 @@ generated client stubs. Here's an example implementation of these server power APIs: Scala -: @@snip [GreeterServicePowerApiImpl.scala](/plugin-tester-scala/src/main/scala/example/myapp/helloworld/PowerGreeterServiceImpl.scala) { #full-service-impl } +: @@snip [PowerGreeterServiceImpl.scala](/plugin-tester-scala/src/main/scala/example/myapp/helloworld/PowerGreeterServiceImpl.scala) { #full-service-impl } Java -: @@snip [GreeterServicePowerApiImpl.java](/plugin-tester-java/src/main/java/example/myapp/helloworld/GreeterServicePowerApiImpl.java) { #full-service-impl } +: @@snip [PowerGreeterServiceImpl.java](/plugin-tester-java/src/main/java/example/myapp/helloworld/PowerGreeterServiceImpl.java) { #full-service-impl } ## Status codes diff --git a/interop-tests/src/main/java/io/grpc/testing/integration2/TestServiceClient.java b/interop-tests/src/main/java/io/grpc/testing/integration2/TestServiceClient.java index 3b0df682..9fa4d337 100644 --- a/interop-tests/src/main/java/io/grpc/testing/integration2/TestServiceClient.java +++ b/interop-tests/src/main/java/io/grpc/testing/integration2/TestServiceClient.java @@ -156,7 +156,7 @@ private void runTest(TestCases testCase, Settings settings) throws Exception { String jsonKey = Files.asCharSource(new File(settings.getServiceAccountKeyFile()), UTF_8).read(); FileInputStream credentialsStream = - new FileInputStream(new File(settings.getServiceAccountKeyFile())); + new FileInputStream(settings.getServiceAccountKeyFile()); clientTester.serviceAccountCreds(jsonKey, credentialsStream, settings.getOauthScope()); break; } @@ -164,7 +164,7 @@ private void runTest(TestCases testCase, Settings settings) throws Exception { case JWT_TOKEN_CREDS: { FileInputStream credentialsStream = - new FileInputStream(new File(settings.getServiceAccountKeyFile())); + new FileInputStream(settings.getServiceAccountKeyFile()); clientTester.jwtTokenCreds(credentialsStream); break; } @@ -174,7 +174,7 @@ private void runTest(TestCases testCase, Settings settings) throws Exception { String jsonKey = Files.asCharSource(new File(settings.getServiceAccountKeyFile()), UTF_8).read(); FileInputStream credentialsStream = - new FileInputStream(new File(settings.getServiceAccountKeyFile())); + new FileInputStream(settings.getServiceAccountKeyFile()); clientTester.oauth2AuthToken(jsonKey, credentialsStream, settings.getOauthScope()); break; } @@ -184,7 +184,7 @@ private void runTest(TestCases testCase, Settings settings) throws Exception { String jsonKey = Files.asCharSource(new File(settings.getServiceAccountKeyFile()), UTF_8).read(); FileInputStream credentialsStream = - new FileInputStream(new File(settings.getServiceAccountKeyFile())); + new FileInputStream(settings.getServiceAccountKeyFile()); clientTester.perRpcCreds(jsonKey, credentialsStream, settings.getOauthScope()); break; } diff --git a/plugin-tester-java/src/main/java/example/myapp/CombinedServer.java b/plugin-tester-java/src/main/java/example/myapp/CombinedServer.java index 04b38df0..96d03d81 100644 --- a/plugin-tester-java/src/main/java/example/myapp/CombinedServer.java +++ b/plugin-tester-java/src/main/java/example/myapp/CombinedServer.java @@ -62,9 +62,7 @@ public static void main(String[] args) { .newServerAt("127.0.0.1", 8090) .bind(serviceHandlers) //#concatOrNotFound - .thenAccept(binding -> { - System.out.println("gRPC server bound to: " + binding.localAddress()); - }); + .thenAccept(binding -> System.out.println("gRPC server bound to: " + binding.localAddress())); //#grpc-web Function> grpcWebServiceHandlers = @@ -74,9 +72,7 @@ public static void main(String[] args) { .newServerAt("127.0.0.1", 8090) .bind(grpcWebServiceHandlers) //#grpc-web - .thenAccept(binding -> { - System.out.println("gRPC-Web server bound to: " + binding.localAddress()); - }); + .thenAccept(binding -> System.out.println("gRPC-Web server bound to: " + binding.localAddress())); } } diff --git a/plugin-tester-java/src/main/java/example/myapp/helloworld/GreeterClient.java b/plugin-tester-java/src/main/java/example/myapp/helloworld/GreeterClient.java index dc865dd8..e19f2394 100644 --- a/plugin-tester-java/src/main/java/example/myapp/helloworld/GreeterClient.java +++ b/plugin-tester-java/src/main/java/example/myapp/helloworld/GreeterClient.java @@ -17,25 +17,22 @@ import example.myapp.helloworld.grpc.*; import io.grpc.StatusRuntimeException; import java.time.Duration; -import java.util.Arrays; import java.util.List; import java.util.concurrent.CompletionStage; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.pekko.Done; import org.apache.pekko.NotUsed; import org.apache.pekko.actor.ActorSystem; import org.apache.pekko.grpc.GrpcClientSettings; +import org.apache.pekko.japi.Pair; import org.apache.pekko.stream.Materializer; import org.apache.pekko.stream.SystemMaterializer; import org.apache.pekko.stream.javadsl.Source; class GreeterClient { public static void main(String[] args) throws Exception { - - String serverHost = "127.0.0.1"; - int serverPort = 8090; - ActorSystem system = ActorSystem.create("HelloWorldClient"); Materializer materializer = SystemMaterializer.get(system).materializer(); @@ -73,7 +70,7 @@ private static void singleRequestReply(GreeterService client) throws Exception { private static void streamingRequest(GreeterService client) throws Exception { List requests = - Arrays.asList("Alice", "Bob", "Peter").stream() + Stream.of("Alice", "Bob", "Peter") .map(name -> HelloRequest.newBuilder().setName(name).build()) .collect(Collectors.toList()); CompletionStage reply = client.itKeepsTalking(Source.from(requests)); @@ -98,7 +95,7 @@ private static void streamingRequestReply(GreeterService client, Materializer ma Source requestStream = Source.tick(interval, interval, "tick") .zipWithIndex() - .map(pair -> pair.second()) + .map(Pair::second) .map(i -> HelloRequest.newBuilder().setName("Alice-" + i).build()) .take(10) .mapMaterializedValue(m -> NotUsed.getInstance()); diff --git a/plugin-tester-java/src/main/java/example/myapp/helloworld/GreeterServer.java b/plugin-tester-java/src/main/java/example/myapp/helloworld/GreeterServer.java index dffa16cd..9542b3e7 100644 --- a/plugin-tester-java/src/main/java/example/myapp/helloworld/GreeterServer.java +++ b/plugin-tester-java/src/main/java/example/myapp/helloworld/GreeterServer.java @@ -37,9 +37,7 @@ public static void main(String[] args) throws Exception { run(sys) .thenAccept( - binding -> { - System.out.println("gRPC server bound to: " + binding.localAddress()); - }); + binding -> System.out.println("gRPC server bound to: " + binding.localAddress())); // ActorSystem threads will keep the app alive until `system.terminate()` is called } diff --git a/plugin-tester-java/src/main/java/example/myapp/helloworld/GreeterServiceImpl.java b/plugin-tester-java/src/main/java/example/myapp/helloworld/GreeterServiceImpl.java index b8fab657..adb6370b 100644 --- a/plugin-tester-java/src/main/java/example/myapp/helloworld/GreeterServiceImpl.java +++ b/plugin-tester-java/src/main/java/example/myapp/helloworld/GreeterServiceImpl.java @@ -46,12 +46,12 @@ public CompletionStage sayHello(HelloRequest in) { @Override public CompletionStage itKeepsTalking(Source in) { System.out.println("sayHello to in stream..."); - return in.runWith(Sink.seq(), mat) + return in.runWith(Sink.seq(), mat) .thenApply( elements -> { String elementsStr = elements.stream() - .map(elem -> elem.getName()) + .map(HelloRequest::getName) .collect(Collectors.toList()) .toString(); return HelloReply.newBuilder().setMessage("Hello, " + elementsStr).build(); @@ -64,10 +64,7 @@ public Source itKeepsReplying(HelloRequest in) { List characters = ("Hello, " + in.getName()).chars().mapToObj(c -> (char) c).collect(Collectors.toList()); return Source.from(characters) - .map( - character -> { - return HelloReply.newBuilder().setMessage(String.valueOf(character)).build(); - }); + .map(character -> HelloReply.newBuilder().setMessage(String.valueOf(character)).build()); } @Override diff --git a/plugin-tester-java/src/main/java/example/myapp/helloworld/LiftedGreeterClient.java b/plugin-tester-java/src/main/java/example/myapp/helloworld/LiftedGreeterClient.java index 2702d3a4..bac878bc 100644 --- a/plugin-tester-java/src/main/java/example/myapp/helloworld/LiftedGreeterClient.java +++ b/plugin-tester-java/src/main/java/example/myapp/helloworld/LiftedGreeterClient.java @@ -16,25 +16,22 @@ import example.myapp.helloworld.grpc.*; import io.grpc.StatusRuntimeException; import java.time.Duration; -import java.util.Arrays; import java.util.List; import java.util.concurrent.CompletionStage; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.pekko.Done; import org.apache.pekko.NotUsed; import org.apache.pekko.actor.ActorSystem; import org.apache.pekko.grpc.GrpcClientSettings; +import org.apache.pekko.japi.Pair; import org.apache.pekko.stream.Materializer; import org.apache.pekko.stream.SystemMaterializer; import org.apache.pekko.stream.javadsl.Source; class LiftedGreeterClient { public static void main(String[] args) throws Exception { - - String serverHost = "127.0.0.1"; - int serverPort = 8090; - ActorSystem system = ActorSystem.create("HelloWorldClient"); Materializer materializer = SystemMaterializer.get(system).materializer(); @@ -68,7 +65,7 @@ private static void singleRequestReply(GreeterServiceClient client) throws Excep private static void streamingRequest(GreeterServiceClient client) throws Exception { List requests = - Arrays.asList("Alice", "Bob", "Peter").stream() + Stream.of("Alice", "Bob", "Peter") .map(name -> HelloRequest.newBuilder().setName(name).build()) .collect(Collectors.toList()); CompletionStage reply = @@ -96,7 +93,7 @@ private static void streamingRequestReply(GreeterServiceClient client, Materiali Source requestStream = Source.tick(interval, interval, "tick") .zipWithIndex() - .map(pair -> pair.second()) + .map(Pair::second) .map(i -> HelloRequest.newBuilder().setName("Alice-" + i).build()) .take(10) .mapMaterializedValue(m -> NotUsed.getInstance()); diff --git a/plugin-tester-java/src/main/java/example/myapp/helloworld/LoggingErrorHandlingGreeterServer.java b/plugin-tester-java/src/main/java/example/myapp/helloworld/LoggingErrorHandlingGreeterServer.java index 8ccf02de..2b914c76 100644 --- a/plugin-tester-java/src/main/java/example/myapp/helloworld/LoggingErrorHandlingGreeterServer.java +++ b/plugin-tester-java/src/main/java/example/myapp/helloworld/LoggingErrorHandlingGreeterServer.java @@ -50,9 +50,7 @@ public static void main(String[] args) throws Exception { run(sys) .thenAccept( - binding -> { - System.out.println("gRPC server bound to: " + binding.localAddress()); - }); + binding -> System.out.println("gRPC server bound to: " + binding.localAddress())); // ActorSystem threads will keep the app alive until `system.terminate()` is called } diff --git a/plugin-tester-java/src/main/java/example/myapp/helloworld/PowerGreeterServer.java b/plugin-tester-java/src/main/java/example/myapp/helloworld/PowerGreeterServer.java index a588f5fe..6570bec0 100644 --- a/plugin-tester-java/src/main/java/example/myapp/helloworld/PowerGreeterServer.java +++ b/plugin-tester-java/src/main/java/example/myapp/helloworld/PowerGreeterServer.java @@ -37,9 +37,7 @@ public static void main(String[] args) throws Exception { run(sys) .thenAccept( - binding -> { - System.out.println("gRPC server bound to: " + binding.localAddress()); - }); + binding -> System.out.println("gRPC server bound to: " + binding.localAddress())); // ActorSystem threads will keep the app alive until `system.terminate()` is called } @@ -48,7 +46,7 @@ public static CompletionStage run(ActorSystem sys) throws Excepti Materializer mat = SystemMaterializer.get(sys).materializer(); // Instantiate implementation - GreeterServicePowerApi impl = new GreeterServicePowerApiImpl(mat); + GreeterServicePowerApi impl = new PowerGreeterServiceImpl(mat); return Http.get(sys) .newServerAt("127.0.0.1", 8091) diff --git a/plugin-tester-java/src/main/java/example/myapp/helloworld/GreeterServicePowerApiImpl.java b/plugin-tester-java/src/main/java/example/myapp/helloworld/PowerGreeterServiceImpl.java similarity index 89% rename from plugin-tester-java/src/main/java/example/myapp/helloworld/GreeterServicePowerApiImpl.java rename to plugin-tester-java/src/main/java/example/myapp/helloworld/PowerGreeterServiceImpl.java index d358de63..c29e2210 100644 --- a/plugin-tester-java/src/main/java/example/myapp/helloworld/GreeterServicePowerApiImpl.java +++ b/plugin-tester-java/src/main/java/example/myapp/helloworld/PowerGreeterServiceImpl.java @@ -27,10 +27,10 @@ import org.apache.pekko.stream.javadsl.Sink; import org.apache.pekko.stream.javadsl.Source; -public class GreeterServicePowerApiImpl implements GreeterServicePowerApi { +public class PowerGreeterServiceImpl implements GreeterServicePowerApi { private final Materializer mat; - public GreeterServicePowerApiImpl(Materializer mat) { + public PowerGreeterServiceImpl(Materializer mat) { this.mat = mat; } @@ -46,7 +46,7 @@ public CompletionStage sayHello(HelloRequest in, Metadata metadata) public CompletionStage itKeepsTalking( Source in, Metadata metadata) { System.out.println("sayHello to in stream..."); - return in.runWith(Sink.seq(), mat) + return in.runWith(Sink.seq(), mat) .thenApply( elements -> { String elementsStr = @@ -65,10 +65,7 @@ public Source itKeepsReplying(HelloRequest in, Metadata met List characters = ("Hello, " + greetee).chars().mapToObj(c -> (char) c).collect(Collectors.toList()); return Source.from(characters) - .map( - character -> { - return HelloReply.newBuilder().setMessage(String.valueOf(character)).build(); - }); + .map(character -> HelloReply.newBuilder().setMessage(String.valueOf(character)).build()); } @Override @@ -88,7 +85,6 @@ private boolean isAuthenticated(Metadata metadata) { } private String authTaggedName(HelloRequest in, Metadata metadata) { - boolean authenticated = isAuthenticated(metadata); return String.format( "%s (%sauthenticated)", in.getName(), isAuthenticated(metadata) ? "" : "not "); } diff --git a/plugin-tester-scala/src/test/scala/example/myapp/helloworld/GreeterServiceSpec.scala b/plugin-tester-scala/src/test/scala/example/myapp/helloworld/GreeterServiceSpec.scala index 3cdc4af4..0f9f1933 100644 --- a/plugin-tester-scala/src/test/scala/example/myapp/helloworld/GreeterServiceSpec.scala +++ b/plugin-tester-scala/src/test/scala/example/myapp/helloworld/GreeterServiceSpec.scala @@ -31,7 +31,7 @@ import scala.concurrent.{ Await, ExecutionContext } import scala.concurrent.duration._ @RunWith(classOf[JUnitRunner]) -class GreeterSpec extends Matchers with AnyWordSpecLike with BeforeAndAfterAll with ScalaFutures { +class GreeterServiceSpec extends Matchers with AnyWordSpecLike with BeforeAndAfterAll with ScalaFutures { implicit val patience: PatienceConfig = PatienceConfig(10.seconds, Span(100, org.scalatest.time.Millis))