use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplSizeLimitTest method testExceedCacheDirMaxSize.
@Test
public //@Ignore
void testExceedCacheDirMaxSize() throws IOException, InterruptedException {
HazelcastInstance instance = initializeTestHazelcastInstance();
listener.setMaxDirSizeBytes(15);
listener.setHazelcastInstance(instance);
IMap<String, ReliableResource> cacheMap = instance.getMap(PRODUCT_CACHE_NAME);
// Simulate adding product to product cache
String rr1Key = "rr1";
String rr1FileName = "10bytes.txt";
simulateAddFileToProductCache(rr1Key, rr1FileName, rr1FileName, //this may take longer to execute than just the next line.
cacheMap);
// ensure that the entry has not been removed from the cache since it doesn't exceed the max size
verifyCached(cacheMap, rr1Key, rr1FileName);
// simulate adding additional product to cache
String rr2Key = "rr2";
String rr2FileName = "15bytes.txt";
simulateAddFileToProductCache(rr2Key, rr2FileName, rr2FileName, cacheMap);
verifyRemovedFromCache(cacheMap, rr1Key, rr1FileName);
verifyCached(cacheMap, rr2Key, rr2FileName);
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplSizeLimitTest method testNotExceedCacheDirMaxSize.
@Test
public //@Ignore
void testNotExceedCacheDirMaxSize() throws IOException, InterruptedException {
HazelcastInstance instance = initializeTestHazelcastInstance();
listener.setMaxDirSizeBytes(50);
listener.setHazelcastInstance(instance);
IMap<String, ReliableResource> cacheMap = instance.getMap(PRODUCT_CACHE_NAME);
//Simulate adding product to product cache
String rr1Key = "rr1";
String rr1FileName = "10bytes.txt";
simulateAddFileToProductCache(rr1Key, rr1FileName, rr1FileName, cacheMap);
//simulate adding additional product to cache
String rr2Key = "rr2";
String rr2FileName = "15bytes.txt";
simulateAddFileToProductCache(rr2Key, rr2FileName, rr2FileName, cacheMap);
//simulate adding additional product to cache
String rr3Key = "rr3";
String rr3FileName = "15bytes_B.txt";
simulateAddFileToProductCache(rr3Key, rr3FileName, rr3FileName, cacheMap);
verifyCached(cacheMap, rr1Key, rr1FileName);
verifyCached(cacheMap, rr2Key, rr2FileName);
verifyCached(cacheMap, rr3Key, rr3FileName);
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplSizeLimitTest method simulateAddFileToProductCache.
private ReliableResource simulateAddFileToProductCache(String key, String fileName, String destFileName, IMap<String, ReliableResource> cacheMap) throws IOException {
String productOriginalLocation = new File(this.getClass().getClassLoader().getResource(fileName).getPath()).getAbsolutePath();
File rrCachedFile = new File(productCacheDir + "/" + destFileName);
FileUtils.copyFile(new File(productOriginalLocation), rrCachedFile);
ReliableResource rr = new ReliableResource(key, rrCachedFile.getAbsolutePath(), new MimeType(), fileName, new MetacardImpl());
rr.setSize(rrCachedFile.length());
LOGGER.debug("adding entry to cache: {}", key);
cacheMap.put(key, rr);
listener.entryAdded(new EntryEvent<Object, Object>(destFileName, null, EntryEventType.ADDED.getType(), key, rr));
return rr;
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplSizeLimitTest method testSingleFileExceedCacheDirMaxSize.
@Test
public void testSingleFileExceedCacheDirMaxSize() throws IOException, InterruptedException {
HazelcastInstance instance = initializeTestHazelcastInstance();
IMap<String, ReliableResource> cacheMap = instance.getMap(PRODUCT_CACHE_NAME);
listener.setMaxDirSizeBytes(5);
listener.setHazelcastInstance(instance);
//Simulate adding product to product cache
String rr1Key = "rr1";
String rr1FileName = "10bytes.txt";
simulateAddFileToProductCache(rr1Key, rr1FileName, rr1FileName, cacheMap);
verifyRemovedFromCache(cacheMap, rr1Key, rr1FileName);
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ReliableResourceDownloadManagerTest method testDownloadWithCaching.
@Test
public // @Ignore
void testDownloadWithCaching() throws Exception {
mis = new MockInputStream(productInputFilename);
Metacard metacard = getMockMetacard(EXPECTED_METACARD_ID, EXPECTED_METACARD_SOURCE_ID);
resourceResponse = getMockResourceResponse();
ResourceRetriever retriever = mock(ResourceRetriever.class);
when(retriever.retrieveResource()).thenReturn(resourceResponse);
CacheKey cacheKey = new CacheKey(metacard, resourceResponse.getRequest());
String key = cacheKey.generateKey();
when(resourceCache.isPending(key)).thenReturn(false);
int chunkSize = 50;
startDownload(true, chunkSize, false, metacard, retriever);
ByteArrayOutputStream clientBytesRead = clientRead(chunkSize, productInputStream);
// Captures the ReliableResource object that should have been put in the ResourceCacheImpl's map
ArgumentCaptor<ReliableResource> argument = ArgumentCaptor.forClass(ReliableResource.class);
verify(resourceCache).put(argument.capture());
verifyCaching(argument.getValue(), EXPECTED_CACHE_KEY);
verifyClientBytesRead(clientBytesRead);
cleanup();
}
Aggregations