use of ddf.catalog.resourceretriever.ResourceRetriever in project ddf by codice.
the class ReliableResourceDownloadManagerTest method testDownloadWithNullMetacard.
@Test(expected = DownloadException.class)
public void testDownloadWithNullMetacard() throws Exception {
resourceRequest = mock(ResourceRequest.class);
ResourceRetriever retriever = mock(ResourceRetriever.class);
downloadMgr.download(resourceRequest, null, retriever);
}
use of ddf.catalog.resourceretriever.ResourceRetriever 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.resourceretriever.ResourceRetriever in project ddf by codice.
the class ReliableResourceDownloadManagerTest method testClientCancelProductDownloadCachingStops.
/**
* Tests that if user/client cancels a product retrieval that is in progress and
* actively being cached, and the admin has not configured caching to continue,
* that the (partially) cached file is deleted and not placed in the cache map.
*
* @throws Exception
*/
@Test
@Ignore
public void testClientCancelProductDownloadCachingStops() throws Exception {
mis = new MockInputStream(productInputFilename, true);
mis.setReadDelay(MONITOR_PERIOD - 2, TimeUnit.MILLISECONDS);
Metacard metacard = getMockMetacard(EXPECTED_METACARD_ID, EXPECTED_METACARD_SOURCE_ID);
resourceResponse = getMockResourceResponse();
// Need the product InputStream (MockInputStream) to read slower so that client has time to
// start reading from the ReliableResourceInputStream and close it, simulating a cancel of
// the product download
ResourceRetriever retriever = getMockResourceRetrieverWithRetryCapability(RetryType.CLIENT_CANCELS_DOWNLOAD, true);
int chunkSize = 50;
startDownload(true, chunkSize, false, metacard, retriever);
// On second read of ReliableResourceInputStream, client will close the stream simulating a cancel
// of the product download
clientRead(chunkSize, productInputStream, 2);
// Verify product was not cached, i.e., its pending caching entry was removed
String cacheKey = new CacheKey(metacard, resourceResponse.getRequest()).generateKey();
verify(resourceCache, timeout(3000)).removePendingCacheEntry(cacheKey);
cleanup();
}
use of ddf.catalog.resourceretriever.ResourceRetriever in project ddf by codice.
the class ReliableResourceDownloadManagerTest method testStreamToClientExceptionDuringProductDownloadCachingEnabled.
/**
* Tests that if exception with the FileBackedOutputStream being written to and concurrently read by the client occurs
* during a product retrieval, then the product download to the client is stopped, but the caching of the
* file continues.
*
* @throws Exception
*/
@Test
@Ignore
public // does not seem to detect this and continues to stream successfully to the client.
void testStreamToClientExceptionDuringProductDownloadCachingEnabled() throws Exception {
mis = new MockInputStream(productInputFilename);
Metacard metacard = getMockMetacard(EXPECTED_METACARD_ID, EXPECTED_METACARD_SOURCE_ID);
resourceResponse = getMockResourceResponse();
downloadMgr = new ReliableResourceDownloadManager(getDownloaderConfig(), downloadStatusInfo, Executors.newSingleThreadExecutor());
// Use small chunk size so download takes long enough for client
// to have time to simulate FileBackedOutputStream exception
int chunkSize = 2;
downloadMgr.setChunkSize(chunkSize);
ResourceRetriever retriever = mock(ResourceRetriever.class);
when(retriever.retrieveResource()).thenReturn(resourceResponse);
ArgumentCaptor<ReliableResource> argument = ArgumentCaptor.forClass(ReliableResource.class);
ResourceResponse newResourceResponse = downloadMgr.download(resourceRequest, metacard, retriever);
assertThat(newResourceResponse, is(notNullValue()));
productInputStream = newResourceResponse.getResource().getInputStream();
assertThat(productInputStream, is(instanceOf(ReliableResourceInputStream.class)));
// On second chunk read by client it will close the download manager's cache file output stream
// to simulate a cache file exception that should be detected by the ReliableResourceCallable
executor = Executors.newCachedThreadPool();
ProductDownloadClient productDownloadClient = new ProductDownloadClient(productInputStream, chunkSize);
productDownloadClient.setSimulateFbosException(chunkSize, downloadMgr);
future = executor.submit(productDownloadClient);
ByteArrayOutputStream clientBytesRead = future.get();
// Verify client did not receive entire product download
assertTrue(clientBytesRead.size() < expectedFileSize);
// Captures the ReliableResource object that should have been put in the ResourceCacheImpl's map
verify(resourceCache, timeout(3000)).put(argument.capture());
verifyCaching(argument.getValue(), EXPECTED_CACHE_KEY);
cleanup();
}
use of ddf.catalog.resourceretriever.ResourceRetriever in project ddf by codice.
the class ReliableResourceDownloadManagerTest method testRetryAttemptsExhaustedDuringProductDownload.
/**
* Tests that if network connection drops repeatedly during a product retrieval such that all
* of the retry attempts are used up before entire product is downloaded, then the (partially) cached file is deleted and not
* placed in the cache map, and product download fails.
*
* @throws Exception
*/
@Test
@Ignore
public void testRetryAttemptsExhaustedDuringProductDownload() throws Exception {
mis = new MockInputStream(productInputFilename);
Metacard metacard = getMockMetacard(EXPECTED_METACARD_ID, EXPECTED_METACARD_SOURCE_ID);
resourceResponse = getMockResourceResponse();
ResourceRetriever retriever = getMockResourceRetrieverWithRetryCapability(RetryType.NETWORK_CONNECTION_UP_AND_DOWN);
int chunkSize = 50;
startDownload(true, chunkSize, false, metacard, retriever);
ByteArrayOutputStream clientBytesRead = clientRead(chunkSize, productInputStream);
// Verify client did not receive entire product download
assertTrue(clientBytesRead.size() < expectedFileSize);
// Verify product was not cached, i.e., its pending caching entry was removed
String cacheKey = new CacheKey(metacard, resourceResponse.getRequest()).generateKey();
verify(resourceCache, timeout(3000)).removePendingCacheEntry(cacheKey);
cleanup();
}
Aggregations