use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.
the class ContentCacheTests method testJanitor.
@Test
public void testJanitor() 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.DEFAULT);
assertThat(cache.has(key), is(true));
}
// when eviction is performed and the janitor is called
for (ContentCacheKey key : keys) {
cache.evict(key);
}
janitor.janitor();
// then no file in the cache should be left
for (int i = 0; i < 10; i++) {
assertFalse(cache.has(new DummyCacheKey("janitor me " + i + 1)));
}
}
use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.
the class ContentCacheTests method testPutHas.
@Test
public void testPutHas() throws Exception {
// Put a content in cache...
ContentCacheKey key = new DummyCacheKey("titi");
assertThat(cache.has(key), is(false));
addCacheEntry(key, "content", ContentCache.TimeToLive.DEFAULT);
// ... 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 shouldHaveWithMultipleVersions.
@Test
public void shouldHaveWithMultipleVersions() throws Exception {
// Put a content in cache...
ContentCacheKey key = new DummyCacheKey("multipleVersions");
assertThat(cache.has(key), is(false));
addCacheEntry(key, "content", ContentCache.TimeToLive.DEFAULT);
TimeUnit.MILLISECONDS.sleep(500);
addCacheEntry(key, "content", ContentCache.TimeToLive.DEFAULT);
// ... 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 testGet.
@Test
public void testGet() throws Exception {
ContentCacheKey key = new DummyCacheKey("tata");
String content = "yet another content...";
// Put a content in cache...
addCacheEntry(key, content, ContentCache.TimeToLive.DEFAULT);
// ... get() should return this content back.
final String actual = IOUtils.toString(cache.get(key), UTF_8);
assertThat(actual, is(content));
}
use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.
the class ContentCacheTests method testMove.
@Test
public void testMove() throws Exception {
// given
final ContentCacheKey key1 = new DummyCacheKey("tata");
final ContentCacheKey key2 = new DummyCacheKey("tata2");
String content = "yet another content...";
addCacheEntry(key1, content, ContentCache.TimeToLive.DEFAULT);
assertTrue(cache.has(key1));
assertFalse(cache.has(key2));
// when
cache.move(key1, key2, ContentCache.TimeToLive.DEFAULT);
// then
final String actual = IOUtils.toString(cache.get(key2), UTF_8);
assertThat(actual, is(content));
assertFalse(cache.has(key1));
assertTrue(cache.has(key2));
}
Aggregations