use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.
the class ResourceLoaderContentCache method evictMatch.
@Timed
@Override
public void evictMatch(ContentCacheKey key) {
try {
final DeletableResource[] resources = resolver.getResources("/cache/" + key.getPrefix() + "**");
final Predicate<String> matcher = key.getMatcher();
stream(resources).filter(r -> matcher.test(r.getFilename())).forEach(r -> {
try {
r.delete();
} catch (IOException e) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
}
});
} catch (IOException e) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
}
}
use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.
the class TransformationCacheKeyTest method getKey_should_generate_serialized_key.
@Test
public void getKey_should_generate_serialized_key() throws Exception {
// given
final ContentCacheKey key = new TransformationCacheKey("prep1", "dataset1", "JSON", "step1", "param1", HEAD, "user1", "");
// when
final String keyStr = key.getKey();
// then
assertThat(keyStr, is("transformation_prep1_dataset1_b6aa01425c31e1eed71d0c3cbc7763aad865d1b1"));
}
use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.
the class TransformationCacheKeyTest method getMatcher_should_return_matcher_for_partial_key.
@Test
public void getMatcher_should_return_matcher_for_partial_key() throws Exception {
// given
final ContentCacheKey prepKey = new TransformationCacheKey("prep1", null, null, null, null, null, null, "");
final ContentCacheKey dataSetKey = new TransformationCacheKey(null, "dataset1", null, null, null, null, null, "");
final ContentCacheKey matchingKey = new TransformationCacheKey("prep1", "dataset1", "JSON", "step1", "param1", HEAD, "user1", "");
final ContentCacheKey nonMatchingKey = new TransformationCacheKey("prep2", "dataset2", "XLS", "step2", "param2", FILTER, "user2", "");
// when / then
assertThat(prepKey.getMatcher().test(matchingKey.getKey()), is(true));
assertThat(dataSetKey.getMatcher().test(matchingKey.getKey()), is(true));
assertThat(prepKey.getMatcher().test(nonMatchingKey.getKey()), is(false));
assertThat(dataSetKey.getMatcher().test(nonMatchingKey.getKey()), is(false));
}
use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.
the class TransformationMetadataCacheKeyTest method getKey_should_generate_serialized_key.
@Test
public void getKey_should_generate_serialized_key() throws Exception {
// given
final ContentCacheKey key = new TransformationMetadataCacheKey("prep1", "step1", HEAD, "user1");
// when
final String keyStr = key.getKey();
// then
assertThat(keyStr, is("transformation-metadata_prep1_step1_HEAD_user1"));
}
use of org.talend.dataprep.cache.ContentCacheKey in project data-prep by Talend.
the class TransformationMetadataCacheKeyTest method getMatcher_should_return_matcher_for_partial_key.
@Test
public void getMatcher_should_return_matcher_for_partial_key() throws Exception {
// given
final ContentCacheKey prepKey = new TransformationMetadataCacheKey("prep1", null, null, null);
final ContentCacheKey stepKey = new TransformationMetadataCacheKey(null, "step1", null, null);
final ContentCacheKey sourceKey = new TransformationMetadataCacheKey(null, null, HEAD, null);
final ContentCacheKey userKey = new TransformationMetadataCacheKey(null, null, null, "user1");
final ContentCacheKey matchingKey = new TransformationMetadataCacheKey("prep1", "step1", HEAD, "user1");
final ContentCacheKey nonMatchingKey = new TransformationMetadataCacheKey("prep2", "step2", FILTER, "user2");
// when / then
assertThat(prepKey.getMatcher().test(matchingKey.getKey()), is(true));
assertThat(stepKey.getMatcher().test(matchingKey.getKey()), is(true));
assertThat(sourceKey.getMatcher().test(matchingKey.getKey()), is(true));
assertThat(userKey.getMatcher().test(matchingKey.getKey()), is(true));
assertThat(prepKey.getMatcher().test(nonMatchingKey.getKey()), is(false));
assertThat(stepKey.getMatcher().test(nonMatchingKey.getKey()), is(false));
assertThat(sourceKey.getMatcher().test(nonMatchingKey.getKey()), is(false));
assertThat(userKey.getMatcher().test(nonMatchingKey.getKey()), is(false));
}
Aggregations