Search in sources :

Example 1 with ContentCacheKey

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));
}
Also used : ContentCacheKey(org.talend.dataprep.cache.ContentCacheKey) OutputStream(java.io.OutputStream) Test(org.junit.Test)

Example 2 with ContentCacheKey

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));
    }
}
Also used : ContentCacheKey(org.talend.dataprep.cache.ContentCacheKey) ArrayList(java.util.ArrayList) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 3 with ContentCacheKey

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));
}
Also used : ContentCacheKey(org.talend.dataprep.cache.ContentCacheKey) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 4 with ContentCacheKey

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));
}
Also used : ContentCacheKey(org.talend.dataprep.cache.ContentCacheKey) Test(org.junit.Test) ServiceBaseTest(org.talend.ServiceBaseTest)

Example 5 with ContentCacheKey

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