Skip to content

Commit

Permalink
Keep DistSQLExecutor's test case consistent (#29892)
Browse files Browse the repository at this point in the history
* Rename DropReadwriteSplittingRuleExecutor

* Keep DistSQLExecutor's test case consistent
  • Loading branch information
terrymanu authored Jan 28, 2024
1 parent f32b968 commit 2f1b09b
Show file tree
Hide file tree
Showing 38 changed files with 80 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class CreateBroadcastTableRuleStatementUpdaterTest {
class CreateBroadcastTableRuleExecutorTest {

private final CreateBroadcastTableRuleExecutor executor = new CreateBroadcastTableRuleExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class DropBroadcastTableRuleStatementUpdaterTest {
class DropBroadcastTableRuleExecutorTest {

private final DropBroadcastTableRuleExecutor executor = new DropBroadcastTableRuleExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;

class AlterEncryptRuleStatementUpdaterTest {
class AlterEncryptRuleExecutorTest {

private final AlterEncryptRuleExecutor executor = new AlterEncryptRuleExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;

class CreateEncryptRuleStatementUpdaterTest {
class CreateEncryptRuleExecutorTest {

private final CreateEncryptRuleExecutor executor = new CreateEncryptRuleExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;

class DropEncryptRuleStatementUpdaterTest {
class DropEncryptRuleExecutorTest {

private final DropEncryptRuleExecutor executor = new DropEncryptRuleExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;

class AlterMaskRuleStatementUpdaterTest {
class AlterMaskRuleExecutorTest {

private final AlterMaskRuleExecutor executor = new AlterMaskRuleExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;

class CreateMaskRuleStatementUpdaterTest {
class CreateMaskRuleExecutorTest {

private final CreateMaskRuleExecutor executor = new CreateMaskRuleExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;

class DropMaskRuleStatementUpdaterTest {
class DropMaskRuleExecutorTest {

private final DropMaskRuleExecutor executor = new DropMaskRuleExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class AlterReadwriteSplittingRuleStatementUpdaterTest {
class AlterReadwriteSplittingRuleExecutorTest {

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereDatabase database;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

@ExtendWith(AutoMockExtension.class)
@StaticMockSettings(TypedSPILoader.class)
class CreateReadwriteSplittingRuleStatementUpdaterTest {
class CreateReadwriteSplittingRuleExecutorTest {

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereDatabase database;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class DropReadwriteSplittingRuleStatementUpdaterTest {
class DropReadwriteSplittingRuleExecutorTest {

private final DropReadwriteSplittingRuleExecutor executor = new DropReadwriteSplittingRuleExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class AlterDefaultShadowAlgorithmStatementUpdaterTest {
class AlterDefaultShadowAlgorithmExecutorTest {

private final AlterDefaultShadowAlgorithmExecutor executor = new AlterDefaultShadowAlgorithmExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@

@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
class AlterShadowRuleStatementUpdaterTest {
class AlterShadowRuleExecutorTest {

private final AlterShadowRuleExecutor executor = new AlterShadowRuleExecutor();

@Mock
private ResourceMetaData resourceMetaData;

@Mock
private ShadowRuleConfiguration currentConfig;

private final AlterShadowRuleExecutor executor = new AlterShadowRuleExecutor();

@BeforeEach
void setUp() {
Collection<ShadowDataSourceConfiguration> shadowDataSource = new LinkedList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class CreateDefaultShadowAlgorithmStatementUpdaterTest {
class CreateDefaultShadowAlgorithmExecutorTest {

private final CreateDefaultShadowAlgorithmExecutor executor = new CreateDefaultShadowAlgorithmExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@

@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
class CreateShadowRuleStatementUpdaterTest {
class CreateShadowRuleExecutorTest {

private final CreateShadowRuleExecutor executor = new CreateShadowRuleExecutor();

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereDatabase database;
Expand All @@ -63,8 +65,6 @@ class CreateShadowRuleStatementUpdaterTest {
@Mock
private ShadowRuleConfiguration currentConfig;

private final CreateShadowRuleExecutor executor = new CreateShadowRuleExecutor();

@BeforeEach
void setUp() {
when(database.getResourceMetaData()).thenReturn(resourceMetaData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import static org.mockito.Mockito.mock;

@ExtendWith(MockitoExtension.class)
class DropDefaultShadowAlgorithmStatementUpdaterTest {
class DropDefaultShadowAlgorithmExecutorTest {

private final DropDefaultShadowAlgorithmExecutor executor = new DropDefaultShadowAlgorithmExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;

class DropShadowAlgorithmStatementUpdaterTest {
class DropShadowAlgorithmExecutorTest {

private final DropShadowAlgorithmExecutor executor = new DropShadowAlgorithmExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;

class DropShadowRuleStatementUpdaterTest {
class DropShadowRuleExecutorTest {

private final DropShadowRuleExecutor executor = new DropShadowRuleExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class AlterDefaultShardingStrategyStatementUpdaterTest {
class AlterDefaultShardingStrategyExecutorTest {

private final AlterDefaultShardingStrategyExecutor executor = new AlterDefaultShardingStrategyExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;

class AlterShardingTableReferenceRuleStatementUpdaterTest {
class AlterShardingTableReferenceRuleExecutorTest {

private final AlterShardingTableReferenceRuleExecutor executor = new AlterShardingTableReferenceRuleExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class AlterShardingTableRuleStatementUpdaterTest {
class AlterShardingTableRuleExecutorTest {

private final AlterShardingTableRuleExecutor executor = new AlterShardingTableRuleExecutor();

private final ShardingRuleConfiguration currentRuleConfig = createCurrentShardingRuleConfiguration();

private final ResourceMetaData resourceMetaData = new ResourceMetaData(createDataSource());

private final AlterShardingTableRuleExecutor executor = new AlterShardingTableRuleExecutor();

@BeforeEach
void setUp() {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class CreateDefaultShardingStrategyStatementUpdaterTest {
class CreateDefaultShardingStrategyExecutorTest {

private final CreateDefaultShardingStrategyExecutor executor = new CreateDefaultShardingStrategyExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;

class CreateShardingTableReferenceRuleStatementUpdaterTest {
class CreateShardingTableReferenceRuleExecutorTest {

private final CreateShardingTableReferenceRuleExecutor executor = new CreateShardingTableReferenceRuleExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class CreateShardingTableRuleStatementUpdaterTest {

private final ShardingRuleConfiguration currentRuleConfig = createCurrentShardingRuleConfiguration();
class CreateShardingTableRuleExecutorTest {

private final CreateShardingTableRuleExecutor executor = new CreateShardingTableRuleExecutor();

private final ShardingRuleConfiguration currentRuleConfig = createCurrentShardingRuleConfiguration();

@BeforeEach
void before() {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;

class DropDefaultShardingStrategyStatementUpdaterTest {
class DropDefaultShardingStrategyExecutorTest {

private final DropDefaultShardingStrategyExecutor executor = new DropDefaultShardingStrategyExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.distsql.handler.update.DropShardingAlgorithmExecutor;
import org.apache.shardingsphere.sharding.distsql.statement.DropShardingAlgorithmStatement;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Collections;
Expand All @@ -41,49 +40,47 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;

@ExtendWith(MockitoExtension.class)
class DropShardingAlgorithmStatementUpdaterTest {

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereDatabase database;
class DropShardingAlgorithmExecutorTest {

private final DropShardingAlgorithmExecutor executor = new DropShardingAlgorithmExecutor();

@BeforeEach
void setUp() {
executor.setDatabase(mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS));
}

@Test
void assertCheckSQLStatementWithoutCurrentRule() throws RuleDefinitionViolationException {
executor.setDatabase(database);
assertThrows(MissingRequiredAlgorithmException.class, () -> executor.checkBeforeUpdate(new DropShardingAlgorithmStatement(false, Collections.emptyList()), null));
}

@Test
void assertCheckSQLStatementWithoutCurrentRuleWithIfExists() throws RuleDefinitionViolationException {
DropShardingAlgorithmStatement dropShardingAlgorithmStatement = new DropShardingAlgorithmStatement(true, Collections.emptyList());
executor.setDatabase(database);
executor.checkBeforeUpdate(dropShardingAlgorithmStatement, null);
}

@Test
void assertCheckSQLStatementWithoutExistedAlgorithm() throws RuleDefinitionViolationException {
executor.setDatabase(database);
assertThrows(MissingRequiredAlgorithmException.class, () -> executor.checkBeforeUpdate(createSQLStatement("t_order"), new ShardingRuleConfiguration()));
}

@Test
void assertCheckSQLStatementWithoutExistedAlgorithmWithIfExists() throws RuleDefinitionViolationException {
executor.setDatabase(database);
executor.checkBeforeUpdate(createSQLStatementWithIfExists("t_order"), new ShardingRuleConfiguration());
}

@Test
void assertCheckSQLStatementWithBindingTableRule() throws RuleDefinitionViolationException {
executor.setDatabase(database);
assertThrows(AlgorithmInUsedException.class, () -> executor.checkBeforeUpdate(createSQLStatement("t_order_tb_inline"), createCurrentRuleConfiguration()));
}

@Test
void assertCheckSQLStatementWithBindingTableRuleWithIfExists() throws RuleDefinitionViolationException {
executor.setDatabase(database);
assertThrows(AlgorithmInUsedException.class, () -> executor.checkBeforeUpdate(createSQLStatementWithIfExists("t_order_tb_inline"), createCurrentRuleConfiguration()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class DropShardingAuditorStatementUpdaterTest {
class DropShardingAuditorExecutorTest {

private final DropShardingAuditorExecutor executor = new DropShardingAuditorExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;

class DropShardingKeyGeneratorStatementUpdaterTest {
class DropShardingKeyGeneratorExecutorTest {

private final DropShardingKeyGeneratorExecutor executor = new DropShardingKeyGeneratorExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;

class DropShardingTableReferenceRuleStatementUpdaterTest {
class DropShardingTableReferenceExecutorTest {

private final DropShardingTableReferenceExecutor executor = new DropShardingTableReferenceExecutor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;

class DropShardingTableRuleStatementUpdaterTest {
class DropShardingTableRuleExecutorTest {

private final DropShardingTableRuleExecutor executor = new DropShardingTableRuleExecutor();

Expand Down
Loading

0 comments on commit 2f1b09b

Please sign in to comment.