View Javadoc

1   package com.atlassian.vcache.internal.test;
2   
3   import com.atlassian.vcache.RequestCache;
4   import com.atlassian.vcache.VCache;
5   import org.junit.Test;
6   
7   import java.time.Duration;
8   
9   import static org.hamcrest.Matchers.is;
10  import static org.junit.Assert.assertThat;
11  
12  /**
13   * Base test class for the {@link RequestCache}.
14   */
15  public abstract class AbstractRequestCacheTest extends AbstractLocalCacheOperationsTest {
16      @Override
17      protected abstract <K, V> RequestCache<K, V> createCache(String name, Duration lockTimeout);
18  
19      @SuppressWarnings("checkstyle:MagicNumber")
20      protected <K, V> RequestCache<K, V> createCache(String name) {
21          return createCache(name, Duration.ofSeconds(1));
22      }
23  
24      @Test
25      public void testGetName() throws Exception {
26          final VCache namedCache = createCache("netflix");
27          assertThat(namedCache.getName(), is("netflix"));
28      }
29  
30      @Test
31      public void handle_recursion_supplier() {
32          final RequestCache<String, String> cache = createCache("abc");
33  
34          final String result = cache.get("first", () ->
35                  cache.get("first", () -> "stupid"));
36  
37          assertThat(result, is("stupid"));
38      }
39  
40  }