Skip to content

Commit

Permalink
[bug-64441] add test case
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1877747 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
pjfanning committed May 14, 2020
1 parent 23337fa commit 24345ed
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java
Expand Up @@ -28,6 +28,10 @@ Licensed to the Apache Software Foundation (ASF) under one or more
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;
Expand Down Expand Up @@ -437,10 +441,37 @@ public void testCreateEmpty() throws Exception {
closeOrRevert(wb);
}

@Test
public void testOpenManyHSSF() throws Exception {
final int size = 1000;
ExecutorService executorService = Executors.newFixedThreadPool(10);
ArrayList<Future<Boolean>> futures = new ArrayList(size);
for (int i = 0; i < size; i++) {
futures.add(executorService.submit(() -> openHSSFFile()));
}
for (Future<Boolean> 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;
}
}
}

0 comments on commit 24345ed

Please sign in to comment.