Search in sources :

Example 1 with ResourceRetriever

use of ddf.catalog.resourceretriever.ResourceRetriever in project ddf by codice.

the class ReliableResourceDownloadManagerTest method testCacheFileExceptionDuringProductDownload.

/**
     * Tests that if exception with file being cached to occurs during a product retrieval, then the (partially) cached
     * file is deleted and it is not placed in the cache map, but the product continues to be streamed to the client until
     * the EOF is detected.
     *
     * @throws Exception
     */
@Test
@Ignore
public void testCacheFileExceptionDuringProductDownload() throws Exception {
    // Need the product InputStream (MockInputStream) to read slower so that client has time to
    // start reading from the ReliableResourceInputStream and close the FileOutputStream the
    // download manager is writing to, simulating a cache file exception during
    // the product download
    mis = new MockInputStream(productInputFilename, true);
    mis.setReadDelay(MONITOR_PERIOD - 2, TimeUnit.MILLISECONDS);
    Metacard metacard = getMockMetacard(EXPECTED_METACARD_ID, EXPECTED_METACARD_SOURCE_ID);
    resourceResponse = getMockResourceResponse();
    ResourceRetriever retriever = mock(ResourceRetriever.class);
    when(retriever.retrieveResource()).thenReturn(resourceResponse);
    int chunkSize = 2;
    startDownload(true, chunkSize, false, metacard, retriever);
    // 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.setSimulateCacheFileException(2, downloadMgr);
    future = executor.submit(productDownloadClient);
    ByteArrayOutputStream clientBytesRead = future.get();
    verifyClientBytesRead(clientBytesRead);
    // 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();
}
Also used : MockInputStream(ddf.catalog.cache.MockInputStream) Metacard(ddf.catalog.data.Metacard) ResourceRetriever(ddf.catalog.resourceretriever.ResourceRetriever) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CacheKey(ddf.catalog.cache.impl.CacheKey) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with ResourceRetriever

use of ddf.catalog.resourceretriever.ResourceRetriever in project ddf by codice.

the class ReliableResourceDownloadManagerTest method testDownloadWithEmptyMetacardId.

@Test(expected = DownloadException.class)
public void testDownloadWithEmptyMetacardId() throws Exception {
    Metacard metacard = getMockMetacard("", EXPECTED_METACARD_SOURCE_ID);
    resourceRequest = mock(ResourceRequest.class);
    ResourceRetriever retriever = mock(ResourceRetriever.class);
    downloadMgr.download(resourceRequest, metacard, retriever);
}
Also used : Metacard(ddf.catalog.data.Metacard) ResourceRetriever(ddf.catalog.resourceretriever.ResourceRetriever) ResourceRequest(ddf.catalog.operation.ResourceRequest) Test(org.junit.Test)

Example 3 with ResourceRetriever

use of ddf.catalog.resourceretriever.ResourceRetriever in project ddf by codice.

the class ReliableResourceDownloadManagerTest method testStoreWithInputStreamRecoverableErrorCachingDisabled.

/**
     * Test that if an Exception is thrown while reading the product's InputStream that
     * download is interrupted, retried and successfully completes on the second attempt.
     *
     * @throws Exception
     */
@Test
@Ignore
public void testStoreWithInputStreamRecoverableErrorCachingDisabled() throws Exception {
    mis = new MockInputStream(productInputFilename);
    Metacard metacard = getMockMetacard(EXPECTED_METACARD_ID, EXPECTED_METACARD_SOURCE_ID);
    resourceResponse = getMockResourceResponse();
    ResourceRetriever retriever = getMockResourceRetrieverWithRetryCapability(RetryType.INPUT_STREAM_IO_EXCEPTION);
    int chunkSize = 50;
    startDownload(false, chunkSize, false, metacard, retriever);
    ByteArrayOutputStream clientBytesRead = clientRead(chunkSize, productInputStream);
    // Verifies client read same contents as product input file
    verifyClientBytesRead(clientBytesRead);
    cleanup();
}
Also used : MockInputStream(ddf.catalog.cache.MockInputStream) Metacard(ddf.catalog.data.Metacard) ResourceRetriever(ddf.catalog.resourceretriever.ResourceRetriever) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with ResourceRetriever

use of ddf.catalog.resourceretriever.ResourceRetriever in project ddf by codice.

the class ReliableResourceDownloaderTest method getMockRetriever.

private ResourceRetriever getMockRetriever() throws ResourceNotFoundException, ResourceNotSupportedException, IOException {
    ResourceRetriever retriever = mock(ResourceRetriever.class);
    when(retriever.retrieveResource(anyLong())).thenReturn(mockResponse);
    return retriever;
}
Also used : ResourceRetriever(ddf.catalog.resourceretriever.ResourceRetriever)

Example 5 with ResourceRetriever

use of ddf.catalog.resourceretriever.ResourceRetriever in project ddf by codice.

the class ReliableResourceDownloadManagerTest method testDownloadResourceNotSupported.

@Test(expected = DownloadException.class)
public void testDownloadResourceNotSupported() 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 ResourceNotSupportedException());
    downloadMgr.download(resourceRequest, metacard, retriever);
}
Also used : Metacard(ddf.catalog.data.Metacard) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) ResourceRetriever(ddf.catalog.resourceretriever.ResourceRetriever) ResourceRequest(ddf.catalog.operation.ResourceRequest) Test(org.junit.Test)

Aggregations

ResourceRetriever (ddf.catalog.resourceretriever.ResourceRetriever)21 Test (org.junit.Test)19 Metacard (ddf.catalog.data.Metacard)18 MockInputStream (ddf.catalog.cache.MockInputStream)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 Ignore (org.junit.Ignore)8 CacheKey (ddf.catalog.cache.impl.CacheKey)6 ReliableResource (ddf.catalog.resource.data.ReliableResource)6 ResourceRequest (ddf.catalog.operation.ResourceRequest)5 ResourceResponse (ddf.catalog.operation.ResourceResponse)3 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)2 IOException (java.io.IOException)2 DownloadStatusInfoImpl (ddf.catalog.event.retrievestatus.DownloadStatusInfoImpl)1 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CancellationException (java.util.concurrent.CancellationException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 MimeType (javax.activation.MimeType)1 MimeTypeParseException (javax.activation.MimeTypeParseException)1