-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make HTTP call on a blocking execution context in HttpURLConnectionBa…
…ckend
- Loading branch information
1 parent
c164199
commit 2f88ea7
Showing
3 changed files
with
72 additions
and
17 deletions.
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
39 changes: 39 additions & 0 deletions
39
fetch-file/src/test/scala/vdx/fetchfile/HttpURLConnectionBackendSpec.scala
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package vdx.fetchfile | ||
|
||
import cats.effect._ | ||
import cats.effect.Sync.catsWriterTSync | ||
import cats.instances.vector._ | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import cats.data.WriterT | ||
import java.net.URL | ||
import scala.concurrent.ExecutionContext | ||
|
||
class HttpURLConnectionBackendSpec extends AnyFlatSpec with Matchers { | ||
// val contextShiftIO = ContextShift[IO] | ||
|
||
"HttpURLConnectionBackend" should "evaluate the connection on the given blocking context" in { | ||
type TestIO[A] = WriterT[IO, Vector[String], A] | ||
|
||
implicit val syncTestIO: Sync[TestIO] = catsWriterTSync[IO, Vector[String]] | ||
|
||
implicit val contextShiftTestIO: ContextShift[TestIO] = new ContextShift[TestIO] { | ||
|
||
override def shift: TestIO[Unit] = WriterT.tell(Vector("ContextShift.shift")) | ||
|
||
override def evalOn[A](ec: ExecutionContext)(fa: TestIO[A]): TestIO[A] = | ||
WriterT.tell[IO, Vector[String]](Vector(s"ContextShift.evalOn")).flatMap[A](_ => fa) | ||
} | ||
|
||
Blocker[IO].use[IO, Unit] { blocker => | ||
val backend = HttpURLConnectionBackend[TestIO](blocker, 1024 * 8) | ||
|
||
val (logs, _) = backend(new URL("http://localhost:8088/100MB.bin")).use[TestIO, Unit](_ => WriterT.value(())).run.unsafeRunSync() | ||
|
||
logs should be(Vector("ContextShift.evalOn")) | ||
|
||
IO.unit | ||
}.unsafeRunSync() | ||
|
||
} | ||
} |