@@ -32,6 +32,8 @@ public class WebSocketConnectionTest {
32
32
33
33
private static final long ACTIVITY_TIMEOUT = 500 ;
34
34
private static final long PONG_TIMEOUT = 500 ;
35
+ private static final int MAX_RECONNECTIONS = 6 ;
36
+ private static final int MAX_GAP = 30 ;
35
37
private static final String URL = "ws://ws.example.com/" ;
36
38
private static final String EVENT_NAME = "my-event" ;
37
39
private static final String CONN_ESTABLISHED_EVENT = "{\" event\" :\" pusher:connection_established\" ,\" data\" :\" {\\ \" socket_id\\ \" :\\ \" 21112.816204\\ \" }\" }" ;
@@ -65,22 +67,24 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
65
67
}).when (factory ).queueOnEventThread (any (Runnable .class ));
66
68
when (factory .getTimers ()).thenReturn (new DoNothingExecutor ());
67
69
68
- connection = new WebSocketConnection (URL , ACTIVITY_TIMEOUT , PONG_TIMEOUT , PROXY , factory );
70
+ connection = new WebSocketConnection (URL , ACTIVITY_TIMEOUT , PONG_TIMEOUT , MAX_RECONNECTIONS , MAX_GAP , PROXY , factory );
69
71
connection .bind (ConnectionState .ALL , mockEventListener );
70
72
}
71
73
72
74
@ Test
73
75
public void testUnbindingWhenNotAlreadyBoundReturnsFalse () throws URISyntaxException {
74
76
final ConnectionEventListener listener = mock (ConnectionEventListener .class );
75
- final WebSocketConnection connection = new WebSocketConnection (URL , ACTIVITY_TIMEOUT , PONG_TIMEOUT , PROXY , factory );
77
+ final WebSocketConnection connection = new WebSocketConnection (URL , ACTIVITY_TIMEOUT , PONG_TIMEOUT , MAX_RECONNECTIONS , MAX_GAP ,
78
+ PROXY , factory );
76
79
final boolean unbound = connection .unbind (ConnectionState .ALL , listener );
77
80
assertEquals (false , unbound );
78
81
}
79
82
80
83
@ Test
81
84
public void testUnbindingWhenBoundReturnsTrue () throws URISyntaxException {
82
85
final ConnectionEventListener listener = mock (ConnectionEventListener .class );
83
- final WebSocketConnection connection = new WebSocketConnection (URL , ACTIVITY_TIMEOUT , PONG_TIMEOUT , PROXY , factory );
86
+ final WebSocketConnection connection = new WebSocketConnection (URL , ACTIVITY_TIMEOUT , PONG_TIMEOUT , MAX_RECONNECTIONS , MAX_GAP ,
87
+ PROXY , factory );
84
88
85
89
connection .bind (ConnectionState .ALL , listener );
86
90
@@ -118,7 +122,8 @@ public void testConnectDoesNotCallConnectOnUnderlyingConnectionIfAlreadyInConnec
118
122
119
123
@ Test
120
124
public void testListenerDoesNotReceiveConnectingEventIfItIsOnlyBoundToTheConnectedEvent () throws URISyntaxException {
121
- connection = new WebSocketConnection (URL , ACTIVITY_TIMEOUT , PONG_TIMEOUT , PROXY , factory );
125
+ connection = new WebSocketConnection (URL , ACTIVITY_TIMEOUT , PONG_TIMEOUT , MAX_RECONNECTIONS , MAX_GAP ,
126
+ PROXY , factory );
122
127
connection .bind (ConnectionState .CONNECTED , mockEventListener );
123
128
connection .connect ();
124
129
@@ -219,7 +224,8 @@ public void testOnCloseCallbackUpdatesStateToDisconnectedWhenPreviousStateIsDisc
219
224
220
225
@ Test
221
226
public void testOnCloseCallbackDoesNotCallListenerIfItIsNotBoundToDisconnectedEvent () throws URISyntaxException {
222
- connection = new WebSocketConnection (URL , ACTIVITY_TIMEOUT , PONG_TIMEOUT , PROXY , factory );
227
+ connection = new WebSocketConnection (URL , ACTIVITY_TIMEOUT , PONG_TIMEOUT , MAX_RECONNECTIONS , MAX_GAP ,
228
+ PROXY , factory );
223
229
connection .bind (ConnectionState .CONNECTED , mockEventListener );
224
230
225
231
connection .connect ();
0 commit comments