Inventory { public boolean contains(long record) { long stamp = lock.tryOptimisticRead(); boolean result = bitSet.get(record); if(lock.validate(stamp)) { return result; } else { stamp = lock.readLock(); try { return bitSet.get(record); } finally { lock.unlockRead(stamp); } } } private  Inventory(String backingStore); static Inventory create(String backingStore); void add(long record); boolean contains(long record); Set<Long> getAll(); void sync();  }
@Test public void testContains() { int count = TestData.getScaleCount() * TestData.getScaleCount(); Set<Long> longs = Sets.newHashSet(); while (longs.size() < count) { longs.add(TestData.getLong()); } for (long l : longs) { Assert.assertFalse(inventory.contains(l)); inventory.add(l); Assert.assertTrue(inventory.contains(l)); } }