Search in sources :

Example 1 with TransformationCacheKey

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));
}
Also used : TransformationCacheKey(org.talend.dataprep.cache.TransformationCacheKey) DatasetUpdatedEvent(org.talend.dataprep.dataset.event.DatasetUpdatedEvent) Preparation(org.talend.dataprep.api.preparation.Preparation) Test(org.junit.Test)

Example 2 with 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;
    }
}
Also used : TransformationCacheKey(org.talend.dataprep.cache.TransformationCacheKey) ExportParameters(org.talend.dataprep.api.export.ExportParameters) IOException(java.io.IOException)

Example 3 with TransformationCacheKey

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

Example 4 with TransformationCacheKey

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);
        }
    };
}
Also used : TransformationCacheKey(org.talend.dataprep.cache.TransformationCacheKey) ExportFormat(org.talend.dataprep.format.export.ExportFormat) StringUtils(org.apache.commons.lang.StringUtils) ExportParameters(org.talend.dataprep.api.export.ExportParameters) TDPException(org.talend.dataprep.exception.TDPException) BaseExportStrategy(org.talend.dataprep.transformation.service.BaseExportStrategy) IOUtils(org.apache.poi.util.IOUtils) Autowired(org.springframework.beans.factory.annotation.Autowired) StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) PreparationErrorCodes(org.talend.dataprep.exception.error.PreparationErrorCodes) PreparationMessage(org.talend.dataprep.api.preparation.PreparationMessage) CacheKeyGenerator(org.talend.dataprep.cache.CacheKeyGenerator) CSVFormat(org.talend.dataprep.transformation.format.CSVFormat) Component(org.springframework.stereotype.Component) TransformationCacheKey(org.talend.dataprep.cache.TransformationCacheKey) ExportUtils(org.talend.dataprep.transformation.service.ExportUtils) InputStream(java.io.InputStream) InputStream(java.io.InputStream)

Example 5 with TransformationCacheKey

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));
}
Also used : Response(com.jayway.restassured.response.Response) TransformationCacheKey(org.talend.dataprep.cache.TransformationCacheKey) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

TransformationCacheKey (org.talend.dataprep.cache.TransformationCacheKey)16 Test (org.junit.Test)9 Preparation (org.talend.dataprep.api.preparation.Preparation)7 ExportParameters (org.talend.dataprep.api.export.ExportParameters)6 OutputStream (java.io.OutputStream)5 InputStream (java.io.InputStream)4 DataSet (org.talend.dataprep.api.dataset.DataSet)4 TDPException (org.talend.dataprep.exception.TDPException)4 ExportFormat (org.talend.dataprep.format.export.ExportFormat)4 JsonParser (com.fasterxml.jackson.core.JsonParser)3 IOException (java.io.IOException)3 InputStreamReader (java.io.InputStreamReader)3 TeeOutputStream (org.apache.commons.io.output.TeeOutputStream)3 StringUtils (org.apache.commons.lang.StringUtils)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Component (org.springframework.stereotype.Component)3 StreamingResponseBody (org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody)3 PreparationMessage (org.talend.dataprep.api.preparation.PreparationMessage)3 Step (org.talend.dataprep.api.preparation.Step)3 CacheKeyGenerator (org.talend.dataprep.cache.CacheKeyGenerator)3