Exemple #1
0
  @Test
  public void testEvictionSpeedTestPerPartition() {
    final int k = 2;
    final int size = 100;
    final CountDownLatch latch = new CountDownLatch(k);
    final String mapName = "testEvictionSpeedTestPerPartition";
    Config cfg = new Config();
    final MapConfig mc = cfg.getMapConfig(mapName);
    mc.setEvictionPolicy(MapConfig.EvictionPolicy.LRU);
    mc.setEvictionPercentage(25);
    final MaxSizeConfig msc = new MaxSizeConfig();
    msc.setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.PER_PARTITION);
    msc.setSize(size);
    mc.setMaxSizeConfig(msc);

    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(k);
    final HazelcastInstance[] instances = factory.newInstances(cfg);
    final int pnum = instances[0].getPartitionService().getPartitions().size();
    final AtomicInteger failCount = new AtomicInteger(0);

    new Thread() {
      final IMap map = instances[0].getMap(mapName);

      public void run() {
        try {
          Thread.sleep(1000);
          while (latch.getCount() != 0) {
            try {
              int msize = map.size();
              if (msize > (size * pnum * 1.2)) {
                failCount.incrementAndGet();
              }
              Thread.sleep(1000);
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
          }
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }.start();

    for (int i = 0; i < k; i++) {
      final IMap map = instances[i].getMap(mapName);
      new Thread() {
        public void run() {
          for (int j = 0; j < 100000; j++) {
            map.put(k + "-" + j, j);
          }
          latch.countDown();
        }
      }.start();
    }

    try {
      Assert.assertEquals(latch.await(10, TimeUnit.MINUTES), true);
      Assert.assertEquals(0, failCount.get());
    } catch (InterruptedException e) {
      e.printStackTrace();
      Assert.fail(e.getMessage());
    }
  }
Exemple #2
0
  // current eviction check period is 1 second.
  // about 30.000 records can be put in one second
  // so the size should be adapted
  @Test
  public void testEvictionSpeedTest() {
    final int k = 3;
    final int size = 10000;
    final CountDownLatch latch = new CountDownLatch(k);
    final String mapName = "testEvictionSpeedTest";
    Config cfg = new Config();
    final MapConfig mc = cfg.getMapConfig(mapName);
    mc.setEvictionPolicy(MapConfig.EvictionPolicy.LRU);
    mc.setEvictionPercentage(25);
    final MaxSizeConfig msc = new MaxSizeConfig();
    msc.setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.PER_NODE);
    msc.setSize(size);
    mc.setMaxSizeConfig(msc);

    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(k);
    final HazelcastInstance[] instances = factory.newInstances(cfg);
    final AtomicBoolean success = new AtomicBoolean(true);

    new Thread() {
      final IMap map = instances[0].getMap(mapName);

      public void run() {
        try {
          Thread.sleep(1000);
          while (latch.getCount() != 0) {
            try {
              int msize = map.size();
              if (msize > (size * k + size * k * 10 / 100)) {
                success.set(false);
                break;
              }
              Thread.sleep(1000);
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
          }
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }.start();

    for (int i = 0; i < k; i++) {
      final IMap map = instances[i].getMap(mapName);
      new Thread() {
        public void run() {
          for (int j = 0; j < size; j++) {
            map.put(k + "-" + j, j);
          }
          latch.countDown();
        }
      }.start();
    }

    try {
      Assert.assertTrue(latch.await(10, TimeUnit.MINUTES));
      Assert.assertTrue(success.get());
    } catch (InterruptedException e) {
      e.printStackTrace();
      Assert.fail(e.getMessage());
    }
  }