Skip to content

Commit 63f7f7b

Browse files
committed
Upgrade Spring Data to 2022.0.0-M3
Closes gh-2048
1 parent 140cc75 commit 63f7f7b

13 files changed

+208
-30
lines changed

gradle/dependency-management.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dependencyManagement {
44
mavenBom 'com.fasterxml.jackson:jackson-bom:2.13.1'
55
mavenBom 'org.junit:junit-bom:5.8.2'
66
mavenBom 'org.springframework:spring-framework-bom:6.0.0-M2'
7-
mavenBom 'org.springframework.data:spring-data-bom:2022.0.0-M1'
7+
mavenBom 'org.springframework.data:spring-data-bom:2022.0.0-M3'
88
mavenBom 'org.springframework.security:spring-security-bom:6.0.0-M1'
99
mavenBom 'org.testcontainers:testcontainers-bom:1.16.2'
1010
}

spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfigurationClassPathXmlApplicationContextTests.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,11 +23,14 @@
2323

2424
import org.springframework.data.redis.connection.RedisConnection;
2525
import org.springframework.data.redis.connection.RedisConnectionFactory;
26+
import org.springframework.data.redis.connection.SubscriptionListener;
2627
import org.springframework.test.context.ContextConfiguration;
2728
import org.springframework.test.context.junit.jupiter.SpringExtension;
2829

30+
import static org.mockito.ArgumentMatchers.any;
2931
import static org.mockito.ArgumentMatchers.anyString;
3032
import static org.mockito.BDDMockito.given;
33+
import static org.mockito.BDDMockito.willAnswer;
3134
import static org.mockito.Mockito.mock;
3235

