You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2020/12/17 09:24:19 UTC
[shardingsphere] branch master updated: Optimize
StandaloneScalingJobServiceTest (#8668)
This is an automated email from the ASF dual-hosted git repository.
menghaoran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new f143f25 Optimize StandaloneScalingJobServiceTest (#8668)
f143f25 is described below
commit f143f256e821ae7260162604869d2dfdc5578a51
Author: 邱鹿 Lucas <lu...@163.com>
AuthorDate: Thu Dec 17 17:23:56 2020 +0800
Optimize StandaloneScalingJobServiceTest (#8668)
Co-authored-by: qiulu3 <Lucas209910>
---
.../impl/StandaloneScalingJobServiceTest.java | 29 +++++++++++++++++-----
1 file changed, 23 insertions(+), 6 deletions(-)
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/service/impl/StandaloneScalingJobServiceTest.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/service/impl/StandaloneScalingJobServiceTest.java
index cbdbd41..7240f51 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/service/impl/StandaloneScalingJobServiceTest.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/service/impl/StandaloneScalingJobServiceTest.java
@@ -30,25 +30,38 @@ import org.apache.shardingsphere.scaling.core.job.position.resume.FakeResumeBrea
import org.apache.shardingsphere.scaling.core.job.position.resume.IncrementalPositionResumeBreakPointManager;
import org.apache.shardingsphere.scaling.core.job.position.resume.ResumeBreakPointManagerFactory;
import org.apache.shardingsphere.scaling.core.schedule.JobStatus;
+import org.apache.shardingsphere.scaling.core.schedule.ScalingTaskScheduler;
import org.apache.shardingsphere.scaling.core.service.ScalingJobService;
import org.apache.shardingsphere.scaling.core.util.ScalingConfigurationUtil;
import org.apache.shardingsphere.scaling.core.utils.ReflectionUtil;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
import java.io.IOException;
import java.util.Map;
import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+@RunWith(MockitoJUnitRunner.class)
public final class StandaloneScalingJobServiceTest {
private final ScalingJobService scalingJobService = new StandaloneScalingJobService();
+ @Mock
+ private ScalingJob scalingJob;
+
+ @Mock
+ private ScalingTaskScheduler scalingTaskScheduler;
+
@Before
@SneakyThrows(ReflectiveOperationException.class)
public void setUp() {
@@ -67,14 +80,18 @@ public final class StandaloneScalingJobServiceTest {
}
@Test
+ @SuppressWarnings("unchecked")
+ @SneakyThrows(ReflectiveOperationException.class)
public void assertStopExistJob() {
- Optional<ScalingJob> scalingJob = scalingJobService.start(mockScalingConfiguration());
- assertTrue(scalingJob.isPresent());
- long jobId = scalingJob.get().getJobId();
+ Map<Long, ScalingJob> scalingJobMap = ReflectionUtil.getFieldValue(scalingJobService, "scalingJobMap", Map.class);
+ Map<Long, ScalingTaskScheduler> scalingTaskSchedulerMap = ReflectionUtil.getFieldValue(scalingJobService, "scalingTaskSchedulerMap", Map.class);
+ assertNotNull(scalingJobMap);
+ assertNotNull(scalingTaskSchedulerMap);
+ long jobId = 1L;
+ scalingJobMap.put(jobId, scalingJob);
+ scalingTaskSchedulerMap.put(jobId, scalingTaskScheduler);
scalingJobService.stop(jobId);
- JobProgress progress = scalingJobService.getProgress(jobId);
- assertThat(progress.getStatus(), is(JobStatus.STOPPED.name()));
- scalingJobService.remove(jobId);
+ verify(scalingJob).setStatus(JobStatus.STOPPED.name());
}
@Test(expected = ScalingJobNotFoundException.class)