jt2594838 commented on code in PR #201:
URL: https://github.com/apache/tsfile/pull/201#discussion_r1722618974
##########
java/tools/src/test/java/org/apache/tsfile/tools/TsfiletoolsTest.java:
##########
@@ -162,4 +199,31 @@ public void testCsvToTsfile() throws Exception {
assertEquals(20, cnt);
}
}
+
+ @Test
+ public void testCsvToTsfileFailed() {
+ String scFilePath = new File(schemaFile).getAbsolutePath();
+ String csvFilePath = new File(wrongCsvFile).getAbsolutePath();
+ String targetPath = new File(testDir).getAbsolutePath();
+ String fd = new File(failedDir).getAbsolutePath();
+ String[] args =
+ new String[] {
+ "-s" + csvFilePath, "-schema" + scFilePath, "-t" + targetPath,
"-fail_dir" + fd
+ };
+ TsFileTool.main(args);
+ if (new File(failedDir + File.separator + "dataWrong.csv").exists()) {
+ try (BufferedReader br = new BufferedReader(new
FileReader(wrongCsvFile))) {
+ int num = 0;
+ while (br.readLine() != null) {
+ num++;
+ }
+ assertEquals(101, num);
+ } catch (IOException e) {
+ e.printStackTrace();
+ Assert.assertTrue(false);
Review Comment:
fail(e.getMessage()) or simply throw the exception.
##########
java/tools/src/test/java/org/apache/tsfile/tools/TsfiletoolsTest.java:
##########
@@ -95,6 +103,35 @@ public void genSchemaFile() {
}
}
+ public void genWrongCsvFile(int rows) {
+
+ try (BufferedWriter writer = new BufferedWriter(new
FileWriter(wrongCsvFile))) {
+ writer.write("time,tmp1,tmp2,tmp3,tmp4,tmp5");
+ writer.newLine();
+ Random random = new Random();
+ long timestamp = System.currentTimeMillis();
+
+ for (int i = 0; i < rows; i++) {
+ timestamp = timestamp + i;
+ String tmp1 = "s1";
+ float tmp2 = random.nextFloat();
+ float tmp3 = random.nextFloat();
+ float tmp4 = random.nextFloat();
+ float tmp5 = random.nextFloat();
+ if (i % 99 == 0) {
+ writer.write(
+ timestamp + "aa" + "," + tmp1 + "," + tmp2 + "," + tmp3 + "," +
tmp4 + "," + tmp5);
+ } else {
+ writer.write(timestamp + "," + tmp1 + "," + tmp2 + "," + tmp3 + ","
+ tmp4 + "," + tmp5);
+ }
+
+ writer.newLine();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
Review Comment:
May use `fail(e.getMessage())` or simply throw the exception, since this is
a test.
##########
java/tools/src/test/java/org/apache/tsfile/tools/TsfiletoolsTest.java:
##########
@@ -162,4 +199,31 @@ public void testCsvToTsfile() throws Exception {
assertEquals(20, cnt);
}
}
+
+ @Test
+ public void testCsvToTsfileFailed() {
+ String scFilePath = new File(schemaFile).getAbsolutePath();
+ String csvFilePath = new File(wrongCsvFile).getAbsolutePath();
+ String targetPath = new File(testDir).getAbsolutePath();
+ String fd = new File(failedDir).getAbsolutePath();
+ String[] args =
+ new String[] {
+ "-s" + csvFilePath, "-schema" + scFilePath, "-t" + targetPath,
"-fail_dir" + fd
+ };
+ TsFileTool.main(args);
+ if (new File(failedDir + File.separator + "dataWrong.csv").exists()) {
Review Comment:
assertTrue(new File(failedDir + File.separator + "dataWrong.csv").exists())
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]