Search in sources :

Example 6 with ResourceRetriever

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();
}
Also used : MockInputStream(ddf.catalog.cache.MockInputStream) Metacard(ddf.catalog.data.Metacard) ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceRetriever(ddf.catalog.resourceretriever.ResourceRetriever) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 7 with ResourceRetriever

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

Example 8 with ResourceRetriever

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);
}
Also used : Metacard(ddf.catalog.data.Metacard) ResourceRetriever(ddf.catalog.resourceretriever.ResourceRetriever) ResourceRequest(ddf.catalog.operation.ResourceRequest) IOException(java.io.IOException) Test(org.junit.Test)

Example 9 with ResourceRetriever

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();
}
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) ReliableResource(ddf.catalog.resource.data.ReliableResource) Test(org.junit.Test)

Example 10 with ResourceRetriever

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);
}
Also used : Metacard(ddf.catalog.data.Metacard) ResourceRetriever(ddf.catalog.resourceretriever.ResourceRetriever) ResourceRequest(ddf.catalog.operation.ResourceRequest) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) 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