From 04958784ec339f9548b576bce75581c515a99c5f Mon Sep 17 00:00:00 2001 From: Igor Artamonov Date: Mon, 29 Jun 2020 21:49:01 -0400 Subject: [PATCH] problem: tries to connect to Redis even if specified as disabled --- .../dshackle/config/CacheConfigReader.kt | 27 ++++++++++--------- .../config/CacheConfigReaderSpec.groovy | 11 ++++++++ src/test/resources/cache-redis-disabled.yaml | 7 +++++ 3 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 src/test/resources/cache-redis-disabled.yaml diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/CacheConfigReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/CacheConfigReader.kt index bcc49786..38a40ab6 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/CacheConfigReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/CacheConfigReader.kt @@ -35,19 +35,22 @@ class CacheConfigReader : YamlConfigReader(), ConfigReader { val config = CacheConfig() getMapping(node, "redis")?.let { node -> val redis = CacheConfig.Redis() - getValueAsString(node, "host")?.let { - redis.host = it + val enabled = getValueAsBool(node, "enabled") ?: true + if (enabled) { + getValueAsString(node, "host")?.let { + redis.host = it + } + getValueAsInt(node, "port")?.let { + redis.port = it + } + getValueAsInt(node, "db")?.let { + redis.db = it + } + getValueAsString(node, "password")?.let { + redis.password = it + } + config.redis = redis } - getValueAsInt(node, "port")?.let { - redis.port = it - } - getValueAsInt(node, "db")?.let { - redis.db = it - } - getValueAsString(node, "password")?.let { - redis.password = it - } - config.redis = redis } if (config.redis == null) { return null diff --git a/src/test/groovy/io/emeraldpay/dshackle/config/CacheConfigReaderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/config/CacheConfigReaderSpec.groovy index 2c20a3b6..8b0901ed 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/config/CacheConfigReaderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/config/CacheConfigReaderSpec.groovy @@ -36,4 +36,15 @@ class CacheConfigReaderSpec extends Specification { password == "HelloWorld!1" } } + + def "Read disabled"() { + setup: + def config = this.class.getClassLoader().getResourceAsStream("cache-redis-disabled.yaml") + when: + def act = reader.read(config) + + then: + //later may be not null if we support something else besides Redis + act == null + } } diff --git a/src/test/resources/cache-redis-disabled.yaml b/src/test/resources/cache-redis-disabled.yaml new file mode 100644 index 00000000..939cbcb9 --- /dev/null +++ b/src/test/resources/cache-redis-disabled.yaml @@ -0,0 +1,7 @@ +cache: + redis: + enabled: false + host: redis-master + port: 1234 + db: 5 + password: HelloWorld!1 \ No newline at end of file