3336
/**
@@ -50,6 +53,15 @@ static RedisConnectionFactory connectionFactory() {
5053
given(factory.getConnection()).willReturn(connection);
5154
given(connection.getConfig(anyString())).willReturn(new Properties());
5255

56+
willAnswer((it) -> {
57+
SubscriptionListener listener = it.getArgument(0);
58+
listener.onPatternSubscribed(it.getArgument(1), 0);
59+
listener.onChannelSubscribed("__keyevent@0__:del".getBytes(), 0);
60+
listener.onChannelSubscribed("__keyevent@0__:expired".getBytes(), 0);
61+
62+
return null;
63+
}).given(connection).pSubscribe(any(), any());
64+
5365
return factory;
5466
}
5567

spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfigurationNoOpConfigureRedisActionTests.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,12 +21,17 @@
2121

2222
import org.springframework.context.annotation.Bean;
2323
import org.springframework.context.annotation.Configuration;
24+
import org.springframework.data.redis.connection.RedisConnection;
2425
import org.springframework.data.redis.connection.RedisConnectionFactory;
26+
import org.springframework.data.redis.connection.SubscriptionListener;
2527
import org.springframework.session.data.redis.config.ConfigureRedisAction;
2628
import org.springframework.test.context.ContextConfiguration;
2729
import org.springframework.test.context.junit.jupiter.SpringExtension;
2830
import org.springframework.test.context.web.WebAppConfiguration;
2931

32+
import static org.mockito.ArgumentMatchers.any;
33+
import static org.mockito.BDDMockito.given;
34+
import static org.mockito.BDDMockito.willAnswer;
3035
import static org.mockito.Mockito.mock;
3136

3237
/**
@@ -52,7 +57,20 @@ ConfigureRedisAction configureRedisAction() {
5257

5358
@Bean
5459
RedisConnectionFactory redisConnectionFactory() {
55-
return mock(RedisConnectionFactory.class);
60+
RedisConnectionFactory redisConnectionFactory = mock(RedisConnectionFactory.class);
61+
RedisConnection connection = mock(RedisConnection.class);
62+
given(redisConnectionFactory.getConnection()).willReturn(connection);
63+
64+
willAnswer((it) -> {
65+
SubscriptionListener listener = it.getArgument(0);
66+
listener.onPatternSubscribed(it.getArgument(1), 0);
67+
listener.onChannelSubscribed("__keyevent@0__:del".getBytes(), 0);
68+
listener.onChannelSubscribed("__keyevent@0__:expired".getBytes(), 0);
69+
70+
return null;
71+
}).given(connection).pSubscribe(any(), any());
72+
73+
return redisConnectionFactory;
5674
}
5775

5876
}

spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfigurationOverrideDefaultSerializerTests.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
2626
import org.springframework.context.annotation.Configuration;
2727
import org.springframework.data.redis.connection.RedisConnection;
2828
import org.springframework.data.redis.connection.RedisConnectionFactory;
29+
import org.springframework.data.redis.connection.SubscriptionListener;
2930
import org.springframework.data.redis.core.RedisTemplate;
3031
import org.springframework.data.redis.serializer.RedisSerializer;
3132
import org.springframework.session.data.redis.config.annotation.SpringSessionRedisOperations;
@@ -34,8 +35,10 @@
3435
import org.springframework.test.context.web.WebAppConfiguration;
3536

3637
import static org.assertj.core.api.Assertions.assertThat;
38+
import static org.mockito.ArgumentMatchers.any;
3739
import static org.mockito.ArgumentMatchers.anyString;
3840
import static org.mockito.BDDMockito.given;
41+
import static org.mockito.BDDMockito.willAnswer;
3942
import static org.mockito.Mockito.mock;
4043

4144
/**
@@ -76,6 +79,15 @@ RedisConnectionFactory connectionFactory() {
7679
given(factory.getConnection()).willReturn(connection);
7780
given(connection.getConfig(anyString())).willReturn(new Properties());
7881

82+
willAnswer((it) -> {
83+
SubscriptionListener listener = it.getArgument(0);
84+
listener.onPatternSubscribed(it.getArgument(1), 0);
85+
listener.onChannelSubscribed("__keyevent@0__:del".getBytes(), 0);
86+
listener.onChannelSubscribed("__keyevent@0__:expired".getBytes(), 0);
87+
88+
return null;
89+
}).given(connection).pSubscribe(any(), any());
90+
7991
return factory;
8092
}
8193

spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfigurationOverrideSessionTaskExecutor.java

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,15 +27,16 @@
2727
import org.springframework.context.annotation.Configuration;
2828
import org.springframework.data.redis.connection.RedisConnection;
2929
import org.springframework.data.redis.connection.RedisConnectionFactory;
30+
import org.springframework.data.redis.connection.SubscriptionListener;
3031
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
31-
import org.springframework.scheduling.SchedulingAwareRunnable;
3232
import org.springframework.test.context.ContextConfiguration;
3333
import org.springframework.test.context.junit.jupiter.SpringExtension;
3434
import org.springframework.test.context.web.WebAppConfiguration;
3535

3636
import static org.mockito.ArgumentMatchers.any;
3737
import static org.mockito.ArgumentMatchers.anyString;
3838
import static org.mockito.BDDMockito.given;
39+
import static org.mockito.BDDMockito.willAnswer;
3940
import static org.mockito.Mockito.mock;
4041
import static org.mockito.Mockito.times;
4142
import static org.mockito.Mockito.verify;
@@ -57,7 +58,7 @@ class RedisHttpSessionConfigurationOverrideSessionTaskExecutor {
5758

5859
@Test
5960
void overrideSessionTaskExecutor() {
60-
verify(this.springSessionRedisTaskExecutor, times(1)).execute(any(SchedulingAwareRunnable.class));
61+
verify(this.springSessionRedisTaskExecutor, times(1)).execute(any(Runnable.class));
6162
}
6263

6364
@EnableRedisHttpSession
@@ -66,7 +67,13 @@ static class Config {
6667

6768
@Bean
6869
Executor springSessionRedisTaskExecutor() {
69-
return mock(Executor.class);
70+
Executor executor = mock(Executor.class);
71+
willAnswer((it) -> {
72+
Runnable r = it.getArgument(0);
73+
new Thread(r).start();
74+
return null;
75+
}).given(executor).execute(any());
76+
return executor;
7077
}
7178

7279
@Bean
@@ -76,6 +83,15 @@ RedisConnectionFactory connectionFactory() {
7683
given(factory.getConnection()).willReturn(connection);
7784
given(connection.getConfig(anyString())).willReturn(new Properties());
7885

86+
willAnswer((it) -> {
87+
SubscriptionListener listener = it.getArgument(0);
88+
listener.onPatternSubscribed(it.getArgument(1), 0);
89+
listener.onChannelSubscribed("__keyevent@0__:del".getBytes(), 0);
90+
listener.onChannelSubscribed("__keyevent@0__:expired".getBytes(), 0);
91+
92+
return null;
93+
}).given(connection).pSubscribe(any(), any());
94+
7995
return factory;
8096
}
8197

spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfigurationOverrideSessionTaskExecutors.java

+27-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,15 +27,16 @@
2727
import org.springframework.context.annotation.Configuration;
2828
import org.springframework.data.redis.connection.RedisConnection;
2929
import org.springframework.data.redis.connection.RedisConnectionFactory;
30+
import org.springframework.data.redis.connection.SubscriptionListener;
3031
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
31-
import org.springframework.scheduling.SchedulingAwareRunnable;
3232
import org.springframework.test.context.ContextConfiguration;
3333
import org.springframework.test.context.junit.jupiter.SpringExtension;
3434
import org.springframework.test.context.web.WebAppConfiguration;
3535

3636
import static org.mockito.ArgumentMatchers.any;
3737
import static org.mockito.ArgumentMatchers.anyString;
3838
import static org.mockito.BDDMockito.given;
39+
import static org.mockito.BDDMockito.willAnswer;
3940
import static org.mockito.Mockito.mock;
4041
import static org.mockito.Mockito.never;
4142
import static org.mockito.Mockito.times;
@@ -62,7 +63,7 @@ class RedisHttpSessionConfigurationOverrideSessionTaskExecutors {
6263

6364
@Test
6465
void overrideSessionTaskExecutors() {
65-
verify(this.springSessionRedisSubscriptionExecutor, times(1)).execute(any(SchedulingAwareRunnable.class));
66+
verify(this.springSessionRedisSubscriptionExecutor, times(1)).execute(any(Runnable.class));
6667
verify(this.springSessionRedisTaskExecutor, never()).execute(any(Runnable.class));
6768
}
6869

@@ -72,12 +73,24 @@ static class Config {
7273

7374
@Bean
7475
Executor springSessionRedisTaskExecutor() {
75-
return mock(Executor.class);
76+
Executor executor = mock(Executor.class);
77+
willAnswer((it) -> {
78+
Runnable r = it.getArgument(0);
79+
new Thread(r).start();
80+
return null;
81+
}).given(executor).execute(any());
82+
return executor;
7683
}
7784

7885
@Bean
7986
Executor springSessionRedisSubscriptionExecutor() {
80-
return mock(Executor.class);
87+
Executor executor = mock(Executor.class);
88+
willAnswer((it) -> {
89+
Runnable r = it.getArgument(0);
90+
new Thread(r).start();
91+
return null;
92+
}).given(executor).execute(any());
93+
return executor;
8194
}
8295

8396
@Bean
@@ -87,6 +100,15 @@ RedisConnectionFactory connectionFactory() {
87100
given(factory.getConnection()).willReturn(connection);
88101
given(connection.getConfig(anyString())).willReturn(new Properties());
89102

103+
willAnswer((it) -> {
104+
SubscriptionListener listener = it.getArgument(0);
105+
listener.onPatternSubscribed(it.getArgument(1), 0);
106+
listener.onChannelSubscribed("__keyevent@0__:del".getBytes(), 0);
107+
listener.onChannelSubscribed("__keyevent@0__:expired".getBytes(), 0);
108+
109+
return null;
110+
}).given(connection).pSubscribe(any(), any());
111+
90112
return factory;
91113
}
92114

spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfigurationTests.java

+23-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
3232
import org.springframework.core.annotation.Order;
3333
import org.springframework.data.redis.connection.RedisConnection;
3434
import org.springframework.data.redis.connection.RedisConnectionFactory;
35+
import org.springframework.data.redis.connection.SubscriptionListener;
3536
import org.springframework.data.redis.core.RedisOperations;
3637
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
3738
import org.springframework.mock.env.MockEnvironment;
@@ -47,8 +48,9 @@
4748

4849
import static org.assertj.core.api.Assertions.assertThat;
4950
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
50-
import static org.mockito.ArgumentMatchers.anyString;
51+
import static org.mockito.ArgumentMatchers.any;
5152
import static org.mockito.BDDMockito.given;
53+
import static org.mockito.BDDMockito.willAnswer;
5254
import static org.mockito.Mockito.mock;
5355

5456
/**
@@ -264,11 +266,24 @@ private void registerAndRefresh(Class<?>... annotatedClasses) {
264266
}
265267

266268
private static RedisConnectionFactory mockRedisConnectionFactory() {
267-
RedisConnectionFactory connectionFactory = mock(RedisConnectionFactory.class);
268-
RedisConnection connection = mock(RedisConnection.class);
269-
given(connectionFactory.getConnection()).willReturn(connection);
270-
given(connection.getConfig(anyString())).willReturn(new Properties());
271-
return connectionFactory;
269+
RedisConnectionFactory connectionFactoryMock = mock(RedisConnectionFactory.class);
270+
RedisConnection connectionMock = mock(RedisConnection.class);
271+
given(connectionFactoryMock.getConnection()).willReturn(connectionMock);
272+
273+
Properties keyspaceEventsConfig = new Properties();
274+
keyspaceEventsConfig.put("notify-keyspace-events", "KEA");
275+
given(connectionMock.getConfig("notify-keyspace-events")).willReturn(keyspaceEventsConfig);
276+
277+
willAnswer((it) -> {
278+
SubscriptionListener listener = it.getArgument(0);
279+
listener.onPatternSubscribed(it.getArgument(1), 0);
280+
listener.onChannelSubscribed("__keyevent@0__:del".getBytes(), 0);
281+
listener.onChannelSubscribed("__keyevent@0__:expired".getBytes(), 0);
282+
283+
return null;
284+
}).given(connectionMock).pSubscribe(any(), any());
285+
286+
return connectionFactoryMock;
272287
}
273288

274289
@Configuration
@@ -445,7 +460,7 @@ static class CustomRedisMessageListenerContainerConfig {
445460

446461
@Bean
447462
RedisMessageListenerContainer redisMessageListenerContainer() {
448-
return new RedisMessageListenerContainer();
463+
return mock(RedisMessageListenerContainer.class);
449464
}
450465

451466
}

spring-session-data-redis/src/test/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfigurationXmlCustomExpireTests.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,12 +23,15 @@
2323

2424
import org.springframework.data.redis.connection.RedisConnection;
2525
import org.springframework.data.redis.connection.RedisConnectionFactory;
26+
import org.springframework.data.redis.connection.SubscriptionListener;
2627
import org.springframework.test.context.ContextConfiguration;
2728
import org.springframework.test.context.junit.jupiter.SpringExtension;
2829
import org.springframework.test.context.web.WebAppConfiguration;
2930

31+
import static org.mockito.ArgumentMatchers.any;
3032
import static org.mockito.ArgumentMatchers.anyString;
3133
import static org.mockito.BDDMockito.given;
34+
import static org.mockito.BDDMockito.willAnswer;
3235
import static org.mockito.Mockito.mock;
3336

3437
@ExtendWith(SpringExtension.class)
@@ -46,6 +49,15 @@ static RedisConnectionFactory connectionFactory() {
4649
given(factory.getConnection()).willReturn(connection);
4750
given(connection.getConfig(anyString())).willReturn(new Properties());
4851

52+
willAnswer((it) -> {
53+
SubscriptionListener listener = it.getArgument(0);
54+
listener.onPatternSubscribed(it.getArgument(1), 0);
55+
listener.onChannelSubscribed("__keyevent@0__:del".getBytes(), 0);
56+
listener.onChannelSubscribed("__keyevent@0__:expired".getBytes(), 0);
57+
58+
return null;
59+
}).given(connection).pSubscribe(any(), any());
60+
4961
return factory;
5062
}
5163

0 commit comments

Comments
 (0)