ConfigurationService { public JobConfiguration setUpJobConfiguration(final String jobClassName, final JobConfiguration jobConfig) { checkConflictJob(jobClassName, jobConfig); if (!jobNodeStorage.isJobNodeExisted(ConfigurationNode.ROOT) || jobConfig.isOverwrite()) { jobNodeStorage.replaceJobNode(ConfigurationNode.ROOT, YamlEngine.marshal(JobConfigurationPOJO.fromJobConfiguration(jobConfig))); jobNodeStorage.replaceJobRootNode(jobClassName); return jobConfig; } return load(false); } ConfigurationService(final CoordinatorRegistryCenter regCenter, final String jobName); JobConfiguration load(final boolean fromCache); JobConfiguration setUpJobConfiguration(final String jobClassName, final JobConfiguration jobConfig); void checkMaxTimeDiffSecondsTolerable();  }
@Test(expected = JobConfigurationException.class) public void assertSetUpJobConfigurationJobConfigurationForJobConflict() { when(jobNodeStorage.isJobRootNodeExisted()).thenReturn(true); when(jobNodeStorage.getJobRootNodeData()).thenReturn("org.apache.shardingsphere.elasticjob.lite.api.script.api.ScriptJob"); try { configService.setUpJobConfiguration(null, JobConfiguration.newBuilder("test_job", 3).cron("0/1 * * * * ?").build()); } finally { verify(jobNodeStorage).isJobRootNodeExisted(); verify(jobNodeStorage).getJobRootNodeData(); } }
@Test public void assertSetUpJobConfigurationNewJobConfiguration() { JobConfiguration jobConfig = JobConfiguration.newBuilder("test_job", 3).cron("0/1 * * * * ?").build(); assertThat(configService.setUpJobConfiguration(ElasticJob.class.getName(), jobConfig), is(jobConfig)); verify(jobNodeStorage).replaceJobNode("config", YamlEngine.marshal(JobConfigurationPOJO.fromJobConfiguration(jobConfig))); }
@Test public void assertSetUpJobConfigurationExistedJobConfigurationAndOverwrite() { when(jobNodeStorage.isJobNodeExisted(ConfigurationNode.ROOT)).thenReturn(true); JobConfiguration jobConfig = JobConfiguration.newBuilder("test_job", 3).cron("0/1 * * * * ?").overwrite(true).build(); assertThat(configService.setUpJobConfiguration(ElasticJob.class.getName(), jobConfig), is(jobConfig)); verify(jobNodeStorage).replaceJobNode("config", YamlEngine.marshal(JobConfigurationPOJO.fromJobConfiguration(jobConfig))); }
@Test public void assertSetUpJobConfigurationExistedJobConfigurationAndNotOverwrite() { when(jobNodeStorage.isJobNodeExisted(ConfigurationNode.ROOT)).thenReturn(true); when(jobNodeStorage.getJobNodeDataDirectly(ConfigurationNode.ROOT)).thenReturn( YamlEngine.marshal(JobConfigurationPOJO.fromJobConfiguration(JobConfiguration.newBuilder("test_job", 3).cron("0/1 * * * * ?").build()))); JobConfiguration jobConfig = JobConfiguration.newBuilder("test_job", 3).cron("0/1 * * * * ?").overwrite(false).build(); JobConfiguration actual = configService.setUpJobConfiguration(ElasticJob.class.getName(), jobConfig); assertThat(actual, not(jobConfig)); }