Exemplo n.º 1
0
  /** Multi-thread read-write test. */
  @Test
  public void testReadWriteThreadsSurya() throws Exception {
    Assume.assumeThat(JvmInformation.isJRockit(), is(false));

    long start = System.currentTimeMillis();
    final List executables = new ArrayList();
    final Random random = new Random();

    // 50% of the time get data
    for (int i = 0; i < 10; i++) {
      final Executable executable =
          new Executable() {
            public void execute() throws Exception {
              store.get("key" + random.nextInt(10000));
            }
          };
      executables.add(executable);
    }

    // 25% of the time add data
    for (int i = 0; i < 5; i++) {
      final Executable executable =
          new Executable() {
            public void execute() throws Exception {
              store.put(new Element("key" + random.nextInt(20000), "value"));
            }
          };
      executables.add(executable);
    }

    // 25% if the time remove the data
    for (int i = 0; i < 5; i++) {
      final Executable executable =
          new Executable() {
            public void execute() throws Exception {
              store.remove("key" + random.nextInt(10000));
            }
          };
      executables.add(executable);
    }

    runThreads(executables);
    long end = System.currentTimeMillis();
    LOG.info("Total time for the test: " + (end + start) + " ms");
    tearDown();
    System.gc();
    System.gc();
    Thread.sleep(1000);
    System.gc();
    System.gc();
  }
Exemplo n.º 2
0
 /** Test that the memory store can fit 65k elements in a 64Mb heap. */
 @Test
 public void testMemoryStoreOutOfMemoryLimit() throws Exception {
   Assume.assumeThat(JvmInformation.isJRockit(), is(false));
   LOG.info("Starting out of memory limit test");
   // Set size so the second element overflows to disk.
   cache = manager.getCache("memoryLimitTest");
   if (cache == null) {
     cache = new Cache(new CacheConfiguration("memoryLimitTest", 0));
     manager.addCache(cache);
   }
   for (int i = 0; i < 65000; i++) {
     cache.put(new Element(Integer.valueOf(i), new String(new char[218])));
   }
   assertEquals(65000, cache.getSize());
 }