24
24
import java .util .Collections ;
25
25
import java .util .List ;
26
26
27
+ import org .junit .After ;
27
28
import org .junit .AfterClass ;
28
- import org .junit .Before ;
29
29
import org .junit .BeforeClass ;
30
30
import org .junit .Test ;
31
31
import org .springframework .core .io .ClassPathResource ;
35
35
import org .springframework .data .redis .connection .RedisConnectionFactory ;
36
36
import org .springframework .data .redis .connection .lettuce .LettuceConnectionFactory ;
37
37
import org .springframework .data .redis .connection .lettuce .LettuceTestClientConfiguration ;
38
+ import org .springframework .data .redis .core .RedisCallback ;
38
39
import org .springframework .data .redis .core .RedisTemplate ;
39
40
import org .springframework .data .redis .core .StringRedisTemplate ;
40
41
import org .springframework .data .redis .serializer .GenericToStringSerializer ;
48
49
49
50
/**
50
51
* @author Mark Paluch
52
+ * @author Christoph Strobl
51
53
*/
52
54
public class DefaultReactiveScriptExecutorTests {
53
55
@@ -74,12 +76,16 @@ public static void cleanUp() {
74
76
}
75
77
}
76
78
77
- @ Before
78
- public void before () {
79
+ @ After
80
+ public void tearDown () {
79
81
80
82
RedisConnection connection = connectionFactory .getConnection ();
81
- connection .flushDb ();
82
- connection .close ();
83
+ try {
84
+ connection .scriptingCommands ().scriptFlush ();
85
+ connection .flushDb ();
86
+ } finally {
87
+ connection .close ();
88
+ }
83
89
}
84
90
85
91
protected RedisConnectionFactory getConnectionFactory () {
@@ -217,15 +223,25 @@ public void shouldApplyCustomResultSerializer() {
217
223
}
218
224
219
225
@ Test // DATAREDIS-711
220
- public void testExecuteCachedNullKeys () {
226
+ public void executeAddsScriptToScriptCache () {
221
227
222
228
DefaultRedisScript <String > script = new DefaultRedisScript <>();
223
229
script .setScriptText ("return 'HELLO'" );
224
230
script .setResultType (String .class );
225
231
226
232
// Execute script twice, second time should be from cache
233
+
234
+ assertThat (stringTemplate .execute (
235
+ (RedisCallback <List <Boolean >>) connection -> connection .scriptingCommands ().scriptExists (script .getSha1 ())))
236
+ .containsExactly (false );
237
+
227
238
StepVerifier .create (stringScriptExecutor .execute (script , Collections .emptyList ())).expectNext ("HELLO" )
228
239
.verifyComplete ();
240
+
241
+ assertThat (stringTemplate .execute (
242
+ (RedisCallback <List <Boolean >>) connection -> connection .scriptingCommands ().scriptExists (script .getSha1 ())))
243
+ .containsExactly (true );
244
+
229
245
StepVerifier .create (stringScriptExecutor .execute (script , Collections .emptyList ())).expectNext ("HELLO" )
230
246
.verifyComplete ();
231
247
}
0 commit comments