use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ReliableResourceDownloadManagerTest method testStoreWithTimeoutExceptionCachingEnabled.
/**
* Test storing product in cache and one of the chunks being stored takes too long, triggering the
* CacheMonitor to interrupt the caching. Verify that caching is retried and successfully
* completes on the second attempt.
*
* @throws Exception
*/
@Test
public // @Ignore
void testStoreWithTimeoutExceptionCachingEnabled() throws Exception {
mis = new MockInputStream(productInputFilename);
Metacard metacard = getMockMetacard(EXPECTED_METACARD_ID, EXPECTED_METACARD_SOURCE_ID);
resourceResponse = getMockResourceResponse();
ResourceRetriever retriever = getMockResourceRetrieverWithRetryCapability(RetryType.TIMEOUT_EXCEPTION);
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();
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class MetacardResourceSizePluginTest method testMetacardResourceSizePopulatedAndHasProduct.
@Test
public void testMetacardResourceSizePopulatedAndHasProduct() throws Exception {
ResourceCacheInterface cache = mock(ResourceCacheInterface.class);
ReliableResource cachedResource = mock(ReliableResource.class);
when(cachedResource.getSize()).thenReturn(999L);
when(cachedResource.hasProduct()).thenReturn(true);
when(cache.getValid(anyString(), any())).thenReturn(cachedResource);
MetacardImpl metacard = new MetacardImpl();
metacard.setId("abc123");
metacard.setSourceId("ddf-1");
metacard.setResourceSize("N/A");
Result result = new ResultImpl(metacard);
List<Result> results = new ArrayList<Result>();
results.add(result);
QueryResponse input = mock(QueryResponse.class);
when(input.getResults()).thenReturn(results);
MetacardResourceSizePlugin plugin = new MetacardResourceSizePlugin(cache);
QueryResponse queryResponse = plugin.process(input);
assertThat(queryResponse.getResults().size(), is(1));
Metacard resultMetacard = queryResponse.getResults().get(0).getMetacard();
assertThat(metacard, is(notNullValue()));
// Since using Metacard vs. MetacardImpl have to get resource-size as an
// Attribute vs. Long
Attribute resourceSizeAttr = resultMetacard.getAttribute(Metacard.RESOURCE_SIZE);
assertThat((String) resourceSizeAttr.getValue(), is("999"));
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class MetacardResourceSizePluginTest method testMetacardResourceSizePopulatedButNoProduct.
/**
* Verifies case where product has been cached previously but has since been deleted from the
* product-cache directory, so there is still an entry in the cache map but no cache file on disk.
*
* @throws Exception
*/
@Test
public void testMetacardResourceSizePopulatedButNoProduct() throws Exception {
ResourceCacheInterface cache = mock(ResourceCacheInterface.class);
ReliableResource cachedResource = mock(ReliableResource.class);
when(cachedResource.getSize()).thenReturn(999L);
when(cachedResource.hasProduct()).thenReturn(false);
when(cache.getValid(anyString(), any())).thenReturn(cachedResource);
MetacardImpl metacard = new MetacardImpl();
metacard.setId("abc123");
metacard.setSourceId("ddf-1");
metacard.setResourceSize("N/A");
Result result = new ResultImpl(metacard);
List<Result> results = new ArrayList<Result>();
results.add(result);
QueryResponse input = mock(QueryResponse.class);
when(input.getResults()).thenReturn(results);
MetacardResourceSizePlugin plugin = new MetacardResourceSizePlugin(cache);
QueryResponse queryResponse = plugin.process(input);
assertThat(queryResponse.getResults().size(), is(1));
Metacard resultMetacard = queryResponse.getResults().get(0).getMetacard();
assertThat(metacard, is(notNullValue()));
// Since using Metacard vs. MetacardImpl have to get resource-size as an
// Attribute vs. String
Attribute resourceSizeAttr = resultMetacard.getAttribute(Metacard.RESOURCE_SIZE);
assertThat((String) resourceSizeAttr.getValue(), equalTo("N/A"));
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplTest method getDefaultResourceInCache.
@Test
public void getDefaultResourceInCache() {
ReliableResource cachedResource = createCachedResource(cachedMetacard);
resourceCache.put(cachedResource);
Optional<Resource> optionalResource = newResourceCache.get(cachedMetacard);
assertFalse("cache should be noop", optionalResource.isPresent());
}
use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.
the class ResourceCacheImplTest method testValidationNotEqual.
@Test
public void testValidationNotEqual() throws URISyntaxException, IOException {
MetacardImpl metacard = generateMetacard();
MetacardImpl metacard1 = generateMetacard();
metacard1.setId("differentId");
String fileName = "10bytes.txt";
simulateAddFileToCacheDir(fileName);
String cachedResourceMetacardKey = "keyA1";
Path cachedResourceFilePath = Paths.get(defaultProductCacheDirectory.toString(), fileName);
File cachedResourceFile = cachedResourceFilePath.toFile();
assertTrue(cachedResourceFile.exists());
ReliableResource cachedResource = new ReliableResource(cachedResourceMetacardKey, cachedResourceFilePath.toString(), null, null, metacard);
resourceCache.validateCacheEntry(cachedResource, metacard1);
assertTrue("cache should be noop", cachedResourceFile.exists());
}
Aggregations