Skip to content

Commit

Permalink
Reset ScheduleContextFactory after test completed (apache#19723)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Jul 31, 2022
1 parent 33cb909 commit 89e429c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.shardingsphere.schedule.core.ScheduleContextFactory;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
import org.apache.shardingsphere.test.mock.MockedDataSource;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -87,6 +88,11 @@ public void setUp() {
sqlRouter = (DatabaseDiscoverySQLRouter) SQLRouterFactory.getInstances(Collections.singleton(rule)).get(rule);
}

@After
public void tearDown() {
ScheduleContextFactory.getInstance().getScheduleStrategy().remove("foo_id");
}

@Test
public void assertCreateRouteContextToPrimaryWithoutRouteUnits() {
LogicSQL logicSQL = new LogicSQL(mock(SQLStatementContext.class), "", Collections.emptyList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.schedule.core.ScheduleContextFactory;
import org.apache.shardingsphere.test.mock.MockedDataSource;
import org.junit.Before;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import javax.sql.DataSource;
Expand All @@ -49,12 +50,17 @@
public final class DatabaseDiscoveryRuleTest {

private final Map<String, DataSource> dataSourceMap = Collections.singletonMap("primary_ds", new MockedDataSource());

@Before
public void init() {
@BeforeClass
public static void setUp() {
ScheduleContextFactory.getInstance().init("foo_id", new ModeConfiguration("Cluster", mock(PersistRepositoryConfiguration.class), false));
}


@AfterClass
public static void tearDown() {
ScheduleContextFactory.getInstance().getScheduleStrategy().remove("foo_id");
}

@Test
public void assertFindDataSourceRule() {
Optional<DatabaseDiscoveryDataSourceRule> actual = createRule().findDataSourceRule("replica_ds");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ public void assertBuild() {
when(instanceContext.getInstance().getCurrentInstanceId()).thenReturn("foo_id");
assertThat(builder.build(algorithmProvidedRuleConfig, "",
Collections.singletonMap("name", new MockedDataSource()), Collections.emptyList(), instanceContext), instanceOf(DatabaseDiscoveryRule.class));
ScheduleContextFactory.getInstance().getScheduleStrategy().remove("foo_id");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ public void assertBuild() {
when(instanceContext.getInstance().getCurrentInstanceId()).thenReturn("foo_id");
assertThat(builder.build(config, "test_schema",
Collections.singletonMap("name", new MockedDataSource()), Collections.emptyList(), instanceContext), instanceOf(DatabaseDiscoveryRule.class));
ScheduleContextFactory.getInstance().getScheduleStrategy().remove("foo_id");
}
}

0 comments on commit 89e429c

Please sign in to comment.