From 61faa02e75d9145040436a5c05262c19fb42ca4d Mon Sep 17 00:00:00 2001 From: Gonzalo Gallotti Date: Thu, 12 May 2022 15:20:01 -0300 Subject: [PATCH 01/10] Redis connection not supporting some urls. Added UnitTesting --- .../com/genexus/cache/redis/RedisClient.java | 178 +++++++----------- .../cache/redis/TestRedisCacheClient.java | 97 ++++++++++ 2 files changed, 165 insertions(+), 110 deletions(-) create mode 100644 java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java diff --git a/java/src/main/java/com/genexus/cache/redis/RedisClient.java b/java/src/main/java/com/genexus/cache/redis/RedisClient.java index 1d65a2523..c0f62f713 100644 --- a/java/src/main/java/com/genexus/cache/redis/RedisClient.java +++ b/java/src/main/java/com/genexus/cache/redis/RedisClient.java @@ -3,6 +3,7 @@ import java.io.Closeable; import java.io.IOException; import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.List; @@ -26,86 +27,83 @@ import redis.clients.jedis.Pipeline; -public class RedisClient implements ICacheService2, Closeable{ +public class RedisClient implements ICacheService2, Closeable { public static final ILogger logger = LogManager.getLogger(RedisClient.class); private String keyPattern = "%s_%s_%s"; //Namespace_KEY private static int UNDEFINED_PORT = -1; private static int REDIS_DEFAULT_PORT = 6379; private JedisPool pool; - private ObjectMapper objMapper; - public RedisClient() throws IOException { + private ObjectMapper objMapper; + + + public RedisClient() throws Exception { initCache(); } - private void initCache() throws IOException { - objMapper = new ObjectMapper(); - objMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); - objMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); - objMapper.enable(SerializationFeature.INDENT_OUTPUT); + public RedisClient(String hostOrRedisURL, String password, String cacheKeyPattern) throws Exception { + initCache(hostOrRedisURL, password, cacheKeyPattern); + } + private void initCache() throws Exception { GXService providerService = Application.getGXServices().get(GXServices.CACHE_SERVICE); String addresses = providerService.getProperties().get("CACHE_PROVIDER_ADDRESS"); String cacheKeyPattern = providerService.getProperties().get("CACHE_PROVIDER_KEYPATTERN"); String password = providerService.getProperties().get("CACHE_PROVIDER_PASSWORD"); + initCache(addresses, password, cacheKeyPattern); + } - if (!isNullOrEmpty(cacheKeyPattern)) - keyPattern = cacheKeyPattern; - - if (!isNullOrEmpty(addresses)){ + private void initCache(String hostOrRedisURL, String password, String cacheKeyPattern) throws Exception { + keyPattern = isNullOrEmpty(cacheKeyPattern) ? keyPattern : cacheKeyPattern; + String host = "127.0.0.1"; + hostOrRedisURL = isNullOrEmpty(hostOrRedisURL) ? host: hostOrRedisURL; + int port = REDIS_DEFAULT_PORT; - if (!isNullOrEmpty(password)) { + boolean isRedisURIScheme = hostOrRedisURL.startsWith("redis://"); + String sRedisURI = isRedisURIScheme ? hostOrRedisURL : "redis://" + hostOrRedisURL; - addresses = "redis://:" + password.trim() + "@" + addresses.trim(); - try { - URI redisUri = new URI(addresses); - if (redisUri.getPort()==UNDEFINED_PORT){ - redisUri = new URI(addresses + ":" + REDIS_DEFAULT_PORT); - } - pool = new JedisPool(new JedisPoolConfig(), redisUri); - }catch (java.net.URISyntaxException ex){ - logger.error("Invalid redis uri " + addresses, ex); - } + try { + URI redisURI = new URI(sRedisURI); + host = redisURI.getHost(); + if (redisURI.getPort() > 0) { + port = redisURI.getPort(); } - }else{ - addresses ="127.0.0.1:" + REDIS_DEFAULT_PORT; + } catch (URISyntaxException e) { + logger.error(String.format("Could not parse Redis URL. Check for supported URLs: %s" + sRedisURI), e); + throw e; + } + + password = (!isNullOrEmpty(password)) ? password : null; + + pool = new JedisPool(new JedisPoolConfig(), host, port, redis.clients.jedis.Protocol.DEFAULT_TIMEOUT, password); + try (Jedis j = pool.getResource()) { + //Test connection } - if (pool == null) - pool = new JedisPool(new JedisPoolConfig(), addresses); + + objMapper = new ObjectMapper(); + objMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); + objMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + objMapper.enable(SerializationFeature.INDENT_OUTPUT); } - + private boolean isNullOrEmpty(String s) { return s == null || s.trim().length() == 0; } private Boolean containsKey(String key) { - Jedis jedis = null; - try { - jedis = pool.getResource(); + try (Jedis jedis = pool.getResource()) { return jedis.exists(key); } catch (Exception e) { logger.error("Contains failed", e); } - finally { - close(jedis); - } return false; } - private void close(Jedis jedis) { - if (jedis != null) - { - jedis.close(); - } - } - private void set(String key, T value) { set(key, value, 0); } private void set(String key, T value, int expirationSeconds) { - Jedis jedis = null; - try { - jedis = pool.getResource(); + try (Jedis jedis = pool.getResource()) { String valueJSON = objMapper.writeValueAsString(value); if (expirationSeconds > 0) jedis.setex(key, expirationSeconds, valueJSON); @@ -113,18 +111,13 @@ private void set(String key, T value, int expirationSeconds) { jedis.set(key, valueJSON); } catch (Exception e) { logger.error("Set with TTL failed", e); - } - finally { - close(jedis); } } public void setAll(String cacheid, String[] keys, T[] values, int expirationSeconds) { - Jedis jedis = null; - try { - if (keys!=null && values!=null && keys.length == values.length) { + try (Jedis jedis = pool.getResource()) { + if (keys != null && values != null && keys.length == values.length) { String[] prefixedKeys = getKey(cacheid, keys); - jedis = pool.getResource(); Pipeline p = jedis.pipelined(); int idx = 0; for (String key : prefixedKeys) { @@ -140,43 +133,31 @@ public void setAll(String cacheid, String[] keys, T[] values, int expiration } catch (Exception e) { logger.error("SetAll with TTL failed", e); } - finally { - close(jedis); - } } private T get(String key, Class type) { - Jedis jedis = null; - try { - jedis = pool.getResource(); + try (Jedis jedis = pool.getResource()) { String json = jedis.get(key); - if (StringUtils.isNotEmpty(json)) - { - return objMapper.readValue(json, type); - } - else - { + if (StringUtils.isNotEmpty(json)) { + return objMapper.readValue(json, type); + } else { return null; } } catch (Exception e) { logger.error("Get Item failed", e); } - finally { - close(jedis); - } return null; } - public List getAll(String cacheid, String[] keys, Class type){ + + public List getAll(String cacheid, String[] keys, Class type) { List result = null; - Jedis jedis = null; - try { + try (Jedis jedis = pool.getResource()) { String[] prefixedKeys = getKey(cacheid, keys); - jedis = pool.getResource(); List json = jedis.mget(prefixedKeys); result = new ArrayList(); - for (String val: json) { + for (String val : json) { if (val != null) - result.add(objMapper.readValue(val, type)); + result.add(objMapper.readValue(val, type)); else result.add(null); } @@ -184,12 +165,9 @@ public List getAll(String cacheid, String[] keys, Class type){ } catch (Exception e) { logger.error("Get Item failed", e); } - finally { - close(jedis); - } return null; } - + public boolean containtsKey(String cacheid, String key) { return containsKey(getKey(cacheid, key)); @@ -198,7 +176,7 @@ public boolean containtsKey(String cacheid, String key) { public T get(String cacheid, String key, Class type) { return get(getKey(cacheid, key), type); } - + public void set(String cacheid, String key, T value) { set(getKey(cacheid, key), value); @@ -209,72 +187,51 @@ public void set(String cacheid, String key, T value, int duration) { } public void clear(String cacheid, String key) { - Jedis jedis = null; - try { - jedis = pool.getResource(); + try (Jedis jedis = pool.getResource()) { jedis.del(getKey(cacheid, key)); } catch (Exception e) { logger.error("Remove Item failed", e); } - finally { - close(jedis); - } } public void clearCache(String cacheid) { - Jedis jedis = null; - try { - jedis = pool.getResource(); - jedis.incr(cacheid); + try (Jedis jedis = pool.getResource()) { + jedis.incr(cacheid); } catch (Exception e) { logger.error("clearCache failed", e); } - finally { - close(jedis); - } } public void clearKey(String key) { - Jedis jedis = null; - try { - jedis = pool.getResource(); - jedis.del(key); + try (Jedis jedis = pool.getResource()) { + jedis.del(key); } catch (Exception e) { logger.error("Remove Item failed", e); } - finally { - close(jedis); - } } public void clearAllCaches() { - Jedis jedis = null; - try { - jedis = pool.getResource(); - jedis.flushAll(); + try (Jedis jedis = pool.getResource()) { + jedis.flushAll(); } catch (Exception e) { logger.error("Clear All Caches failed", e); } - finally { - close(jedis); - } } private String getKey(String cacheid, String key) { return String.format(keyPattern, cacheid, getKeyPrefix(cacheid), com.genexus.CommonUtil.getHash(key)); } - private String[] getKey(String cacheid, String[] keys) - { + private String[] getKey(String cacheid, String[] keys) { Long prefix = getKeyPrefix(cacheid); String[] prefixedKeys = new String[keys.length]; - for (int idx =0; idx Date: Thu, 12 May 2022 15:26:16 -0300 Subject: [PATCH 02/10] Prepare for Guthub action testing --- .../com/genexus/cache/redis/TestRedisCacheClient.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java b/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java index 8c87323bc..9347e836f 100644 --- a/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java +++ b/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java @@ -8,10 +8,15 @@ import org.junit.Test; public class TestRedisCacheClient { - public static final Logger logger = LogManager.getLogger(TestRedisCacheClient.class); + private static final Logger logger = LogManager.getLogger(TestRedisCacheClient.class); + private String redisHostName = "localhost"; @Before public void beforeTest() { + String envRedisHostName = System.getenv("REDIS_HOST_NAME"); + if (envRedisHostName != null && !envRedisHostName.isEmpty()) { + redisHostName = envRedisHostName.toString(); + } Connect.init(); com.genexus.specific.java.LogManager.initialize("."); } @@ -63,6 +68,8 @@ public void connect_default_host_port() private RedisClient getRedisClient(String hostOrUrl, String password) { RedisClient redis = null; + hostOrUrl = hostOrUrl.replace("localhost", redisHostName); + try { redis = new RedisClient(hostOrUrl, password, "UNIT"); } catch (Exception e) { From 2edd4c501889688137e524dc89208f9da22d0ba2 Mon Sep 17 00:00:00 2001 From: Gonzalo Gallotti Date: Thu, 12 May 2022 15:37:32 -0300 Subject: [PATCH 03/10] Add CI Testing --- .github/workflows/RedisTests.yml | 59 +++++++++++++++++++ .../cache/redis/TestRedisCacheClient.java | 11 ++-- 2 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/RedisTests.yml diff --git a/.github/workflows/RedisTests.yml b/.github/workflows/RedisTests.yml new file mode 100644 index 000000000..74afbaa28 --- /dev/null +++ b/.github/workflows/RedisTests.yml @@ -0,0 +1,59 @@ +name: External Storage Tests + +on: + workflow_dispatch: + pull_request: + branches: + - 'master' + - 'release-*' + push: + branches: + - 'master' + - 'beta' + - 'release-*' + - 'beta-corona' + schedule: + - cron: '0 0 * * 1' # At 00:00 on (every) Monday + +jobs: + test-redis: + name: Test Redis Client + env: + GIT_REF: ${{ github.ref }} + GIT_SHA: ${{ github.sha }} + POM_PATH: ./pom.xml + + runs-on: ubuntu-latest + strategy: + matrix: + redis-version: [ 4, 5, 6 ] + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - name: Setup Java JDK + uses: actions/setup-java@v1.4.3 + with: + java-version: 1.9 + + - name: Setup Maven settings + uses: whelk-io/maven-settings-xml-action@v14 + with: + repositories: '[{ "id": "github-genexuslabs", "url": "https://maven.pkg.github.com/genexuslabs/Private-Maven-for-GX", "releases": { "enabled": "true" }, "snapshots": { "enabled": "true" } }]' + servers: '[{ "id": "github-genexuslabs", "username": "genexusbot", "password": "${{ secrets.SECURE_TOKEN }}" }]' + + - name: Start Redis + uses: supercharge/redis-github-action@1.4.0 + with: + redis-version: ${{ matrix.redis-version }} + + - name: Install + run: mvn -B install --file $POM_PATH + + - name: Test Redis + run: | + export REDIS_HOST_NAME=redis + mvn -B -pl java test --file $POM_PATH diff --git a/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java b/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java index 9347e836f..ff708890a 100644 --- a/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java +++ b/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java @@ -7,16 +7,17 @@ import org.junit.Before; import org.junit.Test; +import static org.junit.Assume.assumeTrue; + public class TestRedisCacheClient { private static final Logger logger = LogManager.getLogger(TestRedisCacheClient.class); private String redisHostName = "localhost"; @Before public void beforeTest() { - String envRedisHostName = System.getenv("REDIS_HOST_NAME"); - if (envRedisHostName != null && !envRedisHostName.isEmpty()) { - redisHostName = envRedisHostName.toString(); - } + redisHostName = System.getenv("REDIS_HOST_NAME"); + assumeTrue( redisHostName != null ); + Connect.init(); com.genexus.specific.java.LogManager.initialize("."); } @@ -69,7 +70,7 @@ private RedisClient getRedisClient(String hostOrUrl, String password) { RedisClient redis = null; hostOrUrl = hostOrUrl.replace("localhost", redisHostName); - + try { redis = new RedisClient(hostOrUrl, password, "UNIT"); } catch (Exception e) { From 6a0f9ceff894ce17c286030f270b406401ec511b Mon Sep 17 00:00:00 2001 From: Gonzalo Gallotti Date: Thu, 12 May 2022 15:39:03 -0300 Subject: [PATCH 04/10] Rename test --- .github/workflows/RedisTests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/RedisTests.yml b/.github/workflows/RedisTests.yml index 74afbaa28..9a8f0e254 100644 --- a/.github/workflows/RedisTests.yml +++ b/.github/workflows/RedisTests.yml @@ -1,4 +1,4 @@ -name: External Storage Tests +name: Redis Cache Tests on: workflow_dispatch: @@ -17,7 +17,7 @@ on: jobs: test-redis: - name: Test Redis Client + name: Test Redis Cache env: GIT_REF: ${{ github.ref }} GIT_SHA: ${{ github.sha }} From c34136b0217a010a3f00b0b0ca7fcab9666fd5a1 Mon Sep 17 00:00:00 2001 From: Gonzalo Gallotti Date: Thu, 12 May 2022 15:40:27 -0300 Subject: [PATCH 05/10] Only redis 6 --- .github/workflows/RedisTests.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/RedisTests.yml b/.github/workflows/RedisTests.yml index 9a8f0e254..e1c1baee5 100644 --- a/.github/workflows/RedisTests.yml +++ b/.github/workflows/RedisTests.yml @@ -12,8 +12,6 @@ on: - 'beta' - 'release-*' - 'beta-corona' - schedule: - - cron: '0 0 * * 1' # At 00:00 on (every) Monday jobs: test-redis: @@ -26,7 +24,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - redis-version: [ 4, 5, 6 ] + redis-version: [ 6 ] steps: - name: Checkout From 69735673f48e44dbdd5458fd4faf8850cf6071e6 Mon Sep 17 00:00:00 2001 From: Gonzalo Gallotti Date: Thu, 12 May 2022 15:51:32 -0300 Subject: [PATCH 06/10] CI redis --- .github/workflows/RedisTests.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/RedisTests.yml b/.github/workflows/RedisTests.yml index e1c1baee5..99135c794 100644 --- a/.github/workflows/RedisTests.yml +++ b/.github/workflows/RedisTests.yml @@ -11,7 +11,6 @@ on: - 'master' - 'beta' - 'release-*' - - 'beta-corona' jobs: test-redis: @@ -53,5 +52,5 @@ jobs: - name: Test Redis run: | - export REDIS_HOST_NAME=redis + export REDIS_HOST_NAME=localhost mvn -B -pl java test --file $POM_PATH From 6066b3ad88f779c8fbb142a063925ddb6d377367 Mon Sep 17 00:00:00 2001 From: Gonzalo Gallotti Date: Thu, 12 May 2022 15:53:52 -0300 Subject: [PATCH 07/10] Change ci order --- .github/workflows/RedisTests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/RedisTests.yml b/.github/workflows/RedisTests.yml index 99135c794..306447d12 100644 --- a/.github/workflows/RedisTests.yml +++ b/.github/workflows/RedisTests.yml @@ -42,14 +42,14 @@ jobs: repositories: '[{ "id": "github-genexuslabs", "url": "https://maven.pkg.github.com/genexuslabs/Private-Maven-for-GX", "releases": { "enabled": "true" }, "snapshots": { "enabled": "true" } }]' servers: '[{ "id": "github-genexuslabs", "username": "genexusbot", "password": "${{ secrets.SECURE_TOKEN }}" }]' + - name: Install + run: mvn -B install --file $POM_PATH + - name: Start Redis uses: supercharge/redis-github-action@1.4.0 with: redis-version: ${{ matrix.redis-version }} - - name: Install - run: mvn -B install --file $POM_PATH - - name: Test Redis run: | export REDIS_HOST_NAME=localhost From 932e811b3fef7f0f3ce9bcf8e9e886da1eb928eb Mon Sep 17 00:00:00 2001 From: Gonzalo Gallotti Date: Thu, 12 May 2022 15:58:12 -0300 Subject: [PATCH 08/10] Minor improvements --- .github/workflows/RedisTests.yml | 2 +- java/src/main/java/com/genexus/cache/redis/RedisClient.java | 2 -- .../java/com/genexus/cache/redis/TestRedisCacheClient.java | 6 +----- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/RedisTests.yml b/.github/workflows/RedisTests.yml index 306447d12..2ff14341d 100644 --- a/.github/workflows/RedisTests.yml +++ b/.github/workflows/RedisTests.yml @@ -52,5 +52,5 @@ jobs: - name: Test Redis run: | - export REDIS_HOST_NAME=localhost + export EXECUTE_REDIS_TESTS=true mvn -B -pl java test --file $POM_PATH diff --git a/java/src/main/java/com/genexus/cache/redis/RedisClient.java b/java/src/main/java/com/genexus/cache/redis/RedisClient.java index c0f62f713..cceb0f8a1 100644 --- a/java/src/main/java/com/genexus/cache/redis/RedisClient.java +++ b/java/src/main/java/com/genexus/cache/redis/RedisClient.java @@ -30,12 +30,10 @@ public class RedisClient implements ICacheService2, Closeable { public static final ILogger logger = LogManager.getLogger(RedisClient.class); private String keyPattern = "%s_%s_%s"; //Namespace_KEY - private static int UNDEFINED_PORT = -1; private static int REDIS_DEFAULT_PORT = 6379; private JedisPool pool; private ObjectMapper objMapper; - public RedisClient() throws Exception { initCache(); } diff --git a/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java b/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java index ff708890a..1538560e7 100644 --- a/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java +++ b/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java @@ -11,12 +11,10 @@ public class TestRedisCacheClient { private static final Logger logger = LogManager.getLogger(TestRedisCacheClient.class); - private String redisHostName = "localhost"; @Before public void beforeTest() { - redisHostName = System.getenv("REDIS_HOST_NAME"); - assumeTrue( redisHostName != null ); + assumeTrue( System.getenv("EXECUTE_REDIS_TESTS") != null ); Connect.init(); com.genexus.specific.java.LogManager.initialize("."); @@ -69,8 +67,6 @@ public void connect_default_host_port() private RedisClient getRedisClient(String hostOrUrl, String password) { RedisClient redis = null; - hostOrUrl = hostOrUrl.replace("localhost", redisHostName); - try { redis = new RedisClient(hostOrUrl, password, "UNIT"); } catch (Exception e) { From d7093b6078e58bdf8fb1c2b5a4d9d65794ffdd0b Mon Sep 17 00:00:00 2001 From: Gonzalo Gallotti Date: Fri, 13 May 2022 10:51:31 -0300 Subject: [PATCH 09/10] Do not check connection on Redis Startup to keep compatibility --- .../java/com/genexus/cache/redis/RedisClient.java | 15 ++++++++------- .../genexus/cache/redis/TestRedisCacheClient.java | 13 +++++++++++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/java/src/main/java/com/genexus/cache/redis/RedisClient.java b/java/src/main/java/com/genexus/cache/redis/RedisClient.java index cceb0f8a1..cbb1453c3 100644 --- a/java/src/main/java/com/genexus/cache/redis/RedisClient.java +++ b/java/src/main/java/com/genexus/cache/redis/RedisClient.java @@ -34,15 +34,19 @@ public class RedisClient implements ICacheService2, Closeable { private JedisPool pool; private ObjectMapper objMapper; - public RedisClient() throws Exception { + public RedisClient() throws URISyntaxException { initCache(); } - public RedisClient(String hostOrRedisURL, String password, String cacheKeyPattern) throws Exception { + public RedisClient(String hostOrRedisURL, String password, String cacheKeyPattern) throws URISyntaxException { initCache(hostOrRedisURL, password, cacheKeyPattern); } - private void initCache() throws Exception { + public JedisPool getConnection() { + return pool; + } + + private void initCache() throws URISyntaxException { GXService providerService = Application.getGXServices().get(GXServices.CACHE_SERVICE); String addresses = providerService.getProperties().get("CACHE_PROVIDER_ADDRESS"); String cacheKeyPattern = providerService.getProperties().get("CACHE_PROVIDER_KEYPATTERN"); @@ -50,7 +54,7 @@ private void initCache() throws Exception { initCache(addresses, password, cacheKeyPattern); } - private void initCache(String hostOrRedisURL, String password, String cacheKeyPattern) throws Exception { + private void initCache(String hostOrRedisURL, String password, String cacheKeyPattern) throws URISyntaxException { keyPattern = isNullOrEmpty(cacheKeyPattern) ? keyPattern : cacheKeyPattern; String host = "127.0.0.1"; hostOrRedisURL = isNullOrEmpty(hostOrRedisURL) ? host: hostOrRedisURL; @@ -73,9 +77,6 @@ private void initCache(String hostOrRedisURL, String password, String cacheKeyPa password = (!isNullOrEmpty(password)) ? password : null; pool = new JedisPool(new JedisPoolConfig(), host, port, redis.clients.jedis.Protocol.DEFAULT_TIMEOUT, password); - try (Jedis j = pool.getResource()) { - //Test connection - } objMapper = new ObjectMapper(); objMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); diff --git a/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java b/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java index 1538560e7..856886e59 100644 --- a/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java +++ b/java/src/test/java/com/genexus/cache/redis/TestRedisCacheClient.java @@ -6,6 +6,10 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; + +import java.net.URISyntaxException; import static org.junit.Assume.assumeTrue; @@ -66,13 +70,18 @@ public void connect_default_host_port() private RedisClient getRedisClient(String hostOrUrl, String password) { RedisClient redis = null; - try { redis = new RedisClient(hostOrUrl, password, "UNIT"); - } catch (Exception e) { + } catch (URISyntaxException e) { logger.debug("failed to create redis client", e); } + try (Jedis p = redis.getConnection().getResource()) { + } + catch (Exception e) { + logger.debug("failed to get redis resource", e); + redis = null; + } return redis; } From cb25e836fb298482b31daa047879c15c0e4c0bc3 Mon Sep 17 00:00:00 2001 From: Gonzalo Gallotti Date: Fri, 13 May 2022 13:58:58 -0300 Subject: [PATCH 10/10] Fix Log Output --- java/src/main/java/com/genexus/cache/redis/RedisClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/src/main/java/com/genexus/cache/redis/RedisClient.java b/java/src/main/java/com/genexus/cache/redis/RedisClient.java index cbb1453c3..003871ca7 100644 --- a/java/src/main/java/com/genexus/cache/redis/RedisClient.java +++ b/java/src/main/java/com/genexus/cache/redis/RedisClient.java @@ -70,7 +70,7 @@ private void initCache(String hostOrRedisURL, String password, String cacheKeyPa port = redisURI.getPort(); } } catch (URISyntaxException e) { - logger.error(String.format("Could not parse Redis URL. Check for supported URLs: %s" + sRedisURI), e); + logger.error(String.format("Could not parse Redis URL. Check for supported URLs: %s" , sRedisURI), e); throw e; }