mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +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:
@@ -31,8 +31,11 @@ import java.io.Serializable;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
@@ -128,34 +131,51 @@ public class PdfBoxMetadataExtracterTest extends AbstractMetadataExtracterTest
|
||||
|
||||
public void testConcurrentExtractions() throws InterruptedException
|
||||
{
|
||||
int threadNum = 10;
|
||||
final CountDownLatch extractionsCountDown = new CountDownLatch(threadNum);
|
||||
int threadNum = 11;
|
||||
Map<String, Boolean> threadResults = new ConcurrentHashMap<>();
|
||||
for (int i = 0; i < threadNum; i++)
|
||||
{
|
||||
Thread t = new Thread(new Runnable()
|
||||
new Thread(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
Map<QName, Serializable> properties = extractFromMimetype(MimetypeMap.MIMETYPE_PDF);
|
||||
if (!properties.isEmpty())
|
||||
{
|
||||
extractionsCountDown.countDown();
|
||||
}
|
||||
threadResults.put(Thread.currentThread().getName(),
|
||||
!extractFromMimetype(MimetypeMap.MIMETYPE_PDF).isEmpty());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
|
||||
}).start();
|
||||
}
|
||||
extractionsCountDown.await(1000, TimeUnit.MILLISECONDS);
|
||||
long rejectedExtractions = extractionsCountDown.getCount();
|
||||
assertTrue("Wrong number of rejected extractions", rejectedExtractions == (threadNum - MAX_CONCURENT_EXTRACTIONS));
|
||||
int numWaits = 100;
|
||||
while (numWaits > 0)
|
||||
{
|
||||
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
|
||||
|
Reference in New Issue
Block a user