Search in sources :

Example 6 with ContentCacheKey

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

Example 7 with ContentCacheKey

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

Example 8 with ContentCacheKey

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

Example 9 with ContentCacheKey

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

Example 10 with ContentCacheKey

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