Skip to content

Commit

Permalink
Refactor StatisticsCollectJob (#34199)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Dec 29, 2024
1 parent dc31380 commit 31df461
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.refresher.ShardingSphereStatisticsRefreshEngine;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import org.apache.shardingsphere.mode.spi.PersistRepository;

/**
* Statistics collect job.
Expand All @@ -35,8 +33,7 @@ public final class StatisticsCollectJob implements SimpleJob {

@Override
public void execute(final ShardingContext shardingContext) {
PersistRepository repository = contextManager.getPersistServiceFacade().getRepository();
if (repository instanceof ClusterPersistRepository) {
if (contextManager.getComputeNodeInstanceContext().getModeConfiguration().isCluster()) {
new ShardingSphereStatisticsRefreshEngine(contextManager).refresh();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void assertExecuteWithStandaloneMode() {

@Test
void assertExecuteWithClusterMode() {
when(contextManager.getComputeNodeInstanceContext().getModeConfiguration().isCluster()).thenReturn(true);
when(contextManager.getPersistServiceFacade().getRepository()).thenReturn(mock(ClusterPersistRepository.class));
when(contextManager.getMetaDataContexts().getMetaData().getTemporaryProps().getValue(TemporaryConfigurationPropertyKey.PROXY_META_DATA_COLLECTOR_ENABLED)).thenReturn(false);
job.execute(null);
Expand Down

0 comments on commit 31df461

Please sign in to comment.