use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class JobOperationRestApiControllerTest method testCreateSuccessfully.
@Test
public void testCreateSuccessfully() throws Exception {
JobEntity jobEntity = constructJobEntity("job1");
mvc.perform(post("/rest/v1/domain/jobs").contentType(MediaType.APPLICATION_JSON).content(jobEntity.toJSON())).andExpect(status().isCreated());
JobConfig jobConfig = convert2JobConfig("domain", jobEntity);
ArgumentCaptor<JobConfig> argument = ArgumentCaptor.forClass(JobConfig.class);
verify(restApiService).createJob(eq("domain"), argument.capture());
assertTrue("jobconfig is not equal", jobConfig.equals(argument.getValue()));
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class JobOverviewControllerTest method buildJobConfig.
private JobConfig buildJobConfig(String name) {
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(name);
return jobConfig;
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class LocalModeIT method test_B.
@Test
public void test_B() throws Exception {
startExecutorList(2);
int shardCount = 3;
final String jobName = "test_B";
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
SimpleJavaJob.statusMap.put(key, 0);
}
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setCron("*/1 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setProcessCountIntervalSeconds(1);
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig.setShardingItemParameters("*=0");
jobConfig.setLocalMode(true);
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobName);
Thread.sleep(1000);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (Main executor : saturnExecutorList) {
String count = zkGetJobNode(jobName, "servers/" + executor.getExecutorName() + "/processSuccessCount");
System.out.println("count:" + count + ";executor:" + executor.getExecutorName());
if (count == null)
return false;
int times = Integer.parseInt(count);
if (times <= 0)
return false;
}
return true;
}
}, 60);
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class LocalModeIT method test_D_fixIssue441.
@Test
public void test_D_fixIssue441() throws Exception {
LogbackListAppender logbackListAppender = new LogbackListAppender();
logbackListAppender.addToLogger(AbstractAsyncShardingTask.class);
logbackListAppender.start();
final int items = 4;
final String jobName = "test_D_fixIssue441";
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setCron("*/1 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setProcessCountIntervalSeconds(1);
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig.setShardingItemParameters("*=0");
jobConfig.setLocalMode(true);
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobName);
Thread.sleep(1000);
startExecutorList(items);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (int i = 0; i < items; i++) {
if (SimpleJavaJob.statusMap.get(jobName + "_" + i) <= 0) {
return false;
}
}
return true;
}
}, 30);
// 下线0,1,2
stopExecutorGracefully(0);
stopExecutorGracefully(1);
stopExecutorGracefully(2);
// 上线一个executor
startOneNewExecutorList();
List<ILoggingEvent> allLogs = logbackListAppender.getAllLogs();
Iterator<ILoggingEvent> iterator = allLogs.iterator();
while (iterator.hasNext()) {
ILoggingEvent event = iterator.next();
if (event != null) {
IThrowableProxy throwableProxy = event.getThrowableProxy();
if (throwableProxy != null) {
assertThat(throwableProxy.getClassName()).isNotEqualTo("java.lang.ArrayIndexOutOfBoundsException");
}
}
}
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
}
use of com.vip.saturn.job.console.domain.JobConfig in project Saturn by vipshop.
the class LocalModeIT method test_C_withPreferList.
@Test
public void test_C_withPreferList() throws Exception {
startExecutorList(2);
int shardCount = 3;
final String jobName = "test_C_withPreferList";
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
SimpleJavaJob.statusMap.put(key, 0);
}
final Main preferExecutor = saturnExecutorList.get(0);
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setCron("*/1 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setProcessCountIntervalSeconds(1);
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig.setShardingItemParameters("*=0");
jobConfig.setLocalMode(true);
jobConfig.setPreferList(preferExecutor.getExecutorName());
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobName);
Thread.sleep(1000);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
String count0 = zkGetJobNode(jobName, "servers/" + preferExecutor.getExecutorName() + "/processSuccessCount");
System.out.println("count:" + count0 + ";executor:" + preferExecutor.getExecutorName());
if (count0 == null)
return false;
int times0 = Integer.parseInt(count0);
if (times0 <= 0)
return false;
for (int i = 1; i < saturnExecutorList.size(); i++) {
Main executor = saturnExecutorList.get(i);
String count = zkGetJobNode(jobName, "servers/" + executor.getExecutorName() + "/processSuccessCount");
System.out.println("count:" + count + ";executor:" + executor.getExecutorName());
if (count != null) {
int times = Integer.parseInt(count);
if (times != 0)
return false;
}
}
return true;
}
}, 30);
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
}
Aggregations