Package org.directmemory.misc

Examples of org.directmemory.misc.DummyPojo


 
  @BenchmarkOptions(benchmarkRounds = 50000, warmupRounds=0, concurrency=1)
  @Test
  public void basicBench() {
   
    DummyPojo d = new DummyPojo("test-" + rnd.nextInt(100000), 1024 + rnd.nextInt(1024));
    Cache.put(d.name, d);
    DummyPojo d2 = (DummyPojo) Cache.retrieve(d.name);
   
    assertEquals(d.name, d2.name);

  }
View Full Code Here


  private static Logger logger=LoggerFactory.getLogger(SerializerTest.class);
  private void testSerializer(String name, Serializer serializer, int size, int howMany) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
    logger.info("begin " + serializer.getClass().toString());
        Monitor stopWatch = Monitor.get("serializer." + name + "." + size + "bytes");
        Monitor stopWatch2 = Monitor.get("deserializer." + name + "." + size + "bytes");
    DummyPojo pojo = new DummyPojo("test", size);
    for (int i = 0; i < howMany; i++) {
          long split = stopWatch.start();
      final byte[] array = serializer.serialize(pojo, pojo.getClass());
      stopWatch.stop(split);
      long split2 = stopWatch2.start();
      DummyPojo check = (DummyPojo) serializer.deserialize(array, pojo.getClass());
      stopWatch2.stop(split2);
      assertNotNull("object has not been serialized", check);
      assertEquals(pojo.name, check.name);
    }
    logger.info("end serialize " + serializer.getClass().toString() + "\r\n" + stopWatch.toString());
View Full Code Here

        public void run() {
          int i = 0;
          try {
            int numOps = 100;
            while (++i < numOps) {
              DummyPojo pojo = new DummyPojo(getName() + "-" + i, 1024);
              cache.put(pojo.name, pojo);
//              DummyPojo otherPojo = (DummyPojo)cache.get(getName() + "-" + i);
//              if (otherPojo == null)
//                System.out.println("errore");;
              int pause = 10;
View Full Code Here

        public void run() {
          int i = 0;
          try {
            int numOps = 100;
            while (++i < numOps) {
              @SuppressWarnings("unused")
              DummyPojo pojo = (DummyPojo)cache.get(getName() + "-" + i);
              int pause = 10;
              sleep(pause);
              }
          } catch (InterruptedException ex) {
View Full Code Here

  }
 
  @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);
View Full Code Here

  @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());
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

  }
 
  @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);
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
View Full Code Here

TOP

Related Classes of org.directmemory.misc.DummyPojo

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.