View Javadoc
1   package com.atlassian.cache.vcache;
2   
3   import java.io.Serializable;
4   
5   import com.atlassian.cache.AbstractCacheEagerTest;
6   import com.atlassian.cache.Cache;
7   import com.atlassian.cache.CacheException;
8   
9   import org.junit.Before;
10  import org.junit.Test;
11  
12  import static org.hamcrest.Matchers.is;
13  import static org.junit.Assert.assertThat;
14  
15  /**
16   * Test the delegated eager Local Cache
17   *
18   * @since 2.0
19   */
20  public class DelegatingRemoteCacheEagerTest extends AbstractCacheEagerTest
21  {
22      public DelegatingRemoteCacheEagerTest()
23      {
24          super(CacheType.REMOTE);
25      }
26  
27      @Before
28      public void setUp() throws Exception
29      {
30          factory = TestUtils.createCacheFactory();
31      }
32  
33      @Override
34      protected <K, V> void assertSize(Cache<K, V> cache, int expectedSize)
35      {
36          // VCache does not allow the size of a remote (external) cache to be obtained.
37      }
38  
39      @Override
40      protected <K, V> void assertEmpty(Cache<K, V> cache)
41      {
42          // VCache does not allow the size of a remote (external) cache to be obtained.
43      }
44  
45      @Test
46      public void testSerializableKeys() throws Exception
47      {
48          final Cache<Serializable, Serializable> cache = factory.getCache("mycache");
49  
50          cache.put("string", "value");
51          assertThat(cache.get("string"), is("value"));
52  
53          cache.put(1, "number");
54          assertThat(cache.get(1), is("number"));
55  
56          cache.put(new byte[] {1}, "bytes");
57          assertThat(cache.get(new byte[] {1}), is("bytes"));
58      }
59  
60      @Test(expected = CacheException.class)
61      public void testObjectKey()
62      {
63          final Cache<Object, Object> cache = factory.getCache("mycache");
64  
65          cache.put(new Object(), "plain object");
66      }
67  }