mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-22 11:38:06 +01:00
Introduce a DynamoDB-backed remote config store
This commit is contained in:
committed by
Jon Chambers
parent
4eb7dde1c8
commit
23bc11f3b6
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -5,62 +5,50 @@
|
||||
|
||||
package org.whispersystems.textsecuregcm.storage;
|
||||
|
||||
import com.opentable.db.postgres.embedded.LiquibasePreparer;
|
||||
import com.opentable.db.postgres.junit.EmbeddedPostgresRules;
|
||||
import com.opentable.db.postgres.junit.PreparedDbRule;
|
||||
import org.jdbi.v3.core.Jdbi;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.whispersystems.textsecuregcm.configuration.CircuitBreakerConfiguration;
|
||||
import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class RemoteConfigsManagerTest {
|
||||
|
||||
@Rule
|
||||
public PreparedDbRule db = EmbeddedPostgresRules.preparedDatabase(LiquibasePreparer.forClasspathLocation("accountsdb.xml"));
|
||||
|
||||
private RemoteConfigsManager remoteConfigs;
|
||||
private RemoteConfigStore remoteConfigs;
|
||||
private RemoteConfigsManager remoteConfigsManager;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.remoteConfigs = new RemoteConfigsManager(new RemoteConfigs(
|
||||
new FaultTolerantDatabase("remote_configs-test", Jdbi.create(db.getTestDatabase()), new CircuitBreakerConfiguration())));
|
||||
this.remoteConfigs = mock(RemoteConfigStore.class);
|
||||
this.remoteConfigsManager = new RemoteConfigsManager(remoteConfigs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate() {
|
||||
remoteConfigs.set(new RemoteConfig("android.stickers", 50, Set.of(AuthHelper.VALID_UUID), "FALSE", "TRUE", null));
|
||||
remoteConfigs.set(new RemoteConfig("value.sometimes", 50, Set.of(), "bar", "baz", 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));
|
||||
remoteConfigs.set(new RemoteConfig("value.sometimes", 25, Set.of(AuthHelper.VALID_UUID), "abc", "def", null));
|
||||
|
||||
List<RemoteConfig> results = remoteConfigs.getAll();
|
||||
|
||||
assertThat(results.size()).isEqualTo(3);
|
||||
|
||||
assertThat(results.get(0).getName()).isEqualTo("android.stickers");
|
||||
assertThat(results.get(0).getPercentage()).isEqualTo(50);
|
||||
assertThat(results.get(0).getUuids().size()).isEqualTo(1);
|
||||
assertThat(results.get(0).getUuids().contains(AuthHelper.VALID_UUID)).isTrue();
|
||||
|
||||
assertThat(results.get(1).getName()).isEqualTo("ios.stickers");
|
||||
assertThat(results.get(1).getPercentage()).isEqualTo(75);
|
||||
assertThat(results.get(1).getUuids()).isEmpty();
|
||||
|
||||
assertThat(results.get(2).getName()).isEqualTo("value.sometimes");
|
||||
assertThat(results.get(2).getUuids()).hasSize(1);
|
||||
assertThat(results.get(2).getUuids()).contains(AuthHelper.VALID_UUID);
|
||||
assertThat(results.get(2).getPercentage()).isEqualTo(25);
|
||||
assertThat(results.get(2).getDefaultValue()).isEqualTo("abc");
|
||||
assertThat(results.get(2).getValue()).isEqualTo("def");
|
||||
public void testGetAll() {
|
||||
remoteConfigsManager.getAll();
|
||||
remoteConfigsManager.getAll();
|
||||
|
||||
// A memoized supplier should prevent multiple calls to the underlying data source
|
||||
verify(remoteConfigs, times(1)).getAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSet() {
|
||||
final RemoteConfig remoteConfig = mock(RemoteConfig.class);
|
||||
|
||||
remoteConfigsManager.set(remoteConfig);
|
||||
remoteConfigsManager.set(remoteConfig);
|
||||
|
||||
verify(remoteConfigs, times(2)).set(remoteConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelete() {
|
||||
final String name = "name";
|
||||
|
||||
remoteConfigsManager.delete(name);
|
||||
remoteConfigsManager.delete(name);
|
||||
|
||||
verify(remoteConfigs, times(2)).delete(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +1,25 @@
|
||||
/*
|
||||
* Copyright 2013-2020 Signal Messenger, LLC
|
||||
* Copyright 2013-2021 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.tests.storage;
|
||||
package org.whispersystems.textsecuregcm.storage;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.codahale.metrics.Timer;
|
||||
import com.opentable.db.postgres.embedded.LiquibasePreparer;
|
||||
import com.opentable.db.postgres.junit5.EmbeddedPostgresExtension;
|
||||
import com.opentable.db.postgres.junit5.PreparedDbExtension;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.jdbi.v3.core.Jdbi;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.whispersystems.textsecuregcm.configuration.CircuitBreakerConfiguration;
|
||||
import org.whispersystems.textsecuregcm.storage.FaultTolerantDatabase;
|
||||
import org.whispersystems.textsecuregcm.storage.RemoteConfig;
|
||||
import org.whispersystems.textsecuregcm.storage.RemoteConfigs;
|
||||
import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
|
||||
abstract class RemoteConfigsTest {
|
||||
|
||||
public class 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);
|
||||
}
|
||||
protected abstract RemoteConfigStore getRemoteConfigStore();
|
||||
|
||||
@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));
|
||||
|
||||
@@ -71,6 +48,8 @@ public 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));
|
||||
@@ -102,6 +81,8 @@ public 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));
|
||||
Reference in New Issue
Block a user