Remove keyspace notification configuration checks because AWS doesn't support `CONFIG GET`.
This commit is contained in:
		
							parent
							
								
									72c6a4289e
								
							
						
					
					
						commit
						77460ba502
					
				| 
						 | 
				
			
			@ -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<String, Str
 | 
			
		|||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void start() {
 | 
			
		||||
        RedisClusterUtil.assertKeyspaceNotificationsConfigured(presenceCluster, "K$");
 | 
			
		||||
 | 
			
		||||
        presenceCluster.usePubSubConnection(connection -> {
 | 
			
		||||
            connection.addListener(this);
 | 
			
		||||
            connection.getResources().eventBus().get()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -78,8 +78,6 @@ public class RedisClusterMessagesCache extends RedisClusterPubSubAdapter<String,
 | 
			
		|||
        this.removeQueueScript        = ClusterLuaScript.fromResource(redisCluster, "lua/remove_queue.lua",          ScriptOutputType.STATUS);
 | 
			
		||||
        this.getQueuesToPersistScript = ClusterLuaScript.fromResource(redisCluster, "lua/get_queues_to_persist.lua", ScriptOutputType.MULTI);
 | 
			
		||||
 | 
			
		||||
        RedisClusterUtil.assertKeyspaceNotificationsConfigured(redisCluster, "K$gz");
 | 
			
		||||
 | 
			
		||||
        redisCluster.usePubSubConnection(connection -> {
 | 
			
		||||
            connection.addListener(this);
 | 
			
		||||
            connection.getResources().eventBus().get()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 <a href="https://redis.io/topics/notifications#configuration">Redis Keyspace Notifications - Configuration</a>
 | 
			
		||||
     */
 | 
			
		||||
    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));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<String, String> 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 },
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue