From 26025e5abd340f474ed2c541848e20cde95e0570 Mon Sep 17 00:00:00 2001 From: Ameya Lokare Date: Wed, 18 Dec 2024 14:53:35 -0800 Subject: [PATCH] Rename preRegistrationExperiments to e164Experiments --- .../dynamic/DynamicConfiguration.java | 6 +-- ...164ExperimentEnrollmentConfiguration.java} | 2 +- .../ExperimentEnrollmentManager.java | 6 +-- .../dynamic/DynamicConfigurationTest.java | 20 ++++----- .../ExperimentEnrollmentManagerTest.java | 42 +++++++++---------- 5 files changed, 38 insertions(+), 38 deletions(-) rename service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/{DynamicPreRegistrationExperimentEnrollmentConfiguration.java => DynamicE164ExperimentEnrollmentConfiguration.java} (94%) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicConfiguration.java index cc67178d5..d6ec9f970 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicConfiguration.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicConfiguration.java @@ -22,7 +22,7 @@ public class DynamicConfiguration { @JsonProperty @Valid - private Map preRegistrationExperiments = Collections.emptyMap(); + private Map e164Experiments = Collections.emptyMap(); @JsonProperty @Valid @@ -77,9 +77,9 @@ public class DynamicConfiguration { return Optional.ofNullable(experiments.get(experimentName)); } - public Optional getPreRegistrationEnrollmentConfiguration( + public Optional getE164ExperimentEnrollmentConfiguration( final String experimentName) { - return Optional.ofNullable(preRegistrationExperiments.get(experimentName)); + return Optional.ofNullable(e164Experiments.get(experimentName)); } public Map getLimits() { diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicPreRegistrationExperimentEnrollmentConfiguration.java b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicE164ExperimentEnrollmentConfiguration.java similarity index 94% rename from service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicPreRegistrationExperimentEnrollmentConfiguration.java rename to service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicE164ExperimentEnrollmentConfiguration.java index e80ad4077..0a7fea5f9 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicPreRegistrationExperimentEnrollmentConfiguration.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicE164ExperimentEnrollmentConfiguration.java @@ -12,7 +12,7 @@ import jakarta.validation.constraints.Min; import java.util.Collections; import java.util.Set; -public class DynamicPreRegistrationExperimentEnrollmentConfiguration { +public class DynamicE164ExperimentEnrollmentConfiguration { @JsonProperty @Valid diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/experiment/ExperimentEnrollmentManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/experiment/ExperimentEnrollmentManager.java index 08bebc2b6..e51c76771 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/experiment/ExperimentEnrollmentManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/experiment/ExperimentEnrollmentManager.java @@ -12,7 +12,7 @@ import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration; import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicExperimentEnrollmentConfiguration; -import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicPreRegistrationExperimentEnrollmentConfiguration; +import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicE164ExperimentEnrollmentConfiguration; import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager; import org.whispersystems.textsecuregcm.util.Util; @@ -73,8 +73,8 @@ public class ExperimentEnrollmentManager { public boolean isEnrolled(final String e164, final String experimentName) { - final Optional maybeConfiguration = dynamicConfigurationManager - .getConfiguration().getPreRegistrationEnrollmentConfiguration(experimentName); + final Optional maybeConfiguration = dynamicConfigurationManager + .getConfiguration().getE164ExperimentEnrollmentConfiguration(experimentName); return maybeConfiguration.map(config -> { diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicConfigurationTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicConfigurationTest.java index fc1597a64..5342415cf 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicConfigurationTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/configuration/dynamic/DynamicConfigurationTest.java @@ -125,18 +125,18 @@ class DynamicConfigurationTest { } @Test - void testParsePreRegistrationExperiments() throws JsonProcessingException { + void testParseE164Experiments() throws JsonProcessingException { { final String emptyConfigYaml = REQUIRED_CONFIG.concat("test: true"); final DynamicConfiguration emptyConfig = DynamicConfigurationManager.parseConfiguration(emptyConfigYaml, DynamicConfiguration.class).orElseThrow(); - assertFalse(emptyConfig.getPreRegistrationEnrollmentConfiguration("test").isPresent()); + assertFalse(emptyConfig.getE164ExperimentEnrollmentConfiguration("test").isPresent()); } { final String experimentConfigYaml = REQUIRED_CONFIG.concat(""" - preRegistrationExperiments: + e164Experiments: percentageOnly: enrollmentPercentage: 17 e164sCountryCodesAndPercentage: @@ -161,11 +161,11 @@ class DynamicConfigurationTest { final DynamicConfiguration config = DynamicConfigurationManager.parseConfiguration(experimentConfigYaml, DynamicConfiguration.class).orElseThrow(); - assertFalse(config.getPreRegistrationEnrollmentConfiguration("unconfigured").isPresent()); + assertFalse(config.getE164ExperimentEnrollmentConfiguration("unconfigured").isPresent()); { - final Optional percentageOnly = config - .getPreRegistrationEnrollmentConfiguration("percentageOnly"); + final Optional percentageOnly = config + .getE164ExperimentEnrollmentConfiguration("percentageOnly"); assertTrue(percentageOnly.isPresent()); assertEquals(17, percentageOnly.get().getEnrollmentPercentage()); @@ -176,8 +176,8 @@ class DynamicConfigurationTest { } { - final Optional e164sCountryCodesAndPercentage = config - .getPreRegistrationEnrollmentConfiguration("e164sCountryCodesAndPercentage"); + final Optional e164sCountryCodesAndPercentage = config + .getE164ExperimentEnrollmentConfiguration("e164sCountryCodesAndPercentage"); assertTrue(e164sCountryCodesAndPercentage.isPresent()); assertEquals(46, @@ -193,8 +193,8 @@ class DynamicConfigurationTest { } { - final Optional e164sAndExcludedCodes = config - .getPreRegistrationEnrollmentConfiguration("e164sAndExcludedCodes"); + final Optional e164sAndExcludedCodes = config + .getE164ExperimentEnrollmentConfiguration("e164sAndExcludedCodes"); assertTrue(e164sAndExcludedCodes.isPresent()); assertEquals(0, e164sAndExcludedCodes.get().getEnrollmentPercentage()); assertEquals(Set.of("+120255551212"), diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/experiment/ExperimentEnrollmentManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/experiment/ExperimentEnrollmentManagerTest.java index ff3010107..cc801651c 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/experiment/ExperimentEnrollmentManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/experiment/ExperimentEnrollmentManagerTest.java @@ -29,7 +29,7 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicConfiguration; import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicExperimentEnrollmentConfiguration; -import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicPreRegistrationExperimentEnrollmentConfiguration; +import org.whispersystems.textsecuregcm.configuration.dynamic.DynamicE164ExperimentEnrollmentConfiguration; import org.whispersystems.textsecuregcm.storage.Account; import org.whispersystems.textsecuregcm.storage.DynamicConfigurationManager; @@ -37,7 +37,7 @@ class ExperimentEnrollmentManagerTest { private DynamicExperimentEnrollmentConfiguration.UuidSelector uuidSelector; private DynamicExperimentEnrollmentConfiguration experimentEnrollmentConfiguration; - private DynamicPreRegistrationExperimentEnrollmentConfiguration preRegistrationExperimentEnrollmentConfiguration; + private DynamicE164ExperimentEnrollmentConfiguration e164ExperimentEnrollmentConfiguration; private ExperimentEnrollmentManager experimentEnrollmentManager; @@ -66,18 +66,18 @@ class ExperimentEnrollmentManagerTest { experimentEnrollmentConfiguration = mock(DynamicExperimentEnrollmentConfiguration.class); when(experimentEnrollmentConfiguration.getUuidSelector()).thenReturn(uuidSelector); - preRegistrationExperimentEnrollmentConfiguration = mock( - DynamicPreRegistrationExperimentEnrollmentConfiguration.class); + e164ExperimentEnrollmentConfiguration = mock( + DynamicE164ExperimentEnrollmentConfiguration.class); when(dynamicConfigurationManager.getConfiguration()).thenReturn(dynamicConfiguration); when(dynamicConfiguration.getExperimentEnrollmentConfiguration(UUID_EXPERIMENT_NAME)) .thenReturn(Optional.of(experimentEnrollmentConfiguration)); - when(dynamicConfiguration.getPreRegistrationEnrollmentConfiguration(E164_EXPERIMENT_NAME)) - .thenReturn(Optional.of(preRegistrationExperimentEnrollmentConfiguration)); + when(dynamicConfiguration.getE164ExperimentEnrollmentConfiguration(E164_EXPERIMENT_NAME)) + .thenReturn(Optional.of(e164ExperimentEnrollmentConfiguration)); when(dynamicConfiguration.getExperimentEnrollmentConfiguration(E164_AND_UUID_EXPERIMENT_NAME)) .thenReturn(Optional.of(experimentEnrollmentConfiguration)); - when(dynamicConfiguration.getPreRegistrationEnrollmentConfiguration(E164_AND_UUID_EXPERIMENT_NAME)) - .thenReturn(Optional.of(preRegistrationExperimentEnrollmentConfiguration)); + when(dynamicConfiguration.getE164ExperimentEnrollmentConfiguration(E164_AND_UUID_EXPERIMENT_NAME)) + .thenReturn(Optional.of(e164ExperimentEnrollmentConfiguration)); account = mock(Account.class); when(account.getUuid()).thenReturn(ACCOUNT_UUID); @@ -127,11 +127,11 @@ class ExperimentEnrollmentManagerTest { @Test void testIsEnrolled_E164AndUuidExperiment() { - when(preRegistrationExperimentEnrollmentConfiguration.getIncludedCountryCodes()).thenReturn(Set.of("1")); - when(preRegistrationExperimentEnrollmentConfiguration.getEnrollmentPercentage()).thenReturn(0); - when(preRegistrationExperimentEnrollmentConfiguration.getEnrolledE164s()).thenReturn(Collections.emptySet()); - when(preRegistrationExperimentEnrollmentConfiguration.getExcludedE164s()).thenReturn(Collections.emptySet()); - when(preRegistrationExperimentEnrollmentConfiguration.getExcludedCountryCodes()).thenReturn(Collections.emptySet()); + when(e164ExperimentEnrollmentConfiguration.getIncludedCountryCodes()).thenReturn(Set.of("1")); + when(e164ExperimentEnrollmentConfiguration.getEnrollmentPercentage()).thenReturn(0); + when(e164ExperimentEnrollmentConfiguration.getEnrolledE164s()).thenReturn(Collections.emptySet()); + when(e164ExperimentEnrollmentConfiguration.getExcludedE164s()).thenReturn(Collections.emptySet()); + when(e164ExperimentEnrollmentConfiguration.getExcludedCountryCodes()).thenReturn(Collections.emptySet()); // test UUID enrollment is prioritized when(uuidSelector.getUuids()).thenReturn(Set.of(ACCOUNT_UUID)); @@ -151,30 +151,30 @@ class ExperimentEnrollmentManagerTest { when(experimentEnrollmentConfiguration.getEnrollmentPercentage()).thenReturn(0); assertTrue(experimentEnrollmentManager.isEnrolled(ENROLLED_164, account.getUuid(), E164_AND_UUID_EXPERIMENT_NAME)); assertFalse(experimentEnrollmentManager.isEnrolled(NOT_ENROLLED_164, account.getUuid(), E164_AND_UUID_EXPERIMENT_NAME)); - when(preRegistrationExperimentEnrollmentConfiguration.getEnrollmentPercentage()).thenReturn(100); + when(e164ExperimentEnrollmentConfiguration.getEnrollmentPercentage()).thenReturn(100); assertTrue(experimentEnrollmentManager.isEnrolled(ENROLLED_164, account.getUuid(), E164_AND_UUID_EXPERIMENT_NAME)); assertTrue(experimentEnrollmentManager.isEnrolled(NOT_ENROLLED_164, account.getUuid(), E164_AND_UUID_EXPERIMENT_NAME)); } @ParameterizedTest @MethodSource - void testIsEnrolled_PreRegistrationExperiment(final String e164, final String experimentName, + void testIsEnrolled_E164Experiment(final String e164, final String experimentName, final Set enrolledE164s, final Set excludedE164s, final Set includedCountryCodes, final Set excludedCountryCodes, final int enrollmentPercentage, final boolean expectEnrolled, final String message) { - when(preRegistrationExperimentEnrollmentConfiguration.getEnrolledE164s()).thenReturn(enrolledE164s); - when(preRegistrationExperimentEnrollmentConfiguration.getExcludedE164s()).thenReturn(excludedE164s); - when(preRegistrationExperimentEnrollmentConfiguration.getEnrollmentPercentage()).thenReturn(enrollmentPercentage); - when(preRegistrationExperimentEnrollmentConfiguration.getIncludedCountryCodes()).thenReturn(includedCountryCodes); - when(preRegistrationExperimentEnrollmentConfiguration.getExcludedCountryCodes()).thenReturn(excludedCountryCodes); + when(e164ExperimentEnrollmentConfiguration.getEnrolledE164s()).thenReturn(enrolledE164s); + when(e164ExperimentEnrollmentConfiguration.getExcludedE164s()).thenReturn(excludedE164s); + when(e164ExperimentEnrollmentConfiguration.getEnrollmentPercentage()).thenReturn(enrollmentPercentage); + when(e164ExperimentEnrollmentConfiguration.getIncludedCountryCodes()).thenReturn(includedCountryCodes); + when(e164ExperimentEnrollmentConfiguration.getExcludedCountryCodes()).thenReturn(excludedCountryCodes); assertEquals(expectEnrolled, experimentEnrollmentManager.isEnrolled(e164, experimentName), message); } @SuppressWarnings("unused") - static Stream testIsEnrolled_PreRegistrationExperiment() { + static Stream testIsEnrolled_E164Experiment() { return Stream.of( Arguments.of(ENROLLED_164, E164_EXPERIMENT_NAME, Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), Collections.emptySet(), 0, false, "default configuration expects no enrollment"),