34
34
*
35
35
* @author Jennifer Hickey
36
36
* @author Christoph Strobl
37
+ * @author Mark Paluch
37
38
*/
38
39
public class LettuceSubscriptionTests {
39
40
@@ -45,16 +46,19 @@ public class LettuceSubscriptionTests {
45
46
46
47
private RedisPubSubCommands <byte [], byte []> asyncCommands ;
47
48
49
+ private LettuceConnectionProvider connectionProvider ;
50
+
48
51
@ SuppressWarnings ("unchecked" )
49
52
@ Before
50
53
public void setUp () {
51
54
52
55
pubsub = Mockito .mock (StatefulRedisPubSubConnection .class );
53
56
listener = Mockito .mock (MessageListener .class );
54
57
asyncCommands = Mockito .mock (RedisPubSubCommands .class );
58
+ connectionProvider = Mockito .mock (LettuceConnectionProvider .class );
55
59
56
60
Mockito .when (pubsub .sync ()).thenReturn (asyncCommands );
57
- subscription = new LettuceSubscription (listener , pubsub );
61
+ subscription = new LettuceSubscription (listener , pubsub , connectionProvider );
58
62
}
59
63
60
64
@ Test
@@ -64,7 +68,7 @@ public void testUnsubscribeAllAndClose() {
64
68
verify (asyncCommands , times (1 )).unsubscribe (new byte [][] { "a" .getBytes () });
65
69
verify (asyncCommands , never ()).unsubscribe (new byte [0 ]);
66
70
verify (asyncCommands , never ()).punsubscribe (new byte [0 ]);
67
- verify (pubsub ). close ( );
71
+ verify (connectionProvider ). release ( pubsub );
68
72
verify (pubsub ).removeListener (any (LettuceMessageListener .class ));
69
73
assertFalse (subscription .isAlive ());
70
74
assertTrue (subscription .getChannels ().isEmpty ());
@@ -94,7 +98,7 @@ public void testUnsubscribeChannelAndClose() {
94
98
verify (asyncCommands , times (1 )).unsubscribe (channel );
95
99
verify (asyncCommands , never ()).unsubscribe (new byte [0 ]);
96
100
verify (asyncCommands , never ()).punsubscribe (new byte [0 ]);
97
- verify (pubsub ). close ( );
101
+ verify (connectionProvider ). release ( pubsub );
98
102
verify (pubsub ).removeListener (any (LettuceMessageListener .class ));
99
103
assertFalse (subscription .isAlive ());
100
104
assertTrue (subscription .getChannels ().isEmpty ());
@@ -167,7 +171,7 @@ public void testUnsubscribeAllNoChannels() {
167
171
public void testUnsubscribeNotAlive () {
168
172
subscription .subscribe (new byte [][] { "a" .getBytes () });
169
173
subscription .unsubscribe ();
170
- verify (pubsub , times (1 )).close ( );
174
+ verify (connectionProvider , times (1 )).release ( pubsub );
171
175
verify (pubsub , times (1 )).removeListener (any (LettuceMessageListener .class ));
172
176
assertFalse (subscription .isAlive ());
173
177
subscription .unsubscribe ();
@@ -192,7 +196,7 @@ public void testPUnsubscribeAllAndClose() {
192
196
verify (asyncCommands , never ()).punsubscribe (new byte [0 ]);
193
197
verify (asyncCommands , times (1 )).punsubscribe (new byte [][] { "a*" .getBytes () });
194
198
assertFalse (subscription .isAlive ());
195
- verify (pubsub ). close ( );
199
+ verify (connectionProvider ). release ( pubsub );
196
200
verify (pubsub ).removeListener (any (LettuceMessageListener .class ));
197
201
assertTrue (subscription .getChannels ().isEmpty ());
198
202
assertTrue (subscription .getPatterns ().isEmpty ());
@@ -221,7 +225,7 @@ public void testPUnsubscribeAndClose() {
221
225
verify (asyncCommands , never ()).unsubscribe (new byte [0 ]);
222
226
verify (asyncCommands , never ()).punsubscribe (new byte [0 ]);
223
227
verify (asyncCommands , times (1 )).punsubscribe (pattern );
224
- verify (pubsub ). close ( );
228
+ verify (connectionProvider ). release ( pubsub );
225
229
verify (pubsub ).removeListener (any (LettuceMessageListener .class ));
226
230
assertFalse (subscription .isAlive ());
227
231
assertTrue (subscription .getChannels ().isEmpty ());
@@ -296,7 +300,7 @@ public void testPUnsubscribeNotAlive() {
296
300
subscription .unsubscribe ();
297
301
assertFalse (subscription .isAlive ());
298
302
subscription .pUnsubscribe ();
299
- verify (pubsub , times (1 )).close ( );
303
+ verify (connectionProvider , times (1 )).release ( pubsub );
300
304
verify (pubsub , times (1 )).removeListener (any (LettuceMessageListener .class ));
301
305
verify (asyncCommands , times (1 )).unsubscribe (new byte [][] { "a" .getBytes () });
302
306
verify (asyncCommands , never ()).unsubscribe (new byte [0 ]);
0 commit comments