From fd04236c930ab1ff73ca0fc80df955c6f5058caa Mon Sep 17 00:00:00 2001 From: Gabriel Volpe Date: Sun, 6 Dec 2020 23:06:00 +0100 Subject: [PATCH] Fix documentation --- .../profunktor/redis4cats/TestScenarios.scala | 21 +++++++++------ site/docs/pipelining.md | 26 ++++++++++++------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/modules/tests/src/test/scala/dev/profunktor/redis4cats/TestScenarios.scala b/modules/tests/src/test/scala/dev/profunktor/redis4cats/TestScenarios.scala index 271ddaf3..fcc28dc9 100644 --- a/modules/tests/src/test/scala/dev/profunktor/redis4cats/TestScenarios.scala +++ b/modules/tests/src/test/scala/dev/profunktor/redis4cats/TestScenarios.scala @@ -17,6 +17,7 @@ package dev.profunktor.redis4cats import java.time.Instant +import java.util.concurrent.TimeoutException import cats.data.NonEmptyList import cats.effect._ @@ -25,7 +26,7 @@ import dev.profunktor.redis4cats.data.KeyScanCursor import dev.profunktor.redis4cats.effect.Log.NoOp._ import dev.profunktor.redis4cats.effects._ import dev.profunktor.redis4cats.hlist._ -import dev.profunktor.redis4cats.pipeline.RedisPipeline +import dev.profunktor.redis4cats.pipeline.{ PipelineError, RedisPipeline } import dev.profunktor.redis4cats.transactions.RedisTransaction import io.lettuce.core.GeoArgs import munit.FunSuite @@ -384,13 +385,17 @@ trait TestScenarios { self: FunSuite => cmd.set(key1, "osx") :: cmd.get(key3) :: cmd.set(key2, "linux") :: cmd.sIsMember("foo", "bar") :: HNil val runPipeline = - RedisPipeline(cmd).filterExec(operations).map { - case res1 ~: res2 ~: HNil => - assertEquals(res1, Some("3")) - assert(!res2) - case tr => - fail(s"Unexpected result: $tr") - } + RedisPipeline(cmd) + .filterExec(operations) + .map { + case res1 ~: res2 ~: HNil => + assertEquals(res1, Some("3")) + assert(!res2) + } + .onError { + case PipelineError => fail("[Error] - Pipeline failed") + case _: TimeoutException => fail("[Error] - Timeout") + } for { _ <- cmd.set(key3, "3") diff --git a/site/docs/pipelining.md b/site/docs/pipelining.md index ab0d22c6..5be4a9e1 100644 --- a/site/docs/pipelining.md +++ b/site/docs/pipelining.md @@ -76,19 +76,25 @@ commandsApi.use { cmd => // RedisCommands[IO, String, String] val getters = cmd.get(key1).flatTap(showResult(key1)) >> cmd.get(key2).flatTap(showResult(key2)) >> - cmd.get(key3).flatTap(showResult(key3)) >> + cmd.get(key3).flatTap(showResult(key3)) val operations = cmd.set(key1, "osx") :: cmd.get(key3) :: cmd.set(key2, "linux") :: cmd.sIsMember("foo", "bar") :: HNil val runPipeline = - RedisPipeline(cmd).filterExec(operations).map { - case res1 ~: res2 ~: HNil => - assertEquals(res1, Some("3")) - assert(!res2) - case tr => - fail(s"Unexpected result: $tr") - } + RedisPipeline(cmd) + .filterExec(operations) + .map { + case res1 ~: res2 ~: HNil => + assert(res1.contains("3")) + assert(!res2) + } + .onError { + case PipelineError => + putStrLn("[Error] - Pipeline failed") + case _: TimeoutException => + putStrLn("[Error] - Timeout") + } val prog = for { @@ -97,8 +103,8 @@ commandsApi.use { cmd => // RedisCommands[IO, String, String] v1 <- cmd.get(key1) v2 <- cmd.get(key2) } yield { - assertEquals(v1, Some("osx")) - assertEquals(v2, Some("linux")) + assert(v1.contains("osx")) + assert(v2.contains("linux")) } getters >> prog >> getters >> putStrLn("keep doing stuff...")