|
16 | 16 |
|
17 | 17 | package org.springframework.data.redis.cache;
|
18 | 18 |
|
19 |
| -import static org.hamcrest.core.Is.is; |
| 19 | +import static edu.umd.cs.mtc.TestFramework.*; |
20 | 20 | import static org.hamcrest.core.IsEqual.*;
|
21 | 21 | import static org.hamcrest.core.IsInstanceOf.*;
|
22 | 22 | import static org.hamcrest.core.IsNot.*;
|
|
32 | 32 | import java.util.concurrent.TimeUnit;
|
33 | 33 | import java.util.concurrent.atomic.AtomicBoolean;
|
34 | 34 |
|
35 |
| -import edu.umd.cs.mtc.MultithreadedTestCase; |
36 |
| -import edu.umd.cs.mtc.TestFramework; |
37 |
| -import org.hamcrest.core.IsEqual; |
38 | 35 | import org.junit.AfterClass;
|
39 | 36 | import org.junit.Before;
|
40 | 37 | import org.junit.Test;
|
|
49 | 46 | import org.springframework.data.redis.core.AbstractOperationsTestParams;
|
50 | 47 | import org.springframework.data.redis.core.RedisTemplate;
|
51 | 48 |
|
| 49 | +import edu.umd.cs.mtc.MultithreadedTestCase; |
| 50 | + |
52 | 51 | /**
|
53 | 52 | * @author Costin Leau
|
54 | 53 | * @author Jennifer Hickey
|
@@ -292,58 +291,55 @@ public void testCacheGetSynchronized() throws Throwable {
|
292 | 291 | assumeThat(cache, instanceOf(RedisCache.class));
|
293 | 292 | assumeThat(valueFactory, instanceOf(StringObjectFactory.class));
|
294 | 293 |
|
295 |
| -TestFramework.runOnce(new CacheGetWithValueLoaderIsThreadSafe((RedisCache) cache)); |
| 294 | +runOnce(new CacheGetWithValueLoaderIsThreadSafe((RedisCache) cache)); |
296 | 295 | }
|
297 | 296 |
|
298 |
| -static class CacheGetWithValueLoaderIsThreadSafe extends MultithreadedTestCase { |
| 297 | +@SuppressWarnings("unused") |
| 298 | +private static class CacheGetWithValueLoaderIsThreadSafe extends MultithreadedTestCase { |
299 | 299 |
|
300 | 300 | RedisCache redisCache;
|
301 | 301 | TestCacheLoader<String> cacheLoader;
|
302 | 302 |
|
303 | 303 | public CacheGetWithValueLoaderIsThreadSafe(RedisCache redisCache) {
|
| 304 | + |
304 | 305 | this.redisCache = redisCache;
|
305 | 306 |
|
306 |
| -cacheLoader = new TestCacheLoader<String>("test"){ |
| 307 | +cacheLoader = new TestCacheLoader<String>("test") { |
307 | 308 |
|
308 | 309 | @Override
|
309 | 310 | public String call() throws Exception {
|
| 311 | + |
310 | 312 | waitForTick(2);
|
311 | 313 | return super.call();
|
312 | 314 | }
|
313 | 315 | };
|
314 | 316 | }
|
315 | 317 |
|
316 |
| -public void thread1(){ |
317 |
| -assertTick(0); |
318 |
| - Thread.currentThread().setName(getClass().getSimpleName() + " Cache Loader Thread"); |
319 |
| - |
320 |
| -String result = redisCache.get("key", cacheLoader); |
| 318 | +public void thread1() { |
321 | 319 |
|
322 |
| -assertThat(result, is("test")); |
| 320 | +assertTick(0); |
| 321 | +assertThat(redisCache.get("key", cacheLoader), equalTo("test")); |
323 | 322 | }
|
324 | 323 |
|
325 |
| -public void thread2(){ |
326 |
| -waitForTick(1); |
327 |
| -Thread.currentThread().setName(getClass().getSimpleName() + " Cache Reader Thread"); |
328 |
| - |
329 |
| -String result = redisCache.get("key", new TestCacheLoader<String>("illegal value")); |
| 324 | +public void thread2() { |
330 | 325 |
|
331 |
| -assertThat(result, is("test")); |
| 326 | +waitForTick(1); |
| 327 | +assertThat(redisCache.get("key", new TestCacheLoader<String>("illegal value")), equalTo("test")); |
332 | 328 | assertTick(2);
|
333 | 329 | }
|
334 | 330 | }
|
335 | 331 |
|
336 |
| -protected static class TestCacheLoader<T> implements Callable<T> { |
| 332 | +private static class TestCacheLoader<T> implements Callable<T> { |
337 | 333 |
|
338 |
| - private final T value; |
| 334 | +private final T value; |
339 | 335 |
|
340 |
| - public TestCacheLoader(T value) { |
341 |
| - this.value = value; |
342 |
| - } |
| 336 | +public TestCacheLoader(T value) { |
| 337 | +this.value = value; |
| 338 | +} |
343 | 339 |
|
344 |
| - @Override |
345 |
| - public T call() throws Exception { |
346 |
| - return value; |
347 |
| - } |
348 |
| - } |
| 340 | +@Override |
| 341 | +public T call() throws Exception { |
| 342 | +return value; |
| 343 | +} |
| 344 | +} |
349 | 345 | }
|
0 commit comments