Add a bit more 'wiggle room' to the timeout test, which missed the cutoff by 8ms, and fixed formatting

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@56009 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2013-09-26 03:30:36 +00:00
parent 6f5e0966bf
commit 0b7bceb769
2 changed files with 60 additions and 60 deletions

View File

@@ -104,8 +104,8 @@ public abstract class AbstractMetadataExtracterTest extends TestCase
Map<QName, Serializable> properties = extractFromMimetype(mimetype); Map<QName, Serializable> properties = extractFromMimetype(mimetype);
// check we got something // check we got something
assertFalse("extractFromMimetype should return at least some properties, none found for " + mimetype, assertFalse("extractFromMimetype should return at least some properties, none found for " + mimetype,
properties.isEmpty()); properties.isEmpty());
// check common metadata // check common metadata
testCommonMetadata(mimetype, properties); testCommonMetadata(mimetype, properties);
@@ -184,10 +184,10 @@ public abstract class AbstractMetadataExtracterTest extends TestCase
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_TITLE))); DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_TITLE)));
if (!skipDescriptionCheck(mimetype)) if (!skipDescriptionCheck(mimetype))
{ {
assertEquals( assertEquals(
"Property " + ContentModel.PROP_DESCRIPTION + " not found for mimetype " + mimetype, "Property " + ContentModel.PROP_DESCRIPTION + " not found for mimetype " + mimetype,
QUICK_DESCRIPTION, QUICK_DESCRIPTION,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_DESCRIPTION))); DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_DESCRIPTION)));
} }
} }
protected abstract void testFileSpecificMetadata(String mimetype, Map<QName, Serializable> properties); protected abstract void testFileSpecificMetadata(String mimetype, Map<QName, Serializable> properties);
@@ -201,7 +201,7 @@ public abstract class AbstractMetadataExtracterTest extends TestCase
*/ */
protected boolean skipAuthorCheck(String mimetype) protected boolean skipAuthorCheck(String mimetype)
{ {
return false; return false;
} }
/** /**
@@ -213,7 +213,7 @@ public abstract class AbstractMetadataExtracterTest extends TestCase
*/ */
protected boolean skipDescriptionCheck(String mimetype) protected boolean skipDescriptionCheck(String mimetype)
{ {
return false; return false;
} }

View File

