Remove old Postgres-backed remote config machinery

This commit is contained in:
Jon Chambers 2021-11-29 15:19:50 -05:00 committed by Jon Chambers
parent 342323a7e6
commit e23a1fac50
11 changed files with 122 additions and 365 deletions

View File

@ -196,7 +196,6 @@ import org.whispersystems.textsecuregcm.storage.PushFeedbackProcessor;
import org.whispersystems.textsecuregcm.storage.RedeemedReceiptsManager;
import org.whispersystems.textsecuregcm.storage.RemoteConfigs;
import org.whispersystems.textsecuregcm.storage.RemoteConfigsManager;
import org.whispersystems.textsecuregcm.storage.RemoteConfigsDynamoDb;
import org.whispersystems.textsecuregcm.storage.ReportMessageDynamoDb;
import org.whispersystems.textsecuregcm.storage.ReportMessageManager;
import org.whispersystems.textsecuregcm.storage.ReservedUsernames;
@ -216,7 +215,6 @@ import org.whispersystems.textsecuregcm.websocket.WebSocketAccountAuthenticator;
import org.whispersystems.textsecuregcm.workers.CertificateCommand;
import org.whispersystems.textsecuregcm.workers.CheckDynamicConfigurationCommand;
import org.whispersystems.textsecuregcm.workers.DeleteUserCommand;
import org.whispersystems.textsecuregcm.workers.MigrateRemoteConfigsCommand;
import org.whispersystems.textsecuregcm.workers.ReserveUsernameCommand;
import org.whispersystems.textsecuregcm.workers.ServerVersionCommand;
import org.whispersystems.textsecuregcm.workers.SetCrawlerAccelerationTask;
@ -244,7 +242,6 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
bootstrap.addCommand(new ServerVersionCommand());
bootstrap.addCommand(new CheckDynamicConfigurationCommand());
bootstrap.addCommand(new SetUserDiscoverabilityCommand());
bootstrap.addCommand(new MigrateRemoteConfigsCommand());
bootstrap.addCommand(new ReserveUsernameCommand());
bootstrap.addBundle(new NameableMigrationsBundle<WhisperServerConfiguration>("accountdb", "accountsdb.xml") {
@ -395,7 +392,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
config.getMessageDynamoDbConfiguration().getTableName(),
config.getMessageDynamoDbConfiguration().getTimeToLive());
AbusiveHostRules abusiveHostRules = new AbusiveHostRules(abuseDatabase);
RemoteConfigsDynamoDb remoteConfigsDynamoDb = new RemoteConfigsDynamoDb(dynamoDbClient, config.getDynamoDbTables().getRemoteConfig().getTableName());
RemoteConfigs remoteConfigs = new RemoteConfigs(dynamoDbClient, config.getDynamoDbTables().getRemoteConfig().getTableName());
PushChallengeDynamoDb pushChallengeDynamoDb = new PushChallengeDynamoDb(pushChallengeDynamoDbClient, config.getPushChallengeDynamoDbConfiguration().getTableName());
ReportMessageDynamoDb reportMessageDynamoDb = new ReportMessageDynamoDb(reportMessageDynamoDbClient, config.getReportMessageDynamoDbConfiguration().getTableName(), config.getReportMessageConfiguration().getReportTtl());
VerificationCodeStore pendingAccounts = new VerificationCodeStore(pendingAccountsDynamoDbClient, config.getPendingAccountsDynamoDbConfiguration().getTableName());
@ -479,7 +476,7 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
AccountsManager accountsManager = new AccountsManager(accounts, phoneNumberIdentifiers, cacheCluster,
deletedAccountsManager, directoryQueue, keys, messagesManager, reservedUsernames, profilesManager,
pendingAccountsManager, secureStorageClient, secureBackupClient, clientPresenceManager, clock);
RemoteConfigsManager remoteConfigsManager = new RemoteConfigsManager(remoteConfigsDynamoDb);
RemoteConfigsManager remoteConfigsManager = new RemoteConfigsManager(remoteConfigs);
DeadLetterHandler deadLetterHandler = new DeadLetterHandler(accountsManager, messagesManager);
DispatchManager dispatchManager = new DispatchManager(pubSubClientFactory, Optional.of(deadLetterHandler));
PubSubManager pubSubManager = new PubSubManager(pubsubClient, dispatchManager);

View File

@ -1,17 +0,0 @@
/*
* Copyright 2013-2021 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.textsecuregcm.storage;
import java.util.List;
public interface RemoteConfigStore {
void set(RemoteConfig remoteConfig);
List<RemoteConfig> getAll();
void delete(String name);
}

View File

@ -1,78 +1,114 @@
/*
* Copyright 2013-2020 Signal Messenger, LLC
* Copyright 2013-2021 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.textsecuregcm.storage;
import static com.codahale.metrics.MetricRegistry.name;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.SharedMetricRegistries;
import com.codahale.metrics.Timer;
import org.whispersystems.textsecuregcm.util.AttributeValues;
import org.whispersystems.textsecuregcm.util.UUIDUtil;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
import software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest;
import software.amazon.awssdk.services.dynamodb.model.PutItemRequest;
import software.amazon.awssdk.services.dynamodb.model.ScanRequest;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.whispersystems.textsecuregcm.storage.mappers.RemoteConfigRowMapper;
import org.whispersystems.textsecuregcm.util.Constants;
import java.util.stream.Collectors;
public class RemoteConfigs implements RemoteConfigStore {
public class RemoteConfigs {
public static final String ID = "id";
public static final String NAME = "name";
public static final String PERCENTAGE = "percentage";
public static final String UUIDS = "uuids";
public static final String DEFAULT_VALUE = "default_value";
public static final String VALUE = "value";
public static final String HASH_KEY = "hash_key";
private final DynamoDbClient dynamoDbClient;
private final String tableName;
private final MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate(Constants.METRICS_NAME);
private final Timer setTimer = metricRegistry.timer(name(RemoteConfigs.class, "set" ));
private final Timer getAllTimer = metricRegistry.timer(name(RemoteConfigs.class, "getAll"));
private final Timer deleteTimer = metricRegistry.timer(name(RemoteConfigs.class, "delete"));
// Config name; string
static final String KEY_NAME = "N";
// Rollout percentage; integer
private static final String ATTR_PERCENTAGE = "P";
// Enrolled UUIDs (ACIs); list of byte arrays
private static final String ATTR_UUIDS = "U";
// Default value; string
private static final String ATTR_DEFAULT_VALUE = "D";
// Value when enrolled; string
private static final String ATTR_VALUE = "V";
// Hash key; string
private static final String ATTR_HASH_KEY = "H";
private final FaultTolerantDatabase database;
public RemoteConfigs(FaultTolerantDatabase database) {
this.database = database;
this.database.getDatabase().registerRowMapper(new RemoteConfigRowMapper());
this.database.getDatabase().registerArrayType(UUID.class, "uuid");
public RemoteConfigs(final DynamoDbClient dynamoDbClient, final String tableName) {
this.dynamoDbClient = dynamoDbClient;
this.tableName = tableName;
}
@Override
public void set(RemoteConfig remoteConfig) {
database.use(jdbi -> jdbi.useHandle(handle -> {
try (Timer.Context ignored = setTimer.time()) {
handle.createUpdate("INSERT INTO remote_config (" + NAME + ", " + PERCENTAGE + ", " + UUIDS + ", " + DEFAULT_VALUE + ", " + VALUE + ", " + HASH_KEY + ") VALUES (:name, :percentage, :uuids, :default_value, :value, :hash_key) ON CONFLICT(" + NAME + ") DO UPDATE SET " + PERCENTAGE + " = EXCLUDED." + PERCENTAGE + ", " + UUIDS + " = EXCLUDED." + UUIDS + ", " + DEFAULT_VALUE + " = EXCLUDED." + DEFAULT_VALUE + ", " + VALUE + " = EXCLUDED." + VALUE + ", " + HASH_KEY + " = EXCLUDED." + HASH_KEY)
.bind("name", remoteConfig.getName())
.bind("percentage", remoteConfig.getPercentage())
.bind("uuids", remoteConfig.getUuids().toArray(new UUID[0]))
.bind("default_value", remoteConfig.getDefaultValue())
.bind("value", remoteConfig.getValue())
.bind("hash_key", remoteConfig.getHashKey())
.execute();
}
}));
public void set(final RemoteConfig remoteConfig) {
final Map<String, AttributeValue> item = new HashMap<>(Map.of(
KEY_NAME, AttributeValues.fromString(remoteConfig.getName()),
ATTR_PERCENTAGE, AttributeValues.fromInt(remoteConfig.getPercentage())));
if (remoteConfig.getUuids() != null && !remoteConfig.getUuids().isEmpty()) {
final List<SdkBytes> uuidByteSets = remoteConfig.getUuids().stream()
.map(UUIDUtil::toByteBuffer)
.map(SdkBytes::fromByteBuffer)
.collect(Collectors.toList());
item.put(ATTR_UUIDS, AttributeValue.builder().bs(uuidByteSets).build());
}
if (remoteConfig.getDefaultValue() != null) {
item.put(ATTR_DEFAULT_VALUE, AttributeValues.fromString(remoteConfig.getDefaultValue()));
}
if (remoteConfig.getValue() != null) {
item.put(ATTR_VALUE, AttributeValues.fromString(remoteConfig.getValue()));
}
if (remoteConfig.getHashKey() != null) {
item.put(ATTR_HASH_KEY, AttributeValues.fromString(remoteConfig.getHashKey()));
}
dynamoDbClient.putItem(PutItemRequest.builder()
.tableName(tableName)
.item(item)
.build());
}
@Override
public List<RemoteConfig> getAll() {
return database.with(jdbi -> jdbi.withHandle(handle -> {
try (Timer.Context ignored = getAllTimer.time()) {
return handle.createQuery("SELECT * FROM remote_config")
.mapTo(RemoteConfig.class)
.list();
}
}));
return dynamoDbClient.scanPaginator(ScanRequest.builder()
.tableName(tableName)
.consistentRead(true)
.build())
.items()
.stream()
.map(item -> {
final String name = AttributeValues.getString(item, KEY_NAME, null);
final int percentage = AttributeValues.getInt(item, ATTR_PERCENTAGE, 0);
final String defaultValue = AttributeValues.getString(item, ATTR_DEFAULT_VALUE, null);
final String value = AttributeValues.getString(item, ATTR_VALUE, null);
final String hashKey = AttributeValues.getString(item, ATTR_HASH_KEY, null);
final Set<UUID> uuids;
if (item.containsKey(ATTR_UUIDS)) {
uuids = item.get(ATTR_UUIDS).bs().stream()
.map(sdkBytes -> UUIDUtil.fromByteBuffer(sdkBytes.asByteBuffer()))
.collect(Collectors.toSet());
} else {
uuids = Collections.emptySet();
}
return new RemoteConfig(name, percentage, uuids, defaultValue, value, hashKey);
})
.collect(Collectors.toList());
}
@Override
public void delete(String name) {
database.use(jdbi -> jdbi.useHandle(handle -> {
try (Timer.Context ignored = deleteTimer.time()) {
handle.createUpdate("DELETE FROM remote_config WHERE " + NAME + " = :name")
.bind("name", name)
.execute();
}
}));
public void delete(final String name) {
dynamoDbClient.deleteItem(DeleteItemRequest.builder()
.tableName(tableName)
.key(Map.of(KEY_NAME, AttributeValues.fromString(name)))
.build());
}
}

View File

@ -1,117 +0,0 @@
/*
* Copyright 2013-2021 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.textsecuregcm.storage;
import org.whispersystems.textsecuregcm.util.AttributeValues;
import org.whispersystems.textsecuregcm.util.UUIDUtil;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
import software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest;
import software.amazon.awssdk.services.dynamodb.model.PutItemRequest;
import software.amazon.awssdk.services.dynamodb.model.ScanRequest;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
public class RemoteConfigsDynamoDb implements RemoteConfigStore {
private final DynamoDbClient dynamoDbClient;
private final String tableName;
// Config name; string
static final String KEY_NAME = "N";
// Rollout percentage; integer
private static final String ATTR_PERCENTAGE = "P";
// Enrolled UUIDs (ACIs); list of byte arrays
private static final String ATTR_UUIDS = "U";
// Default value; string
private static final String ATTR_DEFAULT_VALUE = "D";
// Value when enrolled; string
private static final String ATTR_VALUE = "V";
// Hash key; string
private static final String ATTR_HASH_KEY = "H";
public RemoteConfigsDynamoDb(final DynamoDbClient dynamoDbClient, final String tableName) {
this.dynamoDbClient = dynamoDbClient;
this.tableName = tableName;
}
@Override
public void set(final RemoteConfig remoteConfig) {
final Map<String, AttributeValue> item = new HashMap<>(Map.of(
KEY_NAME, AttributeValues.fromString(remoteConfig.getName()),
ATTR_PERCENTAGE, AttributeValues.fromInt(remoteConfig.getPercentage())));
if (remoteConfig.getUuids() != null && !remoteConfig.getUuids().isEmpty()) {
final List<SdkBytes> uuidByteSets = remoteConfig.getUuids().stream()
.map(UUIDUtil::toByteBuffer)
.map(SdkBytes::fromByteBuffer)
.collect(Collectors.toList());
item.put(ATTR_UUIDS, AttributeValue.builder().bs(uuidByteSets).build());
}
if (remoteConfig.getDefaultValue() != null) {
item.put(ATTR_DEFAULT_VALUE, AttributeValues.fromString(remoteConfig.getDefaultValue()));
}
if (remoteConfig.getValue() != null) {
item.put(ATTR_VALUE, AttributeValues.fromString(remoteConfig.getValue()));
}
if (remoteConfig.getHashKey() != null) {
item.put(ATTR_HASH_KEY, AttributeValues.fromString(remoteConfig.getHashKey()));
}
dynamoDbClient.putItem(PutItemRequest.builder()
.tableName(tableName)
.item(item)
.build());
}
@Override
public List<RemoteConfig> getAll() {
return dynamoDbClient.scanPaginator(ScanRequest.builder()
.tableName(tableName)
.consistentRead(true)
.build())
.items()
.stream()
.map(item -> {
final String name = AttributeValues.getString(item, KEY_NAME, null);
final int percentage = AttributeValues.getInt(item, ATTR_PERCENTAGE, 0);
final String defaultValue = AttributeValues.getString(item, ATTR_DEFAULT_VALUE, null);
final String value = AttributeValues.getString(item, ATTR_VALUE, null);
final String hashKey = AttributeValues.getString(item, ATTR_HASH_KEY, null);
final Set<UUID> uuids;
if (item.containsKey(ATTR_UUIDS)) {
uuids = item.get(ATTR_UUIDS).bs().stream()
.map(sdkBytes -> UUIDUtil.fromByteBuffer(sdkBytes.asByteBuffer()))
.collect(Collectors.toSet());
} else {
uuids = Collections.emptySet();
}
return new RemoteConfig(name, percentage, uuids, defaultValue, value, hashKey);
})
.collect(Collectors.toList());
}
@Override
public void delete(final String name) {
dynamoDbClient.deleteItem(DeleteItemRequest.builder()
.tableName(tableName)
.key(Map.of(KEY_NAME, AttributeValues.fromString(name)))
.build());
}
}

View File

@ -12,11 +12,11 @@ import java.util.function.Supplier;
public class RemoteConfigsManager {
private final RemoteConfigStore remoteConfigs;
private final RemoteConfigs remoteConfigs;
private final Supplier<List<RemoteConfig>> remoteConfigSupplier;
public RemoteConfigsManager(RemoteConfigStore remoteConfigs) {
public RemoteConfigsManager(RemoteConfigs remoteConfigs) {
this.remoteConfigs = remoteConfigs;
remoteConfigSupplier =

View File

@ -1,31 +0,0 @@
/*
* Copyright 2013-2020 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.textsecuregcm.storage.mappers;
import org.jdbi.v3.core.mapper.RowMapper;
import org.jdbi.v3.core.statement.StatementContext;
import org.whispersystems.textsecuregcm.storage.RemoteConfig;
import org.whispersystems.textsecuregcm.storage.RemoteConfigs;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.UUID;
public class RemoteConfigRowMapper implements RowMapper<RemoteConfig> {
@Override
public RemoteConfig map(ResultSet rs, StatementContext ctx) throws SQLException {
return new RemoteConfig(rs.getString(RemoteConfigs.NAME),
rs.getInt(RemoteConfigs.PERCENTAGE),
new HashSet<>(Arrays.asList((UUID[])rs.getArray(RemoteConfigs.UUIDS).getArray())),
rs.getString(RemoteConfigs.DEFAULT_VALUE),
rs.getString(RemoteConfigs.VALUE),
rs.getString(RemoteConfigs.HASH_KEY));
}
}

View File

@ -1,50 +0,0 @@
/*
* Copyright 2013-2021 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.textsecuregcm.workers;
import io.dropwizard.Application;
import io.dropwizard.cli.EnvironmentCommand;
import io.dropwizard.jdbi3.JdbiFactory;
import io.dropwizard.setup.Environment;
import net.sourceforge.argparse4j.inf.Namespace;
import org.jdbi.v3.core.Jdbi;
import org.whispersystems.textsecuregcm.WhisperServerConfiguration;
import org.whispersystems.textsecuregcm.storage.FaultTolerantDatabase;
import org.whispersystems.textsecuregcm.storage.RemoteConfigs;
import org.whispersystems.textsecuregcm.storage.RemoteConfigsDynamoDb;
import org.whispersystems.textsecuregcm.util.DynamoDbFromConfig;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
public class MigrateRemoteConfigsCommand extends EnvironmentCommand<WhisperServerConfiguration> {
public MigrateRemoteConfigsCommand() {
super(new Application<>() {
@Override
public void run(WhisperServerConfiguration configuration, Environment environment) {
}
}, "migrate-remote-config", "Migrate remote configuration from Postgres to DynamoDB");
}
@Override
protected void run(final Environment environment, final Namespace namespace,
final WhisperServerConfiguration configuration) throws Exception {
JdbiFactory jdbiFactory = new JdbiFactory();
Jdbi accountJdbi = jdbiFactory.build(environment, configuration.getAccountsDatabaseConfiguration(), "accountdb");
FaultTolerantDatabase accountDatabase = new FaultTolerantDatabase("account_database_delete_user", accountJdbi,
configuration.getAccountsDatabaseConfiguration().getCircuitBreakerConfiguration());
DynamoDbClient dynamoDbClient = DynamoDbFromConfig.client(
configuration.getDynamoDbClientConfiguration(),
software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider.create());
RemoteConfigs remoteConfigs = new RemoteConfigs(accountDatabase);
RemoteConfigsDynamoDb remoteConfigsDynamoDb =
new RemoteConfigsDynamoDb(dynamoDbClient, configuration.getDynamoDbTables().getRemoteConfig().getTableName());
remoteConfigs.getAll().forEach(remoteConfigsDynamoDb::set);
}
}

View File

@ -1,38 +0,0 @@
/*
* Copyright 2013-2021 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.textsecuregcm.storage;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.RegisterExtension;
import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition;
import software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType;
class RemoteConfigsDynamoDbTest extends RemoteConfigsTest {
private static final String REMOTE_CONFIGS_TABLE_NAME = "remote_configs_test";
@RegisterExtension
static DynamoDbExtension dynamoDbExtension = DynamoDbExtension.builder()
.tableName(REMOTE_CONFIGS_TABLE_NAME)
.hashKey(RemoteConfigsDynamoDb.KEY_NAME)
.attributeDefinition(AttributeDefinition.builder()
.attributeName(RemoteConfigsDynamoDb.KEY_NAME)
.attributeType(ScalarAttributeType.S)
.build())
.build();
private RemoteConfigsDynamoDb remoteConfigs;
@BeforeEach
void setUp() {
remoteConfigs = new RemoteConfigsDynamoDb(dynamoDbExtension.getDynamoDbClient(), REMOTE_CONFIGS_TABLE_NAME);
}
@Override
protected RemoteConfigStore getRemoteConfigStore() {
return remoteConfigs;
}
}

View File

@ -14,12 +14,12 @@ import org.junit.Test;
public class RemoteConfigsManagerTest {
private RemoteConfigStore remoteConfigs;
private RemoteConfigs remoteConfigs;
private RemoteConfigsManager remoteConfigsManager;
@Before
public void setup() {
this.remoteConfigs = mock(RemoteConfigStore.class);
this.remoteConfigs = mock(RemoteConfigs.class);
this.remoteConfigsManager = new RemoteConfigsManager(remoteConfigs);
}

View File

@ -1,38 +0,0 @@
/*
* Copyright 2013-2021 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.textsecuregcm.storage;
import com.opentable.db.postgres.embedded.LiquibasePreparer;
import com.opentable.db.postgres.junit5.EmbeddedPostgresExtension;
import com.opentable.db.postgres.junit5.PreparedDbExtension;
import org.jdbi.v3.core.Jdbi;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.whispersystems.textsecuregcm.configuration.CircuitBreakerConfiguration;
public class RemoteConfigsPostgresTest extends RemoteConfigsTest {
@RegisterExtension
static PreparedDbExtension ACCOUNTS_POSTGRES_EXTENSION =
EmbeddedPostgresExtension.preparedDatabase(LiquibasePreparer.forClasspathLocation("accountsdb.xml"));
private RemoteConfigs remoteConfigs;
@BeforeEach
void setUp() {
final FaultTolerantDatabase remoteConfigDatabase = new FaultTolerantDatabase("remote_configs-test", Jdbi.create(ACCOUNTS_POSTGRES_EXTENSION.getTestDatabase()), new CircuitBreakerConfiguration());
remoteConfigDatabase.use(jdbi -> jdbi.useHandle(handle ->
handle.createUpdate("DELETE FROM remote_config").execute()));
this.remoteConfigs = new RemoteConfigs(remoteConfigDatabase);
}
@Override
protected RemoteConfigStore getRemoteConfigStore() {
return remoteConfigs;
}
}

View File

@ -5,21 +5,40 @@
package org.whispersystems.textsecuregcm.storage;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
import software.amazon.awssdk.services.dynamodb.model.AttributeDefinition;
import software.amazon.awssdk.services.dynamodb.model.ScalarAttributeType;
import java.util.List;
import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
abstract class RemoteConfigsTest {
class RemoteConfigsTest {
protected abstract RemoteConfigStore getRemoteConfigStore();
private static final String REMOTE_CONFIGS_TABLE_NAME = "remote_configs_test";
@RegisterExtension
static DynamoDbExtension dynamoDbExtension = DynamoDbExtension.builder()
.tableName(REMOTE_CONFIGS_TABLE_NAME)
.hashKey(RemoteConfigs.KEY_NAME)
.attributeDefinition(AttributeDefinition.builder()
.attributeName(RemoteConfigs.KEY_NAME)
.attributeType(ScalarAttributeType.S)
.build())
.build();
private RemoteConfigs remoteConfigs;
@BeforeEach
void setUp() {
remoteConfigs = new RemoteConfigs(dynamoDbExtension.getDynamoDbClient(), REMOTE_CONFIGS_TABLE_NAME);
}
@Test
void testStore() {
final RemoteConfigStore remoteConfigs = getRemoteConfigStore();
remoteConfigs.set(new RemoteConfig("android.stickers", 50, Set.of(AuthHelper.VALID_UUID, AuthHelper.VALID_UUID_TWO), "FALSE", "TRUE", null));
remoteConfigs.set(new RemoteConfig("value.sometimes", 25, Set.of(AuthHelper.VALID_UUID_TWO), "default", "custom", null));
@ -48,8 +67,6 @@ abstract class RemoteConfigsTest {
@Test
void testUpdate() {
final RemoteConfigStore remoteConfigs = getRemoteConfigStore();
remoteConfigs.set(new RemoteConfig("android.stickers", 50, Set.of(), "FALSE", "TRUE", null));
remoteConfigs.set(new RemoteConfig("value.sometimes", 22, Set.of(), "def", "!", null));
remoteConfigs.set(new RemoteConfig("ios.stickers", 50, Set.of(AuthHelper.DISABLED_UUID), "FALSE", "TRUE", null));
@ -81,8 +98,6 @@ abstract class RemoteConfigsTest {
@Test
void testDelete() {
final RemoteConfigStore remoteConfigs = getRemoteConfigStore();
remoteConfigs.set(new RemoteConfig("android.stickers", 50, Set.of(AuthHelper.VALID_UUID), "FALSE", "TRUE", null));
remoteConfigs.set(new RemoteConfig("ios.stickers", 50, Set.of(), "FALSE", "TRUE", null));
remoteConfigs.set(new RemoteConfig("ios.stickers", 75, Set.of(), "FALSE", "TRUE", null));