Skip to content

Commit

Permalink
optimize CreateBroadcastTableRuleStatementUpdaterTest
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangML committed Nov 13, 2023
1 parent e89c4a1 commit f875422
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ class CreateBroadcastTableRuleStatementUpdaterTest {

private final CreateBroadcastTableRuleStatementUpdater updater = new CreateBroadcastTableRuleStatementUpdater();

@Test
void assertCreatedRuleConfigurationWithNoStorageUnits() {
BroadcastRuleConfiguration currentConfig = mock(BroadcastRuleConfiguration.class);
when(currentConfig.getTables()).thenReturn(Collections.singleton("t_address"));
CreateBroadcastTableRuleStatement statement = new CreateBroadcastTableRuleStatement(false, Collections.singleton("t_address"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getResourceMetaData().getStorageUnits()).thenReturn(Collections.emptyMap());
assertThrows(EmptyStorageUnitException.class, () -> updater.checkSQLStatement(database, statement, currentConfig));
}

@Test
void assertCheckSQLStatementWithDuplicateBroadcastRule() {
BroadcastRuleConfiguration currentConfig = mock(BroadcastRuleConfiguration.class);
Expand All @@ -64,14 +74,4 @@ private ShardingSphereDatabase mockShardingSphereDatabase() {
when(database.getResourceMetaData().getStorageUnits()).thenReturn(Collections.singletonMap("ds_0", mock(StorageUnit.class)));
return database;
}

@Test
void assertCreatedRuleConfigurationWithNoStorageUnits() {
BroadcastRuleConfiguration currentConfig = mock(BroadcastRuleConfiguration.class);
when(currentConfig.getTables()).thenReturn(Collections.singleton("t_address"));
CreateBroadcastTableRuleStatement statement = new CreateBroadcastTableRuleStatement(false, Collections.singleton("t_address"));
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS);
when(database.getResourceMetaData().getStorageUnits()).thenReturn(Collections.emptyMap());
assertThrows(EmptyStorageUnitException.class, () -> updater.checkSQLStatement(database, statement, currentConfig));
}
}

0 comments on commit f875422

Please sign in to comment.