@@ -144,7 +144,65 @@ public void presence(PubNub pubnub, PNPresenceEventResult presence) {
144144 }
145145
146146 @ Test
147- public void testQueueNotificationsBuilder () {
147+ public void testQueueNotificationsBuilderNoThresholdSpecified () {
148+ pubnub .getConfiguration ().setRequestMessageCountThreshold (null );
149+ final AtomicBoolean gotStatus = new AtomicBoolean ();
150+ stubFor (get (urlPathEqualTo ("/v2/subscribe/mySubscribeKey/ch2,ch1/0" ))
151+ .willReturn (aResponse ().withBody ("{\" t\" :{\" t\" :\" 14607577960932487\" ,\" r\" :1},\" m\" :[{\" a\" :\" 4\" ,\" f\" :0,\" i\" :\" Client-g5d4g\" ,\" p\" :{\" t\" :\" 14607577960925503\" ,\" r\" :1},\" o\" :{\" t\" :\" 14737141991877032\" ,\" r\" :2},\" k\" :\" sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f\" ,\" c\" :\" coolChannel\" ,\" d\" :{\" text\" :\" Message\" },\" b\" :\" coolChannel\" }]}" )));
152+
153+ pubnub .addListener (new SubscribeCallback () {
154+ @ Override
155+ public void status (PubNub pubnub , PNStatus status ) {
156+ if (status .getCategory () == PNStatusCategory .PNRequestMessageCountExceededCategory ) {
157+ gotStatus .set (true );
158+ }
159+ }
160+
161+ @ Override
162+ public void message (PubNub pubnub , PNMessageResult message ) {
163+ }
164+
165+ @ Override
166+ public void presence (PubNub pubnub , PNPresenceEventResult presence ) {
167+ }
168+ });
169+
170+ pubnub .subscribe ().channels (Arrays .asList ("ch1" , "ch2" )).execute ();
171+
172+ Awaitility .await ().atMost (2 , TimeUnit .SECONDS ).untilAtomic (gotStatus , org .hamcrest .core .IsEqual .equalTo (false ));
173+ }
174+
175+ @ Test
176+ public void testQueueNotificationsBuilderBelowThreshold () {
177+ pubnub .getConfiguration ().setRequestMessageCountThreshold (10 );
178+ final AtomicBoolean gotStatus = new AtomicBoolean ();
179+ stubFor (get (urlPathEqualTo ("/v2/subscribe/mySubscribeKey/ch2,ch1/0" ))
180+ .willReturn (aResponse ().withBody ("{\" t\" :{\" t\" :\" 14607577960932487\" ,\" r\" :1},\" m\" :[{\" a\" :\" 4\" ,\" f\" :0,\" i\" :\" Client-g5d4g\" ,\" p\" :{\" t\" :\" 14607577960925503\" ,\" r\" :1},\" o\" :{\" t\" :\" 14737141991877032\" ,\" r\" :2},\" k\" :\" sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f\" ,\" c\" :\" coolChannel\" ,\" d\" :{\" text\" :\" Message\" },\" b\" :\" coolChannel\" }]}" )));
181+
182+ pubnub .addListener (new SubscribeCallback () {
183+ @ Override
184+ public void status (PubNub pubnub , PNStatus status ) {
185+ if (status .getCategory () == PNStatusCategory .PNRequestMessageCountExceededCategory ) {
186+ gotStatus .set (true );
187+ }
188+ }
189+
190+ @ Override
191+ public void message (PubNub pubnub , PNMessageResult message ) {
192+ }
193+
194+ @ Override
195+ public void presence (PubNub pubnub , PNPresenceEventResult presence ) {
196+ }
197+ });
198+
199+ pubnub .subscribe ().channels (Arrays .asList ("ch1" , "ch2" )).execute ();
200+
201+ Awaitility .await ().atMost (2 , TimeUnit .SECONDS ).untilAtomic (gotStatus , org .hamcrest .core .IsEqual .equalTo (false ));
202+ }
203+
204+ @ Test
205+ public void testQueueNotificationsBuilderThresholdMatched () {
148206 pubnub .getConfiguration ().setRequestMessageCountThreshold (1 );
149207 final AtomicBoolean gotStatus = new AtomicBoolean ();
150208 stubFor (get (urlPathEqualTo ("/v2/subscribe/mySubscribeKey/ch2,ch1/0" ))
@@ -167,6 +225,34 @@ public void presence(PubNub pubnub, PNPresenceEventResult presence) {
167225 }
168226 });
169227
228+ pubnub .subscribe ().channels (Arrays .asList ("ch1" , "ch2" )).execute ();
229+
230+ Awaitility .await ().atMost (2 , TimeUnit .SECONDS ).untilAtomic (gotStatus , org .hamcrest .core .IsEqual .equalTo (true ));
231+ }
232+
233+ @ Test
234+ public void testQueueNotificationsBuilderThresholdExceeded () {
235+ pubnub .getConfiguration ().setRequestMessageCountThreshold (1 );
236+ final AtomicBoolean gotStatus = new AtomicBoolean ();
237+ stubFor (get (urlPathEqualTo ("/v2/subscribe/mySubscribeKey/ch2,ch1/0" ))
238+ .willReturn (aResponse ().withBody ("{\" m\" :[{\" a\" :\" 4\" ,\" b\" :\" coolChannel\" ,\" c\" :\" coolChannel\" ,\" d\" :{\" text\" :\" Message\" },\" f\" :0,\" i\" :\" Client-g5d4g\" ,\" k\" :\" sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f\" ,\" o\" :{\" r\" :2,\" t\" :\" 14737141991877032\" },\" p\" :{\" r\" :1,\" t\" :\" 14607577960925503\" }},{\" a\" :\" 5\" ,\" b\" :\" coolChannel2\" ,\" c\" :\" coolChannel2\" ,\" d\" :{\" text\" :\" Message2\" },\" f\" :0,\" i\" :\" Client-g5d4g\" ,\" k\" :\" sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4g\" ,\" o\" :{\" r\" :2,\" t\" :\" 14737141991877033\" },\" p\" :{\" r\" :1,\" t\" :\" 14607577960925504\" }}],\" t\" :{\" r\" :1,\" t\" :\" 14607577960932487\" }}" )));
239+
240+ pubnub .addListener (new SubscribeCallback () {
241+ @ Override
242+ public void status (PubNub pubnub , PNStatus status ) {
243+ if (status .getCategory () == PNStatusCategory .PNRequestMessageCountExceededCategory ) {
244+ gotStatus .set (true );
245+ }
246+ }
247+
248+ @ Override
249+ public void message (PubNub pubnub , PNMessageResult message ) {
250+ }
251+
252+ @ Override
253+ public void presence (PubNub pubnub , PNPresenceEventResult presence ) {
254+ }
255+ });
170256
171257 pubnub .subscribe ().channels (Arrays .asList ("ch1" , "ch2" )).execute ();
172258
0 commit comments