From 8c857614ff153b2a4ef73143337aa5d99c32a2db Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Wed, 3 Sep 2025 17:48:17 +0530 Subject: [PATCH 1/3] [ECO-5553] Fixed omitted tests responsible for handling vcdiff encoding --- .../test/realtime/RealtimeChannelTest.java | 56 +++++++++++-------- .../ably/lib/test/rest/RestPresenceTest.java | 12 ++-- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java index d9824da31..861f7eb3b 100644 --- a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java +++ b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java @@ -31,6 +31,7 @@ import org.junit.Test; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -46,6 +47,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -150,7 +152,7 @@ public void attach_detach() { } } - /*@Test*/ + @Test public void attach_with_channel_params_channels_get() { String channelName = "attach_with_channel_params_channels_get_" + testParams.name; AblyRealtime ably = null; @@ -163,7 +165,7 @@ public void attach_with_channel_params_channels_get() { assertEquals("Verify connected state reached", ConnectionState.connected, ably.connection.state); ChannelOptions options = new ChannelOptions(); - options.params = new HashMap(); + options.params = new HashMap<>(); options.params.put("modes", "subscribe"); options.params.put("delta", "vcdiff"); @@ -183,7 +185,7 @@ public void attach_with_channel_params_channels_get() { } } - /*@Test*/ + @Test public void attach_with_channel_params_set_options() { String channelName = "attach_with_channel_params_set_options_" + testParams.name; AblyRealtime ably = null; @@ -196,6 +198,7 @@ public void attach_with_channel_params_set_options() { assertEquals("Verify connected state reached", ConnectionState.connected, ably.connection.state); ChannelOptions options = new ChannelOptions(); + options.params = new HashMap<>(); options.params.put("modes", "subscribe"); options.params.put("delta", "vcdiff"); @@ -216,7 +219,7 @@ public void attach_with_channel_params_set_options() { } } - /*@Test*/ + @Test public void channels_get_should_throw_when_would_cause_reattach() { String channelName = "channels_get_should_throw_when_would_cause_reattach_" + testParams.name; AblyRealtime ably = null; @@ -228,22 +231,25 @@ public void channels_get_should_throw_when_would_cause_reattach() { (new ConnectionWaiter(ably.connection)).waitFor(ConnectionState.connected); assertEquals("Verify connected state reached", ConnectionState.connected, ably.connection.state); - ChannelOptions options = new ChannelOptions(); - options.params.put("modes", "subscribe"); - options.params.put("delta", "vcdiff"); + ChannelOptions options = new ChannelOptions() {{ + params = new HashMap<>(); + params.put("modes", "subscribe"); + params.put("delta", "vcdiff"); + }}; /* create a channel and attach */ final Channel channel = ably.channels.get(channelName, options); channel.attach(); (new ChannelWaiter(channel)).waitFor(ChannelState.attached); - try { - ably.channels.get(channelName, options); - } catch (AblyException e) { - assertEquals("Verify error code", 400, e.errorInfo.code); - assertEquals("Verify error status code", 40000, e.errorInfo.statusCode); - assertTrue("Verify error message", e.errorInfo.message.contains("setOptions")); - } + AblyRealtime finalAbly = ably; + AblyException exception = assertThrows(AblyException.class, () -> + finalAbly.channels.get(channelName, options)); + + assertEquals("Verify error code", 400, exception.errorInfo.code); + assertEquals("Verify error status code", 40000, exception.errorInfo.statusCode); + assertTrue("Verify error message", exception.errorInfo.message.contains("use Channel.setOptions()")); + } catch (AblyException e) { e.printStackTrace(); fail("init0: Unexpected exception instantiating library"); @@ -253,7 +259,7 @@ public void channels_get_should_throw_when_would_cause_reattach() { } } - /*@Test*/ + @Test public void attach_with_channel_params_modes_and_channel_modes() { String channelName = "attach_with_channel_params_modes_and_channel_modes_" + testParams.name; AblyRealtime ably = null; @@ -289,7 +295,7 @@ public void attach_with_channel_params_modes_and_channel_modes() { } } - /*@Test*/ + @Test public void attach_with_channel_modes() { String channelName = "attach_with_channel_modes_" + testParams.name; AblyRealtime ably = null; @@ -312,7 +318,11 @@ public void attach_with_channel_modes() { channel.attach(); (new ChannelWaiter(channel)).waitFor(ChannelState.attached); assertEquals("Verify attached state reached", ChannelState.attached, channel.state); - assertEquals("Verify channel modes", channel.getModes(), options.modes); + assertEquals(2, channel.getModes().length); + + assertThat("Verify channel modes", + Arrays.asList(channel.getModes()), + Matchers.containsInAnyOrder(ChannelMode.publish, ChannelMode.presence_subscribe)); } catch (AblyException e) { e.printStackTrace(); fail("init0: Unexpected exception instantiating library"); @@ -322,7 +332,7 @@ public void attach_with_channel_modes() { } } - /*@Test*/ + @Test public void attach_with_params_delta_and_channel_modes() { String channelName = "attach_with_params_delta_and_channel_modes_" + testParams.name; AblyRealtime ably = null; @@ -335,7 +345,7 @@ public void attach_with_params_delta_and_channel_modes() { assertEquals("Verify connected state reached", ConnectionState.connected, ably.connection.state); ChannelOptions options = new ChannelOptions(); - options.params = new HashMap(); + options.params = new HashMap<>(); options.params.put("delta", "vcdiff"); options.modes = new ChannelMode[] { ChannelMode.publish, @@ -348,9 +358,11 @@ public void attach_with_params_delta_and_channel_modes() { channel.attach(); (new ChannelWaiter(channel)).waitFor(ChannelState.attached); assertEquals("Verify attached state reached", ChannelState.attached, channel.state); - options.params.put("modes", "publish,subscribe,presence_subscribe"); - assertEquals("Verify channel params", channel.getParams(), options.params); - assertEquals("Verify channel modes", channel.getModes(), options.modes); + + assertEquals("Verify channel params", options.params, channel.getParams()); + assertThat("Verify channel modes", + Arrays.asList(channel.getModes()), + Matchers.containsInAnyOrder(ChannelMode.publish, ChannelMode.subscribe, ChannelMode.presence_subscribe)); } catch (AblyException e) { e.printStackTrace(); fail("init0: Unexpected exception instantiating library"); diff --git a/lib/src/test/java/io/ably/lib/test/rest/RestPresenceTest.java b/lib/src/test/java/io/ably/lib/test/rest/RestPresenceTest.java index 40d87748d..584a53f3c 100644 --- a/lib/src/test/java/io/ably/lib/test/rest/RestPresenceTest.java +++ b/lib/src/test/java/io/ably/lib/test/rest/RestPresenceTest.java @@ -87,7 +87,7 @@ public void rest_presencehistory_simple() { * Get presence history data in the forward direction and check order * DISABLED: See issue https://github.com/ably/ably-java/issues/159 */ - /*@Test*/ + @Test public void rest_presencehistory_order_f() { String channelName = "persisted:restpresence_persisted"; /* get channel */ @@ -114,7 +114,7 @@ public void rest_presencehistory_order_f() { * Get presence history data in the backwards direction using text protocol and check order * DISABLED: See issue https://github.com/ably/ably-java/issues/159 */ - /*@Test*/ + @Test public void rest_presencehistory_order_b() { String channelName = "persisted:restpresence_persisted"; /* get channel */ @@ -141,7 +141,7 @@ public void rest_presencehistory_order_b() { * Get limited presence history data in the forward direction using text protocol and check order * DISABLED: See issue https://github.com/ably/ably-java/issues/159 */ - /*@Test*/ + @Test public void rest_presencehistory_limit_f() { String channelName = "persisted:restpresence_persisted"; /* get channel */ @@ -168,7 +168,7 @@ public void rest_presencehistory_limit_f() { * Get limited presence history data in the backwards direction using text protocol and check order * DISABLED: See issue https://github.com/ably/ably-java/issues/159 */ - /*@Test*/ + @Test public void rest_presencehistory_limit_b() { String channelName = "persisted:restpresence_persisted"; /* get channel */ @@ -195,7 +195,7 @@ public void rest_presencehistory_limit_b() { * Get paginated presence history data in the forward direction using text protocol * DISABLED: See issue https://github.com/ably/ably-java/issues/159 */ - /*@Test*/ + @Test public void rest_presencehistory_paginate_f() { /* get channel */ String channelName = "persisted:restpresence_persisted"; @@ -263,7 +263,7 @@ public void rest_presencehistory_paginate_f() { * Get paginated presence history data in the backwards direction using text protocol * DISABLED: See issue https://github.com/ably/ably-java/issues/159 */ - /*@Test*/ + @Test public void rest_presencehistory_paginate_text_b() { /* get channel */ String channelName = "persisted:restpresence_persisted"; From 754a06469520549ae516fa9ddaf2b7d1a52d4a1f Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Thu, 4 Sep 2025 16:58:05 +0530 Subject: [PATCH 2/3] [ECO-5553] Fixed channel delta encoding integration test assertions for modes and params --- .../ably/lib/test/realtime/RealtimeChannelTest.java | 9 ++++++--- .../lib/test/realtime/RealtimeDeltaDecoderTest.java | 12 ++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java index 861f7eb3b..feca16504 100644 --- a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java +++ b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java @@ -174,7 +174,7 @@ public void attach_with_channel_params_channels_get() { channel.attach(); (new ChannelWaiter(channel)).waitFor(ChannelState.attached); assertEquals("Verify attached state reached", ChannelState.attached, channel.state); - assertEquals("Verify channel params", channel.getParams(), options.params); + assertEquals("Verify channel params", options.params, channel.getParams()); assertArrayEquals("Verify channel modes", new ChannelMode[] { ChannelMode.subscribe }, channel.getModes()); } catch (AblyException e) { e.printStackTrace(); @@ -208,7 +208,7 @@ public void attach_with_channel_params_set_options() { channel.attach(); (new ChannelWaiter(channel)).waitFor(ChannelState.attached); assertEquals("Verify attached state reached", ChannelState.attached, channel.state); - assertEquals("Verify channel params", channel.getParams(), options.params); + assertEquals("Verify channel params", options.params, channel.getParams()); assertArrayEquals("Verify channel modes", new ChannelMode[] { ChannelMode.subscribe }, channel.getModes()); } catch (AblyException e) { e.printStackTrace(); @@ -285,7 +285,10 @@ public void attach_with_channel_params_modes_and_channel_modes() { (new ChannelWaiter(channel)).waitFor(ChannelState.attached); assertEquals("Verify attached state reached", ChannelState.attached, channel.state); assertEquals("Verify channel params", channel.getParams(), options.params); - assertArrayEquals("Verify channel modes", new ChannelMode[] { ChannelMode.subscribe, ChannelMode.presence }, channel.getModes()); + // modes in params overrides individual modes in options + assertThat("Verify channel modes", Arrays.asList(channel.getModes()), + Matchers.containsInAnyOrder(ChannelMode.presence, ChannelMode.subscribe)); + } catch (AblyException e) { e.printStackTrace(); fail("init0: Unexpected exception instantiating library"); diff --git a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeDeltaDecoderTest.java b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeDeltaDecoderTest.java index 78d2ea026..17ada41e5 100644 --- a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeDeltaDecoderTest.java +++ b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeDeltaDecoderTest.java @@ -11,6 +11,7 @@ import io.ably.lib.transport.ConnectionManager; import io.ably.lib.transport.ITransport; import io.ably.lib.transport.WebSocketTransport; +import io.ably.lib.types.ChannelOptions; import io.ably.lib.types.ClientOptions; import io.ably.lib.types.Message; import io.ably.lib.types.MessageExtras; @@ -20,6 +21,7 @@ import org.junit.Test; import org.junit.rules.Timeout; +import java.util.Map; import java.util.Objects; import static org.junit.Assert.assertEquals; @@ -52,6 +54,8 @@ public void simple_delta_codec() { (new ChannelWaiter(channel)).waitFor(ChannelState.attached); + assertEquals("Verify channel params", Map.of("delta", "vcdiff"), channel.getParams()); + for (int i = 0; i < testData.length; i++) { channel.publish(Integer.toString(i), testData[i]); } @@ -90,14 +94,18 @@ private void delta_failure_recovery(final ITransport.Factory websocketFactory, S opts.transportFactory = websocketFactory; ably = new AblyRealtime(opts); - /* create a channel */ - final Channel channel = ably.channels.get("[?delta=vcdiff]" + testName); + ChannelOptions options = new ChannelOptions(); + options.params = Map.of("delta", "vcdiff"); + /* create a channel with channelOptions set to vcdiff*/ + final Channel channel = ably.channels.get(testName, options); /* attach */ channel.attach(); (new ChannelWaiter(channel)).waitFor(ChannelState.attached); assertEquals("Verify attached state reached", channel.state, ChannelState.attached); + assertEquals("Verify channel params", Map.of("delta", "vcdiff"), channel.getParams()); + /* subscribe */ MessageWaiter messageWaiter = new MessageWaiter(channel); From 55bfe11671eae1643f06b7a9ecc09641acd80858 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 9 Sep 2025 16:22:09 +0530 Subject: [PATCH 3/3] [ECO-5553] Replaced List.of with Arrays.asList and Map.of with Collections.singletonMap --- .../io/ably/lib/test/realtime/RealtimeChannelTest.java | 4 ++-- .../ably/lib/test/realtime/RealtimeDeltaDecoderTest.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java index feca16504..6ea352819 100644 --- a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java +++ b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeChannelTest.java @@ -2561,7 +2561,7 @@ public void connect_on_closing_client_should_reinitialize_channels() throws Ably new ConnectionWaiter(ably.connection).waitFor(ConnectionState.closing); new ConnectionWaiter(ably.connection).waitFor(ConnectionState.connected); - assertEquals(List.of(ConnectionState.closing, ConnectionState.connecting, ConnectionState.connected), observedConnectionStates); + assertEquals(Arrays.asList(ConnectionState.closing, ConnectionState.connecting, ConnectionState.connected), observedConnectionStates); assertEquals(ChannelState.initialized, channel.state); channel.attach(); @@ -2569,7 +2569,7 @@ public void connect_on_closing_client_should_reinitialize_channels() throws Ably assertNull(channel.reason); assertEquals(0, ably.connection.connectionManager.msgSerial); - assertEquals(List.of(ChannelState.detached, ChannelState.initialized, ChannelState.attaching, ChannelState.attached), observedChannelStates); + assertEquals(Arrays.asList(ChannelState.detached, ChannelState.initialized, ChannelState.attaching, ChannelState.attached), observedChannelStates); } } diff --git a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeDeltaDecoderTest.java b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeDeltaDecoderTest.java index 17ada41e5..7cffb3940 100644 --- a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeDeltaDecoderTest.java +++ b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeDeltaDecoderTest.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.junit.rules.Timeout; -import java.util.Map; +import java.util.Collections; import java.util.Objects; import static org.junit.Assert.assertEquals; @@ -54,7 +54,7 @@ public void simple_delta_codec() { (new ChannelWaiter(channel)).waitFor(ChannelState.attached); - assertEquals("Verify channel params", Map.of("delta", "vcdiff"), channel.getParams()); + assertEquals("Verify channel params", Collections.singletonMap("delta", "vcdiff"), channel.getParams()); for (int i = 0; i < testData.length; i++) { channel.publish(Integer.toString(i), testData[i]); @@ -95,7 +95,7 @@ private void delta_failure_recovery(final ITransport.Factory websocketFactory, S ably = new AblyRealtime(opts); ChannelOptions options = new ChannelOptions(); - options.params = Map.of("delta", "vcdiff"); + options.params = Collections.singletonMap("delta", "vcdiff"); /* create a channel with channelOptions set to vcdiff*/ final Channel channel = ably.channels.get(testName, options); @@ -104,7 +104,7 @@ private void delta_failure_recovery(final ITransport.Factory websocketFactory, S (new ChannelWaiter(channel)).waitFor(ChannelState.attached); assertEquals("Verify attached state reached", channel.state, ChannelState.attached); - assertEquals("Verify channel params", Map.of("delta", "vcdiff"), channel.getParams()); + assertEquals("Verify channel params", Collections.singletonMap("delta", "vcdiff"), channel.getParams()); /* subscribe */ MessageWaiter messageWaiter = new MessageWaiter(channel);