/** * @param fileName * @return true if there is such a named file in this index */ public boolean fileExists(final String fileName) { readLock.lock(); try { return getFileList().contains(fileName); } finally { readLock.unlock(); } }
/** * @param fileName * @return true if there is such a named file in this index */ public boolean fileExists(final String fileName) { readLock.lock(); try { return getFileList().contains(fileName); } finally { readLock.unlock(); } }
public static void assertFileNotExists(Cache cache, String indexName, String fileName, long maxWaitForCondition, int affinitySegmentId) throws InterruptedException { FileListCacheValue fileList = (FileListCacheValue) cache.get(new FileListCacheKey(indexName, affinitySegmentId)); AssertJUnit.assertNotNull(fileList); AssertJUnit.assertFalse(fileList.contains(fileName)); //check is in sync: no waiting allowed in this case boolean allok = false; while (maxWaitForCondition >= 0 && !allok) { Thread.sleep(10); maxWaitForCondition -= 10; allok=true; FileMetadata metadata = (FileMetadata) cache.get(new FileCacheKey(indexName, fileName, affinitySegmentId)); if (metadata!=null) allok=false; for (int i = 0; i < 100; i++) { //bufferSize set to 0 as metadata might not be available, and it's not part of equals/hashcode anyway. ChunkCacheKey key = new ChunkCacheKey(indexName, fileName, i, 0, affinitySegmentId); if (cache.get(key)!=null) allok=false; } } assertTrue(allok); }
private void assertFileAfterDeletion(Cache cache) { FileListCacheValue fileList = (FileListCacheValue) cache.get(new FileListCacheKey(INDEX_NAME, -1)); AssertJUnit.assertNotNull(fileList); AssertJUnit.assertFalse(fileList.contains(filename)); FileMetadata metadata = (FileMetadata) cache.get(new FileCacheKey(INDEX_NAME, filename, -1)); AssertJUnit.assertNotNull(metadata); long totalFileSize = metadata.getSize(); int chunkNumbers = (int)(totalFileSize / CHUNK_SIZE); for(int i = 0; i < chunkNumbers; i++) { AssertJUnit.assertNotNull(cache.get(new ChunkCacheKey(INDEX_NAME, filename, i, CHUNK_SIZE, -1))); } boolean fileNameExistsInCache = false; for(Object key : cache.keySet()) { if(key instanceof FileCacheKey) { FileCacheKey keyObj = (FileCacheKey) key; if(keyObj.getFileName().contains(filename)) { fileNameExistsInCache = true; } } } AssertJUnit.assertTrue(fileNameExistsInCache); }
/** * Verified the file exists and has a specified value for readLock; * Consider that null should be interpreted as value 1; */ public static void assertFileExistsHavingRLCount(Cache cache, String fileName, String indexName, int expectedReadcount, int chunkSize, boolean expectRegisteredInFat, int affinitySegmentId) { FileListCacheValue fileList = (FileListCacheValue) cache.get(new FileListCacheKey(indexName,affinitySegmentId)); assertNotNull(fileList); assertTrue(fileList.contains(fileName) == expectRegisteredInFat); FileMetadata metadata = (FileMetadata) cache.get(new FileCacheKey(indexName, fileName, affinitySegmentId)); assertNotNull(metadata); long totalFileSize = metadata.getSize(); int chunkNumbers = (int)(totalFileSize / chunkSize); for (int i = 0; i < chunkNumbers; i++) { assertNotNull(cache.get(new ChunkCacheKey(indexName, fileName, i, metadata.getBufferSize(), affinitySegmentId))); } FileReadLockKey readLockKey = new FileReadLockKey(indexName,fileName, affinitySegmentId); Object value = cache.get(readLockKey); if (expectedReadcount <= 1) { assertTrue("readlock value is " + value, value == null || Integer.valueOf(1).equals(value)); } else { assertNotNull(value); assertTrue(value instanceof Integer); int v = (Integer)value; assertEquals(v, expectedReadcount); } }
assertEquals(actualFileSize, totalFileSize); if (!ignoreFiles.contains(fileCacheKey.getFileName())) { assertTrue(fileCacheKey + " should not have existed", fileList.contains(fileCacheKey.getFileName()));