-
-
Notifications
You must be signed in to change notification settings - Fork 64
Allow disabling trailers #809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
e2e/src/test/resources/TestServiceFs2GrpcDisableTrailers.scala.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| package hello.world | ||
|
|
||
| import _root_.cats.syntax.all._ | ||
|
|
||
| /** TestService: Example gRPC service used in e2e tests | ||
| * It demonstrates all four RPC shapes. | ||
| */ | ||
| trait TestServiceFs2GrpcDisableTrailers[F[_], A] { | ||
| /** Unary RPC: no streaming in either direction | ||
| */ | ||
| def noStreaming(request: hello.world.TestMessage, ctx: A): F[hello.world.TestMessage] | ||
| /** Client streaming RPC: client streams, server returns a single response | ||
| */ | ||
| def clientStreaming(request: _root_.fs2.Stream[F, hello.world.TestMessage], ctx: A): F[hello.world.TestMessage] | ||
| /** Server streaming RPC: client sends one request, server streams responses | ||
| */ | ||
| def serverStreaming(request: hello.world.TestMessage, ctx: A): _root_.fs2.Stream[F, hello.world.TestMessage] | ||
| /** Bidirectional streaming RPC: both client and server stream | ||
| */ | ||
| def bothStreaming(request: _root_.fs2.Stream[F, hello.world.TestMessage], ctx: A): _root_.fs2.Stream[F, hello.world.TestMessage] | ||
| } | ||
|
|
||
| object TestServiceFs2GrpcDisableTrailers extends _root_.fs2.grpc.GeneratedCompanion[TestServiceFs2GrpcDisableTrailers] { | ||
|
|
||
| def serviceDescriptor: _root_.io.grpc.ServiceDescriptor = hello.world.TestServiceGrpc.SERVICE | ||
|
|
||
| def mkClientFull[F[_], G[_]: _root_.cats.effect.Async, A]( | ||
| dispatcher: _root_.cats.effect.std.Dispatcher[G], | ||
| channel: _root_.io.grpc.Channel, | ||
| clientAspect: _root_.fs2.grpc.client.ClientAspect[F, G, A], | ||
| clientOptions: _root_.fs2.grpc.client.ClientOptions | ||
| ): TestServiceFs2GrpcDisableTrailers[F, A] = new TestServiceFs2GrpcDisableTrailers[F, A] { | ||
| def noStreaming(request: hello.world.TestMessage, ctx: A): F[hello.world.TestMessage] = | ||
| clientAspect.visitUnaryToUnaryCall[hello.world.TestMessage, hello.world.TestMessage]( | ||
| _root_.fs2.grpc.client.ClientCallContext(ctx, hello.world.TestServiceGrpc.METHOD_NO_STREAMING), | ||
| request, | ||
| (req, m) => _root_.fs2.grpc.client.Fs2ClientCall[G](channel, hello.world.TestServiceGrpc.METHOD_NO_STREAMING, dispatcher, clientOptions).flatMap(_.unaryToUnaryCall(req, m)) | ||
| ) | ||
| def clientStreaming(request: _root_.fs2.Stream[F, hello.world.TestMessage], ctx: A): F[hello.world.TestMessage] = | ||
| clientAspect.visitStreamingToUnaryCall[hello.world.TestMessage, hello.world.TestMessage]( | ||
| _root_.fs2.grpc.client.ClientCallContext(ctx, hello.world.TestServiceGrpc.METHOD_CLIENT_STREAMING), | ||
| request, | ||
| (req, m) => _root_.fs2.grpc.client.Fs2ClientCall[G](channel, hello.world.TestServiceGrpc.METHOD_CLIENT_STREAMING, dispatcher, clientOptions).flatMap(_.streamingToUnaryCall(req, m)) | ||
| ) | ||
| def serverStreaming(request: hello.world.TestMessage, ctx: A): _root_.fs2.Stream[F, hello.world.TestMessage] = | ||
| clientAspect.visitUnaryToStreamingCall[hello.world.TestMessage, hello.world.TestMessage]( | ||
| _root_.fs2.grpc.client.ClientCallContext(ctx, hello.world.TestServiceGrpc.METHOD_SERVER_STREAMING), | ||
| request, | ||
| (req, m) => _root_.fs2.Stream.eval(_root_.fs2.grpc.client.Fs2ClientCall[G](channel, hello.world.TestServiceGrpc.METHOD_SERVER_STREAMING, dispatcher, clientOptions)).flatMap(_.unaryToStreamingCall(req, m)) | ||
| ) | ||
| def bothStreaming(request: _root_.fs2.Stream[F, hello.world.TestMessage], ctx: A): _root_.fs2.Stream[F, hello.world.TestMessage] = | ||
| clientAspect.visitStreamingToStreamingCall[hello.world.TestMessage, hello.world.TestMessage]( | ||
| _root_.fs2.grpc.client.ClientCallContext(ctx, hello.world.TestServiceGrpc.METHOD_BOTH_STREAMING), | ||
| request, | ||
| (req, m) => _root_.fs2.Stream.eval(_root_.fs2.grpc.client.Fs2ClientCall[G](channel, hello.world.TestServiceGrpc.METHOD_BOTH_STREAMING, dispatcher, clientOptions)).flatMap(_.streamingToStreamingCall(req, m)) | ||
| ) | ||
| } | ||
|
|
||
| protected def serviceBindingFull[F[_], G[_]: _root_.cats.effect.Async, A]( | ||
| dispatcher: _root_.cats.effect.std.Dispatcher[G], | ||
| serviceImpl: TestServiceFs2GrpcDisableTrailers[F, A], | ||
| serviceAspect: _root_.fs2.grpc.server.ServiceAspect[F, G, A], | ||
| serverOptions: _root_.fs2.grpc.server.ServerOptions | ||
| ) = { | ||
| _root_.io.grpc.ServerServiceDefinition | ||
| .builder(hello.world.TestServiceGrpc.SERVICE) | ||
| .addMethod( | ||
| hello.world.TestServiceGrpc.METHOD_NO_STREAMING, | ||
| _root_.fs2.grpc.server.Fs2ServerCallHandler[G](dispatcher, serverOptions).unaryToUnaryCall[hello.world.TestMessage, hello.world.TestMessage]{ (r, m) => | ||
| serviceAspect.visitUnaryToUnaryCall[hello.world.TestMessage, hello.world.TestMessage]( | ||
| _root_.fs2.grpc.server.ServiceCallContext(m, hello.world.TestServiceGrpc.METHOD_NO_STREAMING), | ||
| r, | ||
| (r, m) => serviceImpl.noStreaming(r, m) | ||
| ) | ||
| } | ||
| ) | ||
| .addMethod( | ||
| hello.world.TestServiceGrpc.METHOD_CLIENT_STREAMING, | ||
| _root_.fs2.grpc.server.Fs2ServerCallHandler[G](dispatcher, serverOptions).streamingToUnaryCall[hello.world.TestMessage, hello.world.TestMessage]{ (r, m) => | ||
| serviceAspect.visitStreamingToUnaryCall[hello.world.TestMessage, hello.world.TestMessage]( | ||
| _root_.fs2.grpc.server.ServiceCallContext(m, hello.world.TestServiceGrpc.METHOD_CLIENT_STREAMING), | ||
| r, | ||
| (r, m) => serviceImpl.clientStreaming(r, m) | ||
| ) | ||
| } | ||
| ) | ||
| .addMethod( | ||
| hello.world.TestServiceGrpc.METHOD_SERVER_STREAMING, | ||
| _root_.fs2.grpc.server.Fs2ServerCallHandler[G](dispatcher, serverOptions).unaryToStreamingCall[hello.world.TestMessage, hello.world.TestMessage]{ (r, m) => | ||
| serviceAspect.visitUnaryToStreamingCall[hello.world.TestMessage, hello.world.TestMessage]( | ||
| _root_.fs2.grpc.server.ServiceCallContext(m, hello.world.TestServiceGrpc.METHOD_SERVER_STREAMING), | ||
| r, | ||
| (r, m) => serviceImpl.serverStreaming(r, m) | ||
| ) | ||
| } | ||
| ) | ||
| .addMethod( | ||
| hello.world.TestServiceGrpc.METHOD_BOTH_STREAMING, | ||
| _root_.fs2.grpc.server.Fs2ServerCallHandler[G](dispatcher, serverOptions).streamingToStreamingCall[hello.world.TestMessage, hello.world.TestMessage]{ (r, m) => | ||
| serviceAspect.visitStreamingToStreamingCall[hello.world.TestMessage, hello.world.TestMessage]( | ||
| _root_.fs2.grpc.server.ServiceCallContext(m, hello.world.TestServiceGrpc.METHOD_BOTH_STREAMING), | ||
| r, | ||
| (r, m) => serviceImpl.bothStreaming(r, m) | ||
| ) | ||
| } | ||
| ) | ||
| .build() | ||
| } | ||
|
|
||
| } |
52 changes: 52 additions & 0 deletions
52
e2e/src/test/scala/fs2/grpc/e2e/Fs2CodeGeneratorDisableTrailersSpec.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Copyright (c) 2018 Gary Coady / Fs2 Grpc Developers | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| * this software and associated documentation files (the "Software"), to deal in | ||
| * the Software without restriction, including without limitation the rights to | ||
| * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| * the Software, and to permit persons to whom the Software is furnished to do so, | ||
| * subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| */ | ||
|
|
||
| package fs2.grpc.e2e | ||
|
|
||
| import java.io.File | ||
|
|
||
| import fs2.grpc.GeneratedCompanion | ||
| import fs2.grpc.e2e.buildinfo.BuildInfo.sourceManaged | ||
| import hello.world._ | ||
|
|
||
| import scala.io.Source | ||
|
|
||
| class Fs2CodeGeneratorDisableTrailersSpec extends munit.FunSuite { | ||
|
|
||
| val sourcesGenerated = new File(sourceManaged.getAbsolutePath, "disable-trailers/hello/world") | ||
|
|
||
| test("code generator outputs correct service file") { | ||
| val testFileName = "TestServiceFs2GrpcDisableTrailers.scala" | ||
| val reference = Source.fromResource(s"$testFileName.txt").getLines().mkString("\n") | ||
| val generated = Source.fromFile(new File(sourcesGenerated, testFileName)).getLines().mkString("\n") | ||
|
|
||
| assertEquals(generated, reference) | ||
| } | ||
|
|
||
| test("code generator outputs: do not generate trailers") { | ||
| assertEquals(sourcesGenerated.list().length, 1) | ||
| } | ||
|
|
||
| test("implicit of companion resolves") { | ||
| implicitly[GeneratedCompanion[TestServiceFs2GrpcDisableTrailers]] | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.