1 package com.atlassian.cache.memory;
2
3 import com.atlassian.cache.AbstractCacheLazyTest;
4
5 import com.atlassian.cache.Cache;
6 import org.junit.Before;
7 import org.junit.Test;
8
9 import java.util.concurrent.CountDownLatch;
10 import java.util.concurrent.ExecutorService;
11 import java.util.concurrent.Executors;
12
13
14
15
16
17
18 public class DelegatingCacheLazyTest extends AbstractCacheLazyTest
19 {
20 @Before
21 public void setUp() throws Exception
22 {
23 factory = new MemoryCacheManager();
24 }
25
26 @Test(timeout = 15000L)
27 public void testConcurrentRemovesAndGets() throws Exception
28 {
29 final int THREADS = 10;
30 CountDownLatch latch = new CountDownLatch(THREADS);
31 Cache<String, Long> cache = makeSlowCache();
32 ExecutorService executorService = Executors.newFixedThreadPool(THREADS);
33 for (int i = 0; i < THREADS; i++)
34 {
35 executorService.submit(() ->
36 {
37 cache.remove("42");
38 if (((Long) 42L).equals(cache.get("42")))
39 {
40 latch.countDown();
41 }
42 });
43 }
44 latch.await();
45 assertSize(cache, 1);
46 }
47
48 }