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 29756f38f03 Add more test cases on
BroadcastUnregisterStorageUnitRuleAttributeTest and
BroadcastDataNodeRuleAttributeTest (#38224)
29756f38f03 is described below
commit 29756f38f03467b739dcf5cd00f2dc441c4ea198
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Feb 26 22:45:11 2026 +0800
Add more test cases on BroadcastUnregisterStorageUnitRuleAttributeTest and
BroadcastDataNodeRuleAttributeTest (#38224)
* Add more test cases on BroadcastUnregisterStorageUnitRuleAttributeTest
and BroadcastDataNodeRuleAttributeTest
* Add more test cases on BroadcastUnregisterStorageUnitRuleAttributeTest
and BroadcastDataNodeRuleAttributeTest
---
.../BroadcastDataNodeRuleAttributeTest.java | 65 +++++++++++-----------
...castUnregisterStorageUnitRuleAttributeTest.java | 31 +++++++++++
2 files changed, 65 insertions(+), 31 deletions(-)
diff --git
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastDataNodeRuleAttributeTest.java
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastDataNodeRuleAttributeTest.java
index b76a898c7d7..1475a55df23 100644
---
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastDataNodeRuleAttributeTest.java
+++
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastDataNodeRuleAttributeTest.java
@@ -19,15 +19,19 @@ package org.apache.shardingsphere.broadcast.rule.attribute;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
+import java.util.stream.Stream;
-import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -43,60 +47,59 @@ class BroadcastDataNodeRuleAttributeTest {
@Test
void assertGetDataNodesByTableName() {
- Collection<DataNode> actual = new
BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds", "bar_ds"),
Arrays.asList("foo_tbl", "bar_tbl")).getDataNodesByTableName("foo_tbl");
- assertThat(actual, is(Arrays.asList(new DataNode("foo_ds.foo_tbl"),
new DataNode("bar_ds.foo_tbl"))));
+ assertThat(new BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds",
"bar_ds"), Arrays.asList("foo_tbl",
"bar_tbl")).getDataNodesByTableName("foo_tbl"),
+ is(Arrays.asList(new DataNode("foo_ds.foo_tbl"), new
DataNode("bar_ds.foo_tbl"))));
}
@Test
void assertFindFirstActualTable() {
- Optional<String> actual = new
BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds", "bar_ds"),
Arrays.asList("foo_tbl", "bar_tbl")).findFirstActualTable("foo_tbl");
- assertThat(actual, is(Optional.of("foo_tbl")));
+ assertThat(new BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds",
"bar_ds"), Arrays.asList("foo_tbl",
"bar_tbl")).findFirstActualTable("foo_tbl"), is(Optional.of("foo_tbl")));
}
@Test
void assertNotFindFirstActualTable() {
- Optional<String> actual = new
BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds", "bar_ds"),
Arrays.asList("foo_tbl", "bar_tbl")).findFirstActualTable("no_tbl");
- assertFalse(actual.isPresent());
- }
-
- @Test
- void assertIsNeedAccumulateWithEmptyTables() {
- assertTrue(new BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds",
"bar_ds"), Arrays.asList("foo_tbl",
"bar_tbl")).isNeedAccumulate(Collections.emptyList()));
+ assertFalse(new BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds",
"bar_ds"), Arrays.asList("foo_tbl",
"bar_tbl")).findFirstActualTable("no_tbl").isPresent());
}
- @Test
- void assertIsNeedAccumulate() {
- assertTrue(new BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds",
"bar_ds"), Arrays.asList("foo_tbl",
"bar_tbl")).isNeedAccumulate(Collections.singleton("no_tbl")));
- assertFalse(new BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds",
"bar_ds"), Arrays.asList("foo_tbl",
"bar_tbl")).isNeedAccumulate(Arrays.asList("foo_tbl", "bar_tbl")));
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("getIsNeedAccumulateArguments")
+ void assertIsNeedAccumulate(final String name, final Collection<String>
tables, final boolean expected) {
+ assertThat(new BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds",
"bar_ds"), Arrays.asList("foo_tbl", "bar_tbl")).isNeedAccumulate(tables),
is(expected));
}
@Test
void assertFindLogicTableByActualTable() {
- Optional<String> actual = new
BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds", "bar_ds"),
Arrays.asList("foo_tbl", "bar_tbl")).findLogicTableByActualTable("foo_tbl");
- assertThat(actual, is(Optional.of("foo_tbl")));
+ assertThat(new BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds",
"bar_ds"), Arrays.asList("foo_tbl",
"bar_tbl")).findLogicTableByActualTable("foo_tbl"), is(Optional.of("foo_tbl")));
}
@Test
void assertNotFindLogicTableByActualTable() {
- Optional<String> actual = new
BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds", "bar_ds"),
Arrays.asList("foo_tbl", "bar_tbl")).findLogicTableByActualTable("no_tbl");
- assertFalse(actual.isPresent());
+ assertFalse(new BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds",
"bar_ds"), Arrays.asList("foo_tbl",
"bar_tbl")).findLogicTableByActualTable("no_tbl").isPresent());
}
@Test
- void assertFindActualTableByCatalog() {
- Optional<String> actual = new
BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds", "bar_ds"),
Arrays.asList("foo_tbl", "bar_tbl")).findActualTableByCatalog("foo_ds",
"foo_tbl");
- assertThat(actual, is(Optional.of("foo_tbl")));
+ void assertIsReplicaBasedDistribution() {
+ assertTrue(new BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds",
"bar_ds"), Arrays.asList("foo_tbl", "bar_tbl")).isReplicaBasedDistribution());
}
- @Test
- void assertNotFindActualTableByCatalogWithNotExistedCatalog() {
- Optional<String> actual = new
BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds", "bar_ds"),
Arrays.asList("foo_tbl", "bar_tbl")).findActualTableByCatalog("no_ds",
"foo_tbl");
- assertFalse(actual.isPresent());
+ @ParameterizedTest(name = "{0}")
+ @MethodSource("getFindActualTableByCatalogArguments")
+ void assertFindActualTableByCatalog(final String name, final String
catalog, final String logicTable, final String expected) {
+ assertThat(new BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds",
"bar_ds"), Arrays.asList("foo_tbl",
"bar_tbl")).findActualTableByCatalog(catalog, logicTable),
+ is(Optional.ofNullable(expected)));
}
- @Test
- void assertNotFindActualTableByCatalogWithNotExistedTable() {
- Optional<String> actual = new
BroadcastDataNodeRuleAttribute(Arrays.asList("foo_ds", "bar_ds"),
Arrays.asList("foo_tbl", "bar_tbl")).findActualTableByCatalog("foo_ds",
"no_tbl");
- assertFalse(actual.isPresent());
+ private static Stream<Arguments> getIsNeedAccumulateArguments() {
+ return Stream.of(
+ Arguments.of("empty tables", Collections.emptyList(), true),
+ Arguments.of("table not found",
Collections.singleton("no_tbl"), true),
+ Arguments.of("all tables are included",
Arrays.asList("foo_tbl", "bar_tbl"), false));
+ }
+
+ private static Stream<Arguments> getFindActualTableByCatalogArguments() {
+ return Stream.of(
+ Arguments.of("matched data source and table", "foo_ds",
"foo_tbl", "foo_tbl"),
+ Arguments.of("unmatched data source", "no_ds", "foo_tbl",
null),
+ Arguments.of("table not found", "foo_ds", "no_tbl", null));
}
}
diff --git
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastUnregisterStorageUnitRuleAttributeTest.java
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastUnregisterStorageUnitRuleAttributeTest.java
new file mode 100644
index 00000000000..1db8ec3b139
--- /dev/null
+++
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/rule/attribute/BroadcastUnregisterStorageUnitRuleAttributeTest.java
@@ -0,0 +1,31 @@
+/*
+ * 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.rule.attribute;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class BroadcastUnregisterStorageUnitRuleAttributeTest {
+
+ @SuppressWarnings("ConstantValue")
+ @Test
+ void assertIgnoreUsageCheck() {
+ assertTrue(new
BroadcastUnregisterStorageUnitRuleAttribute().ignoreUsageCheck(false, true));
+ }
+}