1515 */
1616package io .lettuce .core .cluster .pubsub ;
1717
18- import static org .assertj .core .api .Assertions .assertThat ;
18+ import static org .assertj .core .api .Assertions .* ;
1919
20- import java .time .Duration ;
2120import java .util .List ;
22- import java .util .Map ;
2321import java .util .concurrent .BlockingQueue ;
24- import java .util .concurrent .ConcurrentHashMap ;
25- import java .util .concurrent .CopyOnWriteArrayList ;
2622import java .util .concurrent .LinkedBlockingQueue ;
2723
2824import javax .inject .Inject ;
3430
3531import io .lettuce .core .RedisURI ;
3632import io .lettuce .core .TestSupport ;
37- import io .lettuce .core .api .push .PushMessage ;
3833import io .lettuce .core .api .sync .RedisCommands ;
3934import io .lettuce .core .cluster .RedisClusterClient ;
4035import io .lettuce .core .cluster .api .StatefulRedisClusterConnection ;
4540import io .lettuce .core .cluster .pubsub .api .reactive .PubSubReactiveNodeSelection ;
4641import io .lettuce .core .cluster .pubsub .api .sync .NodeSelectionPubSubCommands ;
4742import io .lettuce .core .cluster .pubsub .api .sync .PubSubNodeSelection ;
43+ import io .lettuce .core .event .command .CommandFailedEvent ;
44+ import io .lettuce .core .event .command .CommandListener ;
4845import io .lettuce .core .pubsub .StatefulRedisPubSubConnection ;
4946import io .lettuce .core .support .PubSubTestListener ;
5047import io .lettuce .test .LettuceExtension ;
5148import io .lettuce .test .TestFutures ;
5249import io .lettuce .test .Wait ;
53- import io .lettuce .test .condition .EnabledOnCommand ;
5450
5551/**
5652 * @author Mark Paluch
@@ -61,10 +57,13 @@ class RedisClusterPubSubConnectionIntegrationTests extends TestSupport {
6157 private final RedisClusterClient clusterClient ;
6258
6359 private final PubSubTestListener connectionListener = new PubSubTestListener ();
60+
6461 private final PubSubTestListener nodeListener = new PubSubTestListener ();
6562
6663 private StatefulRedisClusterConnection <String , String > connection ;
64+
6765 private StatefulRedisClusterPubSubConnection <String , String > pubSubConnection ;
66+
6867 private StatefulRedisClusterPubSubConnection <String , String > pubSubConnection2 ;
6968
7069 @ Inject
@@ -101,6 +100,34 @@ void testRegularClientPubSubChannels() {
101100 assertThat (channelsOnOtherNode ).isEmpty ();
102101 }
103102
103+ @ Test
104+ void myIdWorksAfterDisconnect () throws InterruptedException {
105+
106+ BlockingQueue <CommandFailedEvent > failedEvents = new LinkedBlockingQueue <CommandFailedEvent >();
107+
108+ CommandListener listener = new CommandListener () {
109+
110+ @ Override
111+ public void commandFailed (CommandFailedEvent event ) {
112+ failedEvents .add (event );
113+ }
114+
115+ };
116+ clusterClient .addListener (listener );
117+
118+ StatefulRedisClusterPubSubConnection <String , String > pubsub = clusterClient .connectPubSub ();
119+ pubsub .sync ().subscribe ("foo" );
120+ pubsub .async ().quit ();
121+
122+ Thread .sleep (100 );
123+ Wait .untilTrue (pubsub ::isOpen ).waitOrTimeout ();
124+
125+ pubsub .close ();
126+ clusterClient .removeListener (listener );
127+
128+ assertThat (failedEvents ).isEmpty ();
129+ }
130+
104131 @ Test
105132 void testRegularClientPublish () throws Exception {
106133
@@ -164,8 +191,7 @@ void testGetConnectionAsyncByNodeId() {
164191 RedisClusterNode partition = pubSubConnection .getPartitions ().getPartition (0 );
165192
166193 StatefulRedisPubSubConnection <String , String > node = TestFutures
167- .getOrTimeout (pubSubConnection .getConnectionAsync (partition
168- .getNodeId ()));
194+ .getOrTimeout (pubSubConnection .getConnectionAsync (partition .getNodeId ()));
169195
170196 assertThat (node .sync ().ping ()).isEqualTo ("PONG" );
171197 }
@@ -177,8 +203,7 @@ void testGetConnectionAsyncByHostAndPort() {
177203
178204 RedisURI uri = partition .getUri ();
179205 StatefulRedisPubSubConnection <String , String > node = TestFutures
180- .getOrTimeout (pubSubConnection .getConnectionAsync (uri .getHost (),
181- uri .getPort ()));
206+ .getOrTimeout (pubSubConnection .getConnectionAsync (uri .getHost (), uri .getPort ()));
182207
183208 assertThat (node .sync ().ping ()).isEqualTo ("PONG" );
184209 }
@@ -297,6 +322,7 @@ void testClusterListener() throws Exception {
297322 public void message (RedisClusterNode node , String pattern , String channel , String message ) {
298323 nodes .add (node );
299324 }
325+
300326 });
301327
302328 PubSubNodeSelection <String , String > masters = pubSubConnection .sync ().masters ();
@@ -326,4 +352,5 @@ private RedisClusterNode getOtherThan(String nodeId) {
326352
327353 throw new IllegalStateException ("No other nodes than " + nodeId + " available" );
328354 }
355+
329356}
0 commit comments