Reduce required memory in tests by not actually creating all the rows/cells when verifying the max number of cellstyles. Hopefully this will avoid the OOMs that we see in various CI environments currently while still verifying the limits correctly.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1697326 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2015-08-24 08:12:01 +00:00
parent 2d677beac8
commit 639b847d6e
2 changed files with 16 additions and 15 deletions

View File

@ -741,6 +741,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
/** /**
* Excel .xls style indexed colours in a .xlsx file * Excel .xls style indexed colours in a .xlsx file
*/ */
@SuppressWarnings("deprecation")
@Test @Test
public void bug50786() throws Exception { public void bug50786() throws Exception {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50786-indexed_colours.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50786-indexed_colours.xlsx");
@ -792,6 +793,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
* then being set explicitly still should allow the * then being set explicitly still should allow the
* fetching of the RGB. * fetching of the RGB.
*/ */
@SuppressWarnings("deprecation")
@Test @Test
public void bug50784() throws Exception { public void bug50784() throws Exception {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50784-font_theme_colours.xlsx"); XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("50784-font_theme_colours.xlsx");
@ -1802,7 +1804,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
// Now check the spreadsheet itself // Now check the spreadsheet itself
try { try {
new XSSFWorkbook(pkg); new XSSFWorkbook(pkg).close();
fail("Should fail as too much expansion occurs"); fail("Should fail as too much expansion occurs");
} catch(POIXMLException e) { } catch(POIXMLException e) {
// Expected // Expected
@ -1848,7 +1850,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
// XSSF Workbook gives helpful error // XSSF Workbook gives helpful error
try { try {
new XSSFWorkbook(pkg); new XSSFWorkbook(pkg).close();
fail(".xlsb files not supported"); fail(".xlsb files not supported");
} catch (XLSBUnsupportedException e) { } catch (XLSBUnsupportedException e) {
// Good, detected and warned // Good, detected and warned
@ -2359,7 +2361,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
public void bug57880() throws Exception { public void bug57880() throws Exception {
int numStyles = 33000; int numStyles = 33000;
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet s = wb.createSheet("TestSheet"); //XSSFSheet s = wb.createSheet("TestSheet");
XSSFDataFormat fmt = wb.getCreationHelper().createDataFormat(); XSSFDataFormat fmt = wb.getCreationHelper().createDataFormat();
for (int i=1; i<numStyles; i++) { for (int i=1; i<numStyles; i++) {
short df = fmt.getFormat("test"+i); short df = fmt.getFormat("test"+i);
@ -2369,9 +2371,9 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
XSSFCellStyle style = wb.createCellStyle(); XSSFCellStyle style = wb.createCellStyle();
assertEquals(i, style.getUIndex()); assertEquals(i, style.getUIndex());
style.setDataFormat(df); style.setDataFormat(df);
XSSFCell c = s.createRow(i).createCell(0, Cell.CELL_TYPE_NUMERIC); /*XSSFCell c = s.createRow(i).createCell(0, Cell.CELL_TYPE_NUMERIC);
c.setCellStyle(style); c.setCellStyle(style);
c.setCellValue(i); c.setCellValue(i);*/
} }
// using temp file instead of ByteArrayOutputStream because of OOM in gump run // using temp file instead of ByteArrayOutputStream because of OOM in gump run
@ -2381,12 +2383,12 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
fos.close(); fos.close();
wb.close(); wb.close();
fmt = null; s = null; wb = null; fmt = null; /*s = null;*/ wb = null;
// System.gc(); // System.gc();
wb = new XSSFWorkbook(tmp); wb = new XSSFWorkbook(tmp);
fmt = wb.getCreationHelper().createDataFormat(); fmt = wb.getCreationHelper().createDataFormat();
s = wb.getSheetAt(0); // s = wb.getSheetAt(0);
for (int i=1; i<numStyles; i++) { for (int i=1; i<numStyles; i++) {
XSSFCellStyle style = wb.getCellStyleAt((short)i); XSSFCellStyle style = wb.getCellStyleAt((short)i);
assertNotNull(style); assertNotNull(style);

View File

@ -30,7 +30,6 @@ import java.io.IOException;
import java.text.AttributedString; import java.text.AttributedString;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Random;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.PaneInformation; import org.apache.poi.hssf.util.PaneInformation;
@ -1177,15 +1176,15 @@ public abstract class BaseTestBugzillaIssues {
public void bug58260() throws IOException { public void bug58260() throws IOException {
//Create workbook and worksheet //Create workbook and worksheet
Workbook wb = _testDataProvider.createWorkbook(); Workbook wb = _testDataProvider.createWorkbook();
Sheet worksheet = wb.createSheet("sample"); //Sheet worksheet = wb.createSheet("sample");
//Loop through and add all values from array list //Loop through and add all values from array list
// use a fixed seed to always produce the same file which makes comparing stuff easier // use a fixed seed to always produce the same file which makes comparing stuff easier
Random rnd = new Random(4352345); //Random rnd = new Random(4352345);
int maxStyles = (wb instanceof HSSFWorkbook) ? 4009 : 64000; int maxStyles = (wb instanceof HSSFWorkbook) ? 4009 : 64000;
for(int i = 0;i < maxStyles;i++) { for(int i = 0;i < maxStyles;i++) {
//Create new row //Create new row
Row row = worksheet.createRow(i); //Row row = worksheet.createRow(i);
//Create cell style //Create cell style
final CellStyle style; final CellStyle style;
@ -1206,13 +1205,13 @@ public abstract class BaseTestBugzillaIssues {
} }
//Create cell //Create cell
Cell cell = row.createCell(0); //Cell cell = row.createCell(0);
//Set cell style //Set cell style
cell.setCellStyle(style); //cell.setCellStyle(style);
//Set cell value //Set cell value
cell.setCellValue("r" + rnd.nextInt()); //cell.setCellValue("r" + rnd.nextInt());
} }
// should fail if we try to add more now // should fail if we try to add more now