Search in sources :

Example 1 with ResourceCacheImpl

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));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Metacard(ddf.catalog.data.Metacard) ResourceCacheImpl(ddf.catalog.cache.impl.ResourceCacheImpl) ResourceResponse(ddf.catalog.operation.ResourceResponse) DownloadStatusInfoImpl(ddf.catalog.event.retrievestatus.DownloadStatusInfoImpl) ReliableResource(ddf.catalog.resource.data.ReliableResource) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with ResourceCacheImpl

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);
}
Also used : ResourceCacheImpl(ddf.catalog.cache.impl.ResourceCacheImpl) ReliableResourceDownloadManager(ddf.catalog.resource.download.ReliableResourceDownloadManager) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ReliableResourceDownloaderConfig(ddf.catalog.resource.download.ReliableResourceDownloaderConfig) BeforeClass(org.junit.BeforeClass)

Example 3 with ResourceCacheImpl

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));
}
Also used : MockInputStream(ddf.catalog.cache.MockInputStream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Metacard(ddf.catalog.data.Metacard) ResourceCacheImpl(ddf.catalog.cache.impl.ResourceCacheImpl) ResourceResponse(ddf.catalog.operation.ResourceResponse) DownloadStatusInfoImpl(ddf.catalog.event.retrievestatus.DownloadStatusInfoImpl) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with ResourceCacheImpl

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));
}
Also used : MockInputStream(ddf.catalog.cache.MockInputStream) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CountingOutputStream(com.google.common.io.CountingOutputStream) Metacard(ddf.catalog.data.Metacard) ResourceCacheImpl(ddf.catalog.cache.impl.ResourceCacheImpl) ResourceResponse(ddf.catalog.operation.ResourceResponse) DownloadStatusInfoImpl(ddf.catalog.event.retrievestatus.DownloadStatusInfoImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Ignore(org.junit.Ignore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with ResourceCacheImpl

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());
}
Also used : Metacard(ddf.catalog.data.Metacard) ResourceCacheImpl(ddf.catalog.cache.impl.ResourceCacheImpl) ResourceResponse(ddf.catalog.operation.ResourceResponse) Matchers.anyString(org.mockito.Matchers.anyString) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ResourceCacheImpl (ddf.catalog.cache.impl.ResourceCacheImpl)5 Metacard (ddf.catalog.data.Metacard)4 ResourceResponse (ddf.catalog.operation.ResourceResponse)4 Test (org.junit.Test)4 DownloadStatusInfoImpl (ddf.catalog.event.retrievestatus.DownloadStatusInfoImpl)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 MockInputStream (ddf.catalog.cache.MockInputStream)2 Ignore (org.junit.Ignore)2 CountingOutputStream (com.google.common.io.CountingOutputStream)1 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)1 ReliableResource (ddf.catalog.resource.data.ReliableResource)1 ReliableResourceDownloadManager (ddf.catalog.resource.download.ReliableResourceDownloadManager)1 ReliableResourceDownloaderConfig (ddf.catalog.resource.download.ReliableResourceDownloaderConfig)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 BeforeClass (org.junit.BeforeClass)1 Matchers.anyString (org.mockito.Matchers.anyString)1