Browse Source

完成large测试

developing
Jiaju Zhuang 3 years ago
parent
commit
c1396b278a
  1. 34
      src/test/java/com/alibaba/easyexcel/test/core/head/ComplexHeadDataTest.java
  2. 17
      src/test/java/com/alibaba/easyexcel/test/core/head/ListHeadDataTest.java
  3. 17
      src/test/java/com/alibaba/easyexcel/test/core/head/NoHeadDataTest.java
  4. 17
      src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataListener.java
  5. 38
      src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataTest.java

34
src/test/java/com/alibaba/easyexcel/test/core/head/ComplexHeadDataTest.java

@ -4,29 +4,35 @@ import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
/**
*
* @author Jiaju Zhuang
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ComplexHeadDataTest {
private static File file07;
private static File file03;
private static File fileCsv;
private static File file07AutomaticMergeHead;
private static File file03AutomaticMergeHead;
private static File fileCsvAutomaticMergeHead;
@BeforeClass
public static void init() {
file07 = TestFileUtil.createNewFile("complexHead07.xlsx");
file03 = TestFileUtil.createNewFile("complexHead03.xls");
fileCsv = TestFileUtil.createNewFile("complexHeadCsv.csv");
file07AutomaticMergeHead = TestFileUtil.createNewFile("complexHeadAutomaticMergeHead07.xlsx");
file03AutomaticMergeHead = TestFileUtil.createNewFile("complexHeadAutomaticMergeHead03.xls");
fileCsvAutomaticMergeHead = TestFileUtil.createNewFile("complexHeadAutomaticMergeHeadCsv.csv");
}
@Test
@ -39,6 +45,11 @@ public class ComplexHeadDataTest {
readAndWrite(file03);
}
@Test
public void t03ReadAndWriteCsv() {
readAndWrite(fileCsv);
}
private void readAndWrite(File file) {
EasyExcel.write(file, ComplexHeadData.class).sheet().doWrite(data());
EasyExcel.read(file, ComplexHeadData.class, new ComplexDataListener())
@ -46,16 +57,21 @@ public class ComplexHeadDataTest {
}
@Test
public void t03ReadAndWriteAutomaticMergeHead07() {
readAndWriteAutomaticMergeHead07(file07AutomaticMergeHead);
public void t11ReadAndWriteAutomaticMergeHead07() {
readAndWriteAutomaticMergeHead(file07AutomaticMergeHead);
}
@Test
public void t12ReadAndWriteAutomaticMergeHead03() {
readAndWriteAutomaticMergeHead(file03AutomaticMergeHead);
}
@Test
public void t04ReadAndWriteAutomaticMergeHead0703() {
readAndWriteAutomaticMergeHead07(file03AutomaticMergeHead);
public void t13ReadAndWriteAutomaticMergeHeadCsv() {
readAndWriteAutomaticMergeHead(fileCsvAutomaticMergeHead);
}
private void readAndWriteAutomaticMergeHead07(File file) {
private void readAndWriteAutomaticMergeHead(File file) {
EasyExcel.write(file, ComplexHeadData.class).automaticMergeHead(Boolean.FALSE).sheet().doWrite(data());
EasyExcel.read(file, ComplexHeadData.class, new ComplexDataListener()).sheet().doRead();
}

17
src/test/java/com/alibaba/easyexcel/test/core/head/ListHeadDataTest.java

@ -5,26 +5,32 @@ import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.util.DateUtils;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
/**
*
* @author Jiaju Zhuang
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ListHeadDataTest {
private static File file07;
private static File file03;
private static File fileCsv;
@BeforeClass
public static void init() {
file07 = TestFileUtil.createNewFile("listHead07.xlsx");
file03 = TestFileUtil.createNewFile("listHead03.xls");
fileCsv = TestFileUtil.createNewFile("listHeadCsv.csv");
}
@Test
@ -37,6 +43,11 @@ public class ListHeadDataTest {
readAndWrite(file03);
}
@Test
public void t03ReadAndWriteCsv() throws Exception {
readAndWrite(fileCsv);
}
private void readAndWrite(File file) throws Exception {
EasyExcel.write(file).head(head()).sheet().doWrite(data());
EasyExcel.read(file).registerReadListener(new ListHeadDataListener()).sheet().doRead();

17
src/test/java/com/alibaba/easyexcel/test/core/head/NoHeadDataTest.java

@ -4,25 +4,29 @@ import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
/**
*
* @author Jiaju Zhuang
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class NoHeadDataTest {
private static File file07;
private static File file03;
private static File fileCsv;
@BeforeClass
public static void init() {
file07 = TestFileUtil.createNewFile("noHead07.xlsx");
file03 = TestFileUtil.createNewFile("noHead03.xls");
fileCsv = TestFileUtil.createNewFile("noHeadCsv.csv");
}
@Test
@ -35,6 +39,11 @@ public class NoHeadDataTest {
readAndWrite(file03);
}
@Test
public void t03ReadAndWriteCsv() {
readAndWrite(fileCsv);
}
private void readAndWrite(File file) {
EasyExcel.write(file, NoHeadData.class).needHead(Boolean.FALSE).sheet().doWrite(data());
EasyExcel.read(file, NoHeadData.class, new NoHeadDataListener()).headRowNumber(0).sheet().doRead();

17
src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataListener.java

@ -1,13 +1,14 @@
package com.alibaba.easyexcel.test.core.large;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.fastjson.JSON;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Jiaju Zhuang
*/
@ -22,13 +23,17 @@ public class LargeDataListener extends AnalysisEventListener<LargeData> {
}
count++;
if (count % 100000 == 0) {
LOGGER.info("Already read:{}", count);
LOGGER.info("Already read:{},{}", count, JSON.toJSONString(data));
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext context) {
LOGGER.info("Large row count:{}", count);
Assert.assertEquals(count, 464509);
if (context.readWorkbookHolder().getExcelType() != ExcelTypeEnum.CSV) {
Assert.assertEquals(count, 464509);
} else {
Assert.assertEquals(count, 499999);
}
}
}

