Skip to content

Commit

Permalink
Rename config
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea committed Dec 5, 2024
1 parent b0b52aa commit 55d3cbb
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void setUp() {

@Test
public void expirationPeriodIsUsed() throws InterruptedException {
test(getTimestampDaysAgo(1), RolloutCacheConfiguration.builder().expiration(1));
test(getTimestampDaysAgo(1), RolloutCacheConfiguration.builder().expirationDays(1));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

public class RolloutCacheConfiguration {

private final int mExpiration;
private final int mExpirationDays;
private final boolean mClearOnInit;

private RolloutCacheConfiguration(int expiration, boolean clearOnInit) {
mExpiration = expiration;
mExpirationDays = expiration;
mClearOnInit = clearOnInit;
}

public int getExpiration() {
return mExpiration;
public int getExpirationDays() {
return mExpirationDays;
}

public boolean isClearOnInit() {
Expand All @@ -38,15 +38,15 @@ private Builder() {

/**
* Set the expiration time for the rollout definitions cache, in days. Default is 10 days.
* @param expiration in days
* @param expirationDays in days
* @return This builder
*/
public Builder expiration(int expiration) {
if (expiration < MIN_EXPIRATION_DAYS) {
public Builder expirationDays(int expirationDays) {
if (expirationDays < MIN_EXPIRATION_DAYS) {
Logger.w("Cache expiration must be at least 1 day. Using default value.");
mExpiration = ServiceConstants.DEFAULT_ROLLOUT_CACHE_EXPIRATION;
} else {
mExpiration = expiration;
mExpiration = expirationDays;
}

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public String trafficType() {

@Deprecated
public long cacheExpirationInSeconds() {
return TimeUnit.DAYS.toSeconds(rolloutCacheConfiguration().getExpiration());
return TimeUnit.DAYS.toSeconds(rolloutCacheConfiguration().getExpirationDays());
}

public long eventFlushInterval() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private boolean validateExpiration() {
// calculate elapsed time since last update
long daysSinceLastUpdate = TimeUnit.MILLISECONDS.toDays(System.currentTimeMillis() - lastUpdateTimestamp);

if (lastUpdateTimestamp > 0 && daysSinceLastUpdate >= mConfig.getExpiration()) {
if (lastUpdateTimestamp > 0 && daysSinceLastUpdate >= mConfig.getExpirationDays()) {
Logger.v("Clearing rollout definitions cache due to expiration");
return true;
} else if (mConfig.isClearOnInit()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ public class RolloutCacheConfigurationTest {
@Test
public void defaultValues() {
RolloutCacheConfiguration config = RolloutCacheConfiguration.builder().build();
assertEquals(10, config.getExpiration());
assertEquals(10, config.getExpirationDays());
assertFalse(config.isClearOnInit());
}

@Test
public void expirationIsCorrectlySet() {
RolloutCacheConfiguration.Builder builder = RolloutCacheConfiguration.builder();
builder.expiration(1);
builder.expirationDays(1);
RolloutCacheConfiguration config = builder.build();
assertEquals(1, config.getExpiration());
assertEquals(1, config.getExpirationDays());
}

@Test
Expand All @@ -34,8 +34,8 @@ public void clearOnInitIsCorrectlySet() {
@Test
public void negativeExpirationIsSetToDefault() {
RolloutCacheConfiguration.Builder builder = RolloutCacheConfiguration.builder();
builder.expiration(-1);
builder.expirationDays(-1);
RolloutCacheConfiguration config = builder.build();
assertEquals(10, config.getExpiration());
assertEquals(10, config.getExpirationDays());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,17 @@ public void observerCacheExpirationPeriodMatchesDedupeTimeIntervalWhenDedupeTime
public void rolloutCacheConfigurationDefaults() {
RolloutCacheConfiguration config = SplitClientConfig.builder().build().rolloutCacheConfiguration();

assertEquals(10, config.getExpiration());
assertEquals(10, config.getExpirationDays());
assertFalse(config.isClearOnInit());
}

@Test
public void rolloutCacheConfigurationExpirationIsCorrectlySet() {
RolloutCacheConfiguration config = SplitClientConfig.builder()
.rolloutCacheConfiguration(RolloutCacheConfiguration.builder().expiration(1).clearOnInit(true).build())
.rolloutCacheConfiguration(RolloutCacheConfiguration.builder().expirationDays(1).clearOnInit(true).build())
.build().rolloutCacheConfiguration();

assertEquals(1, config.getExpiration());
assertEquals(1, config.getExpirationDays());
assertTrue(config.isClearOnInit());
}

Expand All @@ -251,7 +251,7 @@ public void nullRolloutCacheConfigurationSetsDefault() {
.rolloutCacheConfiguration(null)
.build().rolloutCacheConfiguration();

assertEquals(10, config.getExpiration());
assertEquals(10, config.getExpirationDays());
assertFalse(config.isClearOnInit());
assertEquals(1, logMessages.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class RolloutCacheManagerTest {
}

private fun getCacheManager(expiration: Int, clearOnInit: Boolean): RolloutCacheManager {
return RolloutCacheManagerImpl(mGeneralInfoStorage, RolloutCacheConfiguration.builder().expiration(expiration).clearOnInit(clearOnInit).build(), mCleanUpDatabaseTask, mEncryptionMigrationTask, mSplitsCache, mSegmentsCache)
return RolloutCacheManagerImpl(mGeneralInfoStorage, RolloutCacheConfiguration.builder().expirationDays(expiration).clearOnInit(clearOnInit).build(), mCleanUpDatabaseTask, mEncryptionMigrationTask, mSplitsCache, mSegmentsCache)
}

private fun createMockedTimestamp(period: Long): Long {
Expand Down

0 comments on commit 55d3cbb

Please sign in to comment.