Skip to content

Commit bf996e2

Browse files
Adding test case
1 parent edf3f3d commit bf996e2

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

client/src/test/java/io/split/engine/sse/PushStatusTrackerTest.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void HandleControlEventStreamingResumedShouldNotifyEvent() throws Interru
3737
@Test
3838
public void HandleControlEventStreamingResumedShouldNotNotifyEvent() {
3939
LinkedBlockingQueue<PushManager.Status> messages = new LinkedBlockingQueue<>();
40-
OccupancyNotification occupancyNotification = buildOccupancyNotification(0);
40+
OccupancyNotification occupancyNotification = buildOccupancyNotification(0, null);
4141
ControlNotification controlNotification = buildControlNotification(ControlType.STREAMING_RESUMED);
4242

4343
PushStatusTracker pushStatusTracker = new PushStatusTrackerImp(messages);
@@ -65,7 +65,7 @@ public void HandleControlEventStreamingDisabledShouldNotifyShutdownEvent() {
6565
@Test
6666
public void HandleOccupancyEventWithPublishersFirstTimeShouldNotNotifyEvent() {
6767
LinkedBlockingQueue<PushManager.Status> messages = new LinkedBlockingQueue<>();
68-
OccupancyNotification occupancyNotification = buildOccupancyNotification(2);
68+
OccupancyNotification occupancyNotification = buildOccupancyNotification(2, null);
6969

7070
PushStatusTracker pushStatusTracker = new PushStatusTrackerImp(messages);
7171
pushStatusTracker.handleIncomingOccupancyEvent(occupancyNotification);
@@ -76,8 +76,23 @@ public void HandleOccupancyEventWithPublishersFirstTimeShouldNotNotifyEvent() {
7676
public void HandleOccupancyEventWithPublishersAndWithStreamingDisabledShouldNotifyEvent() throws InterruptedException {
7777
LinkedBlockingQueue<PushManager.Status> messages = new LinkedBlockingQueue<>();
7878
PushStatusTracker pushStatusTracker = new PushStatusTrackerImp(messages);
79-
pushStatusTracker.handleIncomingOccupancyEvent(buildOccupancyNotification(0));
80-
pushStatusTracker.handleIncomingOccupancyEvent(buildOccupancyNotification(2));
79+
pushStatusTracker.handleIncomingOccupancyEvent(buildOccupancyNotification(0, null));
80+
pushStatusTracker.handleIncomingOccupancyEvent(buildOccupancyNotification(2, null));
81+
82+
assertThat(messages.size(), is(equalTo(2)));
83+
PushManager.Status m1 = messages.take();
84+
assertThat(m1, is(equalTo(PushManager.Status.STREAMING_DOWN)));
85+
86+
PushManager.Status m2 = messages.take();
87+
assertThat(m2, is(equalTo(PushManager.Status.STREAMING_READY)));
88+
}
89+
90+
@Test
91+
public void HandleOccupancyEventWithDifferentChannelsPublishersShouldNotifyEvent() throws InterruptedException {
92+
LinkedBlockingQueue<PushManager.Status> messages = new LinkedBlockingQueue<>();
93+
PushStatusTracker pushStatusTracker = new PushStatusTrackerImp(messages);
94+
pushStatusTracker.handleIncomingOccupancyEvent(buildOccupancyNotification(0, "control_pri"));
95+
pushStatusTracker.handleIncomingOccupancyEvent(buildOccupancyNotification(2, "control_sec"));
8196

8297
assertThat(messages.size(), is(equalTo(2)));
8398
PushManager.Status m1 = messages.take();
@@ -88,14 +103,14 @@ public void HandleOccupancyEventWithPublishersAndWithStreamingDisabledShouldNoti
88103
}
89104

90105
private ControlNotification buildControlNotification(ControlType controlType) {
91-
return new ControlNotification(buildGenericData(controlType, IncomingNotification.Type.CONTROL,null));
106+
return new ControlNotification(buildGenericData(controlType, IncomingNotification.Type.CONTROL,null, null));
92107
}
93108

94-
private OccupancyNotification buildOccupancyNotification(int publishers) {
95-
return new OccupancyNotification(buildGenericData(null, IncomingNotification.Type.OCCUPANCY, publishers));
109+
private OccupancyNotification buildOccupancyNotification(int publishers, String channel) {
110+
return new OccupancyNotification(buildGenericData(null, IncomingNotification.Type.OCCUPANCY, publishers, channel));
96111
}
97112

98-
private GenericNotificationData buildGenericData(ControlType controlType, IncomingNotification.Type type, Integer publishers) {
113+
private GenericNotificationData buildGenericData(ControlType controlType, IncomingNotification.Type type, Integer publishers, String channel) {
99114
return new GenericNotificationData(
100115
null,
101116
null,
@@ -104,6 +119,6 @@ private GenericNotificationData buildGenericData(ControlType controlType, Incomi
104119
publishers != null ? new OccupancyMetrics(publishers) : null,
105120
null,
106121
type,
107-
"channel-test");
122+
channel == null ? "channel-test" : channel);
108123
}
109124
}

0 commit comments

Comments
 (0)