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:
@@ -31,8 +31,11 @@ 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;
|
||||||
@@ -128,34 +131,51 @@ public class PdfBoxMetadataExtracterTest extends AbstractMetadataExtracterTest
|
|||||||
|
|
||||||
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
|
||||||
|
Reference in New Issue
Block a user