-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
201 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/io/split/android/client/RolloutCacheConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.split.android.client; | ||
|
||
import io.split.android.client.service.ServiceConstants; | ||
import io.split.android.client.utils.logger.Logger; | ||
|
||
public class RolloutCacheConfiguration { | ||
|
||
private final int mExpiration; | ||
private final boolean mClearOnInit; | ||
|
||
private RolloutCacheConfiguration(int expiration, boolean clearOnInit) { | ||
mExpiration = expiration; | ||
mClearOnInit = clearOnInit; | ||
} | ||
|
||
public int getExpiration() { | ||
return mExpiration; | ||
} | ||
|
||
public boolean clearOnInit() { | ||
return mClearOnInit; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder { | ||
|
||
private static final int MIN_EXPIRATION_DAYS = 1; | ||
|
||
private int mExpiration = ServiceConstants.DEFAULT_ROLLOUT_CACHE_EXPIRATION; | ||
private boolean mClearOnInit = false; | ||
|
||
private Builder() { | ||
|
||
} | ||
|
||
/** | ||
* Set the expiration time for the rollout definitions cache, in days. Default is 10 days. | ||
* @param expiration in days | ||
* @return This builder | ||
*/ | ||
public Builder expiration(int expiration) { | ||
if (expiration < 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; | ||
} | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* Set if the rollout definitions cache should be cleared on initialization. Default is false. | ||
* @param clearOnInit whether to clear cache on initialization. | ||
* @return This builder | ||
*/ | ||
public Builder clearOnInit(boolean clearOnInit) { | ||
mClearOnInit = clearOnInit; | ||
return this; | ||
} | ||
|
||
public RolloutCacheConfiguration build() { | ||
return new RolloutCacheConfiguration(mExpiration, mClearOnInit); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
src/main/java/io/split/android/client/service/synchronizer/RolloutCacheManagerConfig.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/test/java/io/split/android/client/RolloutCacheConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.split.android.client; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
public class RolloutCacheConfigurationTest { | ||
|
||
@Test | ||
public void defaultValues() { | ||
RolloutCacheConfiguration config = RolloutCacheConfiguration.builder().build(); | ||
assertEquals(10, config.getExpiration()); | ||
assertFalse(config.clearOnInit()); | ||
} | ||
|
||
@Test | ||
public void expirationIsCorrectlySet() { | ||
RolloutCacheConfiguration.Builder builder = RolloutCacheConfiguration.builder(); | ||
builder.expiration(1); | ||
RolloutCacheConfiguration config = builder.build(); | ||
assertEquals(1, config.getExpiration()); | ||
} | ||
|
||
@Test | ||
public void clearOnInitIsCorrectlySet() { | ||
RolloutCacheConfiguration.Builder builder = RolloutCacheConfiguration.builder(); | ||
builder.clearOnInit(true); | ||
RolloutCacheConfiguration config = builder.build(); | ||
assertTrue(config.clearOnInit()); | ||
} | ||
|
||
@Test | ||
public void negativeExpirationIsSetToDefault() { | ||
RolloutCacheConfiguration.Builder builder = RolloutCacheConfiguration.builder(); | ||
builder.expiration(-1); | ||
RolloutCacheConfiguration config = builder.build(); | ||
assertEquals(10, config.getExpiration()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.