diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/ram/RamTable.java b/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/ram/RamTable.java index 1cbe73afc4..c83d92980f 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/ram/RamTable.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/backend/store/ram/RamTable.java @@ -37,12 +37,6 @@ import java.util.concurrent.ExecutorService; import org.apache.commons.io.FileUtils; -import org.apache.tinkerpop.gremlin.structure.Edge; -import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator; -import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; -import org.slf4j.Logger; - import org.apache.hugegraph.HugeException; import org.apache.hugegraph.HugeGraph; import org.apache.hugegraph.backend.id.Id; @@ -62,6 +56,11 @@ import org.apache.hugegraph.type.define.HugeKeys; import org.apache.hugegraph.util.Consumers; import org.apache.hugegraph.util.Log; +import org.apache.tinkerpop.gremlin.structure.Edge; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator; +import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils; +import org.slf4j.Logger; public final class RamTable { @@ -200,7 +199,6 @@ private void loadFromDB() throws Exception { Id lastId = IdGenerator.ZERO; while (vertices.hasNext()) { Id vertex = (Id) vertices.next().id(); - LOG.info("scan from hbase {} loadfromDB", vertex); if (vertex.compareTo(lastId) < 0) { throw new HugeException("The ramtable feature is not " + "supported by %s backend", @@ -496,6 +494,11 @@ public LoadTraverser() { @Override public void close() throws Exception { if (this.executor != null) { + for (int i = 0; i < Consumers.THREADS; i++) { + this.executor.execute(() -> { + this.graph.tx().commit(); + }); + } this.executor.shutdown(); } } diff --git a/hugegraph-test/src/main/java/org/apache/hugegraph/core/BaseCoreTest.java b/hugegraph-test/src/main/java/org/apache/hugegraph/core/BaseCoreTest.java index ab92ac4178..894b667450 100644 --- a/hugegraph-test/src/main/java/org/apache/hugegraph/core/BaseCoreTest.java +++ b/hugegraph-test/src/main/java/org/apache/hugegraph/core/BaseCoreTest.java @@ -21,27 +21,72 @@ import java.util.Random; -import org.apache.tinkerpop.gremlin.structure.Edge; -import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.junit.After; -import org.junit.Before; -import org.slf4j.Logger; - import org.apache.hugegraph.HugeGraph; import org.apache.hugegraph.HugeGraphParams; +import org.apache.hugegraph.backend.id.IdGenerator; import org.apache.hugegraph.backend.store.BackendFeatures; +import org.apache.hugegraph.dist.RegisterUtil; import org.apache.hugegraph.schema.SchemaManager; +import org.apache.hugegraph.testutil.Utils; import org.apache.hugegraph.testutil.Whitebox; +import org.apache.hugegraph.type.define.NodeRole; import org.apache.hugegraph.util.Log; +import org.apache.tinkerpop.gremlin.structure.Edge; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.slf4j.Logger; public class BaseCoreTest { protected static final Logger LOG = Log.logger(BaseCoreTest.class); protected static final int TX_BATCH = 100; + private static boolean registered = false; + private static HugeGraph graph = null; - public HugeGraph graph() { - return CoreTestSuite.graph(); + public static HugeGraph graph() { + Assert.assertNotNull(graph); + //Assert.assertFalse(graph.closed()); + return graph; + } + + @BeforeClass + public static void initEnv() { + if (registered) { + return; + } + RegisterUtil.registerBackends(); + registered = true; + } + + @BeforeClass + public static void init() { + graph = Utils.open(); + graph.clearBackend(); + graph.initBackend(); + graph.serverStarted(IdGenerator.of("server1"), NodeRole.MASTER); + } + + @AfterClass + public static void clear() { + if (graph == null) { + return; + } + + try { + graph.clearBackend(); + } finally { + try { + graph.close(); + } catch (Throwable e) { + LOG.error("Error when close()", e); + } + graph = null; + } } @Before diff --git a/hugegraph-test/src/main/java/org/apache/hugegraph/core/CoreTestSuite.java b/hugegraph-test/src/main/java/org/apache/hugegraph/core/CoreTestSuite.java index 4d60e86519..83c566dc1b 100644 --- a/hugegraph-test/src/main/java/org/apache/hugegraph/core/CoreTestSuite.java +++ b/hugegraph-test/src/main/java/org/apache/hugegraph/core/CoreTestSuite.java @@ -19,21 +19,10 @@ package org.apache.hugegraph.core; -import org.apache.hugegraph.testutil.Utils; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.slf4j.Logger; - -import org.apache.hugegraph.HugeGraph; -import org.apache.hugegraph.backend.id.IdGenerator; import org.apache.hugegraph.core.PropertyCoreTest.EdgePropertyCoreTest; import org.apache.hugegraph.core.PropertyCoreTest.VertexPropertyCoreTest; -import org.apache.hugegraph.dist.RegisterUtil; -import org.apache.hugegraph.type.define.NodeRole; -import org.apache.hugegraph.util.Log; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ @@ -54,44 +43,4 @@ }) public class CoreTestSuite { - private static final Logger LOG = Log.logger(CoreTestSuite.class); - - private static HugeGraph graph = null; - - @BeforeClass - public static void initEnv() { - RegisterUtil.registerBackends(); - } - - @BeforeClass - public static void init() { - graph = Utils.open(); - graph.clearBackend(); - graph.initBackend(); - graph.serverStarted(IdGenerator.of("server1"), NodeRole.MASTER); - } - - @AfterClass - public static void clear() { - if (graph == null) { - return; - } - - try { - graph.clearBackend(); - } finally { - try { - graph.close(); - } catch (Throwable e) { - LOG.error("Error when close()", e); - } - graph = null; - } - } - - protected static HugeGraph graph() { - Assert.assertNotNull(graph); - //Assert.assertFalse(graph.closed()); - return graph; - } } diff --git a/hugegraph-test/src/main/java/org/apache/hugegraph/core/MultiGraphsTest.java b/hugegraph-test/src/main/java/org/apache/hugegraph/core/MultiGraphsTest.java index 7963c9366d..cef98c3977 100644 --- a/hugegraph-test/src/main/java/org/apache/hugegraph/core/MultiGraphsTest.java +++ b/hugegraph-test/src/main/java/org/apache/hugegraph/core/MultiGraphsTest.java @@ -27,13 +27,6 @@ import org.apache.commons.configuration2.BaseConfiguration; import org.apache.commons.configuration2.Configuration; import org.apache.commons.configuration2.PropertiesConfiguration; -import org.apache.tinkerpop.gremlin.structure.T; -import org.apache.tinkerpop.gremlin.structure.Vertex; -import org.apache.tinkerpop.gremlin.structure.util.GraphFactory; -import org.apache.hugegraph.testutil.Utils; -import org.junit.Test; -import org.rocksdb.RocksDBException; - import org.apache.hugegraph.HugeException; import org.apache.hugegraph.HugeGraph; import org.apache.hugegraph.backend.id.IdGenerator; @@ -48,10 +41,17 @@ import org.apache.hugegraph.schema.SchemaManager; import org.apache.hugegraph.schema.VertexLabel; import org.apache.hugegraph.testutil.Assert; +import org.apache.hugegraph.testutil.Utils; import org.apache.hugegraph.type.define.NodeRole; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.apache.tinkerpop.gremlin.structure.util.GraphFactory; +import org.junit.Test; +import org.rocksdb.RocksDBException; + import com.google.common.collect.ImmutableList; -public class MultiGraphsTest { +public class MultiGraphsTest extends BaseCoreTest { private static final String NAME48 = "g12345678901234567890123456789012345678901234567";