diff --git a/src/main/java/org/springframework/data/redis/core/RedisOperations.java b/src/main/java/org/springframework/data/redis/core/RedisOperations.java index 463526fdd..328761425 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisOperations.java +++ b/src/main/java/org/springframework/data/redis/core/RedisOperations.java @@ -387,6 +387,7 @@ public interface RedisOperations { */ @Nullable Long getExpire(K key, TimeUnit timeUnit); + /** * Move given {@code key} to database with {@code index}. * @@ -591,8 +592,8 @@ public interface RedisOperations { * Publishes the given message to the given channel. * * @param destination the channel to publish to, must not be {@literal null}. - * @param message message to publish - * @return the number of clients that received the message + * @param message message to publish. + * @return the number of clients that received the message. {@literal null} when used in pipeline / transaction. * @see Redis Documentation: PUBLISH */ @Nullable diff --git a/src/test/java/org/springframework/data/redis/config/NamespaceIntegrationTests.java b/src/test/java/org/springframework/data/redis/config/NamespaceIntegrationTests.java index be11bcc2e..0d1f536fe 100644 --- a/src/test/java/org/springframework/data/redis/config/NamespaceIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/config/NamespaceIntegrationTests.java @@ -45,7 +45,7 @@ class NamespaceIntegrationTests { @Test void testWithMessages() { - assertThat(template.convertAndSend("x1", "[X]test")).isEqualTo(1L); - assertThat(template.convertAndSend("z1", "[Z]test")).isEqualTo(1L); + assertThat(template.convertAndSend("x1", "[X]test")).isGreaterThanOrEqualTo(1L); + assertThat(template.convertAndSend("z1", "[Z]test")).isGreaterThanOrEqualTo(1L); } } diff --git a/src/test/java/org/springframework/data/redis/listener/PubSubTests.java b/src/test/java/org/springframework/data/redis/listener/PubSubTests.java index 580b668ed..37e54a6a8 100644 --- a/src/test/java/org/springframework/data/redis/listener/PubSubTests.java +++ b/src/test/java/org/springframework/data/redis/listener/PubSubTests.java @@ -25,14 +25,11 @@ import java.util.Collection; import java.util.Collections; import java.util.concurrent.BlockingDeque; import java.util.concurrent.LinkedBlockingDeque; -import java.util.concurrent.Phaser; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.springframework.core.task.SimpleAsyncTaskExecutor; -import org.springframework.core.task.SyncTaskExecutor; import org.springframework.data.redis.ObjectFactory; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; @@ -82,33 +79,18 @@ public class PubSubTests { } @BeforeEach - void setUp() throws Exception { + void setUp() { bag.clear(); adapter.setSerializer(template.getValueSerializer()); adapter.afterPropertiesSet(); - Phaser phaser = new Phaser(1); - container = new RedisMessageListenerContainer(); container.setConnectionFactory(template.getConnectionFactory()); container.setBeanName("container"); container.addMessageListener(adapter, Arrays.asList(new ChannelTopic(CHANNEL))); - container.setTaskExecutor(new SyncTaskExecutor()); - container.setSubscriptionExecutor(new SimpleAsyncTaskExecutor() { - @Override - protected void doExecute(Runnable task) { - super.doExecute(() -> { - phaser.arriveAndDeregister(); - task.run(); - }); - } - }); container.afterPropertiesSet(); container.start(); - - phaser.arriveAndAwaitAdvance(); - Thread.sleep(250); } @AfterEach @@ -130,17 +112,18 @@ public class PubSubTests { T payload1 = getT(); T payload2 = getT(); - assertThat(template.convertAndSend(CHANNEL, payload1)).isEqualTo(1L); - assertThat(template.convertAndSend(CHANNEL, payload2)).isEqualTo(1L); + template.convertAndSend(CHANNEL, payload1); + template.convertAndSend(CHANNEL, payload2); await().atMost(Duration.ofSeconds(2)).until(() -> bag.contains(payload1) && bag.contains(payload2)); } @ParameterizedRedisTest void testMessageBatch() throws Exception { + int COUNT = 10; for (int i = 0; i < COUNT; i++) { - assertThat(template.convertAndSend(CHANNEL, getT())).isEqualTo(1L); + template.convertAndSend(CHANNEL, getT()); } for (int i = 0; i < COUNT; i++) { @@ -155,8 +138,8 @@ public class PubSubTests { T payload2 = getT(); container.removeMessageListener(adapter, new ChannelTopic(CHANNEL)); - assertThat(template.convertAndSend(CHANNEL, payload1)).isEqualTo(1L); - assertThat(template.convertAndSend(CHANNEL, payload2)).isEqualTo(1L); + template.convertAndSend(CHANNEL, payload1); + template.convertAndSend(CHANNEL, payload2); assertThat(bag.poll(200, TimeUnit.MILLISECONDS)).isNull(); }