From 425c8c4454006d183e480b43ab28147f7cca3525 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Fri, 10 May 2024 21:04:51 +0800 Subject: [PATCH] Refactor ContextManagerBuilderParameter (#31198) * Refactor ContextManagerBuilderParameter * Refactor ContextManagerBuilderParameter --- .../ContextManagerBuilderParameter.java | 10 ---- .../ContextManagerBuilderParameterTest.java | 48 ------------------- 2 files changed, 58 deletions(-) diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameter.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameter.java index d362a7a498f2d..25c09653ffc2e 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameter.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameter.java @@ -54,16 +54,6 @@ public final class ContextManagerBuilderParameter { private final boolean force; - /** - * Whether parameter is empty. - * - * @return parameter is empty or not - */ - public boolean isEmpty() { - return globalRuleConfigs.isEmpty() && props.isEmpty() - && databaseConfigs.entrySet().stream().allMatch(entry -> entry.getValue().getStorageUnits().isEmpty() && entry.getValue().getRuleConfigurations().isEmpty()); - } - /** * Get mode configuration. * diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameterTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameterTest.java index adf5a5d7d5076..2ac9e518e6428 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameterTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerBuilderParameterTest.java @@ -17,69 +17,21 @@ package org.apache.shardingsphere.mode.manager; -import org.apache.shardingsphere.infra.config.database.DatabaseConfiguration; import org.apache.shardingsphere.infra.config.mode.ModeConfiguration; import org.apache.shardingsphere.infra.config.mode.PersistRepositoryConfiguration; -import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; -import org.apache.shardingsphere.test.util.PropertiesBuilder; -import org.apache.shardingsphere.test.util.PropertiesBuilder.Property; import org.junit.jupiter.api.Test; import java.util.Collections; -import java.util.Map; import java.util.Properties; 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.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; class ContextManagerBuilderParameterTest { - @Test - void assertIsEmptyWithoutAllParameters() { - assertTrue(new ContextManagerBuilderParameter(null, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyList(), new Properties(), null, null, false).isEmpty()); - } - - @Test - void assertIsEmptyWithDatabaseAndWithoutConfigurations() { - assertTrue(new ContextManagerBuilderParameter(null, mockDatabaseConfigurations(true, true), Collections.emptyMap(), Collections.emptyList(), new Properties(), null, null, false).isEmpty()); - } - - @Test - void assertIsNotEmptyWhenGlobalRuleIsNotEmpty() { - assertFalse(new ContextManagerBuilderParameter(null, Collections.emptyMap(), Collections.emptyMap(), Collections.singleton(mock(RuleConfiguration.class)), - new Properties(), null, null, false).isEmpty()); - } - - @Test - void assertIsNotEmptyWhenPropsIsNotEmpty() { - assertFalse(new ContextManagerBuilderParameter(null, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyList(), PropertiesBuilder.build(new Property("foo", "foo_value")), - null, null, false).isEmpty()); - } - - @Test - void assertIsEmptyWhenDataSourceIsNotEmpty() { - assertFalse(new ContextManagerBuilderParameter(null, mockDatabaseConfigurations(false, true), Collections.emptyMap(), Collections.emptyList(), new Properties(), null, null, false).isEmpty()); - } - - @Test - void assertIsEmptyWhenDatabaseRuleIsNotEmpty() { - assertFalse(new ContextManagerBuilderParameter(null, mockDatabaseConfigurations(true, false), Collections.emptyMap(), Collections.emptyList(), new Properties(), null, null, false).isEmpty()); - } - - private Map mockDatabaseConfigurations(final boolean isEmptyStorageUnits, final boolean isEmptyRuleConfigs) { - DatabaseConfiguration databaseConfig = mock(DatabaseConfiguration.class, RETURNS_DEEP_STUBS); - when(databaseConfig.getStorageUnits().isEmpty()).thenReturn(isEmptyStorageUnits); - when(databaseConfig.getRuleConfigurations().isEmpty()).thenReturn(isEmptyRuleConfigs); - return Collections.singletonMap("foo_ds", databaseConfig); - } - @Test void assertGetDefaultModeConfiguration() { ContextManagerBuilderParameter param = new ContextManagerBuilderParameter(null, Collections.emptyMap(), Collections.emptyMap(), Collections.emptyList(), new Properties(), null, null, false);