From fbb5e04ad76dbaeb8b7938d3f6e2eedea9a4cabf Mon Sep 17 00:00:00 2001 From: LYD031106 <2565506388@qq.com> Date: Sun, 16 Nov 2025 15:45:10 +0800 Subject: [PATCH 1/4] fix(server): ensure graph clear API does not clear meta table --- .../backend/store/hbase/HbaseStore.java | 2 + .../unit/hbase/BaseHbaseUnitTest.java | 63 +++++++++++++++++++ .../hugegraph/unit/hbase/HbaseUnitTest.java | 58 +++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/BaseHbaseUnitTest.java create mode 100644 hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/HbaseUnitTest.java diff --git a/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java b/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java index 1d75c00944..a17df5f41c 100644 --- a/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java +++ b/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java @@ -402,6 +402,8 @@ public void truncate() { "Failed to truncate table for '%s' store", e, this.store); } + this.init(); + LOG.debug("Store truncated: {}", this.store); } diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/BaseHbaseUnitTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/BaseHbaseUnitTest.java new file mode 100644 index 0000000000..c3fbcb8b13 --- /dev/null +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/BaseHbaseUnitTest.java @@ -0,0 +1,63 @@ +/* + * + * * Licensed to the Apache Software Foundation (ASF) under one or more + * * contributor license agreements. See the NOTICE file distributed with + * * this work for additional information regarding copyright ownership. + * * The ASF licenses this file to You under the Apache License, Version 2.0 + * * (the "License"); you may not use this file except in compliance with + * * the License. You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * + */ + +package org.apache.hugegraph.unit.hbase; + +import org.apache.hugegraph.backend.store.BackendStore; +import org.apache.hugegraph.backend.store.hbase.HbaseStoreProvider; +import org.apache.hugegraph.config.HugeConfig; +import org.apache.hugegraph.unit.BaseUnitTest; +import org.apache.hugegraph.unit.FakeObjects; +import org.junit.After; +import org.junit.Before; + +public class BaseHbaseUnitTest extends BaseUnitTest{ + + protected BackendStore store; + + protected HugeConfig config; + protected HbaseStoreProvider provider; + + @Before + public void setup() { + this.config = FakeObjects.newConfig(); + + this.provider = new HbaseStoreProvider(); + + this.store = this.provider.loadSystemStore(config); + } + + @After + public void down(){ + if (this.store != null) { + try { + this.store.close(); + } catch (Exception e) { + // pass + } + } + if (this.provider != null) { + try { + this.provider.close(); + } catch (Exception e) { + // pass + } + } + } +} diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/HbaseUnitTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/HbaseUnitTest.java new file mode 100644 index 0000000000..c4ed2e38b0 --- /dev/null +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/HbaseUnitTest.java @@ -0,0 +1,58 @@ +/* + * + * * Licensed to the Apache Software Foundation (ASF) under one or more + * * contributor license agreements. See the NOTICE file distributed with + * * this work for additional information regarding copyright ownership. + * * The ASF licenses this file to You under the Apache License, Version 2.0 + * * (the "License"); you may not use this file except in compliance with + * * the License. You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * + */ + +package org.apache.hugegraph.unit.hbase; + +import org.apache.hugegraph.testutil.Assert; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class HbaseUnitTest extends BaseHbaseUnitTest { + + private static final String GRAPH_NAME = "test_graph"; + + @Before + public void setUp(){ + this.provider.open(GRAPH_NAME); + this.provider.init(); + } + + @After + public void teardown(){ + if (this.store != null) { + this.store.close(); + } + if (this.provider != null) { + this.provider.close(); + } + } + + @Test + public void testHbaseMetaVersion(){ + // init store + this.store.init(); + String beforeVersion = this.store.storedVersion(); + this.store.truncate(); + String afterInitVersion = this.store.storedVersion(); + Assert.assertNotNull(beforeVersion); + Assert.assertNotNull(afterInitVersion); + Assert.assertEquals(beforeVersion, afterInitVersion); + } +} From 9c810fd18082a5d6184424b62f2a77f8026b48a5 Mon Sep 17 00:00:00 2001 From: LYD031106 <2565506388@qq.com> Date: Thu, 20 Nov 2025 23:56:27 +0800 Subject: [PATCH 2/4] fix(server): ensure graph clear API does not clear system table --- .../backend/store/hbase/HbaseStore.java | 13 ++++++--- .../unit/hbase/BaseHbaseUnitTest.java | 28 +++++++----------- .../hugegraph/unit/hbase/HbaseUnitTest.java | 29 +++++-------------- 3 files changed, 27 insertions(+), 43 deletions(-) diff --git a/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java b/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java index a17df5f41c..81bbf84db8 100644 --- a/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java +++ b/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java @@ -114,6 +114,14 @@ protected List tableNames() { .collect(Collectors.toList()); } + protected List truncatedTableNames() { + return this.tables.values().stream() + .filter(table -> !(table instanceof HbaseTables.Meta || + table instanceof HbaseTables.Counters)) + .map(BackendTable::table) + .collect(Collectors.toList()); + } + public String namespace() { return this.namespace; } @@ -371,7 +379,7 @@ public void truncate() { }; // Truncate tables - List tables = this.tableNames(); + List tables = this.truncatedTableNames(); Map> futures = new HashMap<>(tables.size()); try { @@ -401,9 +409,6 @@ public void truncate() { throw new BackendException( "Failed to truncate table for '%s' store", e, this.store); } - - this.init(); - LOG.debug("Store truncated: {}", this.store); } diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/BaseHbaseUnitTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/BaseHbaseUnitTest.java index c3fbcb8b13..f162ff68fe 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/BaseHbaseUnitTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/BaseHbaseUnitTest.java @@ -19,44 +19,38 @@ package org.apache.hugegraph.unit.hbase; -import org.apache.hugegraph.backend.store.BackendStore; +import org.apache.commons.configuration2.Configuration; import org.apache.hugegraph.backend.store.hbase.HbaseStoreProvider; import org.apache.hugegraph.config.HugeConfig; +import org.apache.hugegraph.testutil.Utils; import org.apache.hugegraph.unit.BaseUnitTest; -import org.apache.hugegraph.unit.FakeObjects; import org.junit.After; -import org.junit.Before; public class BaseHbaseUnitTest extends BaseUnitTest{ - protected BackendStore store; + private static final String GRAPH_NAME = "test_graph"; protected HugeConfig config; protected HbaseStoreProvider provider; - @Before public void setup() { - this.config = FakeObjects.newConfig(); - + Configuration conf = Utils.getConf(); + this.config = new HugeConfig(conf); this.provider = new HbaseStoreProvider(); - - this.store = this.provider.loadSystemStore(config); + this.provider.open(GRAPH_NAME); + this.provider.loadSystemStore(config).open(config); + this.provider.loadGraphStore(config).open(config); + this.provider.loadSchemaStore(config).open(config); + this.provider.init(); } @After public void down(){ - if (this.store != null) { - try { - this.store.close(); - } catch (Exception e) { - // pass - } - } if (this.provider != null) { try { this.provider.close(); } catch (Exception e) { - // pass + LOG.warn("Failed to close provider",e); } } } diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/HbaseUnitTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/HbaseUnitTest.java index c4ed2e38b0..be594d8809 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/HbaseUnitTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/HbaseUnitTest.java @@ -19,38 +19,23 @@ package org.apache.hugegraph.unit.hbase; +import org.apache.hugegraph.backend.store.BackendStore; import org.apache.hugegraph.testutil.Assert; -import org.junit.After; import org.junit.Before; import org.junit.Test; public class HbaseUnitTest extends BaseHbaseUnitTest { - - private static final String GRAPH_NAME = "test_graph"; - @Before public void setUp(){ - this.provider.open(GRAPH_NAME); - this.provider.init(); - } - - @After - public void teardown(){ - if (this.store != null) { - this.store.close(); - } - if (this.provider != null) { - this.provider.close(); - } + super.setup(); } @Test - public void testHbaseMetaVersion(){ - // init store - this.store.init(); - String beforeVersion = this.store.storedVersion(); - this.store.truncate(); - String afterInitVersion = this.store.storedVersion(); + public void testMysqlMetaVersion(){ + BackendStore systemStore = this.provider.loadSystemStore(config); + String beforeVersion = systemStore.storedVersion(); + this.provider.truncate(); + String afterInitVersion = systemStore.storedVersion(); Assert.assertNotNull(beforeVersion); Assert.assertNotNull(afterInitVersion); Assert.assertEquals(beforeVersion, afterInitVersion); From 004684e3321b1fcebb7d1c7f2b72d2cf3ccf4712 Mon Sep 17 00:00:00 2001 From: LYD031106 <2565506388@qq.com> Date: Sun, 30 Nov 2025 14:35:13 +0800 Subject: [PATCH 3/4] fix(server): Improve the test cases --- .../backend/store/hbase/HbaseStore.java | 8 +-- .../unit/hbase/BaseHbaseUnitTest.java | 8 ++- .../hugegraph/unit/hbase/HbaseUnitTest.java | 58 +++++++++++++++++-- 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java b/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java index 81bbf84db8..d8f7943fac 100644 --- a/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java +++ b/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java @@ -115,10 +115,9 @@ protected List tableNames() { } protected List truncatedTableNames() { - return this.tables.values().stream() - .filter(table -> !(table instanceof HbaseTables.Meta || - table instanceof HbaseTables.Counters)) - .map(BackendTable::table) + return this.tables.entrySet().stream() + .filter(e -> !(HugeType.META == e.getKey())) + .map(e -> e.getValue().table()) .collect(Collectors.toList()); } @@ -409,6 +408,7 @@ public void truncate() { throw new BackendException( "Failed to truncate table for '%s' store", e, this.store); } + LOG.debug("Store truncated: {}", this.store); } diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/BaseHbaseUnitTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/BaseHbaseUnitTest.java index f162ff68fe..1949474ca0 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/BaseHbaseUnitTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/BaseHbaseUnitTest.java @@ -20,20 +20,24 @@ package org.apache.hugegraph.unit.hbase; import org.apache.commons.configuration2.Configuration; +import org.apache.hugegraph.backend.store.hbase.HbaseSessions; import org.apache.hugegraph.backend.store.hbase.HbaseStoreProvider; import org.apache.hugegraph.config.HugeConfig; import org.apache.hugegraph.testutil.Utils; import org.apache.hugegraph.unit.BaseUnitTest; import org.junit.After; +import java.io.IOException; + public class BaseHbaseUnitTest extends BaseUnitTest{ private static final String GRAPH_NAME = "test_graph"; protected HugeConfig config; protected HbaseStoreProvider provider; + protected HbaseSessions sessions; - public void setup() { + public void setup() throws IOException { Configuration conf = Utils.getConf(); this.config = new HugeConfig(conf); this.provider = new HbaseStoreProvider(); @@ -42,6 +46,8 @@ public void setup() { this.provider.loadGraphStore(config).open(config); this.provider.loadSchemaStore(config).open(config); this.provider.init(); + this.sessions = new HbaseSessions(config,GRAPH_NAME, this.provider.loadGraphStore(config).store()); + this.sessions.open(); } @After diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/HbaseUnitTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/HbaseUnitTest.java index be594d8809..c0fca11d8c 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/HbaseUnitTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/HbaseUnitTest.java @@ -19,25 +19,71 @@ package org.apache.hugegraph.unit.hbase; +import org.apache.hadoop.hbase.client.Result; +import org.apache.hugegraph.backend.store.BackendEntry.BackendIterator; import org.apache.hugegraph.backend.store.BackendStore; import org.apache.hugegraph.testutil.Assert; +import org.apache.hugegraph.backend.store.hbase.HbaseSessions; +import org.apache.hugegraph.util.StringEncoding; import org.junit.Before; import org.junit.Test; +import java.io.IOException; + public class HbaseUnitTest extends BaseHbaseUnitTest { + @Before - public void setUp(){ + public void setUp() throws IOException { super.setup(); } @Test - public void testMysqlMetaVersion(){ + public void testHbaseMetaVersionAfterTruncate() { BackendStore systemStore = this.provider.loadSystemStore(config); + + // Record system version before truncation String beforeVersion = systemStore.storedVersion(); + + HbaseSessions.Session testsession = this.sessions.session(); + + // Insert test data + testsession.put("g_v", "f".getBytes(), "row_trunc_v".getBytes(), StringEncoding.encode("q"), StringEncoding.encode("v")); + testsession.put("g_oe", "f".getBytes(), "row_trunc_oe".getBytes(), StringEncoding.encode("q"), StringEncoding.encode("v")); + testsession.put("g_ie", "f".getBytes(), "row_trunc_ie".getBytes(), StringEncoding.encode("q"), StringEncoding.encode("v")); + testsession.commit(); + + // Verify data insertion success + BackendIterator vIterator = testsession.get("g_v", "f".getBytes(), "row_trunc_v".getBytes()); + BackendIterator oeIterator = testsession.get("g_oe", "f".getBytes(), "row_trunc_oe".getBytes()); + BackendIterator ieIterator = testsession.get("g_ie", "f".getBytes(), "row_trunc_ie".getBytes()); + + Assert.assertTrue("data should exist", vIterator.hasNext()); + Assert.assertTrue("data should exist", oeIterator.hasNext()); + Assert.assertTrue("data should exist", ieIterator.hasNext()); + + vIterator.close(); + oeIterator.close(); + ieIterator.close(); + + // Execute truncate operation, clears all graph data but preserves system tables this.provider.truncate(); - String afterInitVersion = systemStore.storedVersion(); - Assert.assertNotNull(beforeVersion); - Assert.assertNotNull(afterInitVersion); - Assert.assertEquals(beforeVersion, afterInitVersion); + + // Verify system version remains unchanged after truncation + String afterVersion = systemStore.storedVersion(); + Assert.assertNotNull("System metadata version should exist",afterVersion); + Assert.assertEquals("System metadata version should remain unchanged after truncation", beforeVersion, afterVersion); + + // Verify data has been cleared + vIterator = testsession.get("g_v", "f".getBytes(), "row_trunc_v".getBytes()); + oeIterator = testsession.get("g_oe", "f".getBytes(), "row_trunc_oe".getBytes()); + ieIterator = testsession.get("g_ie", "f".getBytes(), "row_trunc_ie".getBytes()); + + Assert.assertFalse("data should not exist", vIterator.hasNext()); + Assert.assertFalse("data should not exist", oeIterator.hasNext()); + Assert.assertFalse("data should not exist", ieIterator.hasNext()); + + vIterator.close(); + oeIterator.close(); + ieIterator.close(); } } From 7676f54af0c9b8cccf3798ffdfa97bc96247886c Mon Sep 17 00:00:00 2001 From: LYD031106 <2565506388@qq.com> Date: Sat, 6 Dec 2025 20:10:39 +0800 Subject: [PATCH 4/4] fix(server): ensure graph clear API does not clear meta table --- .../backend/store/hbase/HbaseStore.java | 1 + .../unit/hbase/BaseHbaseUnitTest.java | 48 ++++++---- .../hugegraph/unit/hbase/HbaseUnitTest.java | 91 +++++++++---------- 3 files changed, 71 insertions(+), 69 deletions(-) diff --git a/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java b/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java index d8f7943fac..bc0f9f2b8b 100644 --- a/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java +++ b/hugegraph-server/hugegraph-hbase/src/main/java/org/apache/hugegraph/backend/store/hbase/HbaseStore.java @@ -115,6 +115,7 @@ protected List tableNames() { } protected List truncatedTableNames() { + // Exclude meta table to preserve system metadata during graph clear return this.tables.entrySet().stream() .filter(e -> !(HugeType.META == e.getKey())) .map(e -> e.getValue().table()) diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/BaseHbaseUnitTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/BaseHbaseUnitTest.java index 1949474ca0..c79ab79455 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/BaseHbaseUnitTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/BaseHbaseUnitTest.java @@ -1,20 +1,18 @@ /* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * * Licensed to the Apache Software Foundation (ASF) under one or more - * * contributor license agreements. See the NOTICE file distributed with - * * this work for additional information regarding copyright ownership. - * * The ASF licenses this file to You under the Apache License, Version 2.0 - * * (the "License"); you may not use this file except in compliance with - * * the License. You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.hugegraph.unit.hbase; @@ -26,10 +24,11 @@ import org.apache.hugegraph.testutil.Utils; import org.apache.hugegraph.unit.BaseUnitTest; import org.junit.After; +import org.junit.Before; import java.io.IOException; -public class BaseHbaseUnitTest extends BaseUnitTest{ +public class BaseHbaseUnitTest extends BaseUnitTest { private static final String GRAPH_NAME = "test_graph"; @@ -37,6 +36,7 @@ public class BaseHbaseUnitTest extends BaseUnitTest{ protected HbaseStoreProvider provider; protected HbaseSessions sessions; + @Before public void setup() throws IOException { Configuration conf = Utils.getConf(); this.config = new HugeConfig(conf); @@ -46,17 +46,25 @@ public void setup() throws IOException { this.provider.loadGraphStore(config).open(config); this.provider.loadSchemaStore(config).open(config); this.provider.init(); - this.sessions = new HbaseSessions(config,GRAPH_NAME, this.provider.loadGraphStore(config).store()); + this.sessions = + new HbaseSessions(config, GRAPH_NAME, this.provider.loadGraphStore(config).store()); this.sessions.open(); } @After - public void down(){ - if (this.provider != null) { + public void tearDown() { + if (this.sessions != null) { try { - this.provider.close(); + this.sessions.close(); } catch (Exception e) { - LOG.warn("Failed to close provider",e); + LOG.warn("Failed to close sessions ", e); + } + } + if (this.provider != null){ + try { + this.provider.close(); + }catch (Exception e){ + LOG.warn("Failed to close provider ",e); } } } diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/HbaseUnitTest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/HbaseUnitTest.java index c0fca11d8c..96845b3e9d 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/HbaseUnitTest.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/hbase/HbaseUnitTest.java @@ -1,20 +1,18 @@ /* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * * Licensed to the Apache Software Foundation (ASF) under one or more - * * contributor license agreements. See the NOTICE file distributed with - * * this work for additional information regarding copyright ownership. - * * The ASF licenses this file to You under the Apache License, Version 2.0 - * * (the "License"); you may not use this file except in compliance with - * * the License. You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, software - * * distributed under the License is distributed on an "AS IS" BASIS, - * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * * See the License for the specific language governing permissions and - * * limitations under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.apache.hugegraph.unit.hbase; @@ -25,18 +23,12 @@ import org.apache.hugegraph.testutil.Assert; import org.apache.hugegraph.backend.store.hbase.HbaseSessions; import org.apache.hugegraph.util.StringEncoding; -import org.junit.Before; import org.junit.Test; -import java.io.IOException; +import java.nio.charset.StandardCharsets; public class HbaseUnitTest extends BaseHbaseUnitTest { - @Before - public void setUp() throws IOException { - super.setup(); - } - @Test public void testHbaseMetaVersionAfterTruncate() { BackendStore systemStore = this.provider.loadSystemStore(config); @@ -45,45 +37,46 @@ public void testHbaseMetaVersionAfterTruncate() { String beforeVersion = systemStore.storedVersion(); HbaseSessions.Session testsession = this.sessions.session(); - + // Insert test data - testsession.put("g_v", "f".getBytes(), "row_trunc_v".getBytes(), StringEncoding.encode("q"), StringEncoding.encode("v")); - testsession.put("g_oe", "f".getBytes(), "row_trunc_oe".getBytes(), StringEncoding.encode("q"), StringEncoding.encode("v")); - testsession.put("g_ie", "f".getBytes(), "row_trunc_ie".getBytes(), StringEncoding.encode("q"), StringEncoding.encode("v")); + testsession.put("g_v", "f".getBytes(StandardCharsets.UTF_8), + "row_trunc_v".getBytes(StandardCharsets.UTF_8), StringEncoding.encode("q"), + StringEncoding.encode("v")); + testsession.put("g_oe", "f".getBytes(StandardCharsets.UTF_8), + "row_trunc_oe".getBytes(StandardCharsets.UTF_8), + StringEncoding.encode("q"), StringEncoding.encode("v")); + testsession.put("g_ie", "f".getBytes(StandardCharsets.UTF_8), + "row_trunc_ie".getBytes(StandardCharsets.UTF_8), + StringEncoding.encode("q"), StringEncoding.encode("v")); testsession.commit(); // Verify data insertion success - BackendIterator vIterator = testsession.get("g_v", "f".getBytes(), "row_trunc_v".getBytes()); - BackendIterator oeIterator = testsession.get("g_oe", "f".getBytes(), "row_trunc_oe".getBytes()); - BackendIterator ieIterator = testsession.get("g_ie", "f".getBytes(), "row_trunc_ie".getBytes()); - - Assert.assertTrue("data should exist", vIterator.hasNext()); - Assert.assertTrue("data should exist", oeIterator.hasNext()); - Assert.assertTrue("data should exist", ieIterator.hasNext()); - - vIterator.close(); - oeIterator.close(); - ieIterator.close(); - + try ( + BackendIterator vIterator = testsession.get("g_v", "f".getBytes(StandardCharsets.UTF_8), "row_trunc_v".getBytes(StandardCharsets.UTF_8)); + BackendIterator oeIterator = testsession.get("g_oe", "f".getBytes(StandardCharsets.UTF_8), "row_trunc_oe".getBytes(StandardCharsets.UTF_8)); + BackendIterator ieIterator = testsession.get("g_ie", "f".getBytes(StandardCharsets.UTF_8), "row_trunc_ie".getBytes(StandardCharsets.UTF_8)); + ) { + Assert.assertTrue("data should exist", vIterator.hasNext()); + Assert.assertTrue("data should exist", oeIterator.hasNext()); + Assert.assertTrue("data should exist", ieIterator.hasNext()); + } // Execute truncate operation, clears all graph data but preserves system tables this.provider.truncate(); // Verify system version remains unchanged after truncation String afterVersion = systemStore.storedVersion(); - Assert.assertNotNull("System metadata version should exist",afterVersion); + Assert.assertNotNull("System metadata version should exist", afterVersion); Assert.assertEquals("System metadata version should remain unchanged after truncation", beforeVersion, afterVersion); // Verify data has been cleared - vIterator = testsession.get("g_v", "f".getBytes(), "row_trunc_v".getBytes()); - oeIterator = testsession.get("g_oe", "f".getBytes(), "row_trunc_oe".getBytes()); - ieIterator = testsession.get("g_ie", "f".getBytes(), "row_trunc_ie".getBytes()); - - Assert.assertFalse("data should not exist", vIterator.hasNext()); - Assert.assertFalse("data should not exist", oeIterator.hasNext()); - Assert.assertFalse("data should not exist", ieIterator.hasNext()); - - vIterator.close(); - oeIterator.close(); - ieIterator.close(); + try ( + BackendIterator vIterator = testsession.get("g_v", "f".getBytes(StandardCharsets.UTF_8), "row_trunc_v".getBytes(StandardCharsets.UTF_8)); + BackendIterator oeIterator = testsession.get("g_oe", "f".getBytes(StandardCharsets.UTF_8), "row_trunc_oe".getBytes(StandardCharsets.UTF_8)); + BackendIterator ieIterator = testsession.get("g_ie", "f".getBytes(StandardCharsets.UTF_8), "row_trunc_ie".getBytes(StandardCharsets.UTF_8)); + ) { + Assert.assertFalse("data should not exist", vIterator.hasNext()); + Assert.assertFalse("data should not exist", oeIterator.hasNext()); + Assert.assertFalse("data should not exist", ieIterator.hasNext()); + } } }