This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new d1d9bae0f66 Add more test cases on BroadcastMetaDataReviseEntryTest
and BroadcastSchemaTableAggregationReviserTest (#38216)
d1d9bae0f66 is described below
commit d1d9bae0f66dc89907b7689ea44b6377e2d75198
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Feb 26 19:08:16 2026 +0800
Add more test cases on BroadcastMetaDataReviseEntryTest and
BroadcastSchemaTableAggregationReviserTest (#38216)
---
.../reviser/BroadcastMetaDataReviseEntryTest.java | 48 +++++++++++++
...BroadcastSchemaTableAggregationReviserTest.java | 80 ++++++++++++++++++++++
2 files changed, 128 insertions(+)
diff --git
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/metadata/reviser/BroadcastMetaDataReviseEntryTest.java
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/metadata/reviser/BroadcastMetaDataReviseEntryTest.java
new file mode 100644
index 00000000000..5a701e330de
--- /dev/null
+++
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/metadata/reviser/BroadcastMetaDataReviseEntryTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.shardingsphere.broadcast.metadata.reviser;
+
+import
org.apache.shardingsphere.broadcast.metadata.reviser.schema.BroadcastSchemaTableAggregationReviser;
+import org.apache.shardingsphere.broadcast.rule.BroadcastRule;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
+import
org.apache.shardingsphere.infra.metadata.database.schema.reviser.MetaDataReviseEntry;
+import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader;
+import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
+import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
+import org.junit.jupiter.api.Test;
+import org.mockito.internal.configuration.plugins.Plugins;
+
+import java.util.Collections;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class BroadcastMetaDataReviseEntryTest {
+
+ private final BroadcastMetaDataReviseEntry reviseEntry =
(BroadcastMetaDataReviseEntry) OrderedSPILoader.getServicesByClass(
+ MetaDataReviseEntry.class,
Collections.singleton(BroadcastRule.class)).get(BroadcastRule.class);
+
+ @Test
+ void assertGetSchemaTableAggregationReviser() throws
ReflectiveOperationException {
+ Optional<?> actual = reviseEntry.getSchemaTableAggregationReviser(
+ new ConfigurationProperties(PropertiesBuilder.build(new
Property(ConfigurationPropertyKey.CHECK_TABLE_METADATA_ENABLED.getKey(),
Boolean.TRUE.toString()))));
+ assertTrue(actual.isPresent());
+ assertTrue((boolean)
Plugins.getMemberAccessor().get(BroadcastSchemaTableAggregationReviser.class.getDeclaredField("checkTableMetaDataEnabled"),
actual.get()));
+ }
+}
diff --git
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/metadata/reviser/schema/BroadcastSchemaTableAggregationReviserTest.java
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/metadata/reviser/schema/BroadcastSchemaTableAggregationReviserTest.java
new file mode 100644
index 00000000000..5a3530e8702
--- /dev/null
+++
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/metadata/reviser/schema/BroadcastSchemaTableAggregationReviserTest.java
@@ -0,0 +1,80 @@
+/*
+ * 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.shardingsphere.broadcast.metadata.reviser.schema;
+
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.broadcast.rule.BroadcastRule;
+import
org.apache.shardingsphere.database.connector.core.exception.RuleAndStorageMetaDataMismatchedException;
+import
org.apache.shardingsphere.database.connector.core.metadata.data.model.ColumnMetaData;
+import
org.apache.shardingsphere.database.connector.core.metadata.data.model.TableMetaData;
+import org.junit.jupiter.api.Test;
+import org.mockito.internal.configuration.plugins.Plugins;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+
+class BroadcastSchemaTableAggregationReviserTest {
+
+ @Test
+ void assertAdd() {
+ BroadcastSchemaTableAggregationReviser reviser = new
BroadcastSchemaTableAggregationReviser(false);
+ TableMetaData tableMetaData = new TableMetaData("foo_tbl", null, null,
null);
+ reviser.add(tableMetaData);
+ Map<String, Collection<TableMetaData>> actual =
getTableMetaDataMap(reviser);
+ assertTrue(actual.containsKey("foo_tbl"));
+ assertThat(actual.get("foo_tbl"),
is(Collections.singletonList(tableMetaData)));
+ }
+
+ @Test
+ void assertAggregateWithCheckTableMetaDataDisabled() {
+ BroadcastSchemaTableAggregationReviser reviser = new
BroadcastSchemaTableAggregationReviser(false);
+ Map<String, Collection<TableMetaData>> tableMetaDataMap =
getTableMetaDataMap(reviser);
+ Collection<TableMetaData> tableMetaDataList =
createMismatchedTableMetaDataList();
+ tableMetaDataMap.put("foo_tbl", tableMetaDataList);
+ Collection<TableMetaData> actual =
reviser.aggregate(mock(BroadcastRule.class));
+ assertThat(actual,
is(Collections.singletonList(tableMetaDataList.iterator().next())));
+ }
+
+ @Test
+ void assertAggregateWithCheckTableMetaDataEnabled() {
+ BroadcastSchemaTableAggregationReviser reviser = new
BroadcastSchemaTableAggregationReviser(true);
+ Map<String, Collection<TableMetaData>> tableMetaDataMap =
getTableMetaDataMap(reviser);
+ tableMetaDataMap.put("foo_tbl", createMismatchedTableMetaDataList());
+ assertThrows(RuleAndStorageMetaDataMismatchedException.class, () ->
reviser.aggregate(mock(BroadcastRule.class)));
+ }
+
+ private Collection<TableMetaData> createMismatchedTableMetaDataList() {
+ TableMetaData tableMetaData1 = new TableMetaData("foo_tbl", null,
null, null);
+ TableMetaData tableMetaData2 = new TableMetaData("foo_tbl",
Collections.singletonList(mock(ColumnMetaData.class)), null, null);
+ return Arrays.asList(tableMetaData1, tableMetaData2);
+ }
+
+ @SneakyThrows(ReflectiveOperationException.class)
+ @SuppressWarnings("unchecked")
+ private Map<String, Collection<TableMetaData>> getTableMetaDataMap(final
BroadcastSchemaTableAggregationReviser reviser) {
+ return (Map<String, Collection<TableMetaData>>)
Plugins.getMemberAccessor().get(BroadcastSchemaTableAggregationReviser.class.getDeclaredField("tableMetaDataMap"),
reviser);
+ }
+}