55import java .util .Random ;
66
77import io .ably .lib .test .common .ParameterizedTest ;
8+ import io .ably .lib .test .common .Helpers .ChannelWaiter ;
9+ import io .ably .lib .test .common .Helpers .MessageWaiter ;
810import io .ably .lib .types .*;
911
1012import io .ably .lib .rest .AblyRest ;
13+ import io .ably .lib .realtime .*;
1114import org .junit .Before ;
1215import org .junit .Ignore ;
1316import org .junit .Test ;
@@ -18,15 +21,15 @@ public class RestChannelBulkPublishTest extends ParameterizedTest {
1821
1922 /**
2023 * Publish a single message on multiple channels
21- *
24+ *
2225 * The payload constructed has the form
2326 * [
2427 * {
2528 * channel: [ <channel 0>, <channel 1>, ... ],
2629 * message: [{ data: <message text> }]
2730 * }
2831 * ]
29- *
32+ *
3033 * It publishes the given message on all of the given channels.
3134 */
3235 @ Test
@@ -69,9 +72,66 @@ public void bulk_publish_multiple_channels_simple() {
6972 }
7073 }
7174
75+ /**
76+ * As above but with the param method
77+ */
78+ @ Test
79+ public void bulk_publish_multiple_channels_param () {
80+ AblyRealtime rxAbly = null ;
81+ try {
82+ /* setup library instance */
83+ ClientOptions opts = createOptions (testVars .keys [0 ].keyStr );
84+ AblyRest ably = new AblyRest (opts );
85+ rxAbly = new AblyRealtime (opts );
86+
87+ /* first, publish some messages */
88+ int channelCount = 5 ;
89+ ArrayList <String > channelIds = new ArrayList <String >();
90+ ArrayList <MessageWaiter > rxWaiters = new ArrayList <MessageWaiter >();
91+ for (int i = 0 ; i < channelCount ; i ++) {
92+ String channelId = "persisted:" + randomString ();
93+ channelIds .add (channelId );
94+ Channel rxChannel = rxAbly .channels .get (channelId );
95+ MessageWaiter messageWaiter = new MessageWaiter (rxChannel );
96+ rxWaiters .add (messageWaiter );
97+ new ChannelWaiter (rxChannel ).waitFor (ChannelState .attached );
98+ }
99+
100+ Message message = new Message (null , "bulk_publish_multiple_channels_param" );
101+ String messageId = message .id = randomString ();
102+ Message .Batch payload = new Message .Batch (channelIds , Collections .singleton (message ));
103+
104+ Param [] params = new Param []{new Param ("quickAck" , "true" )};
105+
106+ PublishResponse [] result = ably .publishBatch (new Message .Batch []{payload }, null , params );
107+ for (PublishResponse response : result ) {
108+ assertEquals ("Verify expected response id" , response .messageId , messageId );
109+ assertTrue ("Verify expected channel name" , channelIds .contains (response .channelId ));
110+ assertNull ("Verify no publish error" , response .error );
111+ }
112+
113+ /* Wait to get a message on each channel -- since we're using
114+ * quickAck, getting an ack is no longer a guarantee that the
115+ * message has been processed, so getting history immediately after
116+ * the publish returns may fail */
117+ for (MessageWaiter messageWaiter : rxWaiters ) {
118+ messageWaiter .waitFor (1 );
119+ }
120+ } catch (AblyException e ) {
121+ e .printStackTrace ();
122+ fail ("bulk_publish_multiple_channels_param: Unexpected exception" );
123+ return ;
124+ } finally {
125+ if (rxAbly != null ) {
126+ rxAbly .close ();
127+ }
128+ }
129+
130+ }
131+
72132 /**
73133 * Publish a multiple messages on multiple channels
74- *
134+ *
75135 * The payload constructed has the form
76136 * [
77137 * {
@@ -94,7 +154,7 @@ public void bulk_publish_multiple_channels_simple() {
94154 * },
95155 * ...
96156 * ]
97- *
157+ *
98158 * It publishes the given messages on the associated channels.
99159 */
100160 @ Test
0 commit comments