|
6 | 6 | import static org.junit.Assert.assertTrue; |
7 | 7 | import static org.junit.Assert.fail; |
8 | 8 |
|
| 9 | +import io.ably.lib.test.common.Helpers; |
| 10 | +import io.ably.lib.types.AsyncHttpPaginatedResponse; |
| 11 | +import io.ably.lib.types.ErrorInfo; |
9 | 12 | import org.junit.Ignore; |
10 | 13 | import org.junit.Test; |
11 | 14 |
|
|
23 | 26 | import io.ably.lib.types.ProtocolMessage; |
24 | 27 | import org.junit.rules.Timeout; |
25 | 28 |
|
| 29 | +import java.util.concurrent.atomic.AtomicLong; |
| 30 | + |
26 | 31 | public class RealtimeConnectTest extends ParameterizedTest { |
27 | 32 |
|
28 | 33 | public Timeout testTimeout = Timeout.seconds(30); |
@@ -248,4 +253,35 @@ public void close_when_connecting() { |
248 | 253 | } |
249 | 254 | } |
250 | 255 |
|
| 256 | + @Test |
| 257 | + public void reopened_connection_rest_works() throws Exception { |
| 258 | + try (AblyRealtime realtimeClient = new AblyRealtime(createOptions(testVars.keys[0].keyStr))) { |
| 259 | + realtimeClient.close(); |
| 260 | + realtimeClient.connect(); |
| 261 | + |
| 262 | + long timestamp = System.currentTimeMillis(); |
| 263 | + AtomicLong ablyTime = new AtomicLong(0); |
| 264 | + Helpers.CompletionWaiter waiter = new Helpers.CompletionWaiter(); |
| 265 | + |
| 266 | + realtimeClient.requestAsync("GET", "/time", null, null, null, new AsyncHttpPaginatedResponse.Callback() { |
| 267 | + @Override |
| 268 | + public void onResponse(AsyncHttpPaginatedResponse response) { |
| 269 | + ablyTime.set(response.items()[0].getAsLong()); |
| 270 | + waiter.onSuccess(); |
| 271 | + } |
| 272 | + |
| 273 | + @Override |
| 274 | + public void onError(ErrorInfo reason) { |
| 275 | + waiter.onError(reason); |
| 276 | + } |
| 277 | + }); |
| 278 | + |
| 279 | + waiter.waitFor(); |
| 280 | + |
| 281 | + long thirtySeconds = 30_000L; |
| 282 | + |
| 283 | + assertTrue(ablyTime.get() > timestamp - thirtySeconds && ablyTime.get() < timestamp + thirtySeconds); |
| 284 | + } |
| 285 | + } |
| 286 | + |
251 | 287 | } |
0 commit comments