@@ -20,7 +20,6 @@ package org.alfresco.repo.content.metadata;
import java.io.File; import java.io.File;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -69,15 +68,15 @@ public class PoiMetadataExtracterTest extends AbstractMetadataExtracterTest
{ {
for (String mimetype : PoiMetadataExtracter.SUPPORTED_MIMETYPES) for (String mimetype : PoiMetadataExtracter.SUPPORTED_MIMETYPES)
{ {
testExtractFromMimetype(mimetype); testExtractFromMimetype(mimetype);
} }
} }
@Override @Override
protected boolean skipDescriptionCheck(String mimetype) protected boolean skipDescriptionCheck(String mimetype)
{ {
// Our 3 OpenOffice 07 quick files have no description properties. // Our 3 OpenOffice 07 quick files have no description properties.
return true; return true;
} }
@@ -85,63 +84,64 @@ public class PoiMetadataExtracterTest extends AbstractMetadataExtracterTest
protected void testFileSpecificMetadata(String mimetype, protected void testFileSpecificMetadata(String mimetype,
Map<QName, Serializable> properties) Map<QName, Serializable> properties)
{ {
// This test class is testing 3 files: quick.docx, quick.xlsx & quick.pptx. // This test class is testing 3 files: quick.docx, quick.xlsx & quick.pptx.
// Their created times are hard-coded here for checking. // Their created times are hard-coded here for checking.
// Of course this means that if the files are updated, the test will break // Of course this means that if the files are updated, the test will break
// but those files are rarely modified - only added to. // but those files are rarely modified - only added to.
if (MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING.equals(mimetype)) if (MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING.equals(mimetype))
{ {
checkFileCreationDate(mimetype, properties, "2010-01-06T17:32:00.000Z"); checkFileCreationDate(mimetype, properties, "2010-01-06T17:32:00.000Z");
} }
else if (MimetypeMap.MIMETYPE_OPENXML_SPREADSHEET.equals(mimetype)) else if (MimetypeMap.MIMETYPE_OPENXML_SPREADSHEET.equals(mimetype))
{ {
checkFileCreationDate(mimetype, properties, "1996-10-15T00:33:28.000+01:00"); checkFileCreationDate(mimetype, properties, "1996-10-15T00:33:28.000+01:00");
} }
else if (MimetypeMap.MIMETYPE_OPENXML_PRESENTATION.equals(mimetype)) else if (MimetypeMap.MIMETYPE_OPENXML_PRESENTATION.equals(mimetype))
{ {
// Extraordinary! This document predates Isaac Newton's Principia Mathematica by almost a century. ;) // Extraordinary! This document predates Isaac Newton's Principia Mathematica by almost a century. ;)
checkFileCreationDate(mimetype, properties, "1601-01-01T00:00:00.000Z"); checkFileCreationDate(mimetype, properties, "1601-01-01T00:00:00.000Z");
} }
} }
private void checkFileCreationDate(String mimetype, Map<QName, Serializable> properties, String date) private void checkFileCreationDate(String mimetype, Map<QName, Serializable> properties, String date)
{ {
assertEquals("Property " + ContentModel.PROP_CREATED + " not found for mimetype " + mimetype, date, assertEquals("Property " + ContentModel.PROP_CREATED + " not found for mimetype " + mimetype, date,
DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_CREATED))); DefaultTypeConverter.INSTANCE.convert(String.class, properties.get(ContentModel.PROP_CREATED)));
} }
/** /**
* Tests that metadata extraction from a somewhat corrupt file with several * Tests that metadata extraction from a somewhat corrupt file with several
* thousand footnotes times out properly. * thousand footnotes times out properly.
* *
* @throws Exception * @throws Exception
*/ */
public void testProblemFootnotes() throws Exception public void testProblemFootnotes() throws Exception
{ {
long timeoutMs = 2000; long timeoutMs = 2000;
MetadataExtracterLimits limits = new MetadataExtracterLimits(); MetadataExtracterLimits limits = new MetadataExtracterLimits();
limits.setTimeoutMs(timeoutMs); limits.setTimeoutMs(timeoutMs);
HashMap<String, MetadataExtracterLimits> mimetypeLimits = HashMap<String, MetadataExtracterLimits> mimetypeLimits =
new HashMap<String, MetadataExtracterLimits>(1); new HashMap<String, MetadataExtracterLimits>(1);
mimetypeLimits.put("*", limits); mimetypeLimits.put("*", limits);
((PoiMetadataExtracter) getExtracter()).setMimetypeLimits(mimetypeLimits); ((PoiMetadataExtracter) getExtracter()).setMimetypeLimits(mimetypeLimits);
File sourceFile = AbstractContentTransformerTest.loadNamedQuickTestFile("problemFootnotes.docx"); File sourceFile = AbstractContentTransformerTest.loadNamedQuickTestFile("problemFootnotes.docx");
long startTime = (new Date()).getTime(); Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
// construct a reader onto the source file // construct a reader onto the source file
ContentReader sourceReader = new FileContentReader(sourceFile); ContentReader sourceReader = new FileContentReader(sourceFile);
sourceReader.setMimetype(MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING); sourceReader.setMimetype(MimetypeMap.MIMETYPE_OPENXML_WORDPROCESSING);
long startTime = System.currentTimeMillis();
getExtracter().extract(sourceReader, properties); getExtracter().extract(sourceReader, properties);
long extractionTime = (new Date()).getTime() - startTime; long extractionTime = System.currentTimeMillis() - startTime;
assertTrue("Metadata extraction took (" + extractionTime + "ms) " + assertTrue("Metadata extraction took (" + extractionTime + "ms) " +
"but should have failed with a timeout at " + timeoutMs + "ms", "but should have failed with a timeout at " + timeoutMs + "ms",
extractionTime < (timeoutMs + 50)); // bit of wiggle room for logging, cleanup, etc. extractionTime < (timeoutMs + 100)); // bit of wiggle room for logging, cleanup, etc.
assertFalse("Reader was not closed", sourceReader.isChannelOpen()); assertFalse("Reader was not closed", sourceReader.isChannelOpen());
} }
} }