@@ -18,16 +18,16 @@ package dev.profunktor.redis4cats
18
18
19
19
import cats .effect ._
20
20
import cats .syntax .all ._
21
- import dev .profunktor .redis4cats .Redis4CatsFunSuite .Fs2Streaming
21
+ import dev .profunktor .redis4cats .Redis4CatsFunSuite .{ Fs2PubSub , Fs2Streaming }
22
22
import dev .profunktor .redis4cats .connection ._
23
23
import dev .profunktor .redis4cats .data .RedisCodec
24
24
import dev .profunktor .redis4cats .effect .Log .NoOp ._
25
+ import dev .profunktor .redis4cats .pubsub .{ PubSub , PubSubCommands }
25
26
import dev .profunktor .redis4cats .streams .{ RedisStream , Streaming }
27
+ import io .lettuce .core .{ ClientOptions , TimeoutOptions }
26
28
27
- import scala .concurrent .duration .Duration
29
+ import scala .concurrent .duration .{ Duration , DurationInt }
28
30
import scala .concurrent .{ Await , Future }
29
- import dev .profunktor .redis4cats .pubsub .{ PubSub , PubSubCommands }
30
- import dev .profunktor .redis4cats .Redis4CatsFunSuite .Fs2PubSub
31
31
32
32
abstract class Redis4CatsFunSuite (isCluster : Boolean ) extends IOSuite {
33
33
@@ -54,24 +54,43 @@ abstract class Redis4CatsFunSuite(isCluster: Boolean) extends IOSuite {
54
54
RedisClient [IO ].from(" redis://localhost" ).use(f).as(assert(true )).unsafeToFuture()
55
55
56
56
def withRedisPubSub (f : Fs2PubSub [String , String ] => IO [Unit ]): Future [Unit ] =
57
- (for {
58
- client <- fs2.Stream .resource(RedisClient [IO ].from(" redis://localhost" ))
59
- pubSub <- fs2.Stream .resource(PubSub .mkPubSubConnection[IO , String , String ](client, stringCodec))
60
- _ <- fs2.Stream .eval(f(pubSub))
61
- } yield ()).compile.drain.void.unsafeToFuture()
57
+ withRedisPubSubOptionsResource(ClientOptions .create()).use(f).unsafeToFuture()
58
+
59
+ def withRedisPubSubOptionsResource (options : ClientOptions ): Resource [IO , Fs2PubSub [String , String ]] =
60
+ for {
61
+ client <- RedisClient [IO ].withOptions(" redis://localhost" , options)
62
+ pubSub <- PubSub .mkPubSubConnection[IO , String , String ](client, stringCodec)
63
+ } yield pubSub
62
64
63
65
def withRedisStream (f : (Fs2Streaming [String , String ], Fs2Streaming [String , String ]) => IO [Unit ]): Future [Unit ] =
64
- (for {
65
- client <- fs2.Stream .resource(RedisClient [IO ].from(" redis://localhost" ))
66
- readStream <- RedisStream .mkStreamingConnection[IO , String , String ](client, stringCodec)
67
- writeStream <- RedisStream .mkStreamingConnection[IO , String , String ](client, stringCodec)
68
- _ <- fs2.Stream .eval(f(readStream, writeStream))
69
- } yield ()).compile.drain.void.unsafeToFuture()
66
+ withRedisStreamOptionsResource(ClientOptions .create())
67
+ .use { case (readStream, writeStream) => f(readStream, writeStream) }
68
+ .unsafeToFuture()
69
+
70
+ def withRedisStreamOptionsResource (
71
+ options : ClientOptions
72
+ ): Resource [IO , (Fs2Streaming [String , String ], Fs2Streaming [String , String ])] =
73
+ for {
74
+ client <- RedisClient [IO ].withOptions(" redis://localhost" , options)
75
+ readStream <- RedisStream .mkStreamingConnectionResource[IO , String , String ](client, stringCodec)
76
+ writeStream <- RedisStream .mkStreamingConnectionResource[IO , String , String ](client, stringCodec)
77
+ } yield (readStream, writeStream)
70
78
71
79
private def flushAll (): Future [Unit ] =
72
80
if (isCluster) withRedisCluster(_.flushAll)
73
81
else withRedis(_.flushAll)
74
82
83
+ def timeoutingOperationTest [A ](
84
+ f : (ClientOptions , RestartOnTimeout ) => fs2.Stream [IO , A ]
85
+ ): IO [Unit ] = {
86
+ val options = ClientOptions
87
+ .builder()
88
+ .timeoutOptions(TimeoutOptions .builder().fixedTimeout(java.time.Duration .ofMillis(250 )).build())
89
+ .build()
90
+
91
+ f(options, RestartOnTimeout .always).interruptAfter(750 .millis).compile.drain
92
+ }
93
+
75
94
// --- Cluster ---
76
95
77
96
lazy val redisUri = List (
0 commit comments