/** * @param cnt Count. */ private void checkOffer(int cnt) { init(); for (int i = 0; i < cnt; i++) lru.offer(0, i, i); assertEquals(cnt, lru.size()); info("Finished check offer for stripes count: " + stripes); }
/** * @throws Exception If failed. */ @Test public void testLruMultithreaded() throws Exception { checkLruMultithreaded(1000000); }
/** * */ @Test public void testOffer2() { stripes = 11; checkOffer(1000); }
/** * @param cnt Count. */ private void checkRemove(int cnt) { init(); Collection<Long> set = new HashSet<>(cnt); for (int i = 0; i < cnt; i++) assertTrue(set.add(lru.offer(0, i, i))); assertEquals(cnt, lru.size()); for (long addr : set) lru.remove(addr); assertEquals(0, lru.size()); }
init(); multithreaded(new Runnable() { @Override public void run() { int id = idGen.getAndIncrement(); assertEquals(0, lru.size());
/** * */ @Test public void testPoll1() { checkPoll(1000); }
/** * */ @Test public void testRemove2() { stripes = 35; checkRemove(1000); }
/** * @param cnt Count. */ private void checkPoll(int cnt) { init(); int step = 10; assert cnt % step == 0; Collection<Long> set = new HashSet<>(step); for (int i = 0; i < cnt; i++) lru.offer(0, i, i); assertEquals(cnt, lru.size()); for (int i = 0; i < cnt; i += step) { for (int j = 0; j < step; j++) { long qAddr = lru.prePoll(); assertTrue(qAddr != 0); assertTrue(set.add(qAddr)); } for (long qAddr : set) lru.poll(qAddr); set.clear(); } assertEquals(0, lru.size()); }
/** * */ @Test public void testPoll2() { stripes = 20; checkPoll(1000); }
/** * */ @Test public void testRemove1() { checkRemove(1000); }
/** * */ @Test public void testOffer1() { checkOffer(1000); }