Package org.directmemory

Examples of org.directmemory.CacheStore


  public static CacheStore cache = null;
  public static Split wholeTestSplit = null;
 
  @BeforeClass
  public static void setup() {
    cache = new CacheStore(100, 10 * 1024 * 1024, 1);
    cache.serializer = new ProtoStuffSerializer();
//    cache.supervisor = new AsyncBatchSupervisor(750);
    cache.supervisor = new TimedSupervisor(1500);
  }
View Full Code Here


    return 2048;
  }
 
  @Test
  public void addAndRetrieve() {
    CacheStore cache = new CacheStore(1, CacheStore.KB(4), 1);
    cache.put("test1", new DummyPojo("test1", fixedSize()));
    logger.debug("put test1 " + cache.toString());
    cache.put("test2", new DummyPojo("test2", fixedSize()));
    logger.debug("put test2 " + cache.toString());
    cache.put("test3", new DummyPojo("test3", fixedSize()));
    logger.debug("put test3 " + cache.toString());
    logger.debug("ask for test1 " + cache.toString());
    DummyPojo pojo1 = (DummyPojo)cache.get("test1");
    logger.debug("got test1 " + cache.toString());
    DummyPojo pojo2 = (DummyPojo)cache.get("test2");
    logger.debug("got test2 " + cache.toString());
    DummyPojo pojo3 = (DummyPojo)cache.get("test3");
    logger.debug("got test3 " + cache.toString());
    assertNotNull(pojo1);
    assertEquals("test1", pojo1.name);
    assertNotNull(pojo2);
    assertEquals("test2", pojo2.name);
    assertNotNull(pojo3);
    assertEquals("test3", pojo3.name);
    logger.debug("addAndRetrieve " + cache.toString());
    cache.reset();
  }
View Full Code Here

  private static Logger logger=LoggerFactory.getLogger(BasicProtostuffSingleThreadedTest.class);
 
  @Test public void goOverTheLimitWithProtostuff() {
    int limit = 10;
    CacheStore store = new CacheStore(limit, 1 * 1024 * 1024, 1);
    store.serializer = new ProtoStuffSerializer();
    for (int i = 1; i <= limit * 2; i++) {
      DummyPojo pojo = new  DummyPojo("test" + 1, 1024);
      store.put("test" + i, pojo);
      if (i <= limit) {
        assertEquals(store.heapEntriesCount(), i);
      } else {
        assertEquals(limit, store.heapEntriesCount());
      }
      logger.debug("goOverTheLimit " + store);
    }
    CacheStore.displayTimings();
  }
View Full Code Here

  }
 
 
  @Test public void goOverTheLimitPutAndGetWithProtostuff() {
    int limit = 1000;
    CacheStore cache = new CacheStore(limit, 10 * 1024 * 1024, 1);
    cache.serializer = new ProtoStuffSerializer();
    for (int i = 1; i <= limit * 1.5; i++) {
      DummyPojo pojo = new  DummyPojo("test" + i, 1024);
      cache.put("test" + i, pojo);
      if (i <= limit) {
        assertEquals(cache.heapEntriesCount(), i);
      } else {
        assertEquals(limit, cache.heapEntriesCount());
      }
    }

    logger.debug("goOverTheLimitPutAndGet " + cache.toString());
   
    for (int i = 1; i <= limit * 1.5; i++) {
      @SuppressWarnings("unused")
      DummyPojo pojo = new  DummyPojo("test" + i, 1024);
      @SuppressWarnings("unused")
      DummyPojo newPojo = (DummyPojo)cache.get("test" + i);
    }
   
    assertEquals(limit, cache.heapEntriesCount());
//    assertEquals(518500, cache.usedMemory());
  }
