Skip to content

Commit 9babe49

Browse files
authored
test(server): enable run single unit test (#2940)
* test(server-test): enable run single unit test * fix: thread-safe graph() method * fix: more clear error handling in graph() method
1 parent fc391a7 commit 9babe49

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/CoreTestSuite.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.apache.hugegraph.testutil.Utils;
2727
import org.apache.hugegraph.util.Log;
2828
import org.junit.AfterClass;
29-
import org.junit.Assert;
3029
import org.junit.BeforeClass;
3130
import org.junit.runner.RunWith;
3231
import org.junit.runners.Suite;
@@ -52,11 +51,29 @@
5251
public class CoreTestSuite {
5352

5453
private static boolean registered = false;
55-
private static HugeGraph graph = null;
54+
private static volatile HugeGraph graph = null;
5655

5756
public static HugeGraph graph() {
58-
Assert.assertNotNull(graph);
59-
//Assert.assertFalse(graph.closed());
57+
if (graph == null) {
58+
synchronized (CoreTestSuite.class) {
59+
if (graph == null) {
60+
try {
61+
initEnv();
62+
init();
63+
} catch (Throwable e) {
64+
LOG.error("Failed to initialize HugeGraph instance", e);
65+
graph = null;
66+
throw new RuntimeException("Failed to initialize HugeGraph instance", e);
67+
}
68+
if (graph == null) {
69+
String msg = "HugeGraph instance is null after initialization. " +
70+
"Please check Utils.open() configuration.";
71+
LOG.error(msg);
72+
throw new IllegalStateException(msg);
73+
}
74+
}
75+
}
76+
}
6077
return graph;
6178
}
6279

0 commit comments

Comments
 (0)