Skip to content

Commit 8cccfa6

Browse files
committed
polish
1 parent bcf8014 commit 8cccfa6

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

client/src/main/java/io/split/engine/sse/dtos/CommonChangeNotification.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ public CompressType getCompressType() {
6767
return compressType;
6868
}
6969

70-
public void updateDefinition(byte[] decodedBytes) throws UnsupportedEncodingException {
71-
definition = (Y) Json.fromJson(new String(decodedBytes, "UTF-8"), _definitionClass);
72-
}
73-
7470
public Y getDefinition() {
7571
return definition;
7672
}
@@ -84,4 +80,8 @@ public void handler(NotificationProcessor notificationProcessor) {
8480
public String toString() {
8581
return String.format("Type: %s; Channel: %s; ChangeNumber: %s", getType(), getChannel(), getChangeNumber());
8682
}
83+
84+
private void updateDefinition(byte[] decodedBytes) throws UnsupportedEncodingException {
85+
definition = (Y) Json.fromJson(new String(decodedBytes, "UTF-8"), _definitionClass);
86+
}
8787
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package io.split.engine.sse;
2+
3+
import io.split.client.dtos.RuleBasedSegment;
4+
import io.split.client.dtos.Split;
5+
import io.split.client.dtos.Status;
6+
import io.split.client.utils.Json;
7+
import io.split.engine.sse.dtos.CommonChangeNotification;
8+
import io.split.engine.sse.dtos.GenericNotificationData;
9+
import io.split.engine.sse.dtos.IncomingNotification;
10+
import io.split.engine.sse.dtos.RawMessageNotification;
11+
import io.split.engine.sse.enums.CompressType;
12+
import org.junit.Assert;
13+
import org.junit.Test;
14+
15+
public class CommonChangeNotificationTest {
16+
17+
@Test
18+
public void testFeatureFlagNotification() {
19+
String notification = "{\"id\":\"vQQ61wzBRO:0:0\",\"clientId\":\"pri:MTUxNzg3MDg1OQ==\",\"timestamp\":1684265694676,\"encoding\":\"json\",\"channel\":\"NzM2MDI5Mzc0_MjkyNTIzNjczMw==_splits\",\"data\":\"{\\\"type\\\":\\\"SPLIT_UPDATE\\\",\\\"changeNumber\\\":1684265694505,\\\"pcn\\\":0,\\\"c\\\":2,\\\"d\\\":\\\"eJzMk99u2kwQxV8lOtdryQZj8N6hD5QPlThSTVNVEUKDPYZt1jZar1OlyO9emf8lVFWv2ss5zJyd82O8hTWUZSqZvW04opwhUVdsIKBSSKR+10vS1HWW7pIdz2NyBjRwHS8IXEopTLgbQqDYT+ZUm3LxlV4J4mg81LpMyKqygPRc94YeM6eQTtjphp4fegLVXvD6Qdjt9wPXF6gs2bqCxPC/2eRpDIEXpXXblpGuWCDljGptZ4bJ5lxYSJRZBoFkTcWKozpfsoH0goHfCXpB6PfcngDpVQnZEUjKIlOr2uwWqiC3zU5L1aF+3p7LFhUkPv8/mY2nk3gGgZxssmZzb8p6A9n25ktVtA9iGI3ODXunQ3HDp+AVWT6F+rZWlrWq7MN+YkSWWvuTDvkMSnNV7J6oTdl6qKTEvGnmjcCGjL2IYC/ovPYgUKnvvPtbmrmApiVryLM7p2jE++AfH6fTx09/HvuF32LWnNjStM0Xh3c8ukZcsZlEi3h8/zCObsBpJ0acqYLTmFdtqitK1V6NzrfpdPBbLmVx4uK26e27izpDu/r5yf/16AXun2Cr4u6w591xw7+LfDidLj6Mv8TXwP8xbofv/c7UmtHMmx8BAAD//0fclvU=\\\"}\"}";
20+
RawMessageNotification rawMessageNotification = Json.fromJson(notification, RawMessageNotification.class);
21+
GenericNotificationData genericNotificationData = Json.fromJson(rawMessageNotification.getData(), GenericNotificationData.class);
22+
23+
CommonChangeNotification<Split> featureFlagChangeNotification = new CommonChangeNotification(genericNotificationData, Split.class);
24+
Assert.assertEquals(IncomingNotification.Type.SPLIT_UPDATE, featureFlagChangeNotification.getType());
25+
Assert.assertEquals(1684265694505L, featureFlagChangeNotification.getChangeNumber());
26+
Assert.assertEquals(CompressType.ZLIB, featureFlagChangeNotification.getCompressType());
27+
Assert.assertEquals(0L, featureFlagChangeNotification.getPreviousChangeNumber());
28+
Assert.assertEquals("mauro_java", featureFlagChangeNotification.getDefinition().name);
29+
Assert.assertEquals(-1769377604, featureFlagChangeNotification.getDefinition().seed);
30+
}
31+
32+
@Test
33+
public void testRuleBasedSegmentNotification() {
34+
String notification = "{\"id\":\"vQQ61wzBRO:0:0\",\"clientId\":\"pri:MTUxNzg3MDg1OQ==\",\"timestamp\":1684265694676,\"encoding\":\"json\",\"channel\":\"NzM2MDI5Mzc0_MjkyNTIzNjczMw==_splits\",\"data\":\"{\\\"type\\\":\\\"RB_SEGMENT_UPDATE\\\",\\\"changeNumber\\\":1684265694505,\\\"pcn\\\":0,\\\"c\\\":0,\\\"d\\\":\\\"eyJjaGFuZ2VOdW1iZXIiOiA1LCAibmFtZSI6ICJzYW1wbGVfcnVsZV9iYXNlZF9zZWdtZW50IiwgInN0YXR1cyI6ICJBQ1RJVkUiLCAidHJhZmZpY1R5cGVOYW1lIjogInVzZXIiLCAiZXhjbHVkZWQiOiB7ImtleXMiOiBbIm1hdXJvQHNwbGl0LmlvIiwgImdhc3RvbkBzcGxpdC5pbyJdLCAic2VnbWVudHMiOiBbXX0sICJjb25kaXRpb25zIjogW3sibWF0Y2hlckdyb3VwIjogeyJjb21iaW5lciI6ICJBTkQiLCAibWF0Y2hlcnMiOiBbeyJrZXlTZWxlY3RvciI6IHsidHJhZmZpY1R5cGUiOiAidXNlciIsICJhdHRyaWJ1dGUiOiAiZW1haWwifSwgIm1hdGNoZXJUeXBlIjogIkVORFNfV0lUSCIsICJuZWdhdGUiOiBmYWxzZSwgIndoaXRlbGlzdE1hdGNoZXJEYXRhIjogeyJ3aGl0ZWxpc3QiOiBbIkBzcGxpdC5pbyJdfX1dfX1dfQ==\\\"}\"}";
35+
RawMessageNotification rawMessageNotification = Json.fromJson(notification, RawMessageNotification.class);
36+
GenericNotificationData genericNotificationData = Json.fromJson(rawMessageNotification.getData(), GenericNotificationData.class);
37+
38+
CommonChangeNotification<RuleBasedSegment> ruleBasedSegmentCommonChangeNotification = new CommonChangeNotification(genericNotificationData, RuleBasedSegment.class);
39+
Assert.assertEquals(IncomingNotification.Type.RB_SEGMENT_UPDATE, ruleBasedSegmentCommonChangeNotification.getType());
40+
Assert.assertEquals(1684265694505L, ruleBasedSegmentCommonChangeNotification.getChangeNumber());
41+
Assert.assertEquals(CompressType.NOT_COMPRESSED, ruleBasedSegmentCommonChangeNotification.getCompressType());
42+
Assert.assertEquals(0L, ruleBasedSegmentCommonChangeNotification.getPreviousChangeNumber());
43+
Assert.assertEquals("sample_rule_based_segment", ruleBasedSegmentCommonChangeNotification.getDefinition().name);
44+
Assert.assertEquals(Status.ACTIVE, ruleBasedSegmentCommonChangeNotification.getDefinition().status);
45+
}
46+
}

0 commit comments

Comments
 (0)