use of ddf.catalog.event.retrievestatus.DownloadStatusInfoImpl in project ddf by codice.
the class ReliableResourceDownloaderTest method testBadKeyName.
@Test
public void testBadKeyName() throws Exception {
Metacard metacard = getMockMetacard(DOWNLOAD_ID, ":badsourcename");
downloaderConfig.setCacheEnabled(true);
ResourceResponse mockResponse = getMockResourceResponse(mockStream);
ResourceCacheImpl mockCache = mock(ResourceCacheImpl.class);
when(mockCache.isPending(anyString())).thenReturn(false);
when(mockCache.getProductCacheDirectory()).thenReturn(productCacheDirectory);
downloaderConfig.setResourceCache(mockCache);
ReliableResourceDownloader downloader = new ReliableResourceDownloader(downloaderConfig, new AtomicBoolean(), DOWNLOAD_ID, mockResponse, getMockRetriever());
downloader.setupDownload(metacard, new DownloadStatusInfoImpl());
verify(mockCache, never()).addPendingCacheEntry(any(ReliableResource.class));
}
use of ddf.catalog.event.retrievestatus.DownloadStatusInfoImpl 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.event.retrievestatus.DownloadStatusInfoImpl in project ddf by codice.
the class ReliableResourceDownloaderTest method testCacheExceptionDuringWrite.
@Test
public void testCacheExceptionDuringWrite() throws Exception {
downloaderConfig.setCacheEnabled(true);
ResourceCacheImpl mockCache = mock(ResourceCacheImpl.class);
when(mockCache.isPending(anyString())).thenReturn(false);
when(mockCache.getProductCacheDirectory()).thenReturn(productCacheDirectory);
downloaderConfig.setResourceCache(mockCache);
mis = new MockInputStream(productInputFilename);
ResourceResponse mockResponse = getMockResourceResponse(mis);
ReliableResourceDownloader downloader = new ReliableResourceDownloader(downloaderConfig, new AtomicBoolean(), "123", mockResponse, getMockRetriever());
downloader.setupDownload(mockMetacard, new DownloadStatusInfoImpl());
FileOutputStream mockFos = mock(FileOutputStream.class);
doThrow(new IOException()).when(mockFos).write(any(byte[].class), anyInt(), anyInt());
downloader.setFileOutputStream(mockFos);
downloader.run();
verify(mockPublisher, times(1)).postRetrievalStatus(any(ResourceResponse.class), eq(ProductRetrievalStatus.RETRYING), any(Metacard.class), anyString(), anyLong(), eq(DOWNLOAD_ID));
verify(mockCache, times(1)).removePendingCacheEntry(anyString());
assertThat(downloaderConfig.isCacheEnabled(), is(false));
}
use of ddf.catalog.event.retrievestatus.DownloadStatusInfoImpl in project ddf by codice.
the class ReliableResourceDownloaderTest method testIOExceptionDuringRead.
@Test
public void testIOExceptionDuringRead() throws Exception {
ResourceResponse mockResponse = getMockResourceResponse(mockStream);
when(mockStream.read(any(byte[].class))).thenThrow(new IOException());
int retries = 5;
downloaderConfig.setMaxRetryAttempts(retries);
ReliableResourceDownloader downloader = new ReliableResourceDownloader(downloaderConfig, new AtomicBoolean(), DOWNLOAD_ID, mockResponse, getMockRetriever());
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.event.retrievestatus.DownloadStatusInfoImpl in project ddf by codice.
the class ReliableResourceDownloaderTest method testClientOutputStreamException.
@Test
@Ignore
public // Can't figure out how to throw IOExcetion from CountingOutputStream
void testClientOutputStreamException() throws Exception {
downloaderConfig.setCacheEnabled(true);
ResourceCacheImpl mockCache = mock(ResourceCacheImpl.class);
when(mockCache.isPending(anyString())).thenReturn(false);
when(mockCache.getProductCacheDirectory()).thenReturn(productCacheDirectory);
downloaderConfig.setResourceCache(mockCache);
mis = new MockInputStream(productInputFilename);
ResourceResponse mockResponse = getMockResourceResponse(mis);
ReliableResourceDownloader downloader = new ReliableResourceDownloader(downloaderConfig, new AtomicBoolean(), "123", mockResponse, getMockRetriever());
downloader.setupDownload(mockMetacard, new DownloadStatusInfoImpl());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
CountingOutputStream mockCountingFbos = new CountingOutputStream(baos);
IOUtils.closeQuietly(baos);
downloader.setCountingOutputStream(mockCountingFbos);
downloader.run();
verify(mockPublisher, times(1)).postRetrievalStatus(any(ResourceResponse.class), eq(ProductRetrievalStatus.CANCELLED), any(Metacard.class), anyString(), anyLong(), eq(DOWNLOAD_ID));
verify(mockCache, times(1)).removePendingCacheEntry(anyString());
assertThat(downloaderConfig.isCacheEnabled(), is(false));
}
Aggregations