final List<String> keys = new ArrayList<String>(NUM_KEYS);
for (int j = 0; j < NUM_KEYS; j++) {
String key = "key" + j;
String value = key + "_value_" + j;
keys.add(key);
MarshalledEntryImpl entry = new MarshalledEntryImpl<String, String>(key, value, null, marshaller);
store.write(entry);
}
// Do some reading/writing entries with random size
final CountDownLatch stopLatch = new CountDownLatch(1);
Future[] writeFutures = new Future[NUM_WRITER_THREADS];
for (int i = 0; i < NUM_WRITER_THREADS; i++) {
writeFutures[i] = fork(stopOnException(new WriteTask(store, marshaller, keys, stopLatch), stopLatch));
}
Future[] readFutures = new Future[NUM_READER_THREADS];
for (int i = 0; i < NUM_READER_THREADS; i++) {
readFutures[i] = fork(stopOnException(new ReadTask(store, keys, false, stopLatch), stopLatch));
}
stopLatch.await(TEST_DURATION_SECONDS, SECONDS);
stopLatch.countDown();
for (int i = 0; i < NUM_WRITER_THREADS; i++) {
writeFutures[i].get();
}
for (int i = 0; i < NUM_READER_THREADS; i++) {
readFutures[i].get();
}
File file = new File(location, CACHE_NAME + ".dat");
long length1 = file.length();
ExecutorService executor = Executors.newSingleThreadExecutor();
store.purge(executor, null);
// Give some time for the purge thread to finish
MILLISECONDS.sleep(200);
long length2 = file.length();
// Again write entries with smaller size
for (int j = 0; j < NUM_KEYS; j++) {
String key = "key" + j;
String value = key + "_value_" + j;
keys.add(key);
MarshalledEntryImpl entry = new MarshalledEntryImpl<String, String>(key, value, null, marshaller);
store.write(entry);
}
store.purge(executor, null);
// Give some time for the purge thread to finish