use of ddf.catalog.cache.impl.ResourceCacheImpl 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.cache.impl.ResourceCacheImpl in project ddf by codice.
the class DownloadsStatusEventListenerTest method setUp.
@BeforeClass
public static void setUp() {
ReliableResourceDownloaderConfig downloaderConfig = new ReliableResourceDownloaderConfig();
testDownloadStatusInfo = new DownloadStatusInfoImpl();
hcInstanceFactory = new TestHazelcastInstanceFactory(10);
ResourceCacheImpl testResourceCache = new ResourceCacheImpl();
testResourceCache.setCache(hcInstanceFactory.newHazelcastInstance());
productCacheDir = System.getProperty("user.dir") + "/target" + File.separator + ResourceCacheImpl.DEFAULT_PRODUCT_CACHE_DIRECTORY;
testResourceCache.setProductCacheDirectory(productCacheDir);
DownloadsStatusEventPublisher testEventPublisher = mock(DownloadsStatusEventPublisher.class);
testEventListener = new DownloadsStatusEventListener();
downloaderConfig.setResourceCache(testResourceCache);
downloaderConfig.setEventPublisher(testEventPublisher);
downloaderConfig.setEventListener(testEventListener);
testDownloadManager = new ReliableResourceDownloadManager(downloaderConfig, testDownloadStatusInfo, Executors.newSingleThreadExecutor());
testDownloadManager.setMaxRetryAttempts(1);
testDownloadManager.setDelayBetweenAttempts(0);
testDownloadManager.setMonitorPeriod(5);
}
use of ddf.catalog.cache.impl.ResourceCacheImpl 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.cache.impl.ResourceCacheImpl 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));
}
use of ddf.catalog.cache.impl.ResourceCacheImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testGetResourceWhenNonNullResourceRequestExpectPostResourcePluginToReceiveResourceResponseWithNonNullResourceRequest.
/*
* Test for "ResourceResponse returns null ResourceRequest in the PostResourcePlugin"
*
* The error this test case addresses is as follows: The PostResourcePlugin receives a
* ResourceResponse with a null ResourceRequest.
*/
@Test
@Ignore
public void testGetResourceWhenNonNullResourceRequestExpectPostResourcePluginToReceiveResourceResponseWithNonNullResourceRequest() throws Exception {
String sourceId = "myId";
resourceFramework.setId(sourceId);
ResourceCacheImpl resourceCache = mock(ResourceCacheImpl.class);
when(resourceCache.containsValid(isA(String.class), isA(Metacard.class))).thenReturn(false);
String resourceSiteName = "myId";
// Execute
LOGGER.debug("Testing CatalogFramework.getResource(ResourceRequest, String)...");
ResourceResponse resourceResponse = resourceFramework.getResource(mockResourceRequest, resourceSiteName);
LOGGER.debug("resourceResponse: {}", resourceResponse);
// Verify
/*
* Verify that when PostResoucePlugin.process() is called, the ResourceResponse argument
* contains a non-null ResourceRequest.
*/
verify(mockPostResourcePlugin).process(argument.capture());
assertNotNull("PostResourcePlugin received a ResourceResponse with a null ResourceRequest.", argument.getValue().getRequest());
/*
* We really don't need to assert this since we return our mockResourceResponse from
* PostResourcePlugin.process()
*/
// assertNotNull("ResourceResponse.getResource() returned a ResourceResponse with a null ResourceRequest.",
// resourceResponse.getRequest());
}
Aggregations