diff options
author | PJ Fanning <fanningpj@apache.org> | 2019-03-27 21:24:25 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2019-03-27 21:24:25 +0000 |
commit | 80dc4b34c9223f85093eb816c803e479f08722f5 (patch) | |
tree | 6e4e5651f04f6ec8c117c77a3b81b744ccc04541 /src | |
parent | 89d34e6c64e52f1c279fb5cd074eb5ea0f555207 (diff) | |
download | poi-80dc4b34c9223f85093eb816c803e479f08722f5.tar.gz poi-80dc4b34c9223f85093eb816c803e479f08722f5.zip |
add test for concurrent use of DataFormatter
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1856439 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java index a4aa5f4ea7..8195a92c09 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java +++ b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java @@ -28,11 +28,9 @@ import static org.junit.Assert.fail; import java.io.IOException; import java.text.DateFormat; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Locale; +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.usermodel.HSSFWorkbook; @@ -938,4 +936,46 @@ public class TestDataFormatter { String value = df.formatCellValue(cell, wb.getCreationHelper().createFormulaEvaluator()); assertEquals("-130", value); } + + @Test + public void testConcurrentCellFormat() throws Exception { + int formatIndex = 105; + String formatString = "[$-F400]m/d/yy h:mm:ss\\ AM/PM;[$-F400]m/d/yy h:mm:ss\\ AM/PM;_-* \"\"??_-;_-@_-"; + + DataFormatter formatter = new DataFormatter(); + doFormatTestSequential(formatter, 43551.50990171296, "3/27/19 12:14:15 PM", formatIndex, formatString); + doFormatTestSequential(formatter, 36104.424780092595, "11/5/98 10:11:41 AM", formatIndex, formatString); + + doFormatTestConcurrent(formatter, 43551.50990171296, "3/27/19 12:14:15 PM", formatIndex, formatString); + doFormatTestConcurrent(formatter, 36104.424780092595, "11/5/98 10:11:41 AM", formatIndex, formatString); + } + + private void doFormatTestSequential(DataFormatter formatter, double n, String expected, int formatIndex, + String formatString) { + for (int i = 0; i < 1_000; i++) { + assertTrue(doFormatTest(formatter, n, expected, formatIndex, formatString, i)); + } + } + + private void doFormatTestConcurrent(DataFormatter formatter, double n, String expected, int formatIndex, + String formatString) throws Exception { + ArrayList<CompletableFuture<Boolean>> futures = new ArrayList<>(); + for (int i = 0; i < 1_000; i++) { + final int iteration = i; + CompletableFuture<Boolean> future = CompletableFuture.supplyAsync( + () -> { return doFormatTest(formatter, n, expected, formatIndex, formatString, iteration); }); + futures.add(future); + } + for (CompletableFuture<Boolean> future : futures) { + assertTrue(future.get(1, TimeUnit.MINUTES)); + } + } + + private static boolean doFormatTest(DataFormatter formatter, double n, String expected, int formatIndex, + String formatString, int iteration) { + String actual = formatter.formatRawCellContents(n, formatIndex, formatString); + assertEquals("Failed on iteration " + iteration, expected, actual); + return true; + } + }
\ No newline at end of file |