Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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<String, String>();
options.params = new HashMap<>();
options.params.put("modes", "subscribe");
options.params.put("delta", "vcdiff");

Expand All @@ -172,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();
Expand All @@ -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;
Expand All @@ -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");

Expand All @@ -205,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();
Expand All @@ -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;
Expand All @@ -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");
Expand All @@ -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;
Expand All @@ -279,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");
Expand All @@ -289,7 +298,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;
Expand All @@ -312,7 +321,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");
Expand All @@ -322,7 +335,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;
Expand All @@ -335,7 +348,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<String, String>();
options.params = new HashMap<>();
options.params.put("delta", "vcdiff");
options.modes = new ChannelMode[] {
ChannelMode.publish,
Expand All @@ -348,9 +361,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");
Expand Down Expand Up @@ -2546,15 +2561,15 @@ 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();
new ChannelWaiter(channel).waitFor(ChannelState.attached);

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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +21,7 @@
import org.junit.Test;
import org.junit.rules.Timeout;

import java.util.Collections;
import java.util.Objects;

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

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

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]);
}
Expand Down Expand Up @@ -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 = Collections.singletonMap("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", Collections.singletonMap("delta", "vcdiff"), channel.getParams());

/* subscribe */
MessageWaiter messageWaiter = new MessageWaiter(channel);

Expand Down
12 changes: 6 additions & 6 deletions lib/src/test/java/io/ably/lib/test/rest/RestPresenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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";
Expand Down Expand Up @@ -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";
Expand Down
Loading