From 2bb796acbafb92cd5422c4c69933d2b96662428b Mon Sep 17 00:00:00 2001 From: zhangliang Date: Thu, 14 Nov 2024 15:27:30 +0800 Subject: [PATCH] Refactor usage of IndexMetaData's constructor --- .../metadata/reviser/index/ShardingIndexReviserTest.java | 3 +-- .../schema/reviser/index/IndexReviseEngineTest.java | 4 ++-- .../metadata/data/loader/MySQLMetaDataLoaderTest.java | 3 +-- .../metadata/data/loader/OpenGaussMetaDataLoaderTest.java | 3 +-- .../metadata/data/loader/PostgreSQLMetaDataLoaderTest.java | 7 +++---- .../metadata/data/loader/SQLServerMetaDataLoaderTest.java | 3 +-- 6 files changed, 9 insertions(+), 14 deletions(-) diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/reviser/index/ShardingIndexReviserTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/reviser/index/ShardingIndexReviserTest.java index e4808a9eab425..a54d3fa0fc335 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/reviser/index/ShardingIndexReviserTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/metadata/reviser/index/ShardingIndexReviserTest.java @@ -50,8 +50,7 @@ void assertRevise() { ShardingTable shardingTable = mock(ShardingTable.class); when(shardingTable.getActualDataNodes()).thenReturn(Arrays.asList(new DataNode("SCHEMA_NAME", "TABLE_NAME_0"), new DataNode("SCHEMA_NAME", "TABLE_NAME_1"))); shardingIndexReviser = new ShardingIndexReviser(shardingTable); - IndexMetaData originalMetaData = new IndexMetaData("TEST_INDEX"); - originalMetaData.getColumns().add("TEST_COLUMN"); + IndexMetaData originalMetaData = new IndexMetaData("TEST_INDEX", Collections.singletonList("TEST_COLUMN")); originalMetaData.setUnique(false); Optional revisedMetaData = shardingIndexReviser.revise("TABLE_NAME_0", originalMetaData, shardingRule); assertTrue(revisedMetaData.isPresent()); diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/index/IndexReviseEngineTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/index/IndexReviseEngineTest.java index 6f17024d8dfea..55e4ed0eb3bfd 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/index/IndexReviseEngineTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/database/schema/reviser/index/IndexReviseEngineTest.java @@ -67,8 +67,8 @@ void assertReviseIsPresentIsTrue() { IndexMetaData indexMetaData = new IndexMetaData("index"); doReturn(Optional.of(reviser)).when(metaDataReviseEntry).getIndexReviser(any(), anyString()); when(reviser.revise(anyString(), any(), any())).thenReturn(Optional.of(indexMetaData)); - Collection indexMetaDataCollection = Arrays.asList(new IndexMetaData("index1"), new IndexMetaData("index2")); - Collection actual = indexReviseEngine.revise("tableName", indexMetaDataCollection); + Collection indexMetaDataList = Arrays.asList(new IndexMetaData("index1"), new IndexMetaData("index2")); + Collection actual = indexReviseEngine.revise("tableName", indexMetaDataList); assertThat(actual.size(), equalTo(1)); assertTrue(actual.contains(indexMetaData)); } diff --git a/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/metadata/data/loader/MySQLMetaDataLoaderTest.java b/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/metadata/data/loader/MySQLMetaDataLoaderTest.java index 81baad2b21262..a415f99d50028 100644 --- a/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/metadata/data/loader/MySQLMetaDataLoaderTest.java +++ b/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/metadata/data/loader/MySQLMetaDataLoaderTest.java @@ -129,8 +129,7 @@ private void assertTableMetaDataMap(final Collection schemaMetaD assertThat(columnsIterator.next(), is(new ColumnMetaData("mpt", Types.BINARY, false, false, false, true, false, true))); assertThat(actualTableMetaData.getIndexes().size(), is(1)); Iterator indexesIterator = actualTableMetaData.getIndexes().iterator(); - IndexMetaData expected = new IndexMetaData("id"); - expected.getColumns().add("id"); + IndexMetaData expected = new IndexMetaData("id", Collections.singletonList("id")); expected.setUnique(true); assertThat(indexesIterator.next(), is(expected)); } diff --git a/infra/database/type/opengauss/src/test/java/org/apache/shardingsphere/infra/database/opengauss/metadata/data/loader/OpenGaussMetaDataLoaderTest.java b/infra/database/type/opengauss/src/test/java/org/apache/shardingsphere/infra/database/opengauss/metadata/data/loader/OpenGaussMetaDataLoaderTest.java index 827c0a7475193..60da4cb9a87d8 100644 --- a/infra/database/type/opengauss/src/test/java/org/apache/shardingsphere/infra/database/opengauss/metadata/data/loader/OpenGaussMetaDataLoaderTest.java +++ b/infra/database/type/opengauss/src/test/java/org/apache/shardingsphere/infra/database/opengauss/metadata/data/loader/OpenGaussMetaDataLoaderTest.java @@ -177,9 +177,8 @@ private void assertTableMetaDataMap(final Collection schemaMetaD assertThat(columnsIterator.next(), is(new ColumnMetaData("name", Types.VARCHAR, false, false, true, true, false, true))); assertThat(actualTableMetaData.getIndexes().size(), is(1)); Iterator indexesIterator = actualTableMetaData.getIndexes().iterator(); - IndexMetaData indexMetaData = new IndexMetaData("id"); + IndexMetaData indexMetaData = new IndexMetaData("id", Collections.singletonList("id")); indexMetaData.setUnique(true); - indexMetaData.getColumns().add("id"); assertThat(indexesIterator.next(), is(indexMetaData)); } } diff --git a/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/metadata/data/loader/PostgreSQLMetaDataLoaderTest.java b/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/metadata/data/loader/PostgreSQLMetaDataLoaderTest.java index 00a9496456539..1c14dc6700cc7 100644 --- a/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/metadata/data/loader/PostgreSQLMetaDataLoaderTest.java +++ b/infra/database/type/postgresql/src/test/java/org/apache/shardingsphere/infra/database/postgresql/metadata/data/loader/PostgreSQLMetaDataLoaderTest.java @@ -211,12 +211,11 @@ private void assertTableMetaDataMap(final Collection schemaMetaD assertThat(columnsIterator.next(), is(new ColumnMetaData("name", Types.VARCHAR, false, false, true, true, false, true))); assertThat(actualTableMetaData.getIndexes().size(), is(1)); Iterator indexesIterator = actualTableMetaData.getIndexes().iterator(); - IndexMetaData indexMetaData = new IndexMetaData("id"); + IndexMetaData indexMetaData = new IndexMetaData("id", Collections.singletonList("id")); indexMetaData.setUnique(true); - indexMetaData.getColumns().add("id"); assertThat(indexesIterator.next(), is(indexMetaData)); assertThat(actualTableMetaData.getConstraints().size(), is(1)); - Iterator constrainsIterator = actualTableMetaData.getConstraints().iterator(); - assertThat(constrainsIterator.next(), is(new ConstraintMetaData("tbl_con", "refer_tbl"))); + Iterator constrainsMetaDataList = actualTableMetaData.getConstraints().iterator(); + assertThat(constrainsMetaDataList.next(), is(new ConstraintMetaData("tbl_con", "refer_tbl"))); } } diff --git a/infra/database/type/sqlserver/src/test/java/org/apache/shardingsphere/infra/database/sqlserver/metadata/data/loader/SQLServerMetaDataLoaderTest.java b/infra/database/type/sqlserver/src/test/java/org/apache/shardingsphere/infra/database/sqlserver/metadata/data/loader/SQLServerMetaDataLoaderTest.java index dcc71b93cddbd..a77b86712252f 100644 --- a/infra/database/type/sqlserver/src/test/java/org/apache/shardingsphere/infra/database/sqlserver/metadata/data/loader/SQLServerMetaDataLoaderTest.java +++ b/infra/database/type/sqlserver/src/test/java/org/apache/shardingsphere/infra/database/sqlserver/metadata/data/loader/SQLServerMetaDataLoaderTest.java @@ -204,8 +204,7 @@ private void assertTableMetaDataMap(final Collection schemaMetaD assertThat(actualTableMetaData.getColumns().size(), is(2)); assertThat(actualTableMetaData.getIndexes().size(), is(1)); Iterator indexesIterator = actualTableMetaData.getIndexes().iterator(); - IndexMetaData expected = new IndexMetaData("id"); - expected.getColumns().add("id"); + IndexMetaData expected = new IndexMetaData("id", Collections.singletonList("id")); expected.setUnique(true); assertThat(indexesIterator.next(), is(expected)); }