use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.
the class PreparationAPITest method testPreparationCacheDeletion.
@Test
public void testPreparationCacheDeletion() throws Exception {
// given
String tagadaId = testClient.createDataset("dataset/dataset.csv", "tagada");
final String preparationId = testClient.createPreparationFromDataset(tagadaId, "original_name", home.getId());
final String list = when().get("/api/preparations").asString();
assertThat(list.contains(preparationId), is(true));
final ContentCacheKey metadataKey = cacheKeyGenerator.metadataBuilder().preparationId(preparationId).stepId("step1").sourceType(FILTER).build();
final ContentCacheKey contentKey = cacheKeyGenerator.contentBuilder().datasetId("datasetId").preparationId(preparationId).stepId("step1").format(JSON).parameters(emptyMap()).sourceType(FILTER).build();
try (final OutputStream entry = contentCache.put(metadataKey, PERMANENT)) {
entry.write("metadata".getBytes());
entry.flush();
}
try (final OutputStream entry = contentCache.put(contentKey, PERMANENT)) {
entry.write("content".getBytes());
entry.flush();
}
assertThat(contentCache.has(metadataKey), is(true));
assertThat(contentCache.has(contentKey), is(true));
// when
when().delete("/api/preparations/" + preparationId).asString();
// then
Assert.assertThat(contentCache.has(metadataKey), is(false));
Assert.assertThat(contentCache.has(contentKey), is(false));
}
use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.
the class ContentCacheTests method testJanitorShouldNotCleanAnything.
@Test
public void testJanitorShouldNotCleanAnything() throws Exception {
// given some valid cache entries
List<ContentCacheKey> keys = new ArrayList<>();
for (int i = 0; i < 10; i++) {
keys.add(new DummyCacheKey("do not disturb-" + i + 1));
}
for (ContentCacheKey key : keys) {
addCacheEntry(key, "content", ContentCache.TimeToLive.DEFAULT);
assertThat(cache.has(key), is(true));
}
// when 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));
}
}
use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.
the class ContentCacheTests method shouldHaveWithMultipleVersionsAndDifferentTTL.
@Test
public void shouldHaveWithMultipleVersionsAndDifferentTTL() 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.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 testEvictMatch.
@Test
public void testEvictMatch() throws Exception {
// given
final ContentCacheKey key = new DummyCacheKey("youpala");
final ContentCacheKey keyMatch = new DummyCacheKey("youpala");
// not the same key because of random + hash
assertThat(cache.has(key), not(is(keyMatch.getKey())));
// Put a content in cache...
addCacheEntry(key, "content", DEFAULT);
assertThat(cache.has(key), is(true));
// when
cache.evictMatch(key);
// then
assertThat(cache.has(key), is(false));
}
use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.
the class ContentCacheTests method shouldNotCleanPermanentEntryOnJanitor.
@Test
public void shouldNotCleanPermanentEntryOnJanitor() throws Exception {
// Put a content in cache...
ContentCacheKey key = new DummyCacheKey("permanen");
assertThat(cache.has(key), is(false));
addCacheEntry(key, "content", ContentCache.TimeToLive.PERMANENT);
// Call janitor
janitor.janitor();
// ... has() must return true
assertThat(cache.has(key), is(true));
}
Aggregations