From 77460ba5029889581b68d575b64ba397c27fcb91 Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Thu, 13 Aug 2020 14:03:02 -0400 Subject: [PATCH] Remove keyspace notification configuration checks because AWS doesn't support `CONFIG GET`. --- .../push/ClientPresenceManager.java | 3 -- .../storage/RedisClusterMessagesCache.java | 2 - .../textsecuregcm/util/RedisClusterUtil.java | 24 --------- .../util/RedisClusterUtilTest.java | 50 +------------------ 4 files changed, 1 insertion(+), 78 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/push/ClientPresenceManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/push/ClientPresenceManager.java index c6c01c074..7d29b868f 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/push/ClientPresenceManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/push/ClientPresenceManager.java @@ -17,7 +17,6 @@ import org.slf4j.LoggerFactory; import org.whispersystems.textsecuregcm.redis.ClusterLuaScript; import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisCluster; import org.whispersystems.textsecuregcm.util.Constants; -import org.whispersystems.textsecuregcm.util.RedisClusterUtil; import java.io.IOException; import java.time.Duration; @@ -82,8 +81,6 @@ public class ClientPresenceManager extends RedisClusterPubSubAdapter { connection.addListener(this); connection.getResources().eventBus().get() diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/RedisClusterMessagesCache.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/RedisClusterMessagesCache.java index 3e8b63559..f9b8aa7fd 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/RedisClusterMessagesCache.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/RedisClusterMessagesCache.java @@ -78,8 +78,6 @@ public class RedisClusterMessagesCache extends RedisClusterPubSubAdapter { connection.addListener(this); connection.getResources().eventBus().get() diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/util/RedisClusterUtil.java b/service/src/main/java/org/whispersystems/textsecuregcm/util/RedisClusterUtil.java index 803ff7b86..db76e2839 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/util/RedisClusterUtil.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/util/RedisClusterUtil.java @@ -1,7 +1,6 @@ package org.whispersystems.textsecuregcm.util; import io.lettuce.core.cluster.SlotHash; -import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisCluster; public class RedisClusterUtil { @@ -34,27 +33,4 @@ public class RedisClusterUtil { public static String getMinimalHashTag(final int slot) { return HASHES_BY_SLOT[slot]; } - - /** - * Asserts that a Redis cluster is configured to generate (at least) a specific set of keyspace notification events. - * - * @param redisCluster the Redis cluster to check for the required keyspace notification configuration - * @param requiredKeyspaceNotifications a string representing the required keyspace notification events (e.g. "Kg$lz") - * - * @throws IllegalStateException if the given Redis cluster is not configured to generate the required keyspace - * notification events - * - * @see Redis Keyspace Notifications - Configuration - */ - public static void assertKeyspaceNotificationsConfigured(final FaultTolerantRedisCluster redisCluster, final String requiredKeyspaceNotifications) { - final String configuredKeyspaceNotifications = redisCluster.withReadCluster(connection -> connection.sync().configGet("notify-keyspace-events")) - .getOrDefault("notify-keyspace-events", "") - .replace("A", "g$lshztxe"); - - for (final char requiredNotificationType : requiredKeyspaceNotifications.toCharArray()) { - if (configuredKeyspaceNotifications.indexOf(requiredNotificationType) == -1) { - throw new IllegalStateException(String.format("Required at least \"%s\" for keyspace notifications, but only had \"%s\".", requiredKeyspaceNotifications, configuredKeyspaceNotifications)); - } - } - } } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/util/RedisClusterUtilTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/util/RedisClusterUtilTest.java index f4d144ab8..ab8901367 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/util/RedisClusterUtilTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/util/RedisClusterUtilTest.java @@ -1,26 +1,10 @@ package org.whispersystems.textsecuregcm.util; import io.lettuce.core.cluster.SlotHash; -import io.lettuce.core.cluster.api.sync.Executions; -import io.lettuce.core.cluster.api.sync.NodeSelection; -import io.lettuce.core.cluster.api.sync.NodeSelectionCommands; -import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands; -import io.lettuce.core.cluster.models.partitions.RedisClusterNode; -import junitparams.JUnitParamsRunner; -import junitparams.Parameters; import org.junit.Test; -import org.junit.runner.RunWith; -import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisCluster; -import org.whispersystems.textsecuregcm.tests.util.RedisClusterHelper; -import redis.embedded.Redis; -import java.util.Map; +import static org.junit.Assert.assertEquals; -import static org.junit.Assert.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -@RunWith(JUnitParamsRunner.class) public class RedisClusterUtilTest { @Test @@ -29,36 +13,4 @@ public class RedisClusterUtilTest { assertEquals(slot, SlotHash.getSlot(RedisClusterUtil.getMinimalHashTag(slot))); } } - - @SuppressWarnings("unchecked") - @Test - @Parameters(method = "argumentsForTestAssertKeyspaceNotificationsConfigured") - public void testAssertKeyspaceNotificationsConfigured(final String requiredKeyspaceNotifications, final String configuerdKeyspaceNotifications, final boolean expectException) { - final RedisAdvancedClusterCommands commands = mock(RedisAdvancedClusterCommands.class); - final FaultTolerantRedisCluster redisCluster = RedisClusterHelper.buildMockRedisCluster(commands); - - when(commands.configGet("notify-keyspace-events")).thenReturn(Map.of("notify-keyspace-events", configuerdKeyspaceNotifications)); - - if (expectException) { - try { - RedisClusterUtil.assertKeyspaceNotificationsConfigured(redisCluster, requiredKeyspaceNotifications); - fail("Expected IllegalStateException"); - } catch (final IllegalStateException ignored) { - } - } else { - RedisClusterUtil.assertKeyspaceNotificationsConfigured(redisCluster, requiredKeyspaceNotifications); - } - } - - @SuppressWarnings("unused") - private Object argumentsForTestAssertKeyspaceNotificationsConfigured() { - return new Object[] { - new Object[] { "K$gz", "", true }, - new Object[] { "K$gz", "K$gz", false }, - new Object[] { "K$gz", "K$gzl", false }, - new Object[] { "K$gz", "KA", false }, - new Object[] { "", "A", false }, - new Object[] { "", "", false }, - }; - } }