-
Notifications
You must be signed in to change notification settings - Fork 34
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
Sample http4s REST client/server with client macro derivation #552
Merged
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
ed9cf04
Initial steps for http integration (#203)
juanpedromoreno 93f8ace
Implemented sample client and server REST handlers to be generated
b03637c
Added monix.Observable implementation
2a1cc42
Implemented error handling for unary and streaming REST services (#258)
a74604e
Tentative fix for the hanging Monix-Observable tests
6424dab
Merge branch 'master' into feature/182-http-support-from-protocols
8caee87
Undo Single Abstract Method syntax to restore 2.11 compatibility
65d705d
Merge master into branch
L-Lavigne 98df299
Add auto-derived HTTP client implementation, move packages
L-Lavigne a216c63
Fix Monix/FS2 conversions using updated dependency
L-Lavigne 051519d
fixes Scala 2.11 compilation error
8eb36b4
fixes unit tests to prove http client derivation
c172539
removes some println
20aae64
adds more tests
15abe94
removes the macro params that can be inferred
5d5b726
builds the client according to the typology of the request
683147c
fixes macro
54990d8
advances with client derivation
fe34e47
adds more unit test to prove the derived http client
1132fc2
restores the derivation of the rpc server, without the refactoring
97d1c73
re-applies part of the refactoring little by little
6db7ab3
applies the refactoring again with the fix
2a9cd3d
derived the simplest http route that only serves GET calls
06f2b83
derived the stream reaquests http server
3888be7
fixes the binding pattern in POST routes
965fdd4
adds tests to cover all the possible types of endpoints
d6ce882
removes unused imports
3133ec5
removed unused HttpMethod
34c0504
upgraded http4s and moved Utils
795eb12
Merge branch 'master' into feature/182-http-support-from-protocols
juanpedromoreno c922e0f
solves all the comments in code review
9b0a8f3
expressed type as FQN and propagated encoder/decoders constraints
fb91483
removes the import of monix.Scheduler in the macro
854b0d6
replaces executionContext by Schedule at some points
f6eab68
adds _root_ to ExecutionContext
ad90c2d
Apply suggestions from code review
juanpedromoreno f1f60ff
removes circe-generic
94dba66
Merge remote-tracking branch 'origin/feature/182-http-support-from-pr…
bf6e853
replaces Throwable by UnexpectedError and its encoder/decoder
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 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 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 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 |
---|---|---|
|
@@ -19,7 +19,7 @@ package higherkindness.mu.rpc.http | |
import cats.effect.{IO, _} | ||
import fs2.Stream | ||
import fs2.interop.reactivestreams._ | ||
import higherkindness.mu.http.ResponseError | ||
import higherkindness.mu.http.{ResponseError, UnexpectedError} | ||
import higherkindness.mu.rpc.common.RpcBaseTestSuite | ||
import higherkindness.mu.http.implicits._ | ||
import io.circe.Json | ||
|
@@ -34,14 +34,10 @@ import org.http4s.server.blaze._ | |
import org.scalatest._ | ||
import org.http4s.implicits._ | ||
import org.http4s.server.Router | ||
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks | ||
|
||
import scala.concurrent.duration._ | ||
|
||
class GreeterRestTests | ||
extends RpcBaseTestSuite | ||
with ScalaCheckDrivenPropertyChecks | ||
with BeforeAndAfter { | ||
class GreeterRestTests extends RpcBaseTestSuite with BeforeAndAfter { | ||
|
||
val Hostname = "localhost" | ||
val Port = 8080 | ||
|
@@ -72,7 +68,7 @@ class GreeterRestTests | |
s"/$Fs2ServicePrefix" -> fs2Service, | ||
s"/$MonixServicePrefix" -> monixService).orNotFound) | ||
|
||
var serverTask: Fiber[IO, Nothing] = _ // sorry | ||
var serverTask: Fiber[IO, Nothing] = _ | ||
before(serverTask = server.resource.use(_ => IO.never).start.unsafeRunSync()) | ||
after(serverTask.cancel) | ||
|
||
|
@@ -208,17 +204,17 @@ class GreeterRestTests | |
val request = HelloRequest("") | ||
val responses = | ||
BlazeClientBuilder[IO](ec).stream.flatMap(fs2ServiceClient.sayHelloAll(request)(_)) | ||
the[IllegalArgumentException] thrownBy responses.compile.toList | ||
.unsafeRunSync() should have message "empty greeting" | ||
the[UnexpectedError] thrownBy responses.compile.toList | ||
.unsafeRunSync() should have message "java.lang.IllegalArgumentException: empty greeting" | ||
} | ||
|
||
"handle errors with Observable streaming response" in { | ||
val request = HelloRequest("") | ||
val responses = BlazeClientBuilder[IO](ec).stream | ||
.flatMap(monixServiceClient.sayHelloAll(request)(_).toReactivePublisher.toStream[IO]) | ||
the[IllegalArgumentException] thrownBy responses.compile.toList | ||
the[UnexpectedError] thrownBy responses.compile.toList | ||
.unsafeRunTimed(10.seconds) | ||
.getOrElse(sys.error("Stuck!")) should have message "empty greeting" | ||
.getOrElse(sys.error("Stuck!")) should have message "java.lang.IllegalArgumentException: empty greeting" | ||
} | ||
|
||
"serve a POST request with bidirectional fs2 streaming" in { | ||
|
@@ -254,15 +250,5 @@ class GreeterRestTests | |
.getOrElse(sys.error("Stuck!")) shouldBe Nil | ||
} | ||
|
||
"serve ScalaCheck-generated POST requests with bidirectional Observable streaming" in { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, were there any issues with the ScalaCheck tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (resolved offline) |
||
forAll { strings: List[String] => | ||
val requests = Observable.fromIterable(strings.map(HelloRequest)) | ||
val responses = BlazeClientBuilder[IO](ec).stream | ||
.flatMap(monixServiceClient.sayHellosAll(requests)(_).toReactivePublisher.toStream[IO]) | ||
responses.compile.toList | ||
.unsafeRunTimed(10.seconds) | ||
.getOrElse(sys.error("Stuck!")) shouldBe strings.map(HelloResponse) | ||
} | ||
} | ||
} | ||
} |
This file contains 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name is a bit generic - most errors are unexpected. The way we're using those, they're closer to "RequestException"s, or 4XX-status
ResponseException
s. Can we combine those error types or rename this one?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(resolved offline)