use of org.talend.dataprep.cache.TransformationCacheKey in project data-prep by Talend.
the class TransformAPITest method testShouldEvictPreparationCacheOnDataSetUpdate.
@Test
public void testShouldEvictPreparationCacheOnDataSetUpdate() throws Exception {
// given
final String preparationId = testClient.createPreparationFromFile("dataset/dataset_TDP-2165.csv", "testDataset", home.getId());
testClient.applyAction(preparationId, IOUtils.toString(this.getClass().getResourceAsStream("transformation/TDP-2165.json"), UTF_8));
testClient.getPreparation(preparationId);
final Preparation preparation = preparationRepository.get(preparationId, Preparation.class);
final TransformationCacheKey transformationCacheKey = //
cacheKeyGenerator.generateContentKey(//
preparation.getDataSetId(), //
preparationId, //
preparation.getHeadId(), //
"JSON", //
HEAD, // no filter
"");
assertTrue(contentCache.has(transformationCacheKey));
// when
context.publishEvent(new DatasetUpdatedEvent(dataSetMetadataRepository.get(preparation.getDataSetId())));
// then
assertFalse(contentCache.has(transformationCacheKey));
}
use of org.talend.dataprep.cache.TransformationCacheKey in project data-prep by Talend.
the class PreparationCacheCondition method apply.
@Override
public boolean apply(Object... args) {
// check pre-condition
Validate.notNull(args);
Validate.isTrue(args.length == 1);
Validate.isInstanceOf(ExportParameters.class, args[0]);
try {
ExportParameters exportParameters = exportParametersUtil.populateFromPreparationExportParameter((ExportParameters) args[0]);
TransformationCacheKey cacheKey = cacheKeyGenerator.generateContentKey(exportParameters);
return cacheCondition.apply(cacheKey);
} catch (IOException e) {
LOGGER.error("Cannot get all information from export parameters", e);
return false;
}
}
use of org.talend.dataprep.cache.TransformationCacheKey in project data-prep by Talend.
the class TransformationCacheKeyTest method shouldGenerateKey.
@Test
public void shouldGenerateKey() throws Exception {
// when
final TransformationCacheKey key = createTestDefaultKey();
// then
assertNotNull(key.getKey());
}
use of org.talend.dataprep.cache.TransformationCacheKey in project data-prep by Talend.
the class CachedExportStrategy method execute.
@Override
public StreamingResponseBody execute(ExportParameters parameters) {
final TransformationCacheKey contentKey = getCacheKey(parameters);
//
ExportUtils.setExportHeaders(//
parameters.getExportName(), //
parameters.getArguments().get(ExportFormat.PREFIX + CSVFormat.ParametersCSV.ENCODING), getFormat(parameters.getExportType()));
return outputStream -> {
try (InputStream cachedContent = contentCache.get(contentKey)) {
IOUtils.copy(cachedContent, outputStream);
}
};
}
use of org.talend.dataprep.cache.TransformationCacheKey in project data-prep by Talend.
the class TransformationServiceTest method actionFailure.
// see TDP-3417
@Ignore
@Test
public void actionFailure() throws Exception {
// given
String dataSetId = createDataset("input_dataset.csv", "uppercase", "text/csv");
String preparationId = createEmptyPreparationFromDataset(dataSetId, "uppercase prep");
applyActionFromFile(preparationId, "uppercase_action.json");
applyActionFromFile(preparationId, "failed_transformation.json");
// when
final Response response = //
given().when().get("/apply/preparation/{preparationId}/dataset/{datasetId}/{format}", preparationId, dataSetId, "JSON");
// then
// (failed actions are ignored so the response should be 200)
assertEquals(200, response.getStatusCode());
// (make sure the result was not cached)
final TransformationCacheKey key = //
cacheKeyGenerator.generateContentKey(//
dataSetId, //
preparationId, //
preparationRepository.get(preparationId, Preparation.class).getHeadId(), //
JSON, //
HEAD, // no filter
"");
Assert.assertFalse("content cache '" + key.getKey() + "' was not evicted from the cache", contentCache.has(key));
}
Aggregations