Skip to content

Commit f9e1a5f

Browse files
fixed assertThrow test problems
1 parent 1d15dfe commit f9e1a5f

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

hugegraph-loader/src/main/java/org/apache/hugegraph/loader/HugeGraphLoader.java

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,16 +119,16 @@ public static void main(String[] args) {
119119
return; // 不再抛出,直接返回
120120
}
121121

122-
// try {
123-
// loader.load();
124-
// } finally {
125-
// loader.shutdown(); // 确保释放资源
126-
// GlobalExecutorManager.shutdown(loader.options.shutdownTimeout);
127-
// if (!loader.context.noError()) {
128-
// System.exit(1); // 根据 context 错误情况决定退出码
129-
// }
130-
// }
131-
loader.load();
122+
try {
123+
loader.load();
124+
} finally {
125+
loader.shutdown(); // 确保释放资源
126+
GlobalExecutorManager.shutdown(loader.options.shutdownTimeout);
127+
if (!loader.context.noError()) {
128+
System.exit(1); // 根据 context 错误情况决定退出码
129+
}
130+
}
131+
//loader.load();
132132
}
133133

134134
public HugeGraphLoader(String[] args) {
@@ -701,15 +701,22 @@ private void loadStructs(List<InputStruct> structs) {
701701
CompletableFuture.allOf(loadTasks.toArray(new CompletableFuture[0]))
702702
.join();
703703
} catch (CompletionException e) {
704-
if (e.getCause() instanceof ParseException) {
705-
throw (ParseException) e.getCause();
706-
} else if (e.getCause() instanceof LoadException) {
707-
throw (LoadException) e.getCause();
708-
} else if (e.getCause() != null) {
709-
throw new RuntimeException(e.getCause());
704+
Throwable cause = e.getCause();
705+
if (cause instanceof ParseException) {
706+
throw (ParseException) cause;
707+
} else if (cause instanceof LoadException) {
708+
throw (LoadException) cause;
709+
} else if (cause != null) {
710+
if (cause instanceof RuntimeException) {
711+
throw (RuntimeException) cause;
712+
} else {
713+
throw new RuntimeException(cause);
714+
}
710715
} else {
711716
throw e;
712717
}
718+
} catch (Throwable t) {
719+
throw t;
713720
} finally {
714721
// 关闭 service
715722
this.loadService.shutdown();

hugegraph-loader/src/test/java/org/apache/hugegraph/loader/test/functional/FileLoadTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ public void testCustomizedDelimiterInCsvFile() {
531531
};
532532
// Invalid mapping file
533533
Assert.assertThrows(LoadException.class, () -> {
534-
HugeGraphLoader.main(args);
534+
new HugeGraphLoader(args);
535535
});
536536
}
537537

@@ -732,7 +732,7 @@ public void testValueListPropertyInCSVFileWithSameDelimiter() {
732732
};
733733
// Invalid mapping file
734734
Assert.assertThrows(LoadException.class, () -> {
735-
HugeGraphLoader.main(args);
735+
new HugeGraphLoader(args);
736736
});
737737
}
738738

@@ -1052,7 +1052,7 @@ public void testSelectedAndIgnoredFields() {
10521052
};
10531053
// Invalid mapping file
10541054
Assert.assertThrows(LoadException.class, () -> {
1055-
HugeGraphLoader.main(args);
1055+
new HugeGraphLoader(args);
10561056
});
10571057
}
10581058

@@ -2021,7 +2021,7 @@ public void testBatchUpdateElementWithInvalidStrategy() {
20212021
};
20222022
// Invalid Enum value when parse json
20232023
Assert.assertThrows(Exception.class, () -> {
2024-
HugeGraphLoader.main(args);
2024+
new HugeGraphLoader(args);
20252025
});
20262026
}
20272027

0 commit comments

Comments
 (0)