use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class AbstractSaturnIT method stopExecutor.
public void stopExecutor(int index) throws Exception {
assertThat(saturnExecutorList.size()).isGreaterThan(index);
Main main = saturnExecutorList.get(index);
if (main != null) {
main.shutdown();
} else {
log.warn("the {} Executor has stopped", index);
}
saturnExecutorList.set(index, null);
for (Main tmp : saturnExecutorList) {
if (tmp != null) {
return;
}
}
saturnExecutorList.clear();
}
use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class AbstractSaturnIT method getExecutorConfig.
public ExecutorConfig getExecutorConfig(int index) {
assertThat(saturnExecutorList.size()).isGreaterThan(index);
Main main = saturnExecutorList.get(index);
SaturnExecutor saturnExecutor = (SaturnExecutor) main.getSaturnExecutor();
return saturnExecutor.getSaturnExecutorService().getExecutorConfig();
}
use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class AbstractSaturnIT method startExecutor.
public Main startExecutor(int index) throws Exception {
assertThat(nestedZkUtils.isStarted());
Main main = saturnExecutorList.get(index);
if (main != null) {
// 如果节点正在运行则退出
log.warn("the executor{} already exist.", index);
return main;
} else {
main = new Main();
String executorName = "executorName" + index;
String[] args = { "-namespace", NAMESPACE, "-executorName", executorName };
main.launchInner(args, Main.class.getClassLoader(), Main.class.getClassLoader());
saturnExecutorList.set(index, main);
Thread.sleep(1000);
return main;
}
}
use of com.vip.saturn.job.executor.Main 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.executor.Main 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