use of ddf.catalog.resourceretriever.ResourceRetriever in project ddf by codice.
the class ReliableResourceDownloadManagerTest method testDownloadWithoutCaching.
@Test
public //@Ignore
void testDownloadWithoutCaching() 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);
int chunkSize = 50;
downloadMgr.setChunkSize(chunkSize);
ResourceResponse newResourceResponse = downloadMgr.download(resourceRequest, metacard, retriever);
assertThat(newResourceResponse, is(notNullValue()));
productInputStream = newResourceResponse.getResource().getInputStream();
assertThat(productInputStream, is(instanceOf(ReliableResourceInputStream.class)));
ByteArrayOutputStream clientBytesRead = clientRead(chunkSize, productInputStream);
verifyClientBytesRead(clientBytesRead);
cleanup();
}
use of ddf.catalog.resourceretriever.ResourceRetriever in project ddf by codice.
the class ReliableResourceDownloaderTest method testNullReliableResourceCallableAndStatus.
@Test
public void testNullReliableResourceCallableAndStatus() throws Exception {
ResourceResponse mockResponse = getMockResourceResponse(mockStream);
ResourceRetriever mockResourceRetriever = mock(ResourceRetriever.class);
when(mockResourceRetriever.retrieveResource(any(Byte.class))).thenReturn(mockResponse);
ReliableResourceStatus resourceStatus = new ReliableResourceStatus(DownloadStatus.RESOURCE_DOWNLOAD_INTERRUPTED, 0L);
ReliableResourceCallable mockCallable = mock(ReliableResourceCallable.class);
when(mockCallable.getReliableResourceStatus()).thenReturn(resourceStatus);
PowerMockito.whenNew(ReliableResourceCallable.class).withAnyArguments().thenReturn(null, mockCallable);
PowerMockito.whenNew(ResourceRetrievalMonitor.class).withAnyArguments().thenThrow(new CancellationException());
int retries = 5;
downloaderConfig.setMaxRetryAttempts(retries);
ReliableResourceDownloader downloader = new ReliableResourceDownloader(downloaderConfig, new AtomicBoolean(), DOWNLOAD_ID, mockResponse, mockResourceRetriever);
downloader.setupDownload(mockMetacard, new DownloadStatusInfoImpl());
downloader.run();
verify(mockPublisher, times(retries)).postRetrievalStatus(any(ResourceResponse.class), eq(ProductRetrievalStatus.RETRYING), any(Metacard.class), anyString(), anyLong(), eq(DOWNLOAD_ID));
}
use of ddf.catalog.resourceretriever.ResourceRetriever in project ddf by codice.
the class ReliableResourceDownloadManagerTest method testDownloadIOException.
@Test(expected = DownloadException.class)
public void testDownloadIOException() throws Exception {
Metacard metacard = getMockMetacard(EXPECTED_METACARD_ID, EXPECTED_METACARD_SOURCE_ID);
resourceRequest = mock(ResourceRequest.class);
ResourceRetriever retriever = mock(ResourceRetriever.class);
when(retriever.retrieveResource()).thenThrow(new IOException());
downloadMgr.download(resourceRequest, metacard, retriever);
}
use of ddf.catalog.resourceretriever.ResourceRetriever 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();
}
use of ddf.catalog.resourceretriever.ResourceRetriever in project ddf by codice.
the class ReliableResourceDownloadManagerTest method testDownloadResourceNotFound.
@Test(expected = DownloadException.class)
public void testDownloadResourceNotFound() throws Exception {
Metacard metacard = getMockMetacard(EXPECTED_METACARD_ID, EXPECTED_METACARD_SOURCE_ID);
resourceRequest = mock(ResourceRequest.class);
ResourceRetriever retriever = mock(ResourceRetriever.class);
when(retriever.retrieveResource()).thenThrow(new ResourceNotFoundException());
downloadMgr.download(resourceRequest, metacard, retriever);
}
Aggregations