use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class DeleteJobIT method test_B.
/**
* 部分结点存活
*
* @throws Exception
*/
@Test
public void test_B() throws Exception {
final int shardCount = 3;
final String jobName = "deleteITJob";
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
SimpleJavaJob.statusMap.put(key, 0);
}
stopExecutor(0);
stopExecutor(1);
JobConfiguration jobConfiguration = new JobConfiguration(jobName);
jobConfiguration.setCron("0/2 * * * * ?");
jobConfiguration.setJobType(JobType.JAVA_JOB.toString());
jobConfiguration.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfiguration.setShardingTotalCount(shardCount);
jobConfiguration.setShardingItemParameters("0=0,1=1,2=2");
addJob(jobConfiguration);
Thread.sleep(1000);
enableJob(jobConfiguration.getJobName());
try {
waitForFinish(new FinishCheck() {
@Override
public boolean docheck() {
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
if (SimpleJavaJob.statusMap.get(key) < 1) {
return false;
}
}
return true;
}
}, 4);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
disableJob(jobConfiguration.getJobName());
try {
waitForFinish(new FinishCheck() {
@Override
public boolean docheck() {
for (int j = 0; j < shardCount; j++) {
if (!regCenter.isExisted(JobNodePath.getNodeFullPath(jobName, ExecutionNode.getCompletedNode(j)))) {
return false;
}
}
return true;
}
}, 3);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
removeJob(jobConfiguration.getJobName());
try {
waitForFinish(new FinishCheck() {
@Override
public boolean docheck() {
for (Main executor : saturnExecutorList) {
if (executor == null) {
continue;
}
if (regCenter.isExisted(ServerNode.getServerNode(jobName, executor.getExecutorName()))) {
return false;
}
}
return true;
}
}, 10);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class AbstractSaturnIT method startOneNewExecutorList.
public static Main startOneNewExecutorList() throws Exception {
assertThat(nestedZkUtils.isStarted());
int size = saturnExecutorList.size();
Main main = new Main();
String executorName = "executorName" + size;
/*
* ClassLoader saturnClassloader = classloaders.get(executorName); if(saturnClassloader == null){
* saturnClassloader = new SaturnClassLoader(getAppClassLoaderUrls(Main.class.getClassLoader()), null);
* classloaders.put(executorName,saturnClassloader); }
*/
String[] args = { "-namespace", NAMESPACE, "-executorName", executorName };
main.launchInner(args, Main.class.getClassLoader(), Main.class.getClassLoader());
saturnExecutorList.add(main);
Thread.sleep(1000);
return main;
}
use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class AbstractSaturnIT method stopExecutorGracefully.
public static void stopExecutorGracefully(int index) throws Exception {
assertThat(saturnExecutorList.size()).isGreaterThan(index);
Main main = saturnExecutorList.get(index);
if (main != null) {
main.shutdownGracefully();
} 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 ShardingIT method test_F_LocalModeWithPreferList.
/**
* 本地模式作业,配置了preferList,并且useDispreferList为false,则只有preferList能得到该作业分片
*/
@Test
public void test_F_LocalModeWithPreferList() throws Exception {
Main executor1 = startOneNewExecutorList();
Main executor2 = startOneNewExecutorList();
int shardCount = 2;
final String jobName = "test_F_LocalModeWithPreferList";
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("9 9 9 9 9 ? 2099");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(shardCount);
jobConfig.setShardingItemParameters("*=0");
jobConfig.setLocalMode(true);
// 设置preferList为executor2
jobConfig.setPreferList(executor2.getExecutorName());
// 设置useDispreferList为false
jobConfig.setUseDispreferList(false);
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobName);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return isNeedSharding(jobName);
}
}, 10);
runAtOnce(jobName);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return !isNeedSharding(jobName);
}
}, 10);
List<Integer> items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor2.getExecutorName()))));
assertThat(items).contains(0);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).isEmpty();
// wait running completed
Thread.sleep(1000);
// executor2下线
stopExecutorGracefully(1);
Thread.sleep(1000);
// 等待sharding分片完成
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return isNeedSharding(jobName);
}
}, 10);
runAtOnce(jobName);
// 等待拿走分片
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return !isNeedSharding(jobName);
}
}, 10);
// executor1仍然获取不到分片
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).isEmpty();
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
stopExecutorListGracefully();
}
use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class ShardingIT method test_N_NotifyNecessaryJobs.
/**
* sharding仅仅通知分片信息改变的作业
*/
@Test
public void test_N_NotifyNecessaryJobs() throws Exception {
// 启动1个executor
Main executor1 = startOneNewExecutorList();
Thread.sleep(1000);
// 启动第一个作业
Thread.sleep(1000);
final String jobName1 = "test_N_NotifyNecessaryJobs1";
JobConfig jobConfig1 = new JobConfig();
jobConfig1.setJobName(jobName1);
jobConfig1.setCron("9 9 9 9 9 ? 2099");
jobConfig1.setJobType(JobType.JAVA_JOB.toString());
jobConfig1.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig1.setShardingTotalCount(1);
jobConfig1.setShardingItemParameters("0=0");
addJob(jobConfig1);
Thread.sleep(1000);
enableJob(jobName1);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return isNeedSharding(jobName1);
}
}, 10);
runAtOnce(jobName1);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return !isNeedSharding(jobName1);
}
}, 10);
// 启动第二个作业
Thread.sleep(1000);
final String jobName2 = "test_N_NotifyNecessaryJobs2";
JobConfig jobConfig2 = new JobConfig();
jobConfig2.setJobName(jobName2);
jobConfig2.setCron("9 9 9 9 9 ? 2099");
jobConfig2.setJobType(JobType.JAVA_JOB.toString());
jobConfig2.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig2.setShardingTotalCount(1);
jobConfig2.setShardingItemParameters("0=0");
addJob(jobConfig2);
// job1和job2均无需re-sharding
Thread.sleep(1000);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return !isNeedSharding(jobName1) && !isNeedSharding(jobName2);
}
}, 10);
enableJob(jobName2);
// job1无需re-sharding
Thread.sleep(1000);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return !isNeedSharding(jobName1);
}
}, 10);
disableJob(jobName1);
removeJob(jobName1);
disableJob(jobName2);
removeJob(jobName2);
stopExecutorListGracefully();
}
Aggregations