Skip to content

Commit 0e847a3

Browse files
committed
Polishing.
Reformat code. Refine tests as we do not require assertions for every publish command when testing listeners. See #2209 Original pull request: #2225.
1 parent 178d44c commit 0e847a3

File tree

3 files changed

+12
-28
lines changed

3 files changed

+12
-28
lines changed

src/main/java/org/springframework/data/redis/core/RedisOperations.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ default Boolean expireAt(K key, Instant expireAt) {
387387
*/
388388
@Nullable
389389
Long getExpire(K key, TimeUnit timeUnit);
390+
390391
/**
391392
* Move given {@code key} to database with {@code index}.
392393
*
@@ -591,8 +592,8 @@ default void restore(K key, byte[] value, long timeToLive, TimeUnit unit) {
591592
* Publishes the given message to the given channel.
592593
*
593594
* @param destination the channel to publish to, must not be {@literal null}.
594-
* @param message message to publish
595-
* @return the number of clients that received the message
595+
* @param message message to publish.
596+
* @return the number of clients that received the message. {@literal null} when used in pipeline / transaction.
596597
* @see <a href="https://redis.io/commands/publish">Redis Documentation: PUBLISH</a>
597598
*/
598599
@Nullable

src/test/java/org/springframework/data/redis/config/NamespaceIntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void testSanityTest() throws Exception {
4545

4646
@Test
4747
void testWithMessages() {
48-
assertThat(template.convertAndSend("x1", "[X]test")).isEqualTo(1L);
49-
assertThat(template.convertAndSend("z1", "[Z]test")).isEqualTo(1L);
48+
assertThat(template.convertAndSend("x1", "[X]test")).isGreaterThanOrEqualTo(1L);
49+
assertThat(template.convertAndSend("z1", "[Z]test")).isGreaterThanOrEqualTo(1L);
5050
}
5151
}

src/test/java/org/springframework/data/redis/listener/PubSubTests.java

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,11 @@
2525
import java.util.Collections;
2626
import java.util.concurrent.BlockingDeque;
2727
import java.util.concurrent.LinkedBlockingDeque;
28-
import java.util.concurrent.Phaser;
2928
import java.util.concurrent.TimeUnit;
3029

3130
import org.junit.jupiter.api.AfterEach;
3231
import org.junit.jupiter.api.BeforeEach;
3332

34-
import org.springframework.core.task.SimpleAsyncTaskExecutor;
35-
import org.springframework.core.task.SyncTaskExecutor;
3633
import org.springframework.data.redis.ObjectFactory;
3734
import org.springframework.data.redis.connection.RedisConnectionFactory;
3835
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
@@ -82,33 +79,18 @@ public static Collection<Object[]> testParams() {
8279
}
8380

8481
@BeforeEach
85-
void setUp() throws Exception {
82+
void setUp() {
8683
bag.clear();
8784

8885
adapter.setSerializer(template.getValueSerializer());
8986
adapter.afterPropertiesSet();
9087

91-
Phaser phaser = new Phaser(1);
92-
9388
container = new RedisMessageListenerContainer();
9489
container.setConnectionFactory(template.getConnectionFactory());
9590
container.setBeanName("container");
9691
container.addMessageListener(adapter, Arrays.asList(new ChannelTopic(CHANNEL)));
97-
container.setTaskExecutor(new SyncTaskExecutor());
98-
container.setSubscriptionExecutor(new SimpleAsyncTaskExecutor() {
99-
@Override
100-
protected void doExecute(Runnable task) {
101-
super.doExecute(() -> {
102-
phaser.arriveAndDeregister();
103-
task.run();
104-
});
105-
}
106-
});
10792
container.afterPropertiesSet();
10893
container.start();
109-
110-
phaser.arriveAndAwaitAdvance();
111-
Thread.sleep(250);
11294
}
11395

11496
@AfterEach
@@ -130,17 +112,18 @@ void testContainerSubscribe() {
130112
T payload1 = getT();
131113
T payload2 = getT();
132114

133-
assertThat(template.convertAndSend(CHANNEL, payload1)).isEqualTo(1L);
134-
assertThat(template.convertAndSend(CHANNEL, payload2)).isEqualTo(1L);
115+
template.convertAndSend(CHANNEL, payload1);
116+
template.convertAndSend(CHANNEL, payload2);
135117

136118
await().atMost(Duration.ofSeconds(2)).until(() -> bag.contains(payload1) && bag.contains(payload2));
137119
}
138120

139121
@ParameterizedRedisTest
140122
void testMessageBatch() throws Exception {
123+
141124
int COUNT = 10;
142125
for (int i = 0; i < COUNT; i++) {
143-
assertThat(template.convertAndSend(CHANNEL, getT())).isEqualTo(1L);
126+
template.convertAndSend(CHANNEL, getT());
144127
}
145128

146129
for (int i = 0; i < COUNT; i++) {
@@ -155,8 +138,8 @@ void testContainerUnsubscribe() throws Exception {
155138
T payload2 = getT();
156139

157140
container.removeMessageListener(adapter, new ChannelTopic(CHANNEL));
158-
assertThat(template.convertAndSend(CHANNEL, payload1)).isEqualTo(1L);
159-
assertThat(template.convertAndSend(CHANNEL, payload2)).isEqualTo(1L);
141+
template.convertAndSend(CHANNEL, payload1);
142+
template.convertAndSend(CHANNEL, payload2);
160143

161144
assertThat(bag.poll(200, TimeUnit.MILLISECONDS)).isNull();
162145
}

0 commit comments

Comments
 (0)