From 3979a9327f14e0f937344c1e6ac8d41c35dd8501 Mon Sep 17 00:00:00 2001 From: dengliming Date: Wed, 3 Mar 2021 15:09:28 +0800 Subject: [PATCH] Add support for ping command in Pub/Sub connection #1601 Original pull request: #1641. --- src/main/java/io/lettuce/core/pubsub/PubSubEndpoint.java | 4 +++- src/test/java/io/lettuce/core/pubsub/PubSubCommandTest.java | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/lettuce/core/pubsub/PubSubEndpoint.java b/src/main/java/io/lettuce/core/pubsub/PubSubEndpoint.java index b06e62ed57..da457a8cc3 100644 --- a/src/main/java/io/lettuce/core/pubsub/PubSubEndpoint.java +++ b/src/main/java/io/lettuce/core/pubsub/PubSubEndpoint.java @@ -31,6 +31,7 @@ /** * @author Mark Paluch + * @author dengliming */ public class PubSubEndpoint extends DefaultEndpoint { @@ -50,13 +51,14 @@ public class PubSubEndpoint extends DefaultEndpoint { static { - ALLOWED_COMMANDS_SUBSCRIBED = new HashSet<>(5, 1); + ALLOWED_COMMANDS_SUBSCRIBED = new HashSet<>(6, 1); ALLOWED_COMMANDS_SUBSCRIBED.add(CommandType.SUBSCRIBE.name()); ALLOWED_COMMANDS_SUBSCRIBED.add(CommandType.PSUBSCRIBE.name()); ALLOWED_COMMANDS_SUBSCRIBED.add(CommandType.UNSUBSCRIBE.name()); ALLOWED_COMMANDS_SUBSCRIBED.add(CommandType.PUNSUBSCRIBE.name()); ALLOWED_COMMANDS_SUBSCRIBED.add(CommandType.QUIT.name()); + ALLOWED_COMMANDS_SUBSCRIBED.add(CommandType.PING.name()); SUBSCRIBE_COMMANDS = new HashSet<>(2, 1); diff --git a/src/test/java/io/lettuce/core/pubsub/PubSubCommandTest.java b/src/test/java/io/lettuce/core/pubsub/PubSubCommandTest.java index 82eb62abdd..c475bf00ab 100644 --- a/src/test/java/io/lettuce/core/pubsub/PubSubCommandTest.java +++ b/src/test/java/io/lettuce/core/pubsub/PubSubCommandTest.java @@ -53,6 +53,7 @@ * @author Will Glozer * @author Mark Paluch * @author Tugdual Grall + * @author dengliming */ class PubSubCommandTest extends AbstractRedisClientTest implements RedisPubSubListener { @@ -492,13 +493,13 @@ void pingNotAllowedInSubscriptionState() { TestFutures.awaitOrTimeout(pubsub.subscribe(channel)); - assertThatThrownBy(() -> TestFutures.getOrTimeout(pubsub.ping())).isInstanceOf(RedisException.class) + assertThatThrownBy(() -> TestFutures.getOrTimeout(pubsub.echo("ping"))).isInstanceOf(RedisException.class) .hasMessageContaining("not allowed"); pubsub.unsubscribe(channel); Wait.untilTrue(() -> channels.size() == 2).waitOrTimeout(); - assertThat(TestFutures.getOrTimeout(pubsub.ping())).isEqualTo("PONG"); + assertThat(TestFutures.getOrTimeout(pubsub.echo("ping"))).isEqualTo("ping"); } // RedisPubSubListener implementation