|
26 | 26 | import io.ably.lib.types.ProtocolMessage;
|
27 | 27 | import io.ably.lib.util.Log;
|
28 | 28 | import org.hamcrest.Matchers;
|
| 29 | +import org.junit.Assert; |
29 | 30 | import org.junit.Ignore;
|
30 | 31 | import org.junit.Test;
|
31 | 32 |
|
@@ -1698,15 +1699,15 @@ public void channel_server_initiated_attached() throws AblyException {
|
1698 | 1699 |
|
1699 | 1700 | /*
|
1700 | 1701 | * Establish connection, attach channel, simulate sending detached messages
|
1701 |
| - * from the server, test correct behaviour |
| 1702 | + * from the server for channel in attached state. |
1702 | 1703 | *
|
1703 | 1704 | * Tests RTL13a
|
1704 | 1705 | */
|
1705 | 1706 | @Test
|
1706 |
| - public void channel_server_initiated_detached() throws AblyException { |
| 1707 | + public void server_initiated_detach_for_attached_channel() throws AblyException { |
1707 | 1708 | AblyRealtime ably = null;
|
1708 | 1709 | long oldRealtimeTimeout = Defaults.realtimeRequestTimeout;
|
1709 |
| - final String channelName = "channel_server_initiated_attach_detach"; |
| 1710 | + final String channelName = "channel_server_initiated_detach_for_attached_channel"; |
1710 | 1711 |
|
1711 | 1712 | try {
|
1712 | 1713 | ClientOptions opts = createOptions(testVars.keys[0].keyStr);
|
@@ -1735,6 +1736,70 @@ public void channel_server_initiated_detached() throws AblyException {
|
1735 | 1736 | channelWaiter.waitFor(ChannelState.attaching);
|
1736 | 1737 | channelWaiter.waitFor(ChannelState.attached);
|
1737 | 1738 |
|
| 1739 | + List<ChannelState> channelStates = channelWaiter.getRecordedStates(); |
| 1740 | + Assert.assertEquals(4, channelStates.size()); |
| 1741 | + Assert.assertEquals(ChannelState.attaching, channelStates.get(0)); |
| 1742 | + Assert.assertEquals(ChannelState.attached, channelStates.get(1)); |
| 1743 | + Assert.assertEquals(ChannelState.attaching, channelStates.get(2)); |
| 1744 | + Assert.assertEquals(ChannelState.attached, channelStates.get(3)); |
| 1745 | + |
| 1746 | + } finally { |
| 1747 | + if (ably != null) |
| 1748 | + ably.close(); |
| 1749 | + Defaults.realtimeRequestTimeout = oldRealtimeTimeout; |
| 1750 | + } |
| 1751 | + } |
| 1752 | + |
| 1753 | + /* |
| 1754 | + * Establish connection, attach channel, simulate sending detached messages |
| 1755 | + * from the server for channel in suspended state. |
| 1756 | + * |
| 1757 | + * Tests RTL13a |
| 1758 | + */ |
| 1759 | + @Test |
| 1760 | + public void server_initiated_detach_for_suspended_channel() throws AblyException { |
| 1761 | + AblyRealtime ably = null; |
| 1762 | + long oldRealtimeTimeout = Defaults.realtimeRequestTimeout; |
| 1763 | + final String channelName = "channel_server_initiated_detach_for_suspended_channel"; |
| 1764 | + |
| 1765 | + try { |
| 1766 | + ClientOptions opts = createOptions(testVars.keys[0].keyStr); |
| 1767 | + |
| 1768 | + /* Make test faster */ |
| 1769 | + Defaults.realtimeRequestTimeout = 1000; |
| 1770 | + opts.channelRetryTimeout = 1000; |
| 1771 | + |
| 1772 | + ably = new AblyRealtime(opts); |
| 1773 | + new ConnectionWaiter(ably.connection).waitFor(ConnectionState.connected); |
| 1774 | + |
| 1775 | + Channel channel = ably.channels.get(channelName); |
| 1776 | + ChannelWaiter channelWaiter = new ChannelWaiter(channel); |
| 1777 | + |
| 1778 | + channel.attach(); |
| 1779 | + channelWaiter.waitFor(ChannelState.attached); |
| 1780 | + |
| 1781 | + channel.setSuspended(new ErrorInfo("Set state to suspended", 400), true); |
| 1782 | + channelWaiter.waitFor(ChannelState.suspended); |
| 1783 | + |
| 1784 | + /* Inject detached message as if from the server */ |
| 1785 | + ProtocolMessage detachedMessage = new ProtocolMessage() {{ |
| 1786 | + action = Action.detached; |
| 1787 | + channel = channelName; |
| 1788 | + }}; |
| 1789 | + ably.connection.connectionManager.onMessage(null, detachedMessage); |
| 1790 | + |
| 1791 | + /* Channel should transition to attaching, then to attached */ |
| 1792 | + channelWaiter.waitFor(ChannelState.attaching); |
| 1793 | + channelWaiter.waitFor(ChannelState.attached); |
| 1794 | + |
| 1795 | + List<ChannelState> channelStates = channelWaiter.getRecordedStates(); |
| 1796 | + Assert.assertEquals(5, channelStates.size()); |
| 1797 | + Assert.assertEquals(ChannelState.attaching, channelStates.get(0)); |
| 1798 | + Assert.assertEquals(ChannelState.attached, channelStates.get(1)); |
| 1799 | + Assert.assertEquals(ChannelState.suspended, channelStates.get(2)); |
| 1800 | + Assert.assertEquals(ChannelState.attaching, channelStates.get(3)); |
| 1801 | + Assert.assertEquals(ChannelState.attached, channelStates.get(4)); |
| 1802 | + |
1738 | 1803 | } finally {
|
1739 | 1804 | if (ably != null)
|
1740 | 1805 | ably.close();
|
|
0 commit comments