mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-21 06:28:04 +01:00
Clear each cluster node individually.
This commit is contained in:
committed by
Jon Chambers
parent
db9b7ca447
commit
0fbf31ec98
@@ -0,0 +1,54 @@
|
||||
package org.whispersystems.textsecuregcm.workers;
|
||||
|
||||
import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
|
||||
import org.junit.Test;
|
||||
import org.whispersystems.textsecuregcm.redis.AbstractRedisClusterTest;
|
||||
import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisCluster;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ClearCacheClusterCommandTest extends AbstractRedisClusterTest {
|
||||
|
||||
private static final int KEY_COUNT = 10_000;
|
||||
|
||||
@Test
|
||||
public void testClearCache() throws InterruptedException {
|
||||
final FaultTolerantRedisCluster cluster = getRedisCluster();
|
||||
|
||||
cluster.useWriteCluster(connection -> {
|
||||
final RedisAdvancedClusterCommands<String, String> clusterCommands = connection.sync();
|
||||
|
||||
for (int i = 0; i < KEY_COUNT; i++) {
|
||||
clusterCommands.set("key::" + i, String.valueOf(i));
|
||||
}
|
||||
});
|
||||
|
||||
{
|
||||
final AtomicInteger nodeCount = new AtomicInteger(0);
|
||||
|
||||
cluster.useWriteCluster(connection -> connection.sync().masters().asMap().forEach((node, commands) -> {
|
||||
assertTrue(commands.dbsize() > 0);
|
||||
nodeCount.incrementAndGet();
|
||||
}));
|
||||
|
||||
assertTrue(nodeCount.get() > 0);
|
||||
}
|
||||
|
||||
ClearCacheClusterCommand.clearCache(cluster);
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
{
|
||||
final AtomicInteger nodeCount = new AtomicInteger(0);
|
||||
|
||||
cluster.useWriteCluster(connection -> connection.sync().masters().asMap().forEach((node, commands) -> {
|
||||
assertEquals(0L, (long)commands.dbsize());
|
||||
nodeCount.incrementAndGet();
|
||||
}));
|
||||
|
||||
assertTrue(nodeCount.get() > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user