sandynz commented on code in PR #16854:
URL: https://github.com/apache/shardingsphere/pull/16854#discussion_r851582720


##########
shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/scenario/rulealtered/RuleAlteredJobWorkerTest.java:
##########
@@ -44,7 +67,47 @@ public void assertCreateRuleAlteredContextNoAlteredRule() {
     @Test
     public void assertCreateRuleAlteredContextSuccess() {
         JobConfiguration jobConfig = 
JobConfigurationBuilder.createJobConfiguration();
-        final RuleAlteredContext ruleAlteredContext = 
RuleAlteredJobWorker.createRuleAlteredContext(jobConfig);
-        
Assert.assertNotNull(ruleAlteredContext.getOnRuleAlteredActionConfig());
+        RuleAlteredContext ruleAlteredContext = 
RuleAlteredJobWorker.createRuleAlteredContext(jobConfig);
+        assertNotNull(ruleAlteredContext.getOnRuleAlteredActionConfig());
+    }
+    
+    @Test
+    public void assertRuleAlteredActionEnabled() {
+        ShardingRuleConfiguration ruleConfiguration = new 
ShardingRuleConfiguration();
+        ruleConfiguration.setScalingName("default_scaling");
+        
assertTrue(RuleAlteredJobWorker.isOnRuleAlteredActionEnabled(ruleConfiguration));
+    }
+    
+    @Test
+    public void assertRuleAlteredActionDisabled() throws IOException, 
InvocationTargetException, NoSuchMethodException, IllegalAccessException {
+        URL dataSourceUrl = 
getClass().getClassLoader().getResource("scaling/detector/datasource_config.yaml");
+        assertNotNull(dataSourceUrl);
+        URL sourceRuleUrl = 
getClass().getClassLoader().getResource("scaling/rule_alter/source_rules_config.yaml");
+        assertNotNull(sourceRuleUrl);
+        URL targetRuleUrl = 
getClass().getClassLoader().getResource("scaling/rule_alter/target_rules_config.yaml");
+        assertNotNull(targetRuleUrl);
+        StartScalingEvent startScalingEvent = new 
StartScalingEvent("logic_db", FileUtils.readFileToString(new 
File(dataSourceUrl.getFile())),
+                FileUtils.readFileToString(new File(sourceRuleUrl.getFile())), 
FileUtils.readFileToString(new File(dataSourceUrl.getFile())),
+                FileUtils.readFileToString(new File(targetRuleUrl.getFile())), 
0, 1);
+        RuleAlteredJobWorker ruleAlteredJobWorker = new RuleAlteredJobWorker();
+        Object result = ReflectionUtil.invokeMethod(ruleAlteredJobWorker, 
"createJobConfig", new Class[]{StartScalingEvent.class}, new 
Object[]{startScalingEvent});
+        assertTrue(((Optional<?>) result).isPresent());
+    }
+    
+    @Test
+    public void assertHasUncompletedJob() throws IOException, 
InvocationTargetException, NoSuchMethodException, IllegalAccessException {
+        final JobConfiguration jobConfiguration = 
JobConfigurationBuilder.createJobConfiguration();
+        RuleAlteredJobContext jobContext = new 
RuleAlteredJobContext(jobConfiguration);
+        JobProgress finishProcess = new JobProgress();
+        finishProcess.setStatus(JobStatus.FINISHED);
+        jobContext.setInitProgress(finishProcess);
+        GovernanceRepositoryAPI repositoryAPI = 
PipelineAPIFactory.getGovernanceRepositoryAPI();
+        repositoryAPI.persistJobProgress(jobContext);
+        URL jobConfigUrl = 
getClass().getClassLoader().getResource("scaling/rule_alter/scaling_job_config.yaml");
+        assertNotNull(jobConfigUrl);

Review Comment:
   OK, keep it for now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to