Skip to content

Commit d39929d

Browse files
committed
[ECO-5056] Added test for getObjects when liveobjects plugin is not installed
1 parent cd9490b commit d39929d

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import static org.junit.Assert.assertNull;
4747
import static org.junit.Assert.assertSame;
4848
import static org.junit.Assert.assertThat;
49+
import static org.junit.Assert.assertThrows;
4950
import static org.junit.Assert.assertTrue;
5051
import static org.junit.Assert.fail;
5152

@@ -2578,6 +2579,29 @@ public void connect_should_not_rewrite_immediate_attach() throws AblyException {
25782579
}
25792580
}
25802581

2582+
@Test
2583+
public void channel_get_objects_throws_exception() throws AblyException {
2584+
ClientOptions opts = createOptions(testVars.keys[0].keyStr);
2585+
try (AblyRealtime ably = new AblyRealtime(opts)) {
2586+
2587+
/* wait until connected */
2588+
new ConnectionWaiter(ably.connection).waitFor(ConnectionState.connected);
2589+
assertEquals("Verify connected state reached", ably.connection.state, ConnectionState.connected);
2590+
2591+
/* create a channel and attach */
2592+
final Channel channel = ably.channels.get("channel");
2593+
channel.attach();
2594+
new ChannelWaiter(channel).waitFor(ChannelState.attached);
2595+
assertEquals("Verify attached state reached", channel.state, ChannelState.attached);
2596+
2597+
AblyException exception = assertThrows(AblyException.class, channel::getObjects);
2598+
assertNotNull(exception);
2599+
assertEquals(40019, exception.errorInfo.code);
2600+
assertEquals(400, exception.errorInfo.statusCode);
2601+
assertTrue(exception.errorInfo.message.contains("LiveObjects plugin hasn't been installed"));
2602+
}
2603+
}
2604+
25812605
static class DetachingProtocolListener implements DebugOptions.RawProtocolListener {
25822606

25832607
public Channel theChannel;

liveobjects/src/test/kotlin/io/ably/lib/objects/unit/HelpersTest.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ class HelpersTest {
7676
fun testRetrieveObjectsGCGracePeriodDeferredInvokesOnConnectedWithValue() {
7777
val adapter = getMockObjectsAdapter()
7878
val connManager = adapter.connectionManager
79+
val connection = adapter.connection
7980

8081
var value: Long? = null
81-
every { adapter.connection.once(ConnectionEvent.connected, any()) } answers {
82+
every { connection.once(ConnectionEvent.connected, any()) } answers {
8283
val listener = secondArg<ConnectionStateListener>()
8384
connManager.setPrivateField("objectsGCGracePeriod", 456L)
8485
listener.onConnectionStateChanged(mockk(relaxed = true))
@@ -87,23 +88,24 @@ class HelpersTest {
8788
adapter.retrieveObjectsGCGracePeriod { v -> value = v }
8889

8990
assertEquals(456L, value)
90-
verify(exactly = 1) { adapter.connection.once(ConnectionEvent.connected, any()) }
91+
verify(exactly = 1) { connection.once(ConnectionEvent.connected, any()) }
9192
}
9293

9394
@Test
9495
fun testRetrieveObjectsGCGracePeriodDeferredInvokesOnConnectedWithNull() {
9596
val adapter = getMockObjectsAdapter()
97+
val connection = adapter.connection
9698

9799
var value: Long? = null
98-
every { adapter.connection.once(ConnectionEvent.connected, any()) } answers {
100+
every { connection.once(ConnectionEvent.connected, any()) } answers {
99101
val listener = secondArg<ConnectionStateListener>()
100102
listener.onConnectionStateChanged(mockk(relaxed = true))
101103
}
102104

103105
adapter.retrieveObjectsGCGracePeriod { v -> value = v }
104106

105107
assertNull(value)
106-
verify(exactly = 1) { adapter.connection.once(ConnectionEvent.connected, any()) }
108+
verify(exactly = 1) { connection.once(ConnectionEvent.connected, any()) }
107109
}
108110

109111
@Test

0 commit comments

Comments
 (0)