This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit e3f9451ee97c6ad822d9b3627b50790ca300b1c0
Author: hung phan <[email protected]>
AuthorDate: Mon May 13 16:15:43 2024 +0700

    JAMES-3693 Update document for redis.readFrom
---
 .../james/backends/redis/RedisConfiguration.scala  |  2 +-
 .../backends/redis/RedisConfigurationTest.scala    | 24 +++++++++++++++++++++-
 .../docs/modules/ROOT/pages/configure/redis.adoc   |  5 +++++
 server/mailet/rate-limiter-redis/redis.properties  |  3 ++-
 4 files changed, 31 insertions(+), 3 deletions(-)

diff --git 
a/backends-common/redis/src/main/java/org/apache/james/backends/redis/RedisConfiguration.scala
 
b/backends-common/redis/src/main/java/org/apache/james/backends/redis/RedisConfiguration.scala
index 537774b6f0..5764c6f79f 100644
--- 
a/backends-common/redis/src/main/java/org/apache/james/backends/redis/RedisConfiguration.scala
+++ 
b/backends-common/redis/src/main/java/org/apache/james/backends/redis/RedisConfiguration.scala
@@ -45,7 +45,7 @@ object RedisConfiguration {
       case STANDALONE_TOPOLOGY => StandaloneRedisConfiguration.from(config)
       case CLUSTER_TOPOLOGY => ClusterRedisConfiguration.from(config)
       case MASTER_REPLICA_TOPOLOGY => 
MasterReplicaRedisConfiguration.from(config)
-      case _ => throw new NotImplementedError()
+      case _ => throw new IllegalArgumentException("Invalid topology")
     }
 
     LOGGER.info(s"Configured Redis with: ${redisConfiguration.asString}")
diff --git 
a/backends-common/redis/src/test/java/org/apache/james/backends/redis/RedisConfigurationTest.scala
 
b/backends-common/redis/src/test/java/org/apache/james/backends/redis/RedisConfigurationTest.scala
index f56e61c577..3a36c85169 100644
--- 
a/backends-common/redis/src/test/java/org/apache/james/backends/redis/RedisConfigurationTest.scala
+++ 
b/backends-common/redis/src/test/java/org/apache/james/backends/redis/RedisConfigurationTest.scala
@@ -31,11 +31,12 @@ class RedisConfigurationTest extends AnyFlatSpec with 
Matchers {
     val config = new PropertiesConfiguration()
     config.addProperty("redisURL", "redis://localhost:6379")
     config.addProperty("redis.topology", "master-replica")
+    config.addProperty("redis.readFrom", "any")
     config.addProperty("redis.ioThreads", 16)
     config.addProperty("redis.workerThreads", 32)
 
     val redisConfig = RedisConfiguration.from(config)
-    redisConfig shouldEqual 
MasterReplicaRedisConfiguration.from(Array("redis://localhost:6379"), 
ReadFrom.MASTER, Some(16), Some(32))
+    redisConfig shouldEqual 
MasterReplicaRedisConfiguration.from(Array("redis://localhost:6379"), 
ReadFrom.ANY, Some(16), Some(32))
   }
 
   it should "parse multiple Redis URIs from config" in {
@@ -66,4 +67,25 @@ class RedisConfigurationTest extends AnyFlatSpec with 
Matchers {
       RedisConfiguration.from(config)
     }
   }
+
+  it should "throw exception for invalid Redis topology" in {
+    val config = new PropertiesConfiguration()
+    config.addProperty("redisURL", "redis://localhost:6379")
+    config.addProperty("redis.topology", "invalid")
+
+    intercept[IllegalArgumentException] {
+      RedisConfiguration.from(config)
+    }
+  }
+
+  it should "throw exception for invalid Redis readFrom" in {
+    val config = new PropertiesConfiguration()
+    config.addProperty("redisURL", "redis://localhost:6379")
+    config.addProperty("redis.topology", "master-replica")
+    config.addProperty("redis.readFrom", "invalid")
+
+    intercept[IllegalArgumentException] {
+      RedisConfiguration.from(config)
+    }
+  }
 }
\ No newline at end of file
diff --git 
a/server/apps/distributed-app/docs/modules/ROOT/pages/configure/redis.adoc 
b/server/apps/distributed-app/docs/modules/ROOT/pages/configure/redis.adoc
index 3a4bb1efa4..a67a3a964e 100644
--- a/server/apps/distributed-app/docs/modules/ROOT/pages/configure/redis.adoc
+++ b/server/apps/distributed-app/docs/modules/ROOT/pages/configure/redis.adoc
@@ -18,6 +18,11 @@ to get some examples and hints.
 | redis.topology
 | Redis server topology. Defaults to standalone. Possible values: standalone, 
cluster, master-replica
 
+| redis.readFrom
+| The property to determine how Lettuce routes read operations to Redis server 
with topologies other than standalone. Defaults to master. Possible values: 
master, masterPreferred, replica, replicaPreferred, any
+
+Reference: https://github.com/redis/lettuce/wiki/ReadFrom-Settings
+
 | redis.ioThreads
 | IO threads to be using for the underlying Netty networking resources. If 
unspecified driver defaults applies.
 
diff --git a/server/mailet/rate-limiter-redis/redis.properties 
b/server/mailet/rate-limiter-redis/redis.properties
index a8fe0af1cd..96c6019b26 100644
--- a/server/mailet/rate-limiter-redis/redis.properties
+++ b/server/mailet/rate-limiter-redis/redis.properties
@@ -1,2 +1,3 @@
 redisURL=redis://redis:6379
-redis.topology=standalone
\ No newline at end of file
+redis.topology=standalone
+#redis.readFrom=master
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to