Search in sources :

Example 26 with TransformationOptionLimits

use of org.alfresco.service.cmr.repository.TransformationOptionLimits in project alfresco-repository by Alfresco.

the class PoiOOXMLContentTransformerTest method testMnt12043.

/**
 * MNT-12043: CLONE - Upload of PPTX causes very high memory usage leading to system instability
 *
 * @throws Exception
 */
public void testMnt12043() throws Exception {
    transformer.setMimetypeService(mimetypeService);
    transformer.setAdditionalThreadTimout(0);
    configureExtractorLimits(transformer, SMALL_TIMEOUT);
    File sourceFile = AbstractContentTransformerTest.loadNamedQuickTestFile(TEST_PPTX_FILE_NAME);
    ContentReader sourceReader = new FileContentReader(sourceFile) {

        @Override
        public void setLimits(TransformationOptionLimits limits) {
        // Test without content reader input stream timeout limits
        }
    };
    sourceReader.setMimetype(MimetypeMap.MIMETYPE_OPENXML_PRESENTATION);
    ContentWriter tempWriter = AuthenticationUtil.runAs(new RunAsWork<ContentWriter>() {

        @Override
        public ContentWriter doWork() throws Exception {
            ContentWriter result = contentService.getTempWriter();
            result.setEncoding(ENCODING_UTF_8);
            result.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
            return result;
        }
    }, AuthenticationUtil.getAdminUserName());
    long startTime = System.currentTimeMillis();
    try {
        transformer.transform(sourceReader, tempWriter);
        // should not get here unless transform is too fast
        long transformationTime = System.currentTimeMillis() - startTime;
        fail("Content transformation took " + transformationTime + " ms, but should have failed with a timeout at " + SMALL_TIMEOUT + " ms");
    } catch (ContentIOException e) {
        long transformationTime = System.currentTimeMillis() - startTime;
        assertTrue((TimeoutException.class.getName() + " exception is expected as the cause of transformation failure"), e.getCause() instanceof TimeoutException);
        // Not sure we can have the following assert as we may have introduced an intermittent test failure. Already seen a time of 1009ms
        assertTrue(("Failed content transformation took " + transformationTime + " ms, but should have failed with a timeout at " + SMALL_TIMEOUT + " ms"), transformationTime <= (SMALL_TIMEOUT + ADDITIONAL_PROCESSING_TIME));
    }
    assertFalse("Readable channel was not closed after transformation attempt!", sourceReader.isChannelOpen());
    assertFalse("Writable channel was not closed after transformation attempt!", tempWriter.isChannelOpen());
}
Also used : ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileContentReader(org.alfresco.repo.content.filestore.FileContentReader) TransformationOptionLimits(org.alfresco.service.cmr.repository.TransformationOptionLimits) FileContentReader(org.alfresco.repo.content.filestore.FileContentReader) ContentReader(org.alfresco.service.cmr.repository.ContentReader) File(java.io.File) TimeoutException(java.util.concurrent.TimeoutException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) ContentIOException(org.alfresco.service.cmr.repository.ContentIOException) TimeoutException(java.util.concurrent.TimeoutException)

Example 27 with TransformationOptionLimits

use of org.alfresco.service.cmr.repository.TransformationOptionLimits in project alfresco-repository by Alfresco.

the class TransformerConfigLimitsTest method defaultMimetypesUseTest.

@Test
public // A value is specified as a transformer default with mimetypes and use
void defaultMimetypesUseTest() {
    mockProperties(transformerProperties, "content.transformer.default.extensions.pdf.png.maxSourceSizeKBytes", "10", "content.transformer.default.extensions.pdf.png.maxSourceSizeKBytes.use.index", "20", // The following is ignored when "index" is specified, as the 'use' property is system wide.
    "content.transformer.transformer2.maxSourceSizeKBytes", "30");
    extractor = new TransformerConfigLimits(transformerProperties, mimetypeService);
    TransformationOptionLimits limits = extractor.getLimits(transformer1, "application/pdf", "image/png", null);
    assertEquals(10, limits.getMaxSourceSizeKBytes());
    limits = extractor.getLimits(transformer2, "application/pdf", "image/png", "doclib");
    assertEquals(30, limits.getMaxSourceSizeKBytes());
    limits = extractor.getLimits(transformer2, "application/pdf", "image/png", "index");
    assertEquals(20, limits.getMaxSourceSizeKBytes());
}
Also used : TransformationOptionLimits(org.alfresco.service.cmr.repository.TransformationOptionLimits) Test(org.junit.Test)

