27
27
import org .junit .Ignore ;
28
28
import org .junit .Test ;
29
29
import org .springframework .data .redis .SettingsUtils ;
30
- import org .springframework .data .redis .connection .PoolConfig ;
31
30
import org .springframework .data .redis .connection .PoolException ;
32
31
import org .springframework .data .redis .connection .RedisSentinelConfiguration ;
33
32
@@ -49,20 +48,22 @@ public class DefaultLettucePoolTests {
49
48
50
49
@ After
51
50
public void tearDown () {
52
- if (this .pool != null ) {
53
51
54
- if (this .pool .getClient () != null ) {
55
- this .pool .getClient ().shutdown (0 , 0 , TimeUnit .MILLISECONDS );
52
+ if (pool != null ) {
53
+
54
+ if (pool .getClient () != null ) {
55
+ pool .getClient ().shutdown (0 , 0 , TimeUnit .MILLISECONDS );
56
56
}
57
57
58
- this . pool .destroy ();
58
+ pool .destroy ();
59
59
}
60
60
}
61
61
62
62
@ Test
63
63
public void testGetResource () {
64
- this .pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort ());
65
- this .pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
64
+
65
+ pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort ());
66
+ pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
66
67
pool .afterPropertiesSet ();
67
68
RedisAsyncConnection <byte [], byte []> client = pool .getResource ();
68
69
assertNotNull (client );
@@ -72,11 +73,12 @@ public void testGetResource() {
72
73
73
74
@ Test
74
75
public void testGetResourcePoolExhausted () {
76
+
75
77
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig ();
76
78
poolConfig .setMaxTotal (1 );
77
79
poolConfig .setMaxWaitMillis (1 );
78
- this . pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort (), poolConfig );
79
- this . pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
80
+ pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort (), poolConfig );
81
+ pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
80
82
pool .afterPropertiesSet ();
81
83
RedisAsyncConnection <byte [], byte []> client = pool .getResource ();
82
84
assertNotNull (client );
@@ -90,10 +92,11 @@ public void testGetResourcePoolExhausted() {
90
92
91
93
@ Test
92
94
public void testGetResourceValidate () {
93
- PoolConfig poolConfig = new PoolConfig ();
95
+
96
+ GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig ();
94
97
poolConfig .setTestOnBorrow (true );
95
- this . pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort (), poolConfig );
96
- this . pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
98
+ pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort (), poolConfig );
99
+ pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
97
100
pool .afterPropertiesSet ();
98
101
RedisAsyncConnection <byte [], byte []> client = pool .getResource ();
99
102
assertNotNull (client );
@@ -102,19 +105,21 @@ public void testGetResourceValidate() {
102
105
103
106
@ Test (expected = PoolException .class )
104
107
public void testGetResourceCreationUnsuccessful () throws Exception {
105
- this .pool = new DefaultLettucePool (SettingsUtils .getHost (), 3333 );
106
- this .pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
108
+
109
+ pool = new DefaultLettucePool (SettingsUtils .getHost (), 3333 );
110
+ pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
107
111
pool .afterPropertiesSet ();
108
112
pool .getResource ();
109
113
}
110
114
111
115
@ Test
112
116
public void testReturnResource () {
117
+
113
118
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig ();
114
119
poolConfig .setMaxTotal (1 );
115
120
poolConfig .setMaxWaitMillis (1 );
116
- this . pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort (), poolConfig );
117
- this . pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
121
+ pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort (), poolConfig );
122
+ pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
118
123
pool .afterPropertiesSet ();
119
124
RedisAsyncConnection <byte [], byte []> client = pool .getResource ();
120
125
assertNotNull (client );
@@ -125,11 +130,12 @@ public void testReturnResource() {
125
130
126
131
@ Test
127
132
public void testReturnBrokenResource () {
133
+
128
134
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig ();
129
135
poolConfig .setMaxTotal (1 );
130
136
poolConfig .setMaxWaitMillis (1 );
131
- this . pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort (), poolConfig );
132
- this . pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
137
+ pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort (), poolConfig );
138
+ pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
133
139
pool .afterPropertiesSet ();
134
140
RedisAsyncConnection <byte [], byte []> client = pool .getResource ();
135
141
assertNotNull (client );
@@ -147,26 +153,29 @@ public void testReturnBrokenResource() {
147
153
148
154
@ Test
149
155
public void testCreateWithDbIndex () {
150
- this .pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort ());
151
- this .pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
156
+
157
+ pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort ());
158
+ pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
152
159
pool .setDatabase (1 );
153
160
pool .afterPropertiesSet ();
154
161
assertNotNull (pool .getResource ());
155
162
}
156
163
157
164
@ Test (expected = PoolException .class )
158
165
public void testCreateWithDbIndexInvalid () {
159
- this .pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort ());
160
- this .pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
166
+
167
+ pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort ());
168
+ pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
161
169
pool .setDatabase (17 );
162
170
pool .afterPropertiesSet ();
163
171
pool .getResource ();
164
172
}
165
173
166
174
@ Test (expected = PoolException .class )
167
175
public void testCreateWithPasswordNoPassword () {
168
- this .pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort ());
169
- this .pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
176
+
177
+ pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort ());
178
+ pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
170
179
pool .setPassword ("notthepassword" );
171
180
pool .afterPropertiesSet ();
172
181
pool .getResource ();
@@ -175,8 +184,9 @@ public void testCreateWithPasswordNoPassword() {
175
184
@ Ignore ("Redis must have requirepass set to run this test" )
176
185
@ Test
177
186
public void testCreatePassword () {
178
- this .pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort ());
179
- this .pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
187
+
188
+ pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort ());
189
+ pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
180
190
pool .setPassword ("foo" );
181
191
pool .afterPropertiesSet ();
182
192
RedisAsyncConnection <byte [], byte []> conn = pool .getResource ();
@@ -187,8 +197,9 @@ public void testCreatePassword() {
187
197
@ Ignore ("Redis must have requirepass set to run this test" )
188
198
@ Test (expected = PoolException .class )
189
199
public void testCreateInvalidPassword () {
190
- this .pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort ());
191
- this .pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
200
+
201
+ pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort ());
202
+ pool .setClientResources (LettuceTestClientResources .getSharedClientResources ());
192
203
pool .setPassword ("bad" );
193
204
pool .afterPropertiesSet ();
194
205
pool .getResource ();
@@ -205,9 +216,9 @@ public void testCreateSentinelWithPassword() {
205
216
pool .setPassword ("foo" );
206
217
pool .afterPropertiesSet ();
207
218
208
- RedisURI redisURI = (RedisURI ) getField (pool .getClient (), "redisURI" );
219
+ RedisURI redisUri = (RedisURI ) getField (pool .getClient (), "redisURI" );
209
220
210
- assertThat (redisURI .getPassword (), is (equalTo (pool .getPassword ().toCharArray ())));
221
+ assertThat (redisUri .getPassword (), is (equalTo (pool .getPassword ().toCharArray ())));
211
222
}
212
223
213
224
/**
@@ -216,7 +227,7 @@ public void testCreateSentinelWithPassword() {
216
227
@ Test
217
228
public void poolWorksWithoutClientResources () {
218
229
219
- this . pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort ());
230
+ pool = new DefaultLettucePool (SettingsUtils .getHost (), SettingsUtils .getPort ());
220
231
pool .setDatabase (1 );
221
232
pool .afterPropertiesSet ();
222
233
assertNotNull (pool .getResource ());
0 commit comments