Search in sources :

Example 6 with ReliableResource

use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.

the class ResourceCacheImplSizeLimitTest method verifyCached.

private void verifyCached(IMap<String, ReliableResource> cacheMap, String rrKey, String rrFileName) {
    ReliableResource rrFromCache = (ReliableResource) cacheMap.get(rrKey);
    assertNotNull(rrFromCache);
    File rrCachedFile = new File(productCacheDir + File.separator + rrFileName);
    assertTrue(new File(rrCachedFile.getAbsolutePath()).exists());
}
Also used : File(java.io.File) ReliableResource(ddf.catalog.resource.data.ReliableResource)

Example 7 with ReliableResource

use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.

the class ResourceCacheImplSizeLimitTest method verifyRemovedFromCache.

private void verifyRemovedFromCache(IMap<String, ReliableResource> cacheMap, String rrKey, String rrFileName) {
    ReliableResource rrFromCache = (ReliableResource) cacheMap.get(rrKey);
    assertNull(rrFromCache);
    File rrCachedFile = new File(productCacheDir + File.separator + rrFileName);
    assertFalse(new File(rrCachedFile.getAbsolutePath()).exists());
}
Also used : File(java.io.File) ReliableResource(ddf.catalog.resource.data.ReliableResource)

Example 8 with ReliableResource

use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.

the class ResourceCacheImplSizeLimitTest method testCacheDirMaxSizePaging.

@Test
public void testCacheDirMaxSizePaging() throws IOException, InterruptedException {
    HazelcastInstance instance = initializeTestHazelcastInstance();
    listener.setHazelcastInstance(instance);
    listener.setMaxDirSizeBytes(132);
    IMap<String, ReliableResource> cacheMap = instance.getMap(PRODUCT_CACHE_NAME);
    //Simulate adding product to product cache
    //push 12 files into cache to total a size of 120 bytes
    String rrKeyPrefix = "rr";
    String rr1FileNameBase = "10bytes.txt";
    for (int i = 0; i < 12; i++) {
        simulateAddFileToProductCache(rrKeyPrefix + i, rr1FileNameBase, i + rr1FileNameBase, cacheMap);
    }
    //ensure all 12 10-byte files are cached
    for (int i = 0; i < 12; i++) {
        verifyCached(cacheMap, rrKeyPrefix + i, i + rr1FileNameBase);
    }
    //push 1 large file into cache to total 245 bytes.  This file will be on the second "page" when querying the cache.
    String oneTwentyFiveBytesFileName = "125bytes.txt";
    int indexOf125Bytes = 12;
    simulateAddFileToProductCache(rrKeyPrefix + indexOf125Bytes, oneTwentyFiveBytesFileName, oneTwentyFiveBytesFileName, cacheMap);
    //ensure 125-byte file is cached
    verifyCached(cacheMap, rrKeyPrefix + indexOf125Bytes, oneTwentyFiveBytesFileName);
    //entries from 0-9 should be removed from cache
    for (int i = 0; i < 12; i++) {
        verifyRemovedFromCache(cacheMap, rrKeyPrefix + i, i + rr1FileNameBase);
    }
    verifyCached(cacheMap, rrKeyPrefix + indexOf125Bytes, oneTwentyFiveBytesFileName);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ReliableResource(ddf.catalog.resource.data.ReliableResource) Test(org.junit.Test)

Example 9 with ReliableResource

use of ddf.catalog.resource.data.ReliableResource in project ddf by codice.

the class ResourceCacheImplTest method testContainsNullLatestMetacard.

@Test(expected = IllegalArgumentException.class)
public void testContainsNullLatestMetacard() throws URISyntaxException {
    MetacardImpl cachedMetacard = generateMetacard();
    String cacheKey = "cacheKey1";
    resourceCache.put(new ReliableResource(cacheKey, "", null, "name", cachedMetacard));
    assertFalse(resourceCache.containsValid("cacheKey1", null));
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) ReliableResource(ddf.catalog.resource.data.ReliableResource) Test(org.junit.Test)

Example 10 with ReliableResource

use of ddf.catalog.resource.data.ReliableResource 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)

Aggregations

ReliableResource (ddf.catalog.resource.data.ReliableResource)44 Test (org.junit.Test)32 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)15 Metacard (ddf.catalog.data.Metacard)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 Attribute (ddf.catalog.data.Attribute)7 Result (ddf.catalog.data.Result)7 File (java.io.File)7 MockInputStream (ddf.catalog.cache.MockInputStream)6 ResourceCacheInterface (ddf.catalog.cache.ResourceCacheInterface)6 ResultImpl (ddf.catalog.data.impl.ResultImpl)6 QueryResponse (ddf.catalog.operation.QueryResponse)6 ResourceRetriever (ddf.catalog.resourceretriever.ResourceRetriever)6 ArrayList (java.util.ArrayList)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 CacheKey (ddf.catalog.cache.impl.CacheKey)4 ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)3 Resource (ddf.catalog.resource.Resource)3 MimeType (javax.activation.MimeType)3 Ignore (org.junit.Ignore)3