From 24345edd5e7a98089abac93417522cced20025f0 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 14 May 2020 19:42:06 +0000 Subject: [PATCH] [bug-64441] add test case git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1877747 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/ss/TestWorkbookFactory.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java b/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java index 5df6ce2da3..240ac026c3 100644 --- a/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java +++ b/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java @@ -28,6 +28,10 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import org.apache.poi.EmptyFileException; import org.apache.poi.EncryptedDocumentException; @@ -437,10 +441,37 @@ public final class TestWorkbookFactory { closeOrRevert(wb); } + @Test + public void testOpenManyHSSF() throws Exception { + final int size = 1000; + ExecutorService executorService = Executors.newFixedThreadPool(10); + ArrayList> futures = new ArrayList(size); + for (int i = 0; i < size; i++) { + futures.add(executorService.submit(() -> openHSSFFile())); + } + for (Future future: futures) { + assertTrue(future.get()); + } + } + @Test(expected = IOException.class) public void testInvalidFormatException() throws IOException { String filename = "OPCCompliance_DerivedPartNameFAIL.docx"; WorkbookFactory.create(POIDataSamples.getOpenXML4JInstance().openResourceAsStream(filename)); } + private boolean openHSSFFile() { + try { + // POIFS -> hssf + Workbook wb = WorkbookFactory.create( + new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream(xls)) + ); + assertNotNull(wb); + assertTrue(wb instanceof HSSFWorkbook); + assertCloseDoesNotModifyFile(xls, wb); + return true; + } catch (Exception e) { + return false; + } + } }