Search in sources :

Example 21 with ContentCacheKey

use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.

the class ContentCacheTests method testJanitorEvictionPeriod.

@Test
public void testJanitorEvictionPeriod() throws Exception {
    // given some cache entries
    List<ContentCacheKey> keys = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        keys.add(new DummyCacheKey("janitor me " + i + 1));
    }
    for (ContentCacheKey key : keys) {
        addCacheEntry(key, "janitor content", ContentCache.TimeToLive.IMMEDIATE);
        assertThat(cache.has(key), is(true));
    }
    // when eviction is performed and the janitor is called
    janitor.janitor();
    // then, none of the cache entries should be removed
    for (ContentCacheKey key : keys) {
        assertThat(cache.has(key), is(true));
    }
    Thread.sleep(ContentCache.TimeToLive.IMMEDIATE.getTime() + 500);
    // then, none of the cache entries should be removed
    for (ContentCacheKey key : keys) {
        assertThat(cache.has(key), is(false));
    }
    // when eviction is performed and the janitor is called
    janitor.janitor();
    for (ContentCacheKey key : keys) {
        assertFalse(cache.has(key));
    }
}
Also used : ContentCacheKey(org.talend.dataprep.cache.ContentCacheKey) ArrayList(java.util.ArrayList) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 22 with ContentCacheKey

use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.

the class ContentCacheTests method testEvictWithNoPut.

@Test
public void testEvictWithNoPut() throws Exception {
    ContentCacheKey key = new DummyCacheKey("tutu");
    assertThat(cache.has(key), is(false));
    // evict() a key that does not exist
    cache.evict(key);
    // ... has() must return false
    assertThat(cache.has(key), is(false));
}
Also used : ContentCacheKey(org.talend.dataprep.cache.ContentCacheKey) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 23 with ContentCacheKey

use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.

the class ContentCacheTests method testPermanentEntry.

@Test
public void testPermanentEntry() throws Exception {
    ContentCacheKey key = new DummyCacheKey("tutu");
    // Put a content in cache...
    addCacheEntry(key, "content, yes again", ContentCache.TimeToLive.PERMANENT);
    assertThat(cache.has(key), is(true));
    InputStream actualContentStream = cache.get(key);
    assertThat(IOUtils.toString(actualContentStream, UTF_8), is("content, yes again"));
    // Note : Closing stream so that cache can be evicted
    actualContentStream.close();
    // ... evict() it...
    cache.evict(key);
    // ... has() must immediately return false
    assertThat(cache.has(key), is(false));
    assertThat(cache.get(key), is((InputStream) null));
}
Also used : InputStream(java.io.InputStream) ContentCacheKey(org.talend.dataprep.cache.ContentCacheKey) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 24 with ContentCacheKey

use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.

the class ContentCacheTests method shouldHavePermanentEntry.

@Test
public void shouldHavePermanentEntry() throws Exception {
    // Put a content in cache...
    ContentCacheKey key = new DummyCacheKey("permanent");
    assertThat(cache.has(key), is(false));
    addCacheEntry(key, "content", ContentCache.TimeToLive.PERMANENT);
    // ... has() must return true
    assertThat(cache.has(key), is(true));
}
Also used : ContentCacheKey(org.talend.dataprep.cache.ContentCacheKey) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 25 with ContentCacheKey

use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.

the class ContentCacheTests method testEvict.

@Test
public void testEvict() throws Exception {
    ContentCacheKey key = new DummyCacheKey("tutu");
    // Put a content in cache...
    addCacheEntry(key, "content, yes again", ContentCache.TimeToLive.DEFAULT);
    assertThat(cache.has(key), is(true));
    // ... evict() it...
    cache.evict(key);
    // ... has() must immediately return false
    assertThat(cache.has(key), is(false));
}
Also used : ContentCacheKey(org.talend.dataprep.cache.ContentCacheKey) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Aggregations

ContentCacheKey (org.talend.dataprep.cache.ContentCacheKey)28 Test (org.junit.Test)20 ServiceBaseTest (org.talend.ServiceBaseTest)14 TransformationMetadataCacheKey (org.talend.dataprep.cache.TransformationMetadataCacheKey)4 OutputStream (java.io.OutputStream)3 ArrayList (java.util.ArrayList)3 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)3 TDPException (org.talend.dataprep.exception.TDPException)3 ApiOperation (io.swagger.annotations.ApiOperation)2 InputStream (java.io.InputStream)2 Predicate (java.util.function.Predicate)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Component (org.springframework.stereotype.Component)2 TransformationCacheKey (org.talend.dataprep.cache.TransformationCacheKey)2 Timed (org.talend.dataprep.metrics.Timed)2 JsonParser (com.fasterxml.jackson.core.JsonParser)1 IOException (java.io.IOException)1 Long.parseLong (java.lang.Long.parseLong)1