use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplSizeLimitTest method verifyCached.
private void verifyCached(IMap<String, ReliableResource> cacheMap, String rrKey, String rrFileName) {
ReliableResource rrFromCache = (ReliableResource) cacheMap.get(rrKey);
assertNotNull(rrFromCache);
File rrCachedFile = new File(productCacheDir + File.separator + rrFileName);
assertTrue(new File(rrCachedFile.getAbsolutePath()).exists());
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplSizeLimitTest method verifyRemovedFromCache.
private void verifyRemovedFromCache(IMap<String, ReliableResource> cacheMap, String rrKey, String rrFileName) {
ReliableResource rrFromCache = (ReliableResource) cacheMap.get(rrKey);
assertNull(rrFromCache);
File rrCachedFile = new File(productCacheDir + File.separator + rrFileName);
assertFalse(new File(rrCachedFile.getAbsolutePath()).exists());
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplSizeLimitTest method testCacheDirMaxSizePaging.
@Test
public void testCacheDirMaxSizePaging() throws IOException, InterruptedException {
HazelcastInstance instance = initializeTestHazelcastInstance();
listener.setHazelcastInstance(instance);
listener.setMaxDirSizeBytes(132);
IMap<String, ReliableResource> cacheMap = instance.getMap(PRODUCT_CACHE_NAME);
//Simulate adding product to product cache
//push 12 files into cache to total a size of 120 bytes
String rrKeyPrefix = "rr";
String rr1FileNameBase = "10bytes.txt";
for (int i = 0; i < 12; i++) {
simulateAddFileToProductCache(rrKeyPrefix + i, rr1FileNameBase, i + rr1FileNameBase, cacheMap);
}
//ensure all 12 10-byte files are cached
for (int i = 0; i < 12; i++) {
verifyCached(cacheMap, rrKeyPrefix + i, i + rr1FileNameBase);
}
//push 1 large file into cache to total 245 bytes. This file will be on the second "page" when querying the cache.
String oneTwentyFiveBytesFileName = "125bytes.txt";
int indexOf125Bytes = 12;
simulateAddFileToProductCache(rrKeyPrefix + indexOf125Bytes, oneTwentyFiveBytesFileName, oneTwentyFiveBytesFileName, cacheMap);
//ensure 125-byte file is cached
verifyCached(cacheMap, rrKeyPrefix + indexOf125Bytes, oneTwentyFiveBytesFileName);
//entries from 0-9 should be removed from cache
for (int i = 0; i < 12; i++) {
verifyRemovedFromCache(cacheMap, rrKeyPrefix + i, i + rr1FileNameBase);
}
verifyCached(cacheMap, rrKeyPrefix + indexOf125Bytes, oneTwentyFiveBytesFileName);
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplTest method testContainsNullLatestMetacard.
@Test(expected = IllegalArgumentException.class)
public void testContainsNullLatestMetacard() throws URISyntaxException {
MetacardImpl cachedMetacard = generateMetacard();
String cacheKey = "cacheKey1";
resourceCache.put(new ReliableResource(cacheKey, "", null, "name", cachedMetacard));
assertFalse(resourceCache.containsValid("cacheKey1", null));
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ReliableResourceDownloadManagerTest method testDownloadWithCachingDifferentChunkSizes.
/**
* Verifies that if client is reading from @ReliableResourceInputStream slower than {@link
* ReliableResourceCallable} is reading from product InputStream and writing to
* FileBackedOutputStream, that complete product is still successfully downloaded by the client.
* (This will be the case with CXF and @ReliableResourceCallable)
*
* @throws Exception
*/
@Test
public // @Ignore
void testDownloadWithCachingDifferentChunkSizes() 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);
int clientChunkSize = 2;
ByteArrayOutputStream clientBytesRead = clientRead(clientChunkSize, 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