Skip to content

Commit

Permalink
Remove LS configs (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea authored Aug 19, 2024
2 parents 5468055 + 69fbd01 commit 90605a5
Show file tree
Hide file tree
Showing 29 changed files with 101 additions and 584 deletions.
23 changes: 1 addition & 22 deletions src/androidTest/java/helper/TestableSplitConfigBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ public class TestableSplitConfigBuilder {
private String mPrefix = "";
private CertificatePinningConfiguration mCertificatePinningConfiguration;
private long mImpressionsDedupeTimeInterval = ServiceConstants.DEFAULT_IMPRESSIONS_DEDUPE_TIME_INTERVAL;
private boolean mLargeSegmentsEnabled = false;
private int mLargeSegmentsRefreshRate = 60;
private boolean mWaitForLargeSegments = true;

public TestableSplitConfigBuilder() {
mServiceEndpoints = ServiceEndpoints.builder().build();
Expand Down Expand Up @@ -277,21 +274,6 @@ public TestableSplitConfigBuilder impressionsDedupeTimeInterval(long impressions
return this;
}

public TestableSplitConfigBuilder largeSegmentsEnabled(boolean largeSegmentsEnabled) {
this.mLargeSegmentsEnabled = largeSegmentsEnabled;
return this;
}

public TestableSplitConfigBuilder largeSegmentsRefreshRate(int largeSegmentsRefreshRate) {
this.mLargeSegmentsRefreshRate = largeSegmentsRefreshRate;
return this;
}

public TestableSplitConfigBuilder waitForLargeSegments(boolean waitForLargeSegments) {
this.mWaitForLargeSegments = waitForLargeSegments;
return this;
}

public SplitClientConfig build() {
Constructor constructor = SplitClientConfig.class.getDeclaredConstructors()[0];
constructor.setAccessible(true);
Expand Down Expand Up @@ -347,10 +329,7 @@ public SplitClientConfig build() {
mPrefix,
mObserverCacheExpirationPeriod,
mCertificatePinningConfiguration,
mImpressionsDedupeTimeInterval,
mLargeSegmentsEnabled,
mLargeSegmentsRefreshRate,
mWaitForLargeSegments);
mImpressionsDedupeTimeInterval);

Logger.instance().setLevel(mLogLevel);
return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ private SplitFactory createFactory(
.trafficType("client")
.impressionsMode(impressionsMode)
.impressionsRefreshRate(1000)
.largeSegmentsEnabled(true)
.impressionsCountersRefreshRate(1000)
.streamingEnabled(false)
.eventFlushInterval(1000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,25 +123,20 @@ private void updateEndpointHit(String splitChanges) {
}
}

protected SplitFactory getFactory(boolean largeSegmentsEnabled, boolean waitForLargeSegments) {
return getFactory(largeSegmentsEnabled, waitForLargeSegments, null, 2500, null);
protected SplitFactory getFactory() {
return getFactory(null, 2500, null);
}

protected SplitFactory getFactory(boolean largeSegmentsEnabled,
boolean waitForLargeSegments,
Integer largeSegmentsRefreshRate,
protected SplitFactory getFactory(Integer largeSegmentsRefreshRate,
Integer ready, SplitRoomDatabase database) {
TestableSplitConfigBuilder configBuilder = new TestableSplitConfigBuilder()
.largeSegmentsEnabled(largeSegmentsEnabled)
.waitForLargeSegments(waitForLargeSegments)
.enableDebug()
.serviceEndpoints(ServiceEndpoints.builder()
.apiEndpoint("http://" + mWebServer.getHostName() + ":" + mWebServer.getPort())
.build());

if (largeSegmentsRefreshRate != null) {
configBuilder.streamingEnabled(false);
configBuilder.largeSegmentsRefreshRate(largeSegmentsRefreshRate);
}
if (ready != null) {
configBuilder.ready(ready);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package tests.integration.largesegments;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import android.content.Context;
Expand Down Expand Up @@ -35,7 +33,6 @@
import io.split.android.client.SplitFactory;
import io.split.android.client.dtos.SplitChange;
import io.split.android.client.events.SplitEvent;
import io.split.android.client.storage.db.MyLargeSegmentEntity;
import io.split.android.client.storage.db.SplitRoomDatabase;
import io.split.android.client.storage.mysegments.SegmentChangeDTO;
import io.split.android.client.utils.Json;
Expand Down Expand Up @@ -119,32 +116,6 @@ public void segmentRemovalTriggersSdkUpdateAndRemovesSegmentFromStorage() throws
assertEquals("{\"segments\":[\"large-segment3\"],\"till\":1702507130121}", db.myLargeSegmentDao().getByUserKey(IntegrationHelper.dummyUserKey().matchingKey()).getSegmentList());
}

@Test
public void notificationIsIgnoredWhenLargeSegmentsIsDisabled() throws IOException, InterruptedException {
TestSetup testSetup = getTestSetup(false);

boolean mySegmentsAwait = mLatches.get(MY_SEGMENTS).await(10, TimeUnit.SECONDS);
boolean splitsAwait = mLatches.get(SPLIT_CHANGES).await(10, TimeUnit.SECONDS);
boolean myLargeSegmentsAwait = mLatches.get(MY_LARGE_SEGMENTS).await(3, TimeUnit.SECONDS);
MyLargeSegmentEntity myLargeSegmentEntity = testSetup.database.myLargeSegmentDao().getByUserKey(IntegrationHelper.dummyUserKey().matchingKey());
mRandomizeMyLargeSegments.set(true);

pushMyLargeSegmentsMessage(TestingData.largeSegmentsUnboundedNoCompression("100"));
boolean updateAwait = testSetup.updateLatch.await(3, TimeUnit.SECONDS);

assertTrue(testSetup.await);
assertTrue(testSetup.authAwait);
assertTrue(mySegmentsAwait);
assertTrue(splitsAwait);
assertFalse(myLargeSegmentsAwait);
assertFalse(updateAwait);
assertNull(mEndpointHits.get(MY_LARGE_SEGMENTS));
assertEquals(2, mEndpointHits.get(SPLIT_CHANGES).get());
assertEquals(2, mEndpointHits.get(MY_SEGMENTS).get());
assertNull(myLargeSegmentEntity);
assertNull(testSetup.database.myLargeSegmentDao().getByUserKey(IntegrationHelper.dummyUserKey().matchingKey()));
}

@NonNull
private TestSetup getTestSetup(boolean largeSegmentsEnabled) throws IOException, InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
Expand Down Expand Up @@ -174,8 +145,6 @@ private SplitFactory getFactory(boolean largeSegmentsEnabled,
database = DatabaseHelper.getTestDatabase(mContext);
}
TestableSplitConfigBuilder configBuilder = new TestableSplitConfigBuilder()
.largeSegmentsEnabled(largeSegmentsEnabled)
.waitForLargeSegments(waitForLargeSegments)
.streamingEnabled(true)
.enableDebug();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
public class LargeSegmentsTest extends LargeSegmentTestHelper {

@Test
public void sdkReadyIsEmittedAfterLargeSegmentsAreSyncedWhenWaitForLargeSegmentsIsTrue() {
SplitFactory factory = getFactory(true, true);
public void sdkReadyIsEmittedAfterLargeSegmentsAreSynced() {
SplitFactory factory = getFactory();

SplitClient readyClient = getReadyClient(IntegrationHelper.dummyUserKey().matchingKey(), factory);

Expand All @@ -38,11 +38,11 @@ public void sdkReadyIsEmittedAfterLargeSegmentsAreSyncedWhenWaitForLargeSegments
}

@Test
public void sdkReadyTimeoutIsEmittedWhenWaitForLargeSegmentsIsTrueAndSyncFails() throws InterruptedException {
public void sdkReadyTimeoutIsEmittedWhenLargeSegmentsSyncFails() throws InterruptedException {
CountDownLatch countDownLatch = new CountDownLatch(1);
CountDownLatch sdkReadyTimeoutLatch = new CountDownLatch(1);
mMyLargeSegmentsStatusCode.set(500);
SplitFactory factory = getFactory(true, true, null, 2500, null);
SplitFactory factory = getFactory(null, 2500, null);

SplitClient client = factory.client();
client.on(SplitEvent.SDK_READY, TestingHelper.testTask(countDownLatch));
Expand All @@ -60,7 +60,7 @@ public void sdkReadyTimeoutIsEmittedWhenWaitForLargeSegmentsIsTrueAndSyncFails()
@Test
public void sdkReadyIsEmittedAfterLargeSegmentsAreSyncedWhenWaitForLargeSegmentsIsFalse() {
mMyLargeSegmentsDelay.set(4000);
SplitFactory factory = getFactory(true, false);
SplitFactory factory = getFactory();
getReadyClient(IntegrationHelper.dummyUserKey().matchingKey(), factory);


Expand All @@ -75,7 +75,7 @@ public void sdkUpdateIsEmittedForLargeSegmentsWhenLargeSegmentsChange() throws I
mMyLargeSegmentsDelay.set(0L);
CountDownLatch updateLatch = new CountDownLatch(3);
CountDownLatch readyLatch = new CountDownLatch(1);
SplitFactory factory = getFactory(true, true, 1, null, null);
SplitFactory factory = getFactory(1, null, null);

SplitClient client = factory.client();
client.on(SplitEvent.SDK_READY, TestingHelper.testTask(readyLatch));
Expand All @@ -88,26 +88,12 @@ public void sdkUpdateIsEmittedForLargeSegmentsWhenLargeSegmentsChange() throws I
assertTrue(await);
}

@Test
public void noHitsToMyLargeSegmentsEndpointWhenLargeSegmentsAreDisabled() throws InterruptedException {
mMyLargeSegmentsDelay.set(0L);
SplitFactory factory = getFactory(false, true, 1, null, null);

SplitClient readyClient = getReadyClient(IntegrationHelper.dummyUserKey().matchingKey(), factory);
Thread.sleep(5000);


assertEquals(1, mEndpointHits.get("splitChanges").get());
assertEquals(1, mEndpointHits.get("mySegments").get());
assertNull(mEndpointHits.get("myLargeSegments"));
}

@Test
public void onlyOneHitToLargeSegmentsWhenPollingIsEnabledAndEndpointFailsWith403() throws InterruptedException {
mMyLargeSegmentsDelay.set(0L);
mMyLargeSegmentsStatusCode.set(403);

SplitFactory factory = getFactory(true, false, 3, null, null);
SplitFactory factory = getFactory(3, null, null);

SplitClient readyClient = getReadyClient(IntegrationHelper.dummyUserKey().matchingKey(), factory);
Thread.sleep(5000);
Expand All @@ -120,7 +106,7 @@ public void sdkReadyIsEmittedWhenWaitForLargeSegmentsIsTrueAndSyncFailsWith403Co
CountDownLatch countDownLatch = new CountDownLatch(1);
CountDownLatch sdkReadyTimeoutLatch = new CountDownLatch(1);
mMyLargeSegmentsStatusCode.set(403);
SplitFactory factory = getFactory(true, true, null, 2500, null);
SplitFactory factory = getFactory(null, 2500, null);
SplitClient client = factory.client();
client.on(SplitEvent.SDK_READY, TestingHelper.testTask(countDownLatch));
client.on(SplitEvent.SDK_READY_TIMED_OUT, TestingHelper.testTask(sdkReadyTimeoutLatch));
Expand All @@ -139,7 +125,7 @@ public void multipleHitsToLargeSegmentsWhenWhenEndpointFailsWithErrorCodeDiffere
mMyLargeSegmentsDelay.set(0L);
mMyLargeSegmentsStatusCode.set(500);

SplitFactory factory = getFactory(true, false, null, null, null);
SplitFactory factory = getFactory(null, null, null);

SplitClient readyClient = getReadyClient(IntegrationHelper.dummyUserKey().matchingKey(), factory);
mMyLargeSegmentsStatusCode.set(200);
Expand All @@ -152,18 +138,18 @@ public void multipleHitsToLargeSegmentsWhenWhenEndpointFailsWithErrorCodeDiffere
}

@Test
public void sdkReadyFromCacheIsEmittedAfterLargeSegmentsAreSyncedWhenWaitForLargeSegmentsIsTrue() throws InterruptedException {
public void sdkReadyFromCacheIsEmittedAfterLargeSegmentsAreSynced() throws InterruptedException {
SplitRoomDatabase testDatabase = DatabaseHelper.getTestDatabase(mContext);
// first, prepopulate local cache
SplitFactory factory = getFactory(true, true, null, null, testDatabase);
SplitFactory factory = getFactory(null, null, testDatabase);
SplitClient readyClient = getReadyClient(IntegrationHelper.dummyUserKey().matchingKey(), factory);

String firstEval = readyClient.getTreatment("ls_split");

// make all api requests fail, we only want sdk_ready_from_cache
mBrokenApi.set(true);

factory = getFactory(true, false, null, 1000, testDatabase);
factory = getFactory(null, 1000, testDatabase);
CountDownLatch fromCacheLatch = new CountDownLatch(1);
CountDownLatch timeoutLatch = new CountDownLatch(1);
SplitClient client = factory.client();
Expand All @@ -186,7 +172,7 @@ public void sdkReadyFromCacheIsEmittedAfterLargeSegmentsAreSyncedWhenWaitForLarg
public void successfulSyncOfLargeSegmentsContainsSegmentsInDatabase() {
SplitRoomDatabase testDatabase = DatabaseHelper.getTestDatabase(mContext);

SplitFactory factory = getFactory(true, true, null, null, testDatabase);
SplitFactory factory = getFactory(null, null, testDatabase);
getReadyClient(IntegrationHelper.dummyUserKey().matchingKey(), factory);

SegmentChangeDTO largeSegments = Json.fromJson(testDatabase.myLargeSegmentDao()
Expand All @@ -203,7 +189,7 @@ public void successfulSyncOfLargeSegmentsContainsSegmentsInDatabase() {
public void syncOfLargeSegmentsForMultiClient() throws InterruptedException {
mRandomizeMyLargeSegments.set(true);
SplitRoomDatabase testDatabase = DatabaseHelper.getTestDatabase(mContext);
SplitFactory factory = getFactory(true, true, 10, null, testDatabase);
SplitFactory factory = getFactory(10, null, testDatabase);

SplitClient client1 = factory.client();
SplitClient client2 = factory.client("key2");
Expand All @@ -230,7 +216,7 @@ public void syncOfLargeSegmentsForMultiClient() throws InterruptedException {
public void emptyMyLargeSegmentsSdkIsReady() throws InterruptedException {
mMyLargeSegmentsDelay.set(0L);
mEmptyMyLargeSegments.set(true);
SplitFactory factory = getFactory(true, true, null, null, null);
SplitFactory factory = getFactory(null, null, null);
SplitClient client = factory.client();
CountDownLatch readyLatch = new CountDownLatch(1);
client.on(SplitEvent.SDK_READY, TestingHelper.testTask(readyLatch));
Expand All @@ -245,10 +231,7 @@ public void emptyMyLargeSegmentsSdkIsReady() throws InterruptedException {
@Test
public void localhostModeIsReadyWhenWaitForLargeSegmentsIsTrue() throws SplitInstantiationException, InterruptedException {
SplitFactory factory = SplitFactoryBuilder.build("localhost", IntegrationHelper.dummyUserKey(),
new TestableSplitConfigBuilder()
.largeSegmentsEnabled(true)
.waitForLargeSegments(true)
.build(), mContext);
new TestableSplitConfigBuilder().build(), mContext);

CountDownLatch readyLatch = new CountDownLatch(1);
factory.client().on(SplitEvent.SDK_READY, TestingHelper.testTask(readyLatch));
Expand Down
46 changes: 8 additions & 38 deletions src/androidTest/java/tests/service/SseJwtTokenParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void testOkToken() throws InvalidJwtTokenException {
"E1ODM5NDc4MTIsImlhdCI6MTU4Mzk0NDIxMn0.bSkxugrXKLaJJkvlND1QEd7vrwqWiPjn77pkrJOl4t8";

SseJwtParser parser = new SseJwtParser();
SseJwtToken parsedToken = parser.parse(jwtToken, false);
SseJwtToken parsedToken = parser.parse(jwtToken);
List<String> channels = parsedToken.getChannels();

Assert.assertEquals(1583947812L, parsedToken.getExpirationTime());
Expand All @@ -52,7 +52,7 @@ public void onlyHeader() {

SseJwtToken parsedToken = null;
try {
parsedToken = parser.parse(jwtToken, false);
parsedToken = parser.parse(jwtToken);
} catch (InvalidJwtTokenException e) {
thrownEx = e;
}
Expand All @@ -73,7 +73,7 @@ public void testOnlyChannelsWithSeparator() throws InvalidJwtTokenException {
"E1ODM5NDc4MTIsImlhdCI6MTU4Mzk0NDIxMn0.bSkxugrXKLaJJkvlND1QEd7vrwqWiPjn77pkrJOl4t8";

SseJwtParser parser = new SseJwtParser();
SseJwtToken parsedToken = parser.parse(jwtToken, false);
SseJwtToken parsedToken = parser.parse(jwtToken);
List<String> channels = parsedToken.getChannels();

Assert.assertEquals(1583947812L, parsedToken.getExpirationTime());
Expand Down Expand Up @@ -102,7 +102,7 @@ public void testOnlyChannelsWithoutSeparator() {

SseJwtToken parsedToken = null;
try {
parsedToken = parser.parse(jwtToken, false);
parsedToken = parser.parse(jwtToken);
} catch (InvalidJwtTokenException e) {
thrownEx = e;
}
Expand All @@ -120,7 +120,7 @@ public void garbageToken() {

SseJwtToken parsedToken = null;
try {
parsedToken = parser.parse(jwtToken, false);
parsedToken = parser.parse(jwtToken);
} catch (InvalidJwtTokenException e) {
thrownEx = e;
}
Expand All @@ -138,7 +138,7 @@ public void emptyToken() {

SseJwtToken parsedToken = null;
try {
parsedToken = parser.parse(jwtToken, false);
parsedToken = parser.parse(jwtToken);
} catch (InvalidJwtTokenException e) {
thrownEx = e;
}
Expand All @@ -156,7 +156,7 @@ public void nullToken() {

SseJwtToken parsedToken = null;
try {
parsedToken = parser.parse(jwtToken, false);
parsedToken = parser.parse(jwtToken);
} catch (InvalidJwtTokenException e) {
thrownEx = e;
}
Expand All @@ -179,7 +179,7 @@ public void testLargeSegmentsToken() throws InvalidJwtTokenException {
"DQzODgKfQ==.LcKAXnkr-CiYVxZ7l38w9i98Y-BMAv9JlGP2i92nVQY";

SseJwtParser parser = new SseJwtParser();
SseJwtToken parsedToken = parser.parse(jwtToken, true);
SseJwtToken parsedToken = parser.parse(jwtToken);
List<String> channels = parsedToken.getChannels();

Assert.assertEquals(2208988800L, parsedToken.getExpirationTime());
Expand All @@ -195,34 +195,4 @@ public void testLargeSegmentsToken() throws InvalidJwtTokenException {
Assert.assertEquals("[?occupancy=metrics.publishers]control_sec",
channels.get(4));
}

@Test
public void testLargeSegmentsTokenLargeSegmentsDisabled() throws InvalidJwtTokenException {

String jwtToken = "eyJhbGciOiJIUzI1NiIsImtpZCI6IjVZOU05US45QnJtR0EiLCJ0eXAiOiJKV1QifQ." +
"ewogICJ4LWFibHktY2FwYWJpbGl0eSI6ICJ7XCJNek01TmpjME9EY3lOZz09X01URXhNemd3Tm" +
"pneF9NVGN3TlRJMk1UTTBNZz09X215U2VnbWVudHNcIjpbXCJzdWJzY3JpYmVcIl0sXCJNek01" +
"TmpjME9EY3lOZz09X01URXhNemd3TmpneF9NVGN3TlRJMk1UTTBNZz09X215bGFyZ2VzZWdtZW" +
"50c1wiOltcInN1YnNjcmliZVwiXSxcIk16TTVOamMwT0RjeU5nPT1fTVRFeE16Z3dOamd4X3Nw" +
"bGl0c1wiOltcInN1YnNjcmliZVwiXSxcImNvbnRyb2xfcHJpXCI6W1wic3Vic2NyaWJlXCIsXC" +
"JjaGFubmVsLW1ldGFkYXRhOnB1Ymxpc2hlcnNcIl0sXCJjb250cm9sX3NlY1wiOltcInN1YnNj" +
"cmliZVwiLFwiY2hhbm5lbC1tZXRhZGF0YTpwdWJsaXNoZXJzXCJdfSIsCiAgIngtYWJseS1jbG" +
"llbnRJZCI6ICJjbGllbnRJZCIsCiAgImV4cCI6IDIyMDg5ODg4MDAsCiAgImlhdCI6IDE1ODc0M" +
"DQzODgKfQ==.LcKAXnkr-CiYVxZ7l38w9i98Y-BMAv9JlGP2i92nVQY";

SseJwtParser parser = new SseJwtParser();
SseJwtToken parsedToken = parser.parse(jwtToken, false);
List<String> channels = parsedToken.getChannels();

Assert.assertEquals(2208988800L, parsedToken.getExpirationTime());
Assert.assertEquals(jwtToken, parsedToken.getRawJwt());
Assert.assertEquals("MzM5Njc0ODcyNg==_MTExMzgwNjgx_MTcwNTI2MTM0Mg==_mySegments",
channels.get(0));
Assert.assertEquals("MzM5Njc0ODcyNg==_MTExMzgwNjgx_splits",
channels.get(1));
Assert.assertEquals("[?occupancy=metrics.publishers]control_pri",
channels.get(2));
Assert.assertEquals("[?occupancy=metrics.publishers]control_sec",
channels.get(3));
}
}
Loading

0 comments on commit 90605a5

Please sign in to comment.