@@ -0,0 +1,2413 @@
+// Copyright (c) 2012 Microsoft Corporation.  All rights reserved.%0Apackage tlc2.tool.fp;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0Aimport java.nio.file.FileSystems;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Path;%0Aimport java.util.Random;%0A%0Aimport util.TLCRuntime;%0A%0Apublic class RecoveredOffHeapDiskFPSetTest extends AbstractFPSetTest %7B%0A%0A%09private static final String javaUserDir = System.getProperty(RecoveredOffHeapDiskFPSetTest.class.getName() + %22.chkpt%22,%0A%09%09%09System.getProperty(%22user.home%22));%0A%09%0A%09/* (non-Javadoc)%0A%09 * @see tlc2.tool.fp.AbstractFPSetTest#getFPSet(long)%0A%09 */%0A%09@Override%0A%09protected FPSet getFPSet(long freeMemoryInBytes) throws IOException %7B%0A%09%09long freeMemoryInFPs = TLCRuntime.getInstance().getNonHeapPhysicalMemory() / (long) FPSet.LongSize;%0A%09%09return new OffHeapDiskFPSet(freeMemoryInFPs);%0A%09%7D%0A%0A%09/* (non-Javadoc)%0A%09 * @see tlc2.tool.fp.AbstractFPSetTest#getFPSetInitialized(int)%0A%09 */%0A%09@Override%0A%09protected FPSet getFPSetInitialized(int numThreads) throws IOException %7B%0A%09%09final DiskFPSet set = (DiskFPSet) super.getFPSetInitialized(numThreads);%0A%09%09%0A%09%09// Create a new FPSet and recover the .fp file that has been generated%0A%09%09// by the same Java random (seed). This implies, that contains() should%0A%09%09// return true for all fingerprints in the set. Ideally, we would know%0A%09%09// the number of fingerprints in .fp.%0A%09%09%0A%09%09final String fname = %22TestFPSet%22;%0A%09%09%0A%09%09// Create symbolic link to (archived) .chkpt file. One has to create a%0A%09%09// chkpt file manually by e.g. running testMaxFPSetSizeRnd once. It is%0A%09%09// important that the chkpt file and this test use the same seed for the%0A%09%09// RNG though.%0A%09%09//TODO automagically create the chkpt file or upload to some cloud storage%0A%09%09final Path link = FileSystems.getDefault().getPath(tmpdir + File.separator + fname + %22.fp.chkpt%22);%0A%09%09final Path target = FileSystems.getDefault().getPath(javaUserDir + File.separator + fname + %22.fp.chkpt%22);%0A%09%09Files.createSymbolicLink(link, target);%0A%09%09%0A%09%09// diskfpset prepends .fp.chkpt%0A%09%09set.recover(fname);%0A%09%09%0A%09%09return set;%0A%09%7D%0A%09%0A%09/**%0A%09 * Test is all fingerprints are duplicates. This is the case if the .chkpt file has been created with the same seed.%0A%09 */%0A%09public void testAllDuplicates() throws IOException %7B%0A%09%09final Random rnd = new Random(RNG_SEED);%0A%09%09final FPSet fpSet = getFPSetInitialized();%0A%09%09%0A%09%09for (int i = 0; i %3C fpSet.size(); i++) %7B%0A%09%09%09long fp = rnd.nextLong();%0A%09%09%09assertTrue(fpSet.contains(fp));%0A%09%09%7D%0A%09%7D%0A%7D%0A

Add tests that checks if a DiskFPSet correctly recovers from a chkpt.