Skip to content

Commit

Permalink
Merge branch 'master' into update/redis4cats-effects-1.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mijicd authored Aug 23, 2024
2 parents b3092fa + 913e650 commit 94e3651
Show file tree
Hide file tree
Showing 27 changed files with 496 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.8.2"
version = "3.8.3"
maxColumn = 120
align.preset = most
continuationIndent.defnSite = 2
Expand Down
38 changes: 19 additions & 19 deletions modules/redis-it/src/test/resources/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
version: "3.3"

services:
single-node-0:
single-node0:
image: bitnami/redis:7.2
environment:
- 'ALLOW_EMPTY_PASSWORD=yes'

single-node-1:
single-node1:
image: bitnami/redis:7.2
environment:
- 'ALLOW_EMPTY_PASSWORD=yes'

cluster-node-0:
cluster-node0:
image: bitnami/redis-cluster:7.2
environment:
- 'ALLOW_EMPTY_PASSWORD=yes'
- 'REDIS_NODES=cluster-node-0 cluster-node-1 cluster-node-2 cluster-node-3 cluster-node-4 cluster-node-5'
- 'REDIS_NODES=cluster-node0 cluster-node1 cluster-node2 cluster-node3 cluster-node4 cluster-node5'

cluster-node-1:
cluster-node1:
image: bitnami/redis-cluster:7.2
environment:
- 'ALLOW_EMPTY_PASSWORD=yes'
- 'REDIS_NODES=cluster-node-0 cluster-node-1 cluster-node-2 cluster-node-3 cluster-node-4 cluster-node-5'
- 'REDIS_NODES=cluster-node0 cluster-node1 cluster-node2 cluster-node3 cluster-node4 cluster-node5'

cluster-node-2:
cluster-node2:
image: bitnami/redis-cluster:7.2
environment:
- 'ALLOW_EMPTY_PASSWORD=yes'
- 'REDIS_NODES=cluster-node-0 cluster-node-1 cluster-node-2 cluster-node-3 cluster-node-4 cluster-node-5'
- 'REDIS_NODES=cluster-node0 cluster-node1 cluster-node2 cluster-node3 cluster-node4 cluster-node5'

cluster-node-3:
cluster-node3:
image: bitnami/redis-cluster:7.2
environment:
- 'ALLOW_EMPTY_PASSWORD=yes'
- 'REDIS_NODES=cluster-node-0 cluster-node-1 cluster-node-2 cluster-node-3 cluster-node-4 cluster-node-5'
- 'REDIS_NODES=cluster-node0 cluster-node1 cluster-node2 cluster-node3 cluster-node4 cluster-node5'

cluster-node-4:
cluster-node4:
image: bitnami/redis-cluster:7.2
environment:
- 'ALLOW_EMPTY_PASSWORD=yes'
- 'REDIS_NODES=cluster-node-0 cluster-node-1 cluster-node-2 cluster-node-3 cluster-node-4 cluster-node-5'
- 'REDIS_NODES=cluster-node0 cluster-node1 cluster-node2 cluster-node3 cluster-node4 cluster-node5'

cluster-node-5:
cluster-node5:
image: bitnami/redis-cluster:7.2
depends_on:
- cluster-node-0
- cluster-node-1
- cluster-node-2
- cluster-node-3
- cluster-node-4
- cluster-node0
- cluster-node1
- cluster-node2
- cluster-node3
- cluster-node4
environment:
- 'ALLOW_EMPTY_PASSWORD=yes'
- 'REDIS_CLUSTER_REPLICAS=1'
- 'REDIS_NODES=cluster-node-0 cluster-node-1 cluster-node-2 cluster-node-3 cluster-node-4 cluster-node-5'
- 'REDIS_NODES=cluster-node0 cluster-node1 cluster-node2 cluster-node3 cluster-node4 cluster-node5'
- 'REDIS_CLUSTER_CREATOR=yes'
10 changes: 5 additions & 5 deletions modules/redis-it/src/test/scala/zio/redis/ApiSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ object ApiSpec
suite("Redis commands")(ClusterSuite, SingleNodeSuite)
.provideShared(
compose(
service(BaseSpec.SingleNode0, ".*Ready to accept connections.*"),
service(BaseSpec.SingleNode1, ".*Ready to accept connections.*"),
service(BaseSpec.MasterNode, ".*Cluster correctly created.*")
service(IntegrationSpec.SingleNode0, ".*Ready to accept connections.*"),
service(IntegrationSpec.SingleNode1, ".*Ready to accept connections.*"),
service(IntegrationSpec.MasterNode, ".*Cluster correctly created.*")
)
) @@ sequential @@ withLiveEnvironment

