From 3ef9804dac151d5a14d133681f00ad06ebe0f377 Mon Sep 17 00:00:00 2001 From: zhangliang Date: Tue, 24 Sep 2024 13:18:56 +0800 Subject: [PATCH] Add more test cases on TableMetaDataNode --- .../node/metadata/TableMetaDataNodeTest.java | 51 ++++++++++++++----- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/metadata/TableMetaDataNodeTest.java b/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/metadata/TableMetaDataNodeTest.java index abbaf8333f972..7d44d7a359358 100644 --- a/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/metadata/TableMetaDataNodeTest.java +++ b/kernel/metadata/core/src/test/java/org/apache/shardingsphere/metadata/persist/node/metadata/TableMetaDataNodeTest.java @@ -23,25 +23,14 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; class TableMetaDataNodeTest { @Test - void assertGetTableNameByActiveVersionNode() { - Optional actual = TableMetaDataNode.getTableNameByActiveVersionNode("/metadata/foo_db/schemas/foo_schema/tables/foo_table/active_version"); - assertTrue(actual.isPresent()); - assertThat(actual.get(), is("foo_table")); - } - - @Test - void assertIsTableActiveVersionNode() { - assertTrue(TableMetaDataNode.isTableActiveVersionNode("/metadata/foo_db/schemas/foo_schema/tables/foo_table/active_version")); - } - - @Test - void assertIsTableNode() { - assertTrue(TableMetaDataNode.isTableNode("/metadata/foo_db/schemas/foo_schema/tables/foo_table")); + void assertGetMetaDataTablesNode() { + assertThat(TableMetaDataNode.getMetaDataTablesNode("foo_db", "foo_schema"), is("/metadata/foo_db/schemas/foo_schema/tables")); } @Test @@ -63,4 +52,38 @@ void assertGetTableVersionNode() { void assertGetTableNode() { assertThat(TableMetaDataNode.getTableNode("foo_db", "foo_schema", "foo_table"), is("/metadata/foo_db/schemas/foo_schema/tables/foo_table")); } + + @Test + void assertGetTableNameByActiveVersionNode() { + Optional actual = TableMetaDataNode.getTableNameByActiveVersionNode("/metadata/foo_db/schemas/foo_schema/tables/foo_table/active_version"); + assertTrue(actual.isPresent()); + assertThat(actual.get(), is("foo_table")); + } + + @Test + void assertGetTableNameByActiveVersionNodeIfNotFound() { + assertFalse(TableMetaDataNode.getTableNameByActiveVersionNode("/xxx/foo_db/schemas/foo_schema/tables/foo_table/active_version").isPresent()); + } + + @Test + void assertGetTableName() { + Optional actual = TableMetaDataNode.getTableName("/metadata/foo_db/schemas/foo_schema/tables/foo_table"); + assertTrue(actual.isPresent()); + assertThat(actual.get(), is("foo_table")); + } + + @Test + void assertGetTableNameIfNotFound() { + assertFalse(TableMetaDataNode.getTableName("/xxx/foo_db/schemas/foo_schema/tables/foo_table").isPresent()); + } + + @Test + void assertIsTableActiveVersionNode() { + assertTrue(TableMetaDataNode.isTableActiveVersionNode("/metadata/foo_db/schemas/foo_schema/tables/foo_table/active_version")); + } + + @Test + void assertIsTableNode() { + assertTrue(TableMetaDataNode.isTableNode("/metadata/foo_db/schemas/foo_schema/tables/foo_table")); + } }