Search in sources :

Example 1 with DownloadStatusInfoImpl

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));
}
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 DownloadStatusInfoImpl

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));
}
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 3 with DownloadStatusInfoImpl

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));
}
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 DownloadStatusInfoImpl

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

Example 5 with DownloadStatusInfoImpl

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));
}
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)

Aggregations

DownloadStatusInfoImpl (ddf.catalog.event.retrievestatus.DownloadStatusInfoImpl)6 Metacard (ddf.catalog.data.Metacard)5 ResourceResponse (ddf.catalog.operation.ResourceResponse)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 ResourceCacheImpl (ddf.catalog.cache.impl.ResourceCacheImpl)4 MockInputStream (ddf.catalog.cache.MockInputStream)2 IOException (java.io.IOException)2 CountingOutputStream (com.google.common.io.CountingOutputStream)1 DownloadsStatusEventListener (ddf.catalog.event.retrievestatus.DownloadsStatusEventListener)1 DownloadsStatusEventPublisher (ddf.catalog.event.retrievestatus.DownloadsStatusEventPublisher)1 ReliableResource (ddf.catalog.resource.data.ReliableResource)1 ResourceRetriever (ddf.catalog.resourceretriever.ResourceRetriever)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 CancellationException (java.util.concurrent.CancellationException)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1