Skip to content

Commit 3f9d007

Browse files
authored
Merge pull request #1161 from ably/fix/vcdiff-encoding
[ECO-5553] Fixed omitted tests responsible for handling vcdiff encoding
2 parents 993b308 + 55bfe11 commit 3f9d007

3 files changed

Lines changed: 58 additions & 35 deletions

File tree

lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.junit.Test;
3232

3333
import java.util.ArrayList;
34+
import java.util.Arrays;
3435
import java.util.Collections;
3536
import java.util.Comparator;
3637
import java.util.HashMap;
@@ -46,6 +47,7 @@
4647
import static org.junit.Assert.assertNull;
4748
import static org.junit.Assert.assertSame;
4849
import static org.junit.Assert.assertThat;
50+
import static org.junit.Assert.assertThrows;
4951
import static org.junit.Assert.assertTrue;
5052
import static org.junit.Assert.fail;
5153

@@ -150,7 +152,7 @@ public void attach_detach() {
150152
}
151153
}
152154

153-
/*@Test*/
155+
@Test
154156
public void attach_with_channel_params_channels_get() {
155157
String channelName = "attach_with_channel_params_channels_get_" + testParams.name;
156158
AblyRealtime ably = null;
@@ -163,7 +165,7 @@ public void attach_with_channel_params_channels_get() {
163165
assertEquals("Verify connected state reached", ConnectionState.connected, ably.connection.state);
164166

165167
ChannelOptions options = new ChannelOptions();
166-
options.params = new HashMap<String, String>();
168+
options.params = new HashMap<>();
167169
options.params.put("modes", "subscribe");
168170
options.params.put("delta", "vcdiff");
169171

@@ -172,7 +174,7 @@ public void attach_with_channel_params_channels_get() {
172174
channel.attach();
173175
(new ChannelWaiter(channel)).waitFor(ChannelState.attached);
174176
assertEquals("Verify attached state reached", ChannelState.attached, channel.state);
175-
assertEquals("Verify channel params", channel.getParams(), options.params);
177+
assertEquals("Verify channel params", options.params, channel.getParams());
176178
assertArrayEquals("Verify channel modes", new ChannelMode[] { ChannelMode.subscribe }, channel.getModes());
177179
} catch (AblyException e) {
178180
e.printStackTrace();
@@ -183,7 +185,7 @@ public void attach_with_channel_params_channels_get() {
183185
}
184186
}
185187

186-
/*@Test*/
188+
@Test
187189
public void attach_with_channel_params_set_options() {
188190
String channelName = "attach_with_channel_params_set_options_" + testParams.name;
189191
AblyRealtime ably = null;
@@ -196,6 +198,7 @@ public void attach_with_channel_params_set_options() {
196198
assertEquals("Verify connected state reached", ConnectionState.connected, ably.connection.state);
197199

198200
ChannelOptions options = new ChannelOptions();
201+
options.params = new HashMap<>();
199202
options.params.put("modes", "subscribe");
200203
options.params.put("delta", "vcdiff");
201204

@@ -205,7 +208,7 @@ public void attach_with_channel_params_set_options() {
205208
channel.attach();
206209
(new ChannelWaiter(channel)).waitFor(ChannelState.attached);
207210
assertEquals("Verify attached state reached", ChannelState.attached, channel.state);
208-
assertEquals("Verify channel params", channel.getParams(), options.params);
211+
assertEquals("Verify channel params", options.params, channel.getParams());
209212
assertArrayEquals("Verify channel modes", new ChannelMode[] { ChannelMode.subscribe }, channel.getModes());
210213
} catch (AblyException e) {
211214
e.printStackTrace();
@@ -216,7 +219,7 @@ public void attach_with_channel_params_set_options() {
216219
}
217220
}
218221

219-
/*@Test*/
222+
@Test
220223
public void channels_get_should_throw_when_would_cause_reattach() {
221224
String channelName = "channels_get_should_throw_when_would_cause_reattach_" + testParams.name;
222225
AblyRealtime ably = null;
@@ -228,22 +231,25 @@ public void channels_get_should_throw_when_would_cause_reattach() {
228231
(new ConnectionWaiter(ably.connection)).waitFor(ConnectionState.connected);
229232
assertEquals("Verify connected state reached", ConnectionState.connected, ably.connection.state);
230233

231-
ChannelOptions options = new ChannelOptions();
232-
options.params.put("modes", "subscribe");
233-
options.params.put("delta", "vcdiff");
234+
ChannelOptions options = new ChannelOptions() {{
235+
params = new HashMap<>();
236+
params.put("modes", "subscribe");
237+
params.put("delta", "vcdiff");
238+
}};
234239

235240
/* create a channel and attach */
236241
final Channel channel = ably.channels.get(channelName, options);
237242
channel.attach();
238243
(new ChannelWaiter(channel)).waitFor(ChannelState.attached);
239244

240-
try {
241-
ably.channels.get(channelName, options);
242-
} catch (AblyException e) {
243-
assertEquals("Verify error code", 400, e.errorInfo.code);
244-
assertEquals("Verify error status code", 40000, e.errorInfo.statusCode);
245-
assertTrue("Verify error message", e.errorInfo.message.contains("setOptions"));
246-
}
245+
AblyRealtime finalAbly = ably;
246+
AblyException exception = assertThrows(AblyException.class, () ->
247+
finalAbly.channels.get(channelName, options));
248+
249+
assertEquals("Verify error code", 400, exception.errorInfo.code);
250+
assertEquals("Verify error status code", 40000, exception.errorInfo.statusCode);
251+
assertTrue("Verify error message", exception.errorInfo.message.contains("use Channel.setOptions()"));
252+
247253
} catch (AblyException e) {
248254
e.printStackTrace();
249255
fail("init0: Unexpected exception instantiating library");
@@ -253,7 +259,7 @@ public void channels_get_should_throw_when_would_cause_reattach() {
253259
}
254260
}
255261

256-
/*@Test*/
262+
@Test
257263
public void attach_with_channel_params_modes_and_channel_modes() {
258264
String channelName = "attach_with_channel_params_modes_and_channel_modes_" + testParams.name;
259265
AblyRealtime ably = null;
@@ -279,7 +285,10 @@ public void attach_with_channel_params_modes_and_channel_modes() {
279285
(new ChannelWaiter(channel)).waitFor(ChannelState.attached);
280286
assertEquals("Verify attached state reached", ChannelState.attached, channel.state);
281287
assertEquals("Verify channel params", channel.getParams(), options.params);
282-
assertArrayEquals("Verify channel modes", new ChannelMode[] { ChannelMode.subscribe, ChannelMode.presence }, channel.getModes());
288+
// modes in params overrides individual modes in options
289+
assertThat("Verify channel modes", Arrays.asList(channel.getModes()),
290+
Matchers.containsInAnyOrder(ChannelMode.presence, ChannelMode.subscribe));
291+
283292
} catch (AblyException e) {
284293
e.printStackTrace();
285294
fail("init0: Unexpected exception instantiating library");
@@ -289,7 +298,7 @@ public void attach_with_channel_params_modes_and_channel_modes() {
289298
}
290299
}
291300

292-
/*@Test*/
301+
@Test
293302
public void attach_with_channel_modes() {
294303
String channelName = "attach_with_channel_modes_" + testParams.name;
295304
AblyRealtime ably = null;
@@ -312,7 +321,11 @@ public void attach_with_channel_modes() {
312321
channel.attach();
313322
(new ChannelWaiter(channel)).waitFor(ChannelState.attached);
314323
assertEquals("Verify attached state reached", ChannelState.attached, channel.state);
315-
assertEquals("Verify channel modes", channel.getModes(), options.modes);
324+
assertEquals(2, channel.getModes().length);
325+
326+
assertThat("Verify channel modes",
327+
Arrays.asList(channel.getModes()),
328+
Matchers.containsInAnyOrder(ChannelMode.publish, ChannelMode.presence_subscribe));
316329
} catch (AblyException e) {
317330
e.printStackTrace();
318331
fail("init0: Unexpected exception instantiating library");
@@ -322,7 +335,7 @@ public void attach_with_channel_modes() {
322335
}
323336
}
324337

325-
/*@Test*/
338+
@Test
326339
public void attach_with_params_delta_and_channel_modes() {
327340
String channelName = "attach_with_params_delta_and_channel_modes_" + testParams.name;
328341
AblyRealtime ably = null;
@@ -335,7 +348,7 @@ public void attach_with_params_delta_and_channel_modes() {
335348
assertEquals("Verify connected state reached", ConnectionState.connected, ably.connection.state);
336349

337350
ChannelOptions options = new ChannelOptions();
338-
options.params = new HashMap<String, String>();
351+
options.params = new HashMap<>();
339352
options.params.put("delta", "vcdiff");
340353
options.modes = new ChannelMode[] {
341354
ChannelMode.publish,
@@ -348,9 +361,11 @@ public void attach_with_params_delta_and_channel_modes() {
348361
channel.attach();
349362
(new ChannelWaiter(channel)).waitFor(ChannelState.attached);
350363
assertEquals("Verify attached state reached", ChannelState.attached, channel.state);
351-
options.params.put("modes", "publish,subscribe,presence_subscribe");
352-
assertEquals("Verify channel params", channel.getParams(), options.params);
353-
assertEquals("Verify channel modes", channel.getModes(), options.modes);
364+
365+
assertEquals("Verify channel params", options.params, channel.getParams());
366+
assertThat("Verify channel modes",
367+
Arrays.asList(channel.getModes()),
368+
Matchers.containsInAnyOrder(ChannelMode.publish, ChannelMode.subscribe, ChannelMode.presence_subscribe));
354369
} catch (AblyException e) {
355370
e.printStackTrace();
356371
fail("init0: Unexpected exception instantiating library");
@@ -2546,15 +2561,15 @@ public void connect_on_closing_client_should_reinitialize_channels() throws Ably
25462561
new ConnectionWaiter(ably.connection).waitFor(ConnectionState.closing);
25472562
new ConnectionWaiter(ably.connection).waitFor(ConnectionState.connected);
25482563

2549-
assertEquals(List.of(ConnectionState.closing, ConnectionState.connecting, ConnectionState.connected), observedConnectionStates);
2564+
assertEquals(Arrays.asList(ConnectionState.closing, ConnectionState.connecting, ConnectionState.connected), observedConnectionStates);
25502565
assertEquals(ChannelState.initialized, channel.state);
25512566

25522567
channel.attach();
25532568
new ChannelWaiter(channel).waitFor(ChannelState.attached);
25542569

25552570
assertNull(channel.reason);
25562571
assertEquals(0, ably.connection.connectionManager.msgSerial);
2557-
assertEquals(List.of(ChannelState.detached, ChannelState.initialized, ChannelState.attaching, ChannelState.attached), observedChannelStates);
2572+
assertEquals(Arrays.asList(ChannelState.detached, ChannelState.initialized, ChannelState.attaching, ChannelState.attached), observedChannelStates);
25582573
}
25592574
}
25602575

lib/src/test/java/io/ably/lib/test/realtime/RealtimeDeltaDecoderTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.ably.lib.transport.ConnectionManager;
1212
import io.ably.lib.transport.ITransport;
1313
import io.ably.lib.transport.WebSocketTransport;
14+
import io.ably.lib.types.ChannelOptions;
1415
import io.ably.lib.types.ClientOptions;
1516
import io.ably.lib.types.Message;
1617
import io.ably.lib.types.MessageExtras;
@@ -20,6 +21,7 @@
2021
import org.junit.Test;
2122
import org.junit.rules.Timeout;
2223

24+
import java.util.Collections;
2325
import java.util.Objects;
2426

2527
import static org.junit.Assert.assertEquals;
@@ -52,6 +54,8 @@ public void simple_delta_codec() {
5254

5355
(new ChannelWaiter(channel)).waitFor(ChannelState.attached);
5456

57+
assertEquals("Verify channel params", Collections.singletonMap("delta", "vcdiff"), channel.getParams());
58+
5559
for (int i = 0; i < testData.length; i++) {
5660
channel.publish(Integer.toString(i), testData[i]);
5761
}
@@ -90,14 +94,18 @@ private void delta_failure_recovery(final ITransport.Factory websocketFactory, S
9094
opts.transportFactory = websocketFactory;
9195
ably = new AblyRealtime(opts);
9296

93-
/* create a channel */
94-
final Channel channel = ably.channels.get("[?delta=vcdiff]" + testName);
97+
ChannelOptions options = new ChannelOptions();
98+
options.params = Collections.singletonMap("delta", "vcdiff");
99+
/* create a channel with channelOptions set to vcdiff*/
100+
final Channel channel = ably.channels.get(testName, options);
95101

96102
/* attach */
97103
channel.attach();
98104
(new ChannelWaiter(channel)).waitFor(ChannelState.attached);
99105
assertEquals("Verify attached state reached", channel.state, ChannelState.attached);
100106

107+
assertEquals("Verify channel params", Collections.singletonMap("delta", "vcdiff"), channel.getParams());
108+
101109
/* subscribe */
102110
MessageWaiter messageWaiter = new MessageWaiter(channel);
103111

lib/src/test/java/io/ably/lib/test/rest/RestPresenceTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void rest_presencehistory_simple() {
8787
* Get presence history data in the forward direction and check order
8888
* DISABLED: See issue https://github.com/ably/ably-java/issues/159
8989
*/
90-
/*@Test*/
90+
@Test
9191
public void rest_presencehistory_order_f() {
9292
String channelName = "persisted:restpresence_persisted";
9393
/* get channel */
@@ -114,7 +114,7 @@ public void rest_presencehistory_order_f() {
114114
* Get presence history data in the backwards direction using text protocol and check order
115115
* DISABLED: See issue https://github.com/ably/ably-java/issues/159
116116
*/
117-
/*@Test*/
117+
@Test
118118
public void rest_presencehistory_order_b() {
119119
String channelName = "persisted:restpresence_persisted";
120120
/* get channel */
@@ -141,7 +141,7 @@ public void rest_presencehistory_order_b() {
141141
* Get limited presence history data in the forward direction using text protocol and check order
142142
* DISABLED: See issue https://github.com/ably/ably-java/issues/159
143143
*/
144-
/*@Test*/
144+
@Test
145145
public void rest_presencehistory_limit_f() {
146146
String channelName = "persisted:restpresence_persisted";
147147
/* get channel */
@@ -168,7 +168,7 @@ public void rest_presencehistory_limit_f() {
168168
* Get limited presence history data in the backwards direction using text protocol and check order
169169
* DISABLED: See issue https://github.com/ably/ably-java/issues/159
170170
*/
171-
/*@Test*/
171+
@Test
172172
public void rest_presencehistory_limit_b() {
173173
String channelName = "persisted:restpresence_persisted";
174174
/* get channel */
@@ -195,7 +195,7 @@ public void rest_presencehistory_limit_b() {
195195
* Get paginated presence history data in the forward direction using text protocol
196196
* DISABLED: See issue https://github.com/ably/ably-java/issues/159
197197
*/
198-
/*@Test*/
198+
@Test
199199
public void rest_presencehistory_paginate_f() {
200200
/* get channel */
201201
String channelName = "persisted:restpresence_persisted";
@@ -263,7 +263,7 @@ public void rest_presencehistory_paginate_f() {
263263
* Get paginated presence history data in the backwards direction using text protocol
264264
* DISABLED: See issue https://github.com/ably/ably-java/issues/159
265265
*/
266-
/*@Test*/
266+
@Test
267267
public void rest_presencehistory_paginate_text_b() {
268268
/* get channel */
269269
String channelName = "persisted:restpresence_persisted";

0 commit comments

Comments
 (0)