public static void verifyDirectoryStructure(Cache cache, String indexName) {
verifyDirectoryStructure(cache, indexName, false);
}
public static void verifyDirectoryStructure(Cache cache, String indexName, boolean wasAStressTest) {
FileListCacheValue fileList = (FileListCacheValue) cache.get(new FileListCacheKey(indexName));
AssertJUnit.assertNotNull(fileList);
int fileListCacheKeyInstances = 0;
for (Object key : cache.keySet()) {
if (key instanceof ChunkCacheKey) {
ChunkCacheKey existingChunkKey = (ChunkCacheKey) key;
String filename = existingChunkKey.getFileName();
AssertJUnit.assertEquals(existingChunkKey.getIndexName(), indexName);
// the chunk must either match an entry in fileList or have a pending readLock:
// if (fileList.contains(filename) == false) {
// verifyReadlockExists(cache, indexName, filename);
// }
Object value = cache.get(existingChunkKey);
AssertJUnit.assertNotNull(value);
AssertJUnit.assertTrue(value instanceof byte[]);
byte[] buffer = (byte[]) cache.get(existingChunkKey);
AssertJUnit.assertTrue(buffer.length != 0);
} else if (key instanceof FileCacheKey) {
FileCacheKey fileCacheKey = (FileCacheKey) key;
AssertJUnit.assertEquals(fileCacheKey.getIndexName(), indexName);
String filename = fileCacheKey.getFileName();
// if (fileList.contains(filename) == false) {
// // if the file is not registered, assert that a readlock prevented it from being
// // deleted:
// verifyReadlockExists(cache, indexName, filename);
// }
Object value = cache.get(fileCacheKey);
AssertJUnit.assertNotNull(value);
AssertJUnit.assertTrue(value instanceof FileMetadata);
FileMetadata metadata = (FileMetadata) value;
long totalFileSize = metadata.getSize();
long actualFileSize = deepCountFileSize(fileCacheKey, cache);
AssertJUnit.assertEquals(actualFileSize, totalFileSize);
AssertJUnit.assertTrue(fileCacheKey + " should not have existed", fileList.contains(fileCacheKey.getFileName()));
} else if (key instanceof FileListCacheKey) {
fileListCacheKeyInstances++;
AssertJUnit.assertEquals(1, fileListCacheKeyInstances);
} else if (key instanceof FileReadLockKey) {
/*//FIXME testcase to be fixed after ISPN-616