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