mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-15 15:02:20 +00:00
REPO-1525: PdfBoxMetadataExtracterTest failures on Oracle, MSSQL Server, DB2
- An attempt to fix the test (refactored the checks and timeouts) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@132496 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -23,41 +23,44 @@
|
|||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.repo.content.metadata;
|
package org.alfresco.repo.content.metadata;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.repo.content.MimetypeMap;
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
|
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
|
||||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
import org.apache.pdfbox.util.DateConverter;
|
import org.apache.pdfbox.util.DateConverter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.alfresco.repo.content.metadata.PdfBoxMetadataExtracter
|
* @see org.alfresco.repo.content.metadata.PdfBoxMetadataExtracter
|
||||||
*
|
*
|
||||||
* @author Jesper Steen Møller
|
* @author Jesper Steen Møller
|
||||||
*/
|
*/
|
||||||
public class PdfBoxMetadataExtracterTest extends AbstractMetadataExtracterTest
|
public class PdfBoxMetadataExtracterTest extends AbstractMetadataExtracterTest
|
||||||
{
|
{
|
||||||
private PdfBoxMetadataExtracter extracter;
|
private PdfBoxMetadataExtracter extracter;
|
||||||
|
|
||||||
private static final int MAX_CONCURENT_EXTRACTIONS = 5;
|
private static final int MAX_CONCURENT_EXTRACTIONS = 5;
|
||||||
private static final double MAX_DOC_SIZE_MB = 0.03;
|
private static final double MAX_DOC_SIZE_MB = 0.03;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception
|
public void setUp() throws Exception
|
||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
extracter = new PdfBoxMetadataExtracter();
|
extracter = new PdfBoxMetadataExtracter();
|
||||||
extracter.setDictionaryService(dictionaryService);
|
extracter.setDictionaryService(dictionaryService);
|
||||||
|
|
||||||
MetadataExtracterLimits pdfLimit = new MetadataExtracterLimits();
|
MetadataExtracterLimits pdfLimit = new MetadataExtracterLimits();
|
||||||
@@ -66,96 +69,113 @@ public class PdfBoxMetadataExtracterTest extends AbstractMetadataExtracterTest
|
|||||||
Map<String,MetadataExtracterLimits> limits = new HashMap<>();
|
Map<String,MetadataExtracterLimits> limits = new HashMap<>();
|
||||||
limits.put(MimetypeMap.MIMETYPE_PDF,pdfLimit);
|
limits.put(MimetypeMap.MIMETYPE_PDF,pdfLimit);
|
||||||
|
|
||||||
extracter.setMimetypeLimits(limits);
|
extracter.setMimetypeLimits(limits);
|
||||||
extracter.register();
|
extracter.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the same transformer regardless - it is allowed
|
* @return Returns the same transformer regardless - it is allowed
|
||||||
*/
|
*/
|
||||||
protected MetadataExtracter getExtracter()
|
protected MetadataExtracter getExtracter()
|
||||||
{
|
{
|
||||||
return extracter;
|
return extracter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSupports() throws Exception
|
public void testSupports() throws Exception
|
||||||
{
|
{
|
||||||
for (String mimetype : PdfBoxMetadataExtracter.SUPPORTED_MIMETYPES)
|
for (String mimetype : PdfBoxMetadataExtracter.SUPPORTED_MIMETYPES)
|
||||||
{
|
{
|
||||||
boolean supports = extracter.isSupported(mimetype);
|
boolean supports = extracter.isSupported(mimetype);
|
||||||
assertTrue("Mimetype should be supported: " + mimetype, supports);
|
assertTrue("Mimetype should be supported: " + mimetype, supports);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPdfExtraction() throws Exception
|
public void testPdfExtraction() throws Exception
|
||||||
{
|
{
|
||||||
testExtractFromMimetype(MimetypeMap.MIMETYPE_PDF);
|
testExtractFromMimetype(MimetypeMap.MIMETYPE_PDF);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test method extracts metadata from an Adobe Illustrator file (which in recent versions is a pdf file).
|
* This test method extracts metadata from an Adobe Illustrator file (which in recent versions is a pdf file).
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*/
|
*/
|
||||||
public void testAiExtraction() throws Exception
|
public void testAiExtraction() throws Exception
|
||||||
{
|
{
|
||||||
testExtractFromMimetype(MimetypeMap.MIMETYPE_APPLICATION_ILLUSTRATOR);
|
testExtractFromMimetype(MimetypeMap.MIMETYPE_APPLICATION_ILLUSTRATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We can also return a created date
|
* We can also return a created date
|
||||||
*/
|
*/
|
||||||
protected void testFileSpecificMetadata(String mimetype,
|
protected void testFileSpecificMetadata(String mimetype,
|
||||||
Map<QName, Serializable> properties) {
|
Map<QName, Serializable> properties) {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Property " + ContentModel.PROP_CREATED + " not found for mimetype " + mimetype,
|
"Property " + ContentModel.PROP_CREATED + " not found for mimetype " + mimetype,
|
||||||
"2005-05-26T19:52:58.000Z",
|
"2005-05-26T19:52:58.000Z",
|
||||||
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_CREATED)));
|
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_CREATED)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that will show when the workaround is in place.
|
* Test that will show when the workaround is in place.
|
||||||
*/
|
*/
|
||||||
public void testDateConversion() throws Exception {
|
public void testDateConversion() throws Exception {
|
||||||
Calendar c = DateConverter.toCalendar("D:20050526205258+01'00'");
|
Calendar c = DateConverter.toCalendar("D:20050526205258+01'00'");
|
||||||
assertEquals(2005, c.get(Calendar.YEAR));
|
assertEquals(2005, c.get(Calendar.YEAR));
|
||||||
assertEquals(05-1, c.get(Calendar.MONTH));
|
assertEquals(05-1, c.get(Calendar.MONTH));
|
||||||
assertEquals(26, c.get(Calendar.DAY_OF_MONTH));
|
assertEquals(26, c.get(Calendar.DAY_OF_MONTH));
|
||||||
assertEquals(20, c.get(Calendar.HOUR_OF_DAY));
|
assertEquals(20, c.get(Calendar.HOUR_OF_DAY));
|
||||||
assertEquals(52, c.get(Calendar.MINUTE));
|
assertEquals(52, c.get(Calendar.MINUTE));
|
||||||
assertEquals(58, c.get(Calendar.SECOND));
|
assertEquals(58, c.get(Calendar.SECOND));
|
||||||
//assertEquals(0, c.get(Calendar.MILLISECOND));
|
//assertEquals(0, c.get(Calendar.MILLISECOND));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConcurrentExtractions() throws InterruptedException
|
public void testConcurrentExtractions() throws InterruptedException
|
||||||
{
|
{
|
||||||
int threadNum = 10;
|
int threadNum = 11;
|
||||||
final CountDownLatch extractionsCountDown = new CountDownLatch(threadNum);
|
Map<String, Boolean> threadResults = new ConcurrentHashMap<>();
|
||||||
for (int i = 0; i < threadNum; i++)
|
for (int i = 0; i < threadNum; i++)
|
||||||
{
|
{
|
||||||
Thread t = new Thread(new Runnable()
|
new Thread(new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Map<QName, Serializable> properties = extractFromMimetype(MimetypeMap.MIMETYPE_PDF);
|
threadResults.put(Thread.currentThread().getName(),
|
||||||
if (!properties.isEmpty())
|
!extractFromMimetype(MimetypeMap.MIMETYPE_PDF).isEmpty());
|
||||||
{
|
|
||||||
extractionsCountDown.countDown();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
t.start();
|
}).start();
|
||||||
}
|
}
|
||||||
extractionsCountDown.await(1000, TimeUnit.MILLISECONDS);
|
int numWaits = 100;
|
||||||
long rejectedExtractions = extractionsCountDown.getCount();
|
while (numWaits > 0)
|
||||||
assertTrue("Wrong number of rejected extractions", rejectedExtractions == (threadNum - MAX_CONCURENT_EXTRACTIONS));
|
{
|
||||||
|
Thread.sleep(50);
|
||||||
|
if (threadResults.size() == threadNum)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
numWaits--;
|
||||||
|
}
|
||||||
|
Map<Boolean, Integer> counted = new HashMap<>();
|
||||||
|
counted.put(Boolean.FALSE, 0);
|
||||||
|
counted.put(Boolean.TRUE, 0);
|
||||||
|
for (Boolean result : threadResults.values())
|
||||||
|
{
|
||||||
|
counted.put(result, counted.get(result)+1);
|
||||||
|
}
|
||||||
|
assertEquals("Wrong number of failed extractions.",
|
||||||
|
new Integer(threadNum - MAX_CONCURENT_EXTRACTIONS),
|
||||||
|
counted.get(Boolean.FALSE));
|
||||||
|
assertEquals("Wrong number of successful extractions.",
|
||||||
|
new Integer(MAX_CONCURENT_EXTRACTIONS),
|
||||||
|
counted.get(Boolean.TRUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMaxDocumentSizeLimit() throws Exception
|
public void testMaxDocumentSizeLimit() throws Exception
|
||||||
@@ -168,5 +188,5 @@ public class PdfBoxMetadataExtracterTest extends AbstractMetadataExtracterTest
|
|||||||
}
|
}
|
||||||
Map<QName, Serializable> properties = extractFromFile(sourceFile, MimetypeMap.MIMETYPE_PDF);
|
Map<QName, Serializable> properties = extractFromFile(sourceFile, MimetypeMap.MIMETYPE_PDF);
|
||||||
assertTrue(properties.isEmpty());
|
assertTrue(properties.isEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user