Search in sources :

Example 26 with ReliableResource

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

the class ResourceCacheImplSizeLimitTest method testExceedCacheDirMaxSize.

@Test
public //@Ignore
void testExceedCacheDirMaxSize() throws IOException, InterruptedException {
    HazelcastInstance instance = initializeTestHazelcastInstance();
    listener.setMaxDirSizeBytes(15);
    listener.setHazelcastInstance(instance);
    IMap<String, ReliableResource> cacheMap = instance.getMap(PRODUCT_CACHE_NAME);
    // Simulate adding product to product cache
    String rr1Key = "rr1";
    String rr1FileName = "10bytes.txt";
    simulateAddFileToProductCache(rr1Key, rr1FileName, rr1FileName, //this may take longer to execute than just the next line.
    cacheMap);
    // ensure that the entry has not been removed from the cache since it doesn't exceed the max size
    verifyCached(cacheMap, rr1Key, rr1FileName);
    // simulate adding additional product to cache
    String rr2Key = "rr2";
    String rr2FileName = "15bytes.txt";
    simulateAddFileToProductCache(rr2Key, rr2FileName, rr2FileName, cacheMap);
    verifyRemovedFromCache(cacheMap, rr1Key, rr1FileName);
    verifyCached(cacheMap, rr2Key, rr2FileName);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ReliableResource(ddf.catalog.resource.data.ReliableResource) Test(org.junit.Test)

Example 27 with ReliableResource

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

the class ResourceCacheImplSizeLimitTest method testNotExceedCacheDirMaxSize.

@Test
public //@Ignore
void testNotExceedCacheDirMaxSize() throws IOException, InterruptedException {
    HazelcastInstance instance = initializeTestHazelcastInstance();
    listener.setMaxDirSizeBytes(50);
    listener.setHazelcastInstance(instance);
    IMap<String, ReliableResource> cacheMap = instance.getMap(PRODUCT_CACHE_NAME);
    //Simulate adding product to product cache
    String rr1Key = "rr1";
    String rr1FileName = "10bytes.txt";
    simulateAddFileToProductCache(rr1Key, rr1FileName, rr1FileName, cacheMap);
    //simulate adding additional product to cache
    String rr2Key = "rr2";
    String rr2FileName = "15bytes.txt";
    simulateAddFileToProductCache(rr2Key, rr2FileName, rr2FileName, cacheMap);
    //simulate adding additional product to cache
    String rr3Key = "rr3";
    String rr3FileName = "15bytes_B.txt";
    simulateAddFileToProductCache(rr3Key, rr3FileName, rr3FileName, cacheMap);
    verifyCached(cacheMap, rr1Key, rr1FileName);
    verifyCached(cacheMap, rr2Key, rr2FileName);
    verifyCached(cacheMap, rr3Key, rr3FileName);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ReliableResource(ddf.catalog.resource.data.ReliableResource) Test(org.junit.Test)

Example 28 with ReliableResource

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

the class ResourceCacheImplSizeLimitTest method simulateAddFileToProductCache.

private ReliableResource simulateAddFileToProductCache(String key, String fileName, String destFileName, IMap<String, ReliableResource> cacheMap) throws IOException {
    String productOriginalLocation = new File(this.getClass().getClassLoader().getResource(fileName).getPath()).getAbsolutePath();
    File rrCachedFile = new File(productCacheDir + "/" + destFileName);
    FileUtils.copyFile(new File(productOriginalLocation), rrCachedFile);
    ReliableResource rr = new ReliableResource(key, rrCachedFile.getAbsolutePath(), new MimeType(), fileName, new MetacardImpl());
    rr.setSize(rrCachedFile.length());
    LOGGER.debug("adding entry to cache: {}", key);
    cacheMap.put(key, rr);
    listener.entryAdded(new EntryEvent<Object, Object>(destFileName, null, EntryEventType.ADDED.getType(), key, rr));
    return rr;
}
Also used : File(java.io.File) ReliableResource(ddf.catalog.resource.data.ReliableResource) MimeType(javax.activation.MimeType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Example 29 with ReliableResource

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

the class ResourceCacheImplSizeLimitTest method testSingleFileExceedCacheDirMaxSize.

@Test
public void testSingleFileExceedCacheDirMaxSize() throws IOException, InterruptedException {
    HazelcastInstance instance = initializeTestHazelcastInstance();
    IMap<String, ReliableResource> cacheMap = instance.getMap(PRODUCT_CACHE_NAME);
    listener.setMaxDirSizeBytes(5);
    listener.setHazelcastInstance(instance);
    //Simulate adding product to product cache
    String rr1Key = "rr1";
    String rr1FileName = "10bytes.txt";
    simulateAddFileToProductCache(rr1Key, rr1FileName, rr1FileName, cacheMap);
    verifyRemovedFromCache(cacheMap, rr1Key, rr1FileName);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ReliableResource(ddf.catalog.resource.data.ReliableResource) Test(org.junit.Test)

Example 30 with ReliableResource

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

the class ReliableResourceDownloadManagerTest method testDownloadWithCaching.

@Test
public // @Ignore
void testDownloadWithCaching() 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);
    ByteArrayOutputStream clientBytesRead = clientRead(chunkSize, 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