mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-02 11:46:53 +00:00
Use DynamoDB for change number waiting periods
DynamoDB is even simpler for integration tests.
This commit is contained in:
1 parent
23305e4460
commit
460e5cb499
14 files changed
+236
-90
No files matched your search
+9
-17
@@ -5,9 +5,9 @@
|
||||
|
||||
package org.whispersystems.textsecuregcm.storage;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
@@ -15,12 +15,13 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.whispersystems.textsecuregcm.redis.RedisClusterExtension;
|
||||
import org.whispersystems.textsecuregcm.storage.DynamoDbExtensionSchema.Tables;
|
||||
|
||||
class ChangeNumberWaitingPeriodManagerTest {
|
||||
|
||||
@RegisterExtension
|
||||
static final RedisClusterExtension REDIS_CLUSTER_EXTENSION = RedisClusterExtension.builder().build();
|
||||
static final DynamoDbExtension DYNAMO_DB_EXTENSION =
|
||||
new DynamoDbExtension(Tables.CHANGE_NUMBER_WAITING_PERIODS);
|
||||
|
||||
private static final Duration WAITING_PERIOD = Duration.ofDays(7);
|
||||
|
||||
@@ -29,7 +30,11 @@ class ChangeNumberWaitingPeriodManagerTest {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
changeNumberWaitingPeriodManager = new ChangeNumberWaitingPeriodManager(
|
||||
REDIS_CLUSTER_EXTENSION.getRedisCluster(), WAITING_PERIOD);
|
||||
new ChangeNumberWaitingPeriods(Tables.CHANGE_NUMBER_WAITING_PERIODS.tableName(),
|
||||
DYNAMO_DB_EXTENSION.getDynamoDbAsyncClient(),
|
||||
DYNAMO_DB_EXTENSION.getDynamoDbClient()),
|
||||
WAITING_PERIOD,
|
||||
Clock.systemUTC());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -54,17 +59,4 @@ class ChangeNumberWaitingPeriodManagerTest {
|
||||
|
||||
assertTrue(changeNumberWaitingPeriodManager.getWaitingPeriodRemaining(aci).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNoTtlException() throws Exception {
|
||||
final UUID aci = UUID.randomUUID();
|
||||
|
||||
changeNumberWaitingPeriodManager.handleAccountCreated(aci, Instant.now()).get(5, TimeUnit.SECONDS);
|
||||
|
||||
REDIS_CLUSTER_EXTENSION.getRedisCluster().useCluster(conn ->
|
||||
conn.sync().persist(ChangeNumberWaitingPeriodManager.key(aci)));
|
||||
|
||||
assertThrows(RuntimeException.class, () -> changeNumberWaitingPeriodManager.getWaitingPeriodRemaining(aci),
|
||||
"This is an impossible scenario, and it should throw an exception");
|
||||
}
|
||||
}
|
||||
+96
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 2026 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.storage;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.whispersystems.textsecuregcm.storage.DynamoDbExtensionSchema.Tables;
|
||||
|
||||
class ChangeNumberWaitingPeriodsTest {
|
||||
|
||||
@RegisterExtension
|
||||
static final DynamoDbExtension DYNAMO_DB_EXTENSION =
|
||||
new DynamoDbExtension(Tables.CHANGE_NUMBER_WAITING_PERIODS);
|
||||
|
||||
private ChangeNumberWaitingPeriods changeNumberWaitingPeriods;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
changeNumberWaitingPeriods = new ChangeNumberWaitingPeriods(
|
||||
Tables.CHANGE_NUMBER_WAITING_PERIODS.tableName(),
|
||||
DYNAMO_DB_EXTENSION.getDynamoDbAsyncClient(),
|
||||
DYNAMO_DB_EXTENSION.getDynamoDbClient());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getExpiration_unknownAci() throws Exception {
|
||||
assertTrue(changeNumberWaitingPeriods.getExpiration(UUID.randomUUID()).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void setAndGetExpiration() throws Exception {
|
||||
final UUID aci = UUID.randomUUID();
|
||||
// truncate to seconds because the TTL attribute stores epoch seconds
|
||||
final Instant expiration = Instant.now().plusSeconds(3600).truncatedTo(ChronoUnit.SECONDS);
|
||||
|
||||
changeNumberWaitingPeriods.setExpiration(aci, expiration).get();
|
||||
|
||||
final Optional<Instant> result = changeNumberWaitingPeriods.getExpiration(aci);
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(expiration, result.get());
|
||||
|
||||
assertTrue(changeNumberWaitingPeriods.getExpiration(UUID.randomUUID()).isEmpty(), "new UUID has no entry");
|
||||
}
|
||||
|
||||
@Test
|
||||
void setExpiration_overwritesExistingEntry() throws Exception {
|
||||
final UUID aci = UUID.randomUUID();
|
||||
final Instant first = Instant.now().plusSeconds(3600).truncatedTo(ChronoUnit.SECONDS);
|
||||
final Instant second = Instant.now().plusSeconds(7200).truncatedTo(ChronoUnit.SECONDS);
|
||||
|
||||
changeNumberWaitingPeriods.setExpiration(aci, first).get();
|
||||
|
||||
{
|
||||
final Optional<Instant> result = changeNumberWaitingPeriods.getExpiration(aci);
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(first, result.get());
|
||||
}
|
||||
|
||||
changeNumberWaitingPeriods.setExpiration(aci, second).get();
|
||||
|
||||
{
|
||||
final Optional<Instant> result = changeNumberWaitingPeriods.getExpiration(aci);
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals(second, result.get());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_removesExisting() throws Exception {
|
||||
final UUID aci = UUID.randomUUID();
|
||||
changeNumberWaitingPeriods.setExpiration(aci, Instant.now().plusSeconds(3600)).get();
|
||||
|
||||
assertTrue( changeNumberWaitingPeriods.getExpiration(aci).isPresent());
|
||||
|
||||
changeNumberWaitingPeriods.delete(aci);
|
||||
|
||||
assertTrue(changeNumberWaitingPeriods.getExpiration(aci).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_missingIsNoop() {
|
||||
assertDoesNotThrow(() -> changeNumberWaitingPeriods.delete(UUID.randomUUID()));
|
||||
}
|
||||
}
|
||||
+9
@@ -60,6 +60,15 @@ public final class DynamoDbExtensionSchema {
|
||||
.attributeType(ScalarAttributeType.B).build()),
|
||||
Collections.emptyList(), Collections.emptyList()),
|
||||
|
||||
CHANGE_NUMBER_WAITING_PERIODS("change_number_waiting_periods_test",
|
||||
ChangeNumberWaitingPeriods.KEY_ACCOUNT_UUID,
|
||||
null,
|
||||
List.of(AttributeDefinition.builder()
|
||||
.attributeName(ChangeNumberWaitingPeriods.KEY_ACCOUNT_UUID)
|
||||
.attributeType(ScalarAttributeType.B)
|
||||
.build()),
|
||||
List.of(), List.of()),
|
||||
|
||||
CLIENT_RELEASES("client_releases_test",
|
||||
ClientReleases.ATTR_PLATFORM,
|
||||
ClientReleases.ATTR_VERSION,
|
||||
|
||||
Reference in new issue
Block a user