Expand All @@ -48,7 +48,7 @@ object ApiSpec
Redis.cluster,
masterNodeConfig,
ZLayer.succeed(ProtobufCodecSupplier)
).filterNotTags(_.contains(BaseSpec.ClusterExecutorUnsupported))
).filterNotTags(_.contains(IntegrationSpec.ClusterExecutorUnsupported))
.getOrElse(Spec.empty) @@ flaky @@ ifEnvNotSet("CI")

private final val SingleNodeSuite =
Expand All @@ -68,7 +68,7 @@ object ApiSpec
).provideSomeShared[DockerComposeContainer](
Redis.singleNode,
RedisSubscription.singleNode,
singleNodeConfig(BaseSpec.SingleNode0),
singleNodeConfig(IntegrationSpec.SingleNode0),
ZLayer.succeed(ProtobufCodecSupplier)
)
}
6 changes: 3 additions & 3 deletions modules/redis-it/src/test/scala/zio/redis/ClusterSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.dimafeng.testcontainers.DockerComposeContainer
import zio._
import zio.test._

trait ClusterSpec extends BaseSpec {
trait ClusterSpec extends IntegrationSpec {
def clusterSpec: Spec[DockerComposeContainer & Redis, RedisError] =
suite("cluster")(
suite("slots")(
Expand All @@ -17,8 +17,8 @@ trait ClusterSpec extends BaseSpec {
ZIO
.foreach(0 to 5) { n =>
ZIO
.attempt(docker.getServiceHost(s"cluster-node-$n", port))
.map(host => RedisUri(s"$host:$port"))
.attempt(docker.getServiceHost(s"cluster-node$n", port))
.map(host => RedisUri(host, port))
}
.orDie
actual = res.map(_.master.address) ++ res.flatMap(_.slaves.map(_.address))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import zio.test.Assertion._
import zio.test.TestAspect._
import zio.test._

trait ConnectionSpec extends BaseSpec {
trait ConnectionSpec extends IntegrationSpec {
def connectionSuite: Spec[Redis, RedisError] =
suite("connection")(
suite("authenticating")(
Expand Down
2 changes: 1 addition & 1 deletion modules/redis-it/src/test/scala/zio/redis/GeoSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import zio.test.Assertion._
import zio.test._
import zio.{Chunk, ZIO}

trait GeoSpec extends BaseSpec {
trait GeoSpec extends IntegrationSpec {
def geoSuite: Spec[Redis, RedisError] =
suite("geo")(
test("geoAdd followed by geoPos") {
Expand Down
2 changes: 1 addition & 1 deletion modules/redis-it/src/test/scala/zio/redis/HashSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import zio.test.Assertion._
import zio.test._
import zio.{Chunk, ZIO}

trait HashSpec extends BaseSpec {
trait HashSpec extends IntegrationSpec {
def hashSuite: Spec[Redis, RedisError] =
suite("hash")(
suite("hSet, hGet, hGetAll and hDel")(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import zio.ZIO
import zio.test.Assertion._
import zio.test._

trait HyperLogLogSpec extends BaseSpec {
trait HyperLogLogSpec extends IntegrationSpec {
def hyperLogLogSuite: Spec[Redis, RedisError] =
suite("hyperloglog")(
suite("add elements")(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import zio.{ULayer, _}
import java.io.File
import java.util.UUID

trait BaseSpec extends ZIOSpecDefault {
trait IntegrationSpec extends ZIOSpecDefault {
implicit def summonCodec[A: Schema]: BinaryCodec[A] = ProtobufCodec.protobufCodec

override def aspects: Chunk[TestAspectAtLeastR[Live]] =
Expand All @@ -30,8 +30,8 @@ trait BaseSpec extends ZIOSpecDefault {
ZLayer {
for {
docker <- ZIO.service[DockerComposeContainer]
hostAndPort <- docker.getHostAndPort(BaseSpec.MasterNode)(6379)
uri = RedisUri(s"${hostAndPort._1}:${hostAndPort._2}")
hostAndPort <- docker.getHostAndPort(IntegrationSpec.MasterNode)(6379)
uri = RedisUri(hostAndPort._1, hostAndPort._2)
} yield RedisClusterConfig(Chunk(uri))
}

Expand All @@ -53,7 +53,7 @@ trait BaseSpec extends ZIOSpecDefault {
* - fork/join approach for commands that operate on keys with different slots
*/
final val clusterExecutorUnsupported: TestAspectPoly =
tag(BaseSpec.ClusterExecutorUnsupported)
tag(IntegrationSpec.ClusterExecutorUnsupported)

final val genStringRedisTypeOption: Gen[Any, Option[RedisType]] =
Gen.option(Gen.constSample(Sample.noShrink(RedisType.String)))
Expand All @@ -68,9 +68,9 @@ trait BaseSpec extends ZIOSpecDefault {
ZIO.succeed(UUID.randomUUID().toString)
}

object BaseSpec {
object IntegrationSpec {
final val ClusterExecutorUnsupported = "cluster executor not supported"
final val MasterNode = "cluster-node-5"
final val SingleNode0 = "single-node-0"
final val SingleNode1 = "single-node-1"
final val MasterNode = "cluster-node5"
final val SingleNode0 = "single-node0"
final val SingleNode1 = "single-node1"
}
10 changes: 5 additions & 5 deletions modules/redis-it/src/test/scala/zio/redis/KeysSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import zio.test.Assertion.{exists => _, _}
import zio.test.TestAspect.{restore => _, _}
import zio.test._

trait KeysSpec extends BaseSpec {
trait KeysSpec extends IntegrationSpec {
def keysSuite: Spec[DockerComposeContainer & Redis, RedisError] = {
suite("keys")(
test("set followed by get") {
Expand Down Expand Up @@ -177,7 +177,7 @@ trait KeysSpec extends BaseSpec {
_ <- redis.set(key, value)
response <- redis
.migrate(
BaseSpec.SingleNode1,
IntegrationSpec.SingleNode1,
6379,
key,
0L,
Expand All @@ -199,7 +199,7 @@ trait KeysSpec extends BaseSpec {
redis <- ZIO.service[Redis]
_ <- redis.set(key, value)
response <- redis.migrate(
BaseSpec.SingleNode1,
IntegrationSpec.SingleNode1,
6379L,
key,
0L,
Expand All @@ -225,7 +225,7 @@ trait KeysSpec extends BaseSpec {
.provideLayer(secondExecutor) // also add to second Redis
response <- redis
.migrate(
BaseSpec.SingleNode1,
IntegrationSpec.SingleNode1,
6379,
key,
0L,
Expand Down Expand Up @@ -515,7 +515,7 @@ trait KeysSpec extends BaseSpec {
private val secondExecutor =
ZLayer
.makeSome[DockerComposeContainer, Redis](
singleNodeConfig(BaseSpec.SingleNode1),
singleNodeConfig(IntegrationSpec.SingleNode1),
ZLayer.succeed[CodecSupplier](ProtobufCodecSupplier),
Redis.singleNode
)
Expand Down
18 changes: 17 additions & 1 deletion modules/redis-it/src/test/scala/zio/redis/ListSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import zio.test._

import java.util.concurrent.TimeUnit

trait ListSpec extends BaseSpec {
trait ListSpec extends IntegrationSpec {
def listSuite: Spec[Redis, Any] =
suite("lists")(
suite("pop")(
Expand Down Expand Up @@ -341,6 +341,14 @@ trait ListSpec extends BaseSpec {
range <- redis.lRange(key, 0 to 1).returning[String]
} yield assert(range)(equalTo(Chunk("hello", "world")))
},
test("lRange elements by exclusive range") {
for {
redis <- ZIO.service[Redis]
key <- uuid
_ <- redis.lPush(key, "c", "b", "a")
range <- redis.lRange(key, 0 until 2).returning[String]
} yield assert(range)(equalTo(Chunk("a", "b")))
},
test("lRange two elements negative indices") {
for {
redis <- ZIO.service[Redis]
Expand All @@ -349,6 +357,14 @@ trait ListSpec extends BaseSpec {
range <- redis.lRange(key, -2 to -1).returning[String]
} yield assert(range)(equalTo(Chunk("hello", "world")))
},
test("lRange elements by exclusive range with negative indices") {
for {
redis <- ZIO.service[Redis]
key <- uuid
_ <- redis.lPush(key, "d", "c", "b", "a")
range <- redis.lRange(key, -3 until -1).returning[String]
} yield assert(range)(equalTo(Chunk("b", "c")))
},
test("lRange start out of bounds") {
for {
redis <- ZIO.service[Redis]
Expand Down
2 changes: 1 addition & 1 deletion modules/redis-it/src/test/scala/zio/redis/PubSubSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import zio.{Promise, ZIO}

import scala.util.Random

trait PubSubSpec extends BaseSpec {
trait PubSubSpec extends IntegrationSpec {
def pubSubSuite: Spec[Redis with RedisSubscription, RedisError] =
suite("pubSubs")(
suite("subscribe")(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import zio.test._

import scala.util.Random

trait ScriptingSpec extends BaseSpec {
trait ScriptingSpec extends IntegrationSpec {
def scriptingSpec: Spec[Redis, RedisError] =
suite("scripting")(
suite("eval")(
Expand Down
2 changes: 1 addition & 1 deletion modules/redis-it/src/test/scala/zio/redis/SetsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import zio.stream.ZStream
import zio.test.Assertion._
import zio.test._

trait SetsSpec extends BaseSpec {
trait SetsSpec extends IntegrationSpec {
def setsSuite: Spec[Redis, RedisError] =
suite("sets")(
suite("sAdd")(
Expand Down
Loading

0 comments on commit 94e3651

Please sign in to comment.