public void checkCHKPresentWithClose(int persistenceTime) throws IOException, CHKEncodeException, CHKVerifyException, CHKDecodeException {
ResizablePersistentIntBuffer.setPersistenceTime(persistenceTime);
File f = new File(tempDir, "saltstore");
FileUtil.removeAll(f);
CHKStore store = new CHKStore();
SaltedHashFreenetStore<CHKBlock> saltStore = SaltedHashFreenetStore.construct(f, "testCachingFreenetStoreCHK", store, weakPRNG, STORE_SIZE, true, SemiOrderedShutdownHook.get(), true, true, ticker, null);
saltStore.start(null, true);
int falsePositives = 0;
for(int i=0;i<TEST_COUNT;i++) {
String test = "test" + i;
ClientCHKBlock block = encodeBlockCHK(test);
ClientCHK key = block.getClientKey();
byte[] routingKey = key.getRoutingKey();
if(saltStore.probablyInStore(routingKey))
falsePositives++;
store.put(block.getBlock(), false);
assertTrue(saltStore.probablyInStore(routingKey));
CHKBlock verify = store.fetch(key.getNodeCHK(), false, false, null);
String data = decodeBlockCHK(verify, key);
assertEquals(test, data);
}
assertTrue(falsePositives <= ACCEPTABLE_FALSE_POSITIVES);
saltStore.close();
store = new CHKStore();
saltStore = SaltedHashFreenetStore.construct(f, "testCachingFreenetStoreCHK", store, weakPRNG, STORE_SIZE, true, SemiOrderedShutdownHook.get(), true, true, ticker, null);
saltStore.start(null, true);
for(int i=0;i<TEST_COUNT;i++) {
String test = "test" + i;
ClientCHKBlock block = encodeBlockCHK(test);
ClientCHK key = block.getClientKey();
byte[] routingKey = key.getRoutingKey();
assertTrue(saltStore.probablyInStore(routingKey));
CHKBlock verify = store.fetch(key.getNodeCHK(), false, false, null);
String data = decodeBlockCHK(verify, key);
assertEquals(test, data);
}
saltStore.close();