mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-21 20:18:05 +01:00
Estimate message byte limit exceeded error count
This commit is contained in:
@@ -100,6 +100,7 @@ import org.whispersystems.textsecuregcm.entities.StaleDevices;
|
||||
import org.whispersystems.textsecuregcm.identity.AciServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.identity.PniServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.identity.ServiceIdentifier;
|
||||
import org.whispersystems.textsecuregcm.limits.CardinalityEstimator;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimiter;
|
||||
import org.whispersystems.textsecuregcm.limits.RateLimiters;
|
||||
import org.whispersystems.textsecuregcm.mappers.RateLimitExceededExceptionMapper;
|
||||
@@ -161,6 +162,7 @@ class MessageControllerTest {
|
||||
private static final DeletedAccounts deletedAccounts = mock(DeletedAccounts.class);
|
||||
private static final MessagesManager messagesManager = mock(MessagesManager.class);
|
||||
private static final RateLimiters rateLimiters = mock(RateLimiters.class);
|
||||
private static final CardinalityEstimator cardinalityEstimator = mock(CardinalityEstimator.class);
|
||||
private static final RateLimiter rateLimiter = mock(RateLimiter.class);
|
||||
private static final PushNotificationManager pushNotificationManager = mock(PushNotificationManager.class);
|
||||
private static final ReportMessageManager reportMessageManager = mock(ReportMessageManager.class);
|
||||
@@ -177,7 +179,7 @@ class MessageControllerTest {
|
||||
.addProvider(MultiRecipientMessageProvider.class)
|
||||
.setTestContainerFactory(new GrizzlyWebTestContainerFactory())
|
||||
.addResource(
|
||||
new MessageController(rateLimiters, messageSender, receiptSender, accountsManager, deletedAccounts,
|
||||
new MessageController(rateLimiters, cardinalityEstimator, messageSender, receiptSender, accountsManager, deletedAccounts,
|
||||
messagesManager, pushNotificationManager, reportMessageManager, multiRecipientMessageExecutor,
|
||||
messageDeliveryScheduler, ReportSpamTokenProvider.noop(), mock(ClientReleaseManager.class), dynamicConfigurationManager))
|
||||
.build();
|
||||
@@ -247,6 +249,7 @@ class MessageControllerTest {
|
||||
messagesManager,
|
||||
rateLimiters,
|
||||
rateLimiter,
|
||||
cardinalityEstimator,
|
||||
pushNotificationManager,
|
||||
reportMessageManager,
|
||||
multiRecipientMessageExecutor
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2023 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.limits;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.whispersystems.textsecuregcm.redis.FaultTolerantRedisCluster;
|
||||
import org.whispersystems.textsecuregcm.redis.RedisClusterExtension;
|
||||
import java.time.Duration;
|
||||
|
||||
public class CardinalityEstimatorTest {
|
||||
|
||||
@RegisterExtension
|
||||
private static final RedisClusterExtension REDIS_CLUSTER_EXTENSION = RedisClusterExtension.builder().build();
|
||||
|
||||
@Test
|
||||
public void testAdd() throws Exception {
|
||||
final FaultTolerantRedisCluster redisCluster = REDIS_CLUSTER_EXTENSION.getRedisCluster();
|
||||
final CardinalityEstimator estimator = new CardinalityEstimator(redisCluster, "test", Duration.ofSeconds(1));
|
||||
|
||||
estimator.add("1");
|
||||
|
||||
long count = redisCluster.withCluster(conn -> conn.sync().pfcount("cardinality_estimator::test"));
|
||||
assertThat(count).isEqualTo(1).isEqualTo(estimator.estimate());
|
||||
|
||||
estimator.add("2");
|
||||
count = redisCluster.withCluster(conn -> conn.sync().pfcount("cardinality_estimator::test"));
|
||||
assertThat(count).isEqualTo(2).isEqualTo(estimator.estimate());
|
||||
|
||||
estimator.add("1");
|
||||
count = redisCluster.withCluster(conn -> conn.sync().pfcount("cardinality_estimator::test"));
|
||||
assertThat(count).isEqualTo(2).isEqualTo(estimator.estimate());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Timeout(5)
|
||||
public void testEventuallyExpires() throws InterruptedException {
|
||||
final FaultTolerantRedisCluster redisCluster = REDIS_CLUSTER_EXTENSION.getRedisCluster();
|
||||
final CardinalityEstimator estimator = new CardinalityEstimator(redisCluster, "test", Duration.ofMillis(100));
|
||||
estimator.add("1");
|
||||
long count;
|
||||
do {
|
||||
count = redisCluster.withCluster(conn -> conn.sync().pfcount("cardinality_estimator::test"));
|
||||
Thread.sleep(1);
|
||||
} while (count != 0);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user