38
src/test/java/com/alibaba/easyexcel/test/core/large/LargeDataTest.java

@ -4,31 +4,34 @@ import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.easyexcel.test.demo.write.DemoData;
import com.alibaba.easyexcel.test.util.TestFileUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Jiaju Zhuang
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class LargeDataTest {
private static final Logger LOGGER = LoggerFactory.getLogger(LargeDataTest.class);
private static File fileFill07;
private static File template07;
private static File fileCsv;
private int i = 0;
@BeforeClass
public static void init() {
fileFill07 = TestFileUtil.createNewFile("largefill07.xlsx");
template07 = TestFileUtil.readFile("large" + File.separator + "fill.xlsx");
fileCsv = TestFileUtil.createNewFile("largefileCsv.csv");
}
@Test
@ -50,8 +53,27 @@ public class LargeDataTest {
excelWriter.finish();
}
@Test
public void t03ReadAndWriteCsv() {
// write
long start = System.currentTimeMillis();
ExcelWriter excelWriter = EasyExcel.write(fileCsv).build();
WriteSheet writeSheet = EasyExcel.writerSheet().build();
for (int j = 0; j < 100; j++) {
excelWriter.write(data(), writeSheet);
LOGGER.info("{} write success.", j);
}
excelWriter.finish();
LOGGER.info("CSV large data total time spent:{}", System.currentTimeMillis() - start);
// read
start = System.currentTimeMillis();
EasyExcel.read(fileCsv, LargeData.class, new LargeDataListener()).sheet().doRead();
LOGGER.info("CSV large data total time spent:{}", System.currentTimeMillis() - start);
}
private List<LargeData> data() {
List<LargeData> list = new ArrayList<LargeData>();
List<LargeData> list = new ArrayList<>();
int size = i + 5000;
for (; i < size; i++) {
LargeData largeData = new LargeData();

Loading…
Cancel
Save