コード例 #1
0
 /**
  * Creates a cache with the given policy with a MemoryStore only and adds it to the manager.
  *
  * @param evictionPolicy
  * @throws CacheException
  */
 protected void createMemoryOnlyStore(
     MemoryStoreEvictionPolicy evictionPolicy, int memoryStoreSize) throws CacheException {
   manager.removeCache("test");
   cache =
       new Cache(
           "test", memoryStoreSize, evictionPolicy, false, null, false, 60, 30, false, 60, null);
   manager.addCache(cache);
   store = cache.getStore();
 }
コード例 #2
0
  @Test
  public void testShrinkingAndGrowingMemoryStore() {
    cache = new Cache("testShrinkingAndGrowingMemoryStore", 50, false, false, 120, 120);
    manager.addCache(cache);
    store = cache.getStore();

    if (!(store instanceof MemoryStore)) {
      LOG.info(
          "Skipping Growing/Shrinking Memory Store Test - Store is not a subclass of MemoryStore!");
      return;
    }

    int i = 0;
    for (; ; ) {
      int size = store.getSize();
      store.put(new Element(Integer.valueOf(i++), new byte[100]));
      if (store.getSize() <= size) break;
    }

    final int initialSize = store.getSize();
    final int shrinkSize = initialSize / 2;
    ((MemoryStore) store).memoryCapacityChanged(initialSize, shrinkSize);

    for (; ; ) {
      int size = store.getSize();
      store.put(new Element(Integer.valueOf(i++), new byte[100]));
      if (store.getSize() >= size) break;
    }

    {
      int size = store.getSize();
      assertTrue(size < (shrinkSize * 1.1));
      assertTrue(size > (shrinkSize * 0.9));
    }

    final int growSize = initialSize * 2;
    ((MemoryStore) store).memoryCapacityChanged(shrinkSize, growSize);

    for (; ; ) {
      int size = store.getSize();
      store.put(new Element(Integer.valueOf(i++), new byte[100]));
      if (store.getSize() <= size) break;
    }

    {
      int size = store.getSize();
      assertTrue(size < (growSize * 1.1));
      assertTrue(size > (growSize * 0.9));
    }
  }
コード例 #3
0
 /**
  * Creates a cache with the given policy and adds it to the manager.
  *
  * @param evictionPolicy
  * @throws CacheException
  */
 protected void createMemoryOnlyStore(MemoryStoreEvictionPolicy evictionPolicy)
     throws CacheException {
   manager.removeCache("testMemoryOnly");
   cache =
       new Cache(
           "testMemoryOnly",
           12000,
           evictionPolicy,
           false,
           System.getProperty("java.io.tmpdir"),
           false,
           60,
           30,
           false,
           60,
           null);
   manager.addCache(cache);
   store = cache.getStore();
 }
コード例 #4
0
 /**
  * Creates a store from the given configuration and cache within it.
  *
  * @param filePath
  * @param cacheName
  * @throws CacheException
  */
 protected void createMemoryStore(String filePath, String cacheName) throws CacheException {
   manager.shutdown();
   manager = CacheManager.create(filePath);
   cache = manager.getCache(cacheName);
   store = cache.getStore();
 }