View Full Code Here

    return 1024 + random.nextInt(1024);
  }
 
  @Test
  public void addAndRetrieve() {
    CacheStore cache = new CacheStore(1, CacheStore.MB(1), 1);
    cache.put("test1", new DummyPojo("test1", randomSize()));
    cache.put("test2", new DummyPojo("test2", randomSize()));
    cache.put("test3", new DummyPojo("test3", randomSize()));
    DummyPojo pojo1 = (DummyPojo)cache.get("test1");
    DummyPojo pojo2 = (DummyPojo)cache.get("test2");
    DummyPojo pojo3 = (DummyPojo)cache.get("test3");
    assertNotNull(pojo1);
    assertEquals("test1", pojo1.name);
    assertNotNull(pojo2);
    assertEquals("test2", pojo2.name);
    assertNotNull(pojo3);
    assertEquals("test3", pojo3.name);
    logger.debug("addAndRetrieve " + cache.toString());
    cache.reset();
  }
View Full Code Here

  }
 
 
  @Test public void goOverTheOffheapLimitPutAndGet() {
    int limit = 1000;
    CacheStore cache = new CacheStore(limit, CacheStore.MB(2), 1);
//    cache.serializer = new ProtoStuffSerializer();
    for (int i = 1; i <= limit * 2; i++) {
      DummyPojo pojo = new  DummyPojo("test" + i, randomSize());
      cache.put("test" + i, pojo);
      if (i <= limit) {
        assertEquals(i, cache.heapEntriesCount());
      } else {
        assertEquals(limit, cache.heapEntriesCount());
      }
    }

    logger.debug("goOverTheLimitPutAndGet " + cache.toString());
   
    for (int i = 1; i <= limit * 2; i++) {
      String key = "test" + i;
      DummyPojo newPojo = (DummyPojo)cache.get(key);
      assertNotNull(newPojo);
      assertEquals("test"+i, newPojo.name);
    }
    logger.debug("finally " + cache.toString());
    cache.reset();
 
View Full Code Here

 

 
  @Test
  public void removeLast() {
    CacheStore cache = new CacheStore(-1, 1 * 1024 * 1024, 1);
    cache.put("test1", new DummyPojo("test1", 1024));
    cache.put("test2", new DummyPojo("test2", 1024));
    cache.put("test3", new DummyPojo("test3", 1024));
    cache.put("test4", new DummyPojo("test4", 1024));
    cache.put("test5", new DummyPojo("test5", 1024));
    CacheEntry last = cache.removeLast();
    // should be the first one inserted
    assertEquals("test1", last.key);
    cache.get("test2");
    // accessing an element should put it back at the beginning of the list
    last = cache.removeLast();
    // so the last should be now test3
    assertEquals("test3", last.key);
    cache.reset();
  }
View Full Code Here

    cache.reset();
  }
 
  @Test
  public void remove() {
    CacheStore cache = new CacheStore(-1, 1 * 1024 * 1024, 1);
    cache.put("test1", new DummyPojo("test1", 1024));
    CacheEntry entry = cache.remove("test1");
    assertEquals("test1", entry.key);
    entry = cache.getEntry("test1");
    assertNull(entry);
    cache.reset();
  }
View Full Code Here

    cache.reset();
  }
 
  @Test public void reachLimit() {
    int limit = 10;
    CacheStore cache = new CacheStore(limit, 1 * 1024 * 1024, 1);
   
    for (int i = 1; i <= limit; i++) {
      cache.put("test" + i, new DummyPojo("test" + 1, 1024));
      if (i < limit) {
        assert(limit >= cache.heapEntriesCount());
      }
      logger.debug("reachLimit " + cache);
    }
    cache.reset();
  }
View Full Code Here

    cache.reset();
  }
 
  @Test public void goOverTheLimit() {
    int limit = 10;
    CacheStore cache = new CacheStore(limit, 1 * 1024 * 1024, 1);
    for (int i = 1; i <= limit * 2; i++) {
      DummyPojo pojo = new  DummyPojo("test" + i, 1024);
      cache.put("test" + i, pojo);
      if (i <= limit ) {
        assertEquals(i, cache.heapEntriesCount());
      } else {
        assertEquals(limit, cache.heapEntriesCount());
      }
      logger.debug("goOverTheLimit " + cache);
    }
    cache.reset();   
  }
View Full Code Here

TOP

Related Classes of org.directmemory.CacheStore

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.