Skip to content

Commit

Permalink
Removing unused classes (#695)
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea authored Aug 29, 2024
2 parents 4b3726a + a667761 commit 06d465d
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 180 deletions.
2 changes: 1 addition & 1 deletion src/androidTest/java/helper/IntegrationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,6 @@ public interface StreamingResponseClosure {
}

public static class ServicePath {
public static final String MEMBERSHIPS = "membership";
public static final String MEMBERSHIPS = "memberships";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import io.split.android.client.SplitClientConfig;
import io.split.android.client.SplitFactory;
import io.split.android.client.api.Key;
import io.split.android.client.dtos.MySegment;
import io.split.android.client.dtos.Partition;
import io.split.android.client.dtos.Segment;
import io.split.android.client.dtos.Split;
Expand Down

This file was deleted.

31 changes: 0 additions & 31 deletions src/main/java/io/split/android/client/dtos/MySegment.java

This file was deleted.

48 changes: 0 additions & 48 deletions src/main/java/io/split/android/client/dtos/MySegmentsResponse.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class SdkTargetPath {
public static final String SPLIT_CHANGES = "/splitChanges";
public static final String MEMBERSHIPS = "/membership";
public static final String MEMBERSHIPS = "/memberships";
public static final String EVENTS = "/events/bulk";
public static final String IMPRESSIONS = "/testImpressions/bulk";
public static final String IMPRESSIONS_COUNT = "/testImpressions/count";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ private void fetch(int initialRetries) throws HttpFetcherException, InterruptedE
}

if (isStaleResponse(response)) {
Logger.d("Retrying memberships fetch due to change number mismatch");
long waitMillis = TimeUnit.SECONDS.toMillis(mBackoffCounter.getNextRetryTime());
Thread.sleep(waitMillis);
remainingRetries--;
Expand All @@ -175,53 +176,45 @@ private void fetch(int initialRetries) throws HttpFetcherException, InterruptedE
private Map<String, Object> getParams(boolean addTill) {
Map<String, Object> params = new HashMap<>();
if (addTill) {
long segmentsTarget = Utils.getOrDefault(mTargetSegmentsChangeNumber, -1L);
long largeSegmentsTarget = Utils.getOrDefault(mTargetLargeSegmentsChangeNumber, -1L);
params.put(TILL_PARAM, Math.max(segmentsTarget, largeSegmentsTarget));
params.put(TILL_PARAM, Math.max(
Utils.getOrDefault(mTargetSegmentsChangeNumber, -1L),
Utils.getOrDefault(mTargetLargeSegmentsChangeNumber, -1L)));
}

return params;
}

private boolean isStaleResponse(AllSegmentsChange response) {
boolean checkSegments = Utils.getOrDefault(mTargetSegmentsChangeNumber, -1L) != -1;
boolean checkLargeSegments = Utils.getOrDefault(mTargetLargeSegmentsChangeNumber, -1L) != -1;

boolean segmentsTargetMatched = !checkSegments ||
response.getSegmentsChange() != null && mTargetSegmentsChangeNumber.equals(response.getSegmentsChange().getChangeNumber());
boolean largeSegmentsTargetMatched = !checkLargeSegments ||
response.getLargeSegmentsChange() != null && mTargetLargeSegmentsChangeNumber.equals(response.getLargeSegmentsChange().getChangeNumber());

if (!segmentsTargetMatched) {
Logger.v("Segments target change number not matched. Expected: " + mTargetSegmentsChangeNumber + " - Actual: " + response.getSegmentsChange().getChangeNumber());
}

if (!largeSegmentsTargetMatched) {
Logger.v("Large segments target change number not matched. Expected: " + mTargetLargeSegmentsChangeNumber + " - Actual: " + response.getLargeSegmentsChange().getChangeNumber());
}
private boolean isStaleResponse(@NonNull AllSegmentsChange response) {
boolean segmentsTargetMatched = targetMatched(mTargetSegmentsChangeNumber, response.getSegmentsChange());
boolean largeSegmentsTargetMatched = targetMatched(mTargetLargeSegmentsChangeNumber, response.getLargeSegmentsChange());

return !segmentsTargetMatched || !largeSegmentsTargetMatched;
}

private boolean targetMatched(@Nullable Long targetChangeNumber, SegmentsChange change) {
Long target = Utils.getOrDefault(targetChangeNumber, -1L);
return target == -1 ||
change == null ||
change.getChangeNumber() == null ||
change.getChangeNumber() != null && target <= change.getChangeNumber();
}

private void updateStorage(AllSegmentsChange response) {
UpdateSegmentsResult segmentsResult = updateSegments(response.getSegmentsChange(), mMySegmentsStorage);
UpdateSegmentsResult largeSegmentsResult = updateSegments(response.getLargeSegmentsChange(), mMyLargeSegmentsStorage);
fireMySegmentsUpdatedIfNeeded(segmentsResult, largeSegmentsResult);
}

@NonNull
private static UpdateSegmentsResult updateSegments(SegmentsChange segmentsChange, MySegmentsStorage storage) {
List<String> oldSegments = new ArrayList<>();
List<String> mySegments = new ArrayList<>();
SegmentsChange segmentsChange = response.getSegmentsChange();
if (segmentsChange != null) {
oldSegments = new ArrayList<>(mMySegmentsStorage.getAll());
oldSegments = new ArrayList<>(storage.getAll());
mySegments = segmentsChange.getNames();
mMySegmentsStorage.set(segmentsChange);
storage.set(segmentsChange);
}

List<String> oldLargeSegments = new ArrayList<>();
List<String> myLargeSegments = new ArrayList<>();
SegmentsChange largeSegmentsChange = response.getLargeSegmentsChange();
if (largeSegmentsChange != null) {
myLargeSegments = largeSegmentsChange.getNames();
oldLargeSegments = new ArrayList<>(mMyLargeSegmentsStorage.getAll());
mMyLargeSegmentsStorage.set(largeSegmentsChange);
}
fireMySegmentsUpdatedIfNeeded(oldSegments, mySegments, oldLargeSegments, myLargeSegments);
return new UpdateSegmentsResult(oldSegments, mySegments);
}

private void logError(String message) {
Expand All @@ -235,26 +228,18 @@ private void logError(String message) {
return null;
}

private void fireMySegmentsUpdatedIfNeeded(List<String> oldSegments, List<String> newSegments, List<String> oldLargeSegments, List<String> newLargeSegments) {
private void fireMySegmentsUpdatedIfNeeded(UpdateSegmentsResult segmentsResult, UpdateSegmentsResult largeSegmentsResult) {
if (mEventsManager == null) {
return;
}

// MY_SEGMENTS_UPDATED event when segments have changed
boolean segmentsHaveChanged = mMySegmentsChangeChecker.mySegmentsHaveChanged(oldSegments, newSegments);
boolean largeSegmentsHaveChanged = mMySegmentsChangeChecker.mySegmentsHaveChanged(oldLargeSegments, newLargeSegments);

if (segmentsHaveChanged) {
Logger.v("New segments fetched: " + String.join(", ", newSegments));
}
if (largeSegmentsHaveChanged) {
Logger.v("New large segments fetched: " + String.join(", ", newLargeSegments));
}
boolean segmentsHaveChanged = mMySegmentsChangeChecker.mySegmentsHaveChanged(segmentsResult.oldSegments, segmentsResult.newSegments);
boolean largeSegmentsHaveChanged = mMySegmentsChangeChecker.mySegmentsHaveChanged(largeSegmentsResult.oldSegments, largeSegmentsResult.newSegments);

if (segmentsHaveChanged) {
mEventsManager.notifyInternalEvent(mUpdateEvent);
} else {

// MY_LARGE_SEGMENTS_UPDATED event when large segments have changed
if (largeSegmentsHaveChanged) {
mEventsManager.notifyInternalEvent(SplitInternalEvent.MY_LARGE_SEGMENTS_UPDATED);
Expand All @@ -264,4 +249,14 @@ private void fireMySegmentsUpdatedIfNeeded(List<String> oldSegments, List<String
}
}
}

private static class UpdateSegmentsResult {
public final List<String> oldSegments;
public final List<String> newSegments;

private UpdateSegmentsResult(List<String> oldSegments, List<String> newSegments) {
this.oldSegments = oldSegments;
this.newSegments = newSegments;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ public class SdkTargetPathTest {
public void userKeyWithSpaces() throws URISyntaxException {
URI uri = SdkTargetPath.mySegments("https://split.io", "CABM, CCIB Marketing");

assertEquals("/membership/CABM,%20CCIB%20Marketing", uri.getRawPath());
assertEquals(SdkTargetPath.MEMBERSHIPS+"/CABM,%20CCIB%20Marketing", uri.getRawPath());
}

@Test
public void userKeyWithSlash() throws URISyntaxException {
URI uri = SdkTargetPath.mySegments("https://split.io", "user/key");

assertEquals("/membership/user%2Fkey", uri.getRawPath());
assertEquals(SdkTargetPath.MEMBERSHIPS+"/user%2Fkey", uri.getRawPath());
}

@Test
public void userKeyWithSpecialChars() throws URISyntaxException {
URI uri = SdkTargetPath.mySegments("https://split.io", "grüneStraße");

assertEquals("/membership/gr%C3%BCneStra%C3%9Fe", uri.getRawPath());
assertEquals(SdkTargetPath.MEMBERSHIPS+"/gr%C3%BCneStra%C3%9Fe", uri.getRawPath());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import io.split.android.client.dtos.MatcherCombiner;
import io.split.android.client.dtos.MatcherGroup;
import io.split.android.client.dtos.MatcherType;
import io.split.android.client.dtos.MySegment;
import io.split.android.client.dtos.Partition;
import io.split.android.client.dtos.Split;
import io.split.android.client.dtos.Status;
Expand Down

0 comments on commit 06d465d

Please sign in to comment.