REPO-1525: PdfBoxMetadataExtracterTest failures on all DBs (including main PostgreSQL build)

- Committed whitespaces to satisfy license checker...


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@132695 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alex Mukha
2016-11-10 22:28:24 +00:00
parent 52d8d9cf59
commit 17f9b1cf00

View File

@@ -1,153 +1,153 @@
/* /*
* #%L * #%L
* Alfresco Repository * Alfresco Repository
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* 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 org.alfresco.repo.content.MimetypeMap; import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import java.io.Serializable; import java.io.Serializable;
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.ConcurrentHashMap;
/** /**
* The test designed for testing the concurrent limitations in * The test designed for testing the concurrent limitations in
* {@link AbstractMappingMetadataExtracter#extractRaw(ContentReader, MetadataExtracterLimits)} * {@link AbstractMappingMetadataExtracter#extractRaw(ContentReader, MetadataExtracterLimits)}
* *
* @author amukha * @author amukha
*/ */
public class ConcurrencyPdfBoxMetadataExtracterTest extends AbstractMetadataExtracterTest public class ConcurrencyPdfBoxMetadataExtracterTest extends AbstractMetadataExtracterTest
{ {
private SlowPdfBoxMetadataExtracter extracter; private SlowPdfBoxMetadataExtracter 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;
private static final int NUMBER_OF_CONCURRENT_THREADS = 11; private static final int NUMBER_OF_CONCURRENT_THREADS = 11;
@Override @Override
public void setUp() throws Exception public void setUp() throws Exception
{ {
super.setUp(); super.setUp();
extracter = new SlowPdfBoxMetadataExtracter(); extracter = new SlowPdfBoxMetadataExtracter();
extracter.setDictionaryService(dictionaryService); extracter.setDictionaryService(dictionaryService);
MetadataExtracterLimits pdfLimit = new MetadataExtracterLimits(); MetadataExtracterLimits pdfLimit = new MetadataExtracterLimits();
pdfLimit.setMaxConcurrentExtractionsCount(MAX_CONCURENT_EXTRACTIONS); pdfLimit.setMaxConcurrentExtractionsCount(MAX_CONCURENT_EXTRACTIONS);
pdfLimit.setMaxDocumentSizeMB(MAX_DOC_SIZE_MB); pdfLimit.setMaxDocumentSizeMB(MAX_DOC_SIZE_MB);
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.setDelay(30*NUMBER_OF_CONCURRENT_THREADS); extracter.setDelay(30*NUMBER_OF_CONCURRENT_THREADS);
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;
} }
protected void testFileSpecificMetadata(String mimetype, Map<QName, Serializable> properties) protected void testFileSpecificMetadata(String mimetype, Map<QName, Serializable> properties)
{ {
// not required // not required
} }
public void testConcurrentExtractions() throws InterruptedException public void testConcurrentExtractions() throws InterruptedException
{ {
final Map<String, Boolean> threadResults = new ConcurrentHashMap<>(); final Map<String, Boolean> threadResults = new ConcurrentHashMap<>();
for (int i = 0; i < NUMBER_OF_CONCURRENT_THREADS; i++) for (int i = 0; i < NUMBER_OF_CONCURRENT_THREADS; i++)
{ {
new Thread(new Runnable() new Thread(new Runnable()
{ {
@Override @Override
public void run() public void run()
{ {
System.out.println(Thread.currentThread().getName() + " started " + System.currentTimeMillis()); System.out.println(Thread.currentThread().getName() + " started " + System.currentTimeMillis());
try try
{ {
Map<QName, Serializable> results = extractFromMimetype(MimetypeMap.MIMETYPE_PDF); Map<QName, Serializable> results = extractFromMimetype(MimetypeMap.MIMETYPE_PDF);
System.out.println(Thread.currentThread().getName() + " results are " + results); System.out.println(Thread.currentThread().getName() + " results are " + results);
threadResults.put(Thread.currentThread().getName(), !results.isEmpty()); threadResults.put(Thread.currentThread().getName(), !results.isEmpty());
} }
catch (Exception e) catch (Exception e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
System.out.println(Thread.currentThread().getName() + " finished " + System.currentTimeMillis()); System.out.println(Thread.currentThread().getName() + " finished " + System.currentTimeMillis());
} }
}).start(); }).start();
} }
int numWaits = NUMBER_OF_CONCURRENT_THREADS*10; int numWaits = NUMBER_OF_CONCURRENT_THREADS*10;
while (numWaits > 0) while (numWaits > 0)
{ {
Thread.sleep(50); Thread.sleep(50);
if (threadResults.size() == NUMBER_OF_CONCURRENT_THREADS) if (threadResults.size() == NUMBER_OF_CONCURRENT_THREADS)
{ {
break; break;
} }
numWaits--; numWaits--;
} }
Map<Boolean, Integer> counted = new HashMap<>(); Map<Boolean, Integer> counted = new HashMap<>();
counted.put(Boolean.FALSE, 0); counted.put(Boolean.FALSE, 0);
counted.put(Boolean.TRUE, 0); counted.put(Boolean.TRUE, 0);
for (Boolean result : threadResults.values()) for (Boolean result : threadResults.values())
{ {
counted.put(result, counted.get(result)+1); counted.put(result, counted.get(result)+1);
} }
assertEquals("Wrong number of failed extractions.", assertEquals("Wrong number of failed extractions.",
new Integer(NUMBER_OF_CONCURRENT_THREADS - MAX_CONCURENT_EXTRACTIONS), new Integer(NUMBER_OF_CONCURRENT_THREADS - MAX_CONCURENT_EXTRACTIONS),
counted.get(Boolean.FALSE)); counted.get(Boolean.FALSE));
assertEquals("Wrong number of successful extractions.", assertEquals("Wrong number of successful extractions.",
new Integer(MAX_CONCURENT_EXTRACTIONS), new Integer(MAX_CONCURENT_EXTRACTIONS),
counted.get(Boolean.TRUE)); counted.get(Boolean.TRUE));
} }
private class SlowPdfBoxMetadataExtracter extends PdfBoxMetadataExtracter private class SlowPdfBoxMetadataExtracter extends PdfBoxMetadataExtracter
{ {
private long delay = 0; private long delay = 0;
public void setDelay(long delay) public void setDelay(long delay)
{ {
this.delay = delay; this.delay = delay;
} }
@Override @Override
protected Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable protected Map<String, Serializable> extractRaw(ContentReader reader) throws Throwable
{ {
Thread.sleep(delay); Thread.sleep(delay);
Map<String, Serializable> results = super.extractRaw(reader); Map<String, Serializable> results = super.extractRaw(reader);
System.out.println(Thread.currentThread().getName() + " results are " + results); System.out.println(Thread.currentThread().getName() + " results are " + results);
return results; return results;
} }
} }
} }