1
1
package io .ably .lib .test .realtime ;
2
2
3
- import static org .junit .Assert .assertArrayEquals ;
4
- import static org .junit .Assert .assertEquals ;
5
- import static org .junit .Assert .assertNotEquals ;
6
- import static org .junit .Assert .assertTrue ;
7
- import static org .junit .Assert .fail ;
8
-
9
3
import java .io .IOException ;
10
4
import java .util .ArrayList ;
11
5
import java .util .HashMap ;
51
45
import io .ably .lib .types .ProtocolMessage ;
52
46
import io .ably .lib .util .Log ;
53
47
48
+ import static org .junit .Assert .assertArrayEquals ;
49
+ import static org .junit .Assert .assertEquals ;
50
+ import static org .junit .Assert .assertNotEquals ;
51
+ import static org .junit .Assert .assertNull ;
52
+ import static org .junit .Assert .assertTrue ;
53
+ import static org .junit .Assert .fail ;
54
+
54
55
public class RealtimeMessageTest extends ParameterizedTest {
55
56
56
57
private static final String testMessagesEncodingFile = "ably-common/test-resources/messages-encoding.json" ;
57
- private static Gson gson = new Gson ();
58
+ private static final Gson gson = new Gson ();
58
59
59
60
@ Rule
60
61
public Timeout testTimeout = Timeout .seconds (300 );
61
62
62
63
/**
63
64
* Connect to the service and attach, subscribe to an event, and publish on that channel
64
65
*/
65
- @ Ignore ("FIXME: fix exception" )
66
66
@ Test
67
67
public void single_send () {
68
68
AblyRealtime ably = null ;
@@ -107,7 +107,6 @@ public void single_send() {
107
107
* attach, subscribe to an event, publish on one
108
108
* connection and confirm receipt on the other.
109
109
*/
110
- @ Ignore ("FIXME: fix exception" )
111
110
@ Test
112
111
public void single_send_noecho () {
113
112
AblyRealtime txAbly = null ;
@@ -166,7 +165,6 @@ public void single_send_noecho() {
166
165
* Get a channel and subscribe without explicitly attaching.
167
166
* Verify that the channel reaches the attached state.
168
167
*/
169
- @ Ignore ("FIXME: fix exception" )
170
168
@ Test
171
169
public void subscribe_implicit_attach () {
172
170
AblyRealtime ably = null ;
@@ -243,7 +241,7 @@ private void _multiple_send(String channelName, int messageCount, int msgSize, b
243
241
244
242
/* wait for the publish callback to be called */
245
243
ErrorInfo [] errors = msgComplete .waitFor ();
246
- assertTrue ("Verify success from all message callbacks" , errors .length == 0 );
244
+ assertEquals ("Verify success from all message callbacks" , 0 , errors .length );
247
245
248
246
/* wait for the subscription callback to be called */
249
247
messageWaiter .waitFor (messageCount );
@@ -261,13 +259,13 @@ private void _multiple_send(String channelName, int messageCount, int msgSize, b
261
259
channel .publish ("test_event" , messageData , msgComplete .add ());
262
260
try {
263
261
Thread .sleep (delay );
264
- } catch (InterruptedException e ) {
262
+ } catch (InterruptedException ignored ) {
265
263
}
266
264
}
267
265
268
266
/* wait for the publish callback to be called */
269
267
ErrorInfo [] errors = msgComplete .waitFor ();
270
- assertTrue ("Verify success from all message callbacks" , errors .length == 0 );
268
+ assertEquals ("Verify success from all message callbacks" , 0 , errors .length );
271
269
272
270
/* wait for the subscription callback to be called */
273
271
messageWaiter .waitFor (messageCount );
@@ -293,7 +291,6 @@ private void _multiple_send(String channelName, int messageCount, int msgSize, b
293
291
* Test right and wrong channel states to publish messages
294
292
* Tests RTL6c
295
293
*/
296
- @ Ignore ("FIXME: fix exception" )
297
294
@ Test
298
295
public void publish_channel_state () {
299
296
AblyRealtime ably = null ;
@@ -384,7 +381,7 @@ private void _multiple_send_batch(String channelName, int messageCount, int batc
384
381
385
382
/* wait for the publish callback to be called */
386
383
ErrorInfo [] errors = msgComplete .waitFor ();
387
- assertTrue ("Verify success from all message callbacks" , errors .length == 0 );
384
+ assertEquals ("Verify success from all message callbacks" , 0 , errors .length );
388
385
389
386
/* wait for the subscription callback to be called */
390
387
messageWaiter .waitFor (messageCount );
@@ -399,55 +396,48 @@ private void _multiple_send_batch(String channelName, int messageCount, int batc
399
396
}
400
397
}
401
398
402
- @ Ignore ("FIXME: fix exception" )
403
399
@ Test
404
400
public void multiple_send_10_1000_16_string () {
405
401
int messageCount = 10 ;
406
402
long delay = 1000L ;
407
403
_multiple_send ("multiple_send_10_1000_16_string_" + testParams .name , messageCount , 16 , false , delay );
408
404
}
409
405
410
- @ Ignore ("FIXME: fix exception" )
411
406
@ Test
412
407
public void multiple_send_10_1000_16_binary () {
413
408
int messageCount = 10 ;
414
409
long delay = 1000L ;
415
410
_multiple_send ("multiple_send_10_1000_16_binary_" + testParams .name , messageCount , 16 , true , delay );
416
411
}
417
412
418
- @ Ignore ("FIXME: fix exception" )
419
413
@ Test
420
414
public void multiple_send_10_1000_512_string () {
421
415
int messageCount = 10 ;
422
416
long delay = 1000L ;
423
417
_multiple_send ("multiple_send_10_1000_512_string_" + testParams .name , messageCount , 512 , false , delay );
424
418
}
425
419
426
- @ Ignore ("FIXME: fix exception" )
427
420
@ Test
428
421
public void multiple_send_10_1000_512_binary () {
429
422
int messageCount = 10 ;
430
423
long delay = 1000L ;
431
424
_multiple_send ("multiple_send_10_1000_512_binary_" + testParams .name , messageCount , 512 , true , delay );
432
425
}
433
426
434
- @ Ignore ("FIXME: fix exception" )
435
427
@ Test
436
428
public void multiple_send_20_200 () {
437
429
int messageCount = 20 ;
438
430
long delay = 200L ;
439
431
_multiple_send ("multiple_send_20_200_" + testParams .name , messageCount , 256 , true , delay );
440
432
}
441
433
442
- @ Ignore ("FIXME: fix exception" )
443
434
@ Test
444
435
public void multiple_send_200_50 () {
445
436
int messageCount = 200 ;
446
437
long delay = 50L ;
447
438
_multiple_send ("multiple_send_binary_200_50_" + testParams .name , messageCount , 256 , true , delay );
448
439
}
449
440
450
- @ Ignore ("FIXME: fix exception" )
451
441
@ Test
452
442
public void multiple_send_1000_10 () {
453
443
int messageCount = 1000 ;
@@ -522,7 +512,6 @@ public void ensure_disconnect_with_error_does_not_move_to_failed() {
522
512
}
523
513
}
524
514
525
- @ Ignore ("FIXME: fix exception" )
526
515
@ Test
527
516
public void messages_encoding_fixtures () {
528
517
MessagesEncodingData fixtures ;
@@ -587,7 +576,6 @@ public MessagesEncodingDataItem[] handleResponse(HttpCore.Response response, Err
587
576
}
588
577
}
589
578
590
- @ Ignore ("FIXME: fix exception" )
591
579
@ Test
592
580
public void messages_msgpack_and_json_encoding_is_compatible () {
593
581
MessagesEncodingData fixtures ;
@@ -739,8 +727,10 @@ public void println(int severity, String tag, String msg, Throwable tr) {
739
727
synchronized (log ) {
740
728
boolean foundErrorMessage = false ;
741
729
for (String logMessage : log ) {
742
- if (logMessage .contains ("encryption is not set up" ))
730
+ if (logMessage .contains ("encryption is not set up" )) {
743
731
foundErrorMessage = true ;
732
+ break ;
733
+ }
744
734
}
745
735
assertTrue ("Verify logged error messages" , foundErrorMessage );
746
736
}
@@ -754,22 +744,27 @@ public void println(int severity, String tag, String msg, Throwable tr) {
754
744
}
755
745
756
746
private void expectDataToMatch (MessagesEncodingDataItem fixtureMessage , Message receivedMessage ) {
757
- if (fixtureMessage .expectedType .equals ("string" )) {
758
- assertEquals ("Verify decoded message data" , fixtureMessage .expectedValue .getAsString (), receivedMessage .data );
759
- } else if (fixtureMessage .expectedType .equals ("jsonObject" )) {
760
- assertEquals ("Verify decoded message data" , fixtureMessage .expectedValue .getAsJsonObject (), receivedMessage .data );
761
- } else if (fixtureMessage .expectedType .equals ("jsonArray" )) {
762
- assertEquals ("Verify decoded message data" , fixtureMessage .expectedValue .getAsJsonArray (), receivedMessage .data );
763
- } else if (fixtureMessage .expectedType .equals ("binary" )) {
764
- byte [] receivedData = (byte []) receivedMessage .data ;
765
- StringBuilder sb = new StringBuilder (receivedData .length * 2 );
766
- for (byte b : receivedData ) {
767
- sb .append (String .format ("%02x" , b & 0xff ));
768
- }
769
- String receivedDataHex = sb .toString ();
770
- assertEquals ("Verify decoded message data" , fixtureMessage .expectedHexValue , receivedDataHex );
771
- } else {
772
- throw new RuntimeException (String .format (Locale .ROOT , "unhandled: %s" , fixtureMessage .expectedType ));
747
+ switch (fixtureMessage .expectedType ) {
748
+ case "string" :
749
+ assertEquals ("Verify decoded message data" , fixtureMessage .expectedValue .getAsString (), receivedMessage .data );
750
+ break ;
751
+ case "jsonObject" :
752
+ assertEquals ("Verify decoded message data" , fixtureMessage .expectedValue .getAsJsonObject (), receivedMessage .data );
753
+ break ;
754
+ case "jsonArray" :
755
+ assertEquals ("Verify decoded message data" , fixtureMessage .expectedValue .getAsJsonArray (), receivedMessage .data );
756
+ break ;
757
+ case "binary" :
758
+ byte [] receivedData = (byte []) receivedMessage .data ;
759
+ StringBuilder sb = new StringBuilder (receivedData .length * 2 );
760
+ for (byte b : receivedData ) {
761
+ sb .append (String .format ("%02x" , b & 0xff ));
762
+ }
763
+ String receivedDataHex = sb .toString ();
764
+ assertEquals ("Verify decoded message data" , fixtureMessage .expectedHexValue , receivedDataHex );
765
+ break ;
766
+ default :
767
+ throw new RuntimeException (String .format (Locale .ROOT , "unhandled: %s" , fixtureMessage .expectedType ));
773
768
}
774
769
}
775
770
@@ -804,7 +799,7 @@ public void reject_invalid_message_data() throws AblyException {
804
799
message .encode (null );
805
800
fail ("reject_invalid_message_data: Expected AblyException to be thrown." );
806
801
} catch (AblyException e ) {
807
- assertEquals ( null , message .encoding );
802
+ assertNull ( message .encoding );
808
803
assertEquals (data , message .data );
809
804
} catch (Throwable t ) {
810
805
fail ("reject_invalid_message_data: Unexpected exception" );
@@ -873,7 +868,6 @@ public void message_from_encoded_json_object() throws AblyException {
873
868
* Refer Spec. TM3
874
869
* @throws AblyException
875
870
*/
876
- @ Ignore ("FIXME: fix exception" )
877
871
@ Test
878
872
public void messages_from_encoded_json_array () throws AblyException {
879
873
JsonArray fixtures = null ;
0 commit comments