Skip to content

Commit

Permalink
Rename new notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea committed Sep 3, 2024
1 parent c1a7c25 commit cc17b1f
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static String segmentsUnboundedNoCompression(String intervalMs) {

public static String largeSegmentsUnboundedNoCompression(String intervalMs) {
return "{" +
"\\\"type\\\":\\\"MEMBERSHIP_LS_UPDATE\\\"" +
"\\\"type\\\":\\\"MEMBERSHIPS_LS_UPDATE\\\"" +
",\\\"cn\\\":1702507130121," +
"\\\"n\\\":[\\\"android_test\\\",\\\"ios_test\\\"]," +
"\\\"c\\\":0," +
Expand All @@ -137,7 +137,7 @@ public static String largeSegmentsUnboundedNoCompression(String intervalMs) {

public static String largeSegmentsRemoval() {
return "{" +
"\\\"type\\\":\\\"MEMBERSHIP_LS_UPDATE\\\"" +
"\\\"type\\\":\\\"MEMBERSHIPS_LS_UPDATE\\\"" +
",\\\"cn\\\":1702507130121," +
"\\\"n\\\":[\\\"large-segment1\\\",\\\"large-segment2\\\"]," +
"\\\"c\\\":0," +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public void process(IncomingNotification incomingNotification) {
case SPLIT_KILL:
processSplitKill(mNotificationParser.parseSplitKill(notificationJson));
break;
case MEMBERSHIP_MS_UPDATE:
case MEMBERSHIP_LS_UPDATE:
case MEMBERSHIPS_MS_UPDATE:
case MEMBERSHIPS_LS_UPDATE:
processMembershipsUpdate(mNotificationParser.parseMembershipNotification(notificationJson));
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public enum NotificationType {
@SerializedName("ERROR")
ERROR,

@SerializedName("MEMBERSHIP_LS_UPDATE")
MEMBERSHIP_LS_UPDATE,
@SerializedName("MEMBERSHIP_MS_UPDATE")
MEMBERSHIP_MS_UPDATE,
@SerializedName("MEMBERSHIPS_LS_UPDATE")
MEMBERSHIPS_LS_UPDATE,
@SerializedName("MEMBERSHIPS_MS_UPDATE")
MEMBERSHIPS_MS_UPDATE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ private void processUpdate(NotificationType notificationType, MySegmentUpdateStr
break;
}
} catch (Exception e) {
Logger.e("Executing unbounded fetch because an error has occurred processing my "+(notificationType == NotificationType.MEMBERSHIP_LS_UPDATE ? "large" : "")+" segment notification: " + e.getLocalizedMessage());
Logger.e("Executing unbounded fetch because an error has occurred processing my "+(notificationType == NotificationType.MEMBERSHIPS_LS_UPDATE ? "large" : "")+" segment notification: " + e.getLocalizedMessage());
notifyMySegmentRefreshNeeded(notificationsQueue, syncDelay, notificationType, changeNumber);
}
}

private void notifyMySegmentRefreshNeeded(BlockingQueue<MySegmentUpdateParams> notificationsQueue, long syncDelay, NotificationType notificationType, Long changeNumber) {
Long targetSegmentsCn = (notificationType == NotificationType.MEMBERSHIP_MS_UPDATE) ? changeNumber : null;
Long targetLargeSegmentsCn = (notificationType == NotificationType.MEMBERSHIP_LS_UPDATE) ? changeNumber : null;
Long targetSegmentsCn = (notificationType == NotificationType.MEMBERSHIPS_MS_UPDATE) ? changeNumber : null;
Long targetLargeSegmentsCn = (notificationType == NotificationType.MEMBERSHIPS_LS_UPDATE) ? changeNumber : null;

//noinspection ResultOfMethodCallIgnored
notificationsQueue.offer(new MySegmentUpdateParams(syncDelay, targetSegmentsCn, targetLargeSegmentsCn));
Expand All @@ -112,7 +112,7 @@ private void removeSegment(NotificationType notificationType, Set<String> segmen
if (segmentNames == null) {
return;
}
MySegmentsUpdateTask task = (notificationType == NotificationType.MEMBERSHIP_LS_UPDATE) ?
MySegmentsUpdateTask task = (notificationType == NotificationType.MEMBERSHIPS_LS_UPDATE) ?
mConfiguration.getMySegmentsTaskFactory().createMyLargeSegmentsUpdateTask(false, segmentNames, changeNumber) :
mConfiguration.getMySegmentsTaskFactory().createMySegmentsUpdateTask(false, segmentNames, changeNumber);
mSplitTaskExecutor.submit(task, null);
Expand All @@ -139,7 +139,7 @@ private void updateSegments(NotificationType notificationType, String keyListStr
return;
}

boolean largeSegmentsUpdate = notificationType == NotificationType.MEMBERSHIP_LS_UPDATE;
boolean largeSegmentsUpdate = notificationType == NotificationType.MEMBERSHIPS_LS_UPDATE;
Logger.d("Executing KeyList my "+ (largeSegmentsUpdate ? "large " : "") +"segment fetch request: Adding = " + actionIsAdd);
MySegmentsUpdateTask task = largeSegmentsUpdate ? mConfiguration.getMySegmentsTaskFactory().createMyLargeSegmentsUpdateTask(actionIsAdd, segmentNames, changeNumber) :
mConfiguration.getMySegmentsTaskFactory().createMySegmentsUpdateTask(actionIsAdd, segmentNames, changeNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public boolean isConnectionConfirmed(Map<String, String> values) {
public void handleIncomingMessage(Map<String, String> values) {

String messageData = values.get(EventStreamParser.DATA_FIELD);

if (messageData != null) {
if (mNotificationParser.isError(values)) {
handleError(messageData);
Expand All @@ -84,8 +85,8 @@ public void handleIncomingMessage(Map<String, String> values) {
break;
case SPLIT_KILL:
case SPLIT_UPDATE:
case MEMBERSHIP_MS_UPDATE:
case MEMBERSHIP_LS_UPDATE:
case MEMBERSHIPS_MS_UPDATE:
case MEMBERSHIPS_LS_UPDATE:
if (mNotificationManagerKeeper.isStreamingActive()) {
mNotificationProcessor.process(incomingNotification);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.split.android.client.service.sseclient;

import static org.junit.Assert.assertEquals;
import static io.split.android.client.service.sseclient.notifications.NotificationType.MEMBERSHIP_LS_UPDATE;
import static io.split.android.client.service.sseclient.notifications.NotificationType.MEMBERSHIPS_LS_UPDATE;

import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -38,7 +38,7 @@ public class NotificationParserTest {

private final static String CONTROL = "{\"id\":\"x2dE2TEiJL:0:0\",\"clientId\":\"NDEzMTY5Mzg0MA==:OTc5Nzc4NDYz\",\"timestamp\":1584647533288,\"encoding\":\"json\",\"channel\":\"control_pri\",\"data\":\"{\\\"type\\\":\\\"CONTROL\\\",\\\"controlType\\\":\\\"STREAMING_RESUMED\\\"}\"}";

private static final String MY_LARGE_SEGMENTS_UPDATE = "{\"id\": \"diSrQttrC9:0:0\",\"clientId\": \"pri:MjcyNDE2NDUxMA==\",\"timestamp\": 1702507131100,\"encoding\": \"json\",\"channel\": \"NzM2MDI5Mzc0_MTc1MTYwODQxMQ==_memberships\",\"data\": \"{\\\"type\\\":\\\"MEMBERSHIP_LS_UPDATE\\\",\\\"cn\\\":1702507130121,\\\"n\\\":[\\\"android_test\\\"],\\\"c\\\":2,\\\"u\\\":2,\\\"d\\\":\\\"eJwEwLsRwzAMA9BdWKsg+IFBraJTkRXS5rK7388+tg+KdC8+jq4eBBQLFcUnO8FAAC36gndOSEyFqJFP32Vf2+f+3wAAAP//hUQQ9A==\\\",\\\"i\\\":100,\\\"h\\\":1,\\\"s\\\":325}\"}";
private static final String MY_LARGE_SEGMENTS_UPDATE = "{\"id\": \"diSrQttrC9:0:0\",\"clientId\": \"pri:MjcyNDE2NDUxMA==\",\"timestamp\": 1702507131100,\"encoding\": \"json\",\"channel\": \"NzM2MDI5Mzc0_MTc1MTYwODQxMQ==_memberships\",\"data\": \"{\\\"type\\\":\\\"MEMBERSHIPS_LS_UPDATE\\\",\\\"cn\\\":1702507130121,\\\"n\\\":[\\\"android_test\\\"],\\\"c\\\":2,\\\"u\\\":2,\\\"d\\\":\\\"eJwEwLsRwzAMA9BdWKsg+IFBraJTkRXS5rK7388+tg+KdC8+jq4eBBQLFcUnO8FAAC36gndOSEyFqJFP32Vf2+f+3wAAAP//hUQQ9A==\\\",\\\"i\\\":100,\\\"h\\\":1,\\\"s\\\":325}\"}";

@Before
public void setup() {
Expand Down Expand Up @@ -138,8 +138,8 @@ public void NoCrashIfisNullEventError() {
public void parseMyLargeSegmentsIncomingNotification() {
IncomingNotification incoming = mParser.parseIncoming(MY_LARGE_SEGMENTS_UPDATE);

assertEquals(MEMBERSHIP_LS_UPDATE, incoming.getType());
assertEquals("{\"type\":\"MEMBERSHIP_LS_UPDATE\",\"cn\":1702507130121,\"n\":[\"android_test\"],\"c\":2,\"u\":2,\"d\":\"eJwEwLsRwzAMA9BdWKsg+IFBraJTkRXS5rK7388+tg+KdC8+jq4eBBQLFcUnO8FAAC36gndOSEyFqJFP32Vf2+f+3wAAAP//hUQQ9A==\",\"i\":100,\"h\":1,\"s\":325}", incoming.getJsonData());
assertEquals(MEMBERSHIPS_LS_UPDATE, incoming.getType());
assertEquals("{\"type\":\"MEMBERSHIPS_LS_UPDATE\",\"cn\":1702507130121,\"n\":[\"android_test\"],\"c\":2,\"u\":2,\"d\":\"eJwEwLsRwzAMA9BdWKsg+IFBraJTkRXS5rK7388+tg+KdC8+jq4eBBQLFcUnO8FAAC36gndOSEyFqJFP32Vf2+f+3wAAAP//hUQQ9A==\",\"i\":100,\"h\":1,\"s\":325}", incoming.getJsonData());
assertEquals("NzM2MDI5Mzc0_MTc1MTYwODQxMQ==_memberships", incoming.getChannel());
assertEquals(1702507131100L, incoming.getTimestamp());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void notificationProcessorDelegatesMySegmentsNotificationsV2ToRegisteredP
MembershipNotification mySegmentChangeNotification = mock(MembershipNotification.class);

when(mySegmentChangeNotification.getJsonData()).thenReturn("{}");
when(mIncomingNotification.getType()).thenReturn(NotificationType.MEMBERSHIP_MS_UPDATE);
when(mIncomingNotification.getType()).thenReturn(NotificationType.MEMBERSHIPS_MS_UPDATE);
when(mNotificationParser.parseMembershipNotification(anyString())).thenReturn(mySegmentChangeNotification);

mNotificationProcessor.registerMembershipsNotificationProcessor("1", mySegmentsNotificationProcessor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void incomingSplitKill() {
public void incomingMembershipUpdate() {

IncomingNotification incomingNotification =
new IncomingNotification(NotificationType.MEMBERSHIP_MS_UPDATE, "", "", 100);
new IncomingNotification(NotificationType.MEMBERSHIPS_MS_UPDATE, "", "", 100);
MembershipNotification notification = new MembershipNotification();

when(mNotificationParser.parseIncoming(anyString())).thenReturn(incomingNotification);
Expand All @@ -118,7 +118,7 @@ public void incomingMembershipUpdate() {
public void incomingLargeMembershipUpdate() {

IncomingNotification incomingNotification =
new IncomingNotification(NotificationType.MEMBERSHIP_LS_UPDATE, "", "", 100);
new IncomingNotification(NotificationType.MEMBERSHIPS_LS_UPDATE, "", "", 100);
MembershipNotification notification = new MembershipNotification();

when(mNotificationParser.parseIncoming(anyString())).thenReturn(incomingNotification);
Expand All @@ -134,7 +134,7 @@ public void incomingLargeMembershipUpdate() {
public void streamingPaused() {

IncomingNotification incomingNotification =
new IncomingNotification(NotificationType.MEMBERSHIP_LS_UPDATE, "", "", 100);
new IncomingNotification(NotificationType.MEMBERSHIPS_LS_UPDATE, "", "", 100);
MembershipNotification notification = new MembershipNotification();

when(mNotificationParser.parseIncoming(anyString())).thenReturn(incomingNotification);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void mySegmentsUpdateV2UnboundedNotification() {
MembershipNotification mySegmentChangeNotification
= mock(MembershipNotification.class);
when(mySegmentChangeNotification.getUpdateStrategy()).thenReturn(MySegmentUpdateStrategy.UNBOUNDED_FETCH_REQUEST);
when(mySegmentChangeNotification.getType()).thenReturn(NotificationType.MEMBERSHIP_MS_UPDATE);
when(mySegmentChangeNotification.getType()).thenReturn(NotificationType.MEMBERSHIPS_MS_UPDATE);
when(mNotificationParser.parseMembershipNotification(anyString())).thenReturn(mySegmentChangeNotification);

mNotificationProcessor.process(mySegmentChangeNotification);
Expand All @@ -119,7 +119,7 @@ public void mySegmentsUpdateV2RemovalNotification() {
String segmentName = "ToRemove";
when(mMsMembershipNotification.getUpdateStrategy()).thenReturn(MySegmentUpdateStrategy.SEGMENT_REMOVAL);
when(mMsMembershipNotification.getNames()).thenReturn(Collections.singleton(segmentName));
when(mMsMembershipNotification.getType()).thenReturn(NotificationType.MEMBERSHIP_MS_UPDATE);
when(mMsMembershipNotification.getType()).thenReturn(NotificationType.MEMBERSHIPS_MS_UPDATE);
when(mMsMembershipNotification.getChangeNumber()).thenReturn(25L);
when(mNotificationParser.parseMembershipNotification(anyString())).thenReturn(mMsMembershipNotification);

Expand Down Expand Up @@ -150,8 +150,8 @@ public void mySegmentsUpdateV2BoundedNotification(boolean hasToFetch) {
= mock(MembershipNotification.class);
when(mySegmentChangeNotification.getUpdateStrategy()).thenReturn(MySegmentUpdateStrategy.BOUNDED_FETCH_REQUEST);
when(mySegmentChangeNotification.getData()).thenReturn("dummy");
when(mMsMembershipNotification.getType()).thenReturn(NotificationType.MEMBERSHIP_MS_UPDATE);
when(mySegmentChangeNotification.getType()).thenReturn(NotificationType.MEMBERSHIP_MS_UPDATE);
when(mMsMembershipNotification.getType()).thenReturn(NotificationType.MEMBERSHIPS_MS_UPDATE);
when(mySegmentChangeNotification.getType()).thenReturn(NotificationType.MEMBERSHIPS_MS_UPDATE);
try {
when(mMySegmentsPayloadDecoder.decodeAsBytes(anyString(), any())).thenReturn(new byte[]{});
} catch (MySegmentsParsingException e) {
Expand Down Expand Up @@ -191,8 +191,8 @@ public void mySegmentsUpdateV2KeyListNotificationErrorFallback() throws MySegmen
= mock(MembershipNotification.class);
when(mySegmentChangeNotification.getUpdateStrategy()).thenReturn(MySegmentUpdateStrategy.KEY_LIST);
when(mySegmentChangeNotification.getNames()).thenReturn(Collections.singleton("s1"));
when(mMsMembershipNotification.getType()).thenReturn(NotificationType.MEMBERSHIP_MS_UPDATE);
when(mySegmentChangeNotification.getType()).thenReturn(NotificationType.MEMBERSHIP_MS_UPDATE);
when(mMsMembershipNotification.getType()).thenReturn(NotificationType.MEMBERSHIPS_MS_UPDATE);
when(mySegmentChangeNotification.getType()).thenReturn(NotificationType.MEMBERSHIPS_MS_UPDATE);
when(mMySegmentsPayloadDecoder.decodeAsString(anyString(), any())).thenThrow(MySegmentsParsingException.class);

mNotificationProcessor.process(mMsMembershipNotification);
Expand All @@ -208,8 +208,8 @@ public void mySegmentsUpdateV2BoundedNotificationErrorFallback() throws MySegmen
= mock(MembershipNotification.class);
when(mySegmentChangeNotification.getUpdateStrategy()).thenReturn(MySegmentUpdateStrategy.BOUNDED_FETCH_REQUEST);
when(mySegmentChangeNotification.getNames()).thenReturn(Collections.singleton("s1"));
when(mMsMembershipNotification.getType()).thenReturn(NotificationType.MEMBERSHIP_MS_UPDATE);
when(mySegmentChangeNotification.getType()).thenReturn(NotificationType.MEMBERSHIP_MS_UPDATE);
when(mMsMembershipNotification.getType()).thenReturn(NotificationType.MEMBERSHIPS_MS_UPDATE);
when(mySegmentChangeNotification.getType()).thenReturn(NotificationType.MEMBERSHIPS_MS_UPDATE);
when(mMySegmentsPayloadDecoder.decodeAsBytes(anyString(), any())).thenThrow(MySegmentsParsingException.class);

mNotificationProcessor.process(mMsMembershipNotification);
Expand Down Expand Up @@ -237,8 +237,8 @@ private void mySegmentsUpdateV2KeyListNotification(String segmentName, KeyList.A
when(mMsMembershipNotification.getUpdateStrategy()).thenReturn(MySegmentUpdateStrategy.KEY_LIST);
when(mMsMembershipNotification.getNames()).thenReturn(Collections.singleton(segmentName));
when(mMsMembershipNotification.getChangeNumber()).thenReturn(123456L);
when(mMsMembershipNotification.getType()).thenReturn(NotificationType.MEMBERSHIP_MS_UPDATE);
when(mMsMembershipNotification.getType()).thenReturn(NotificationType.MEMBERSHIP_MS_UPDATE);
when(mMsMembershipNotification.getType()).thenReturn(NotificationType.MEMBERSHIPS_MS_UPDATE);
when(mMsMembershipNotification.getType()).thenReturn(NotificationType.MEMBERSHIPS_MS_UPDATE);
try {
when(mMySegmentsPayloadDecoder.decodeAsString(anyString(), any())).thenReturn("");
} catch (MySegmentsParsingException e) {
Expand Down

0 comments on commit cc17b1f

Please sign in to comment.