Example 28 with TransformationOptionLimits

use of org.alfresco.service.cmr.repository.TransformationOptionLimits in project alfresco-repository by Alfresco.

the class TransformerConfigLimitsTest method propertyOrderJava8or6Test.

@Test
public void propertyOrderJava8or6Test() {
    mockProperties(transformerProperties, "content.transformer.default.timeoutMs", "-1", "content.transformer.default.readLimitTimeMs", "120000");
    extractor = new TransformerConfigLimits(transformerProperties, mimetypeService);
    TransformationOptionLimits limits = extractor.getLimits(transformer1, "text/plain", "image/png", null);
    assertEquals(-1L, limits.getTimeoutMs());
    assertEquals(120000L, limits.getReadLimitTimeMs());
}
Also used : TransformationOptionLimits(org.alfresco.service.cmr.repository.TransformationOptionLimits) Test(org.junit.Test)

Example 29 with TransformationOptionLimits

use of org.alfresco.service.cmr.repository.TransformationOptionLimits in project alfresco-repository by Alfresco.

the class TransformerConfigLimitsTest method transformerUseTest.

@Test
public // A value is specified for a transformer and use
void transformerUseTest() {
    mockProperties(transformerProperties, "content.transformer.transformer2.maxSourceSizeKBytes", "10", "content.transformer.transformer1.maxSourceSizeKBytes.use.index", "20", // The following is ignored when "index" is specified, as the 'use' property is transformer wide.
    "content.transformer.transformer1.maxSourceSizeKBytes", "30");
    extractor = new TransformerConfigLimits(transformerProperties, mimetypeService);
    TransformationOptionLimits limits = extractor.getLimits(transformer1, "application/pdf", "image/png", null);
    assertEquals(30, limits.getMaxSourceSizeKBytes());
    limits = extractor.getLimits(transformer1, "application/pdf", "image/png", "index");
    assertEquals(20, limits.getMaxSourceSizeKBytes());
    limits = extractor.getLimits(transformer2, "application/pdf", "image/png", "index");
    assertEquals(10, limits.getMaxSourceSizeKBytes());
}
Also used : TransformationOptionLimits(org.alfresco.service.cmr.repository.TransformationOptionLimits) Test(org.junit.Test)

Example 30 with TransformationOptionLimits

use of org.alfresco.service.cmr.repository.TransformationOptionLimits in project alfresco-repository by Alfresco.

the class TransformerConfigLimitsTest method defaultUseTest.

@Test
public // A value is specified as a transformer default without mimetypes but with a use
void defaultUseTest() {
    mockProperties(transformerProperties, "content.transformer.default.maxSourceSizeKBytes", "10", "content.transformer.default.maxSourceSizeKBytes.use.index", "20");
    extractor = new TransformerConfigLimits(transformerProperties, mimetypeService);
    TransformationOptionLimits limits = extractor.getLimits(transformer1, "application/pdf", "image/png", null);
    assertEquals(10, limits.getMaxSourceSizeKBytes());
    limits = extractor.getLimits(transformer1, "application/pdf", "image/png", "index");
    assertEquals(20, limits.getMaxSourceSizeKBytes());
}
Also used : TransformationOptionLimits(org.alfresco.service.cmr.repository.TransformationOptionLimits) Test(org.junit.Test)

Aggregations

TransformationOptionLimits (org.alfresco.service.cmr.repository.TransformationOptionLimits)39 Test (org.junit.Test)22 Map (java.util.Map)3 TransformationOptions (org.alfresco.service.cmr.repository.TransformationOptions)3 TimeoutException (java.util.concurrent.TimeoutException)2 AbstractContentReader (org.alfresco.repo.content.AbstractContentReader)2 ImageResizeOptions (org.alfresco.repo.content.transform.magick.ImageResizeOptions)2 ImageTransformationOptions (org.alfresco.repo.content.transform.magick.ImageTransformationOptions)2 SWFTransformationOptions (org.alfresco.repo.content.transform.swf.SWFTransformationOptions)2 ContentIOException (org.alfresco.service.cmr.repository.ContentIOException)2 TransformationOptionPair (org.alfresco.service.cmr.repository.TransformationOptionPair)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1