use of com.vip.saturn.it.base.FinishCheck in project Saturn by vipshop.
the class ShardingIT method test_D_PreferList.
@Test
public void test_D_PreferList() throws Exception {
// 启动第1台executor
Main executor1 = startOneNewExecutorList();
int shardCount = 3;
final String jobName = "test_D_PreferList";
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=0,1=1,2=2");
jobConfig.setPreferList(executor1.getExecutorName());
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobName);
Thread.sleep(1000);
runAtOnce(jobName);
Thread.sleep(1000);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
if (isNeedSharding(jobName)) {
return false;
}
return true;
}
}, 10);
List<Integer> items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).contains(0, 1, 2);
// 启动第2台executor
Main executor2 = startOneNewExecutorList();
Thread.sleep(1000);
runAtOnce(jobName);
Thread.sleep(1000);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
if (isNeedSharding(jobName)) {
return false;
}
return true;
}
}, 10);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).contains(0, 1, 2);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor2.getExecutorName()))));
System.out.println(items);
assertThat(items).isEmpty();
// 停第1个executor
stopExecutorGracefully(0);
Thread.sleep(1000);
runAtOnce(jobName);
Thread.sleep(1000);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
if (isNeedSharding(jobName)) {
return false;
}
return true;
}
}, 10);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor1.getExecutorName()))));
System.out.println(items);
assertThat(items).isEmpty();
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor2.getExecutorName()))));
System.out.println(items);
assertThat(items).contains(0, 1, 2);
// 再次启动第一个executor
startExecutor(0);
Thread.sleep(1000);
runAtOnce(jobName);
Thread.sleep(1000);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
if (isNeedSharding(jobName)) {
return false;
}
return true;
}
}, 10);
// 分片会重新回到executor1上
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor1.getExecutorName()))));
log.info("sharding at executor1 {}: ", items);
assertThat(items).contains(0, 1, 2);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor2.getExecutorName()))));
log.info("sharding at executor2 {}: ", items);
assertThat(items).isEmpty();
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
stopExecutorListGracefully();
}
use of com.vip.saturn.it.base.FinishCheck in project Saturn by vipshop.
the class ShutdownGracefullyIT method test_A_TERM_Signal.
@Test
public void test_A_TERM_Signal() throws Exception {
SystemEnvProperties.VIP_SATURN_SHUTDOWN_TIMEOUT = 10;
startExecutorList(1);
final int shardCount = 3;
final String jobName = "test_A_TERM_Signal";
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
status.runningCount = 0;
status.sleepSeconds = 8;
status.finished = false;
status.timeout = false;
LongtimeJavaJob.statusMap.put(key, status);
}
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setCron("9 9 9 9 9 ? 2099");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(LongtimeJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(shardCount);
jobConfig.setShardingItemParameters("0=0,1=1,2=2");
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobName);
Thread.sleep(1000);
runAtOnce(jobName);
Thread.sleep(50);
ShutdownHandler.exitAfterHandler(false);
Signal.raise(new Signal("TERM"));
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
Collection<LongtimeJavaJob.JobStatus> values = LongtimeJavaJob.statusMap.values();
for (LongtimeJavaJob.JobStatus status : values) {
if (!status.finished) {
return false;
}
}
return true;
}
}, 10);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
stopExecutorListGracefully();
}
use of com.vip.saturn.it.base.FinishCheck in project Saturn by vipshop.
the class ShutdownGracefullyIT method test_B_INT_Signal.
@Test
public void test_B_INT_Signal() throws Exception {
SystemEnvProperties.VIP_SATURN_SHUTDOWN_TIMEOUT = 5;
startExecutorList(1);
final int shardCount = 3;
final String jobName = "test_B_INT_Signal";
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
status.runningCount = 0;
status.sleepSeconds = 3;
status.finished = false;
status.timeout = false;
LongtimeJavaJob.statusMap.put(key, status);
}
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setCron("9 9 9 9 9 ? 2099");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(LongtimeJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(shardCount);
jobConfig.setShardingItemParameters("0=0,1=1,2=2");
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobName);
Thread.sleep(1000);
runAtOnce(jobName);
Thread.sleep(50);
ShutdownHandler.exitAfterHandler(false);
Signal.raise(new Signal("INT"));
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
Collection<LongtimeJavaJob.JobStatus> values = LongtimeJavaJob.statusMap.values();
for (LongtimeJavaJob.JobStatus status : values) {
if (!status.finished) {
return false;
}
}
return true;
}
}, 5);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
stopExecutorListGracefully();
}
use of com.vip.saturn.it.base.FinishCheck in project Saturn by vipshop.
the class ZkStopStartIT method test_A_zkStopStartJobJava.
@Test
public void test_A_zkStopStartJobJava() throws Exception {
final int shardCount = 3;
final String jobName = "test_A_zkStopStartJobJava";
LongtimeJavaJob.statusMap.clear();
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
status.runningCount = 0;
status.sleepSeconds = 60;
status.finished = false;
status.timeout = false;
status.running = false;
LongtimeJavaJob.statusMap.put(key, status);
}
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setCron("9 9 9 9 9 ? 2099");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(LongtimeJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(shardCount);
jobConfig.setShardingItemParameters("0=0,1=1,2=2");
addJob(jobConfig);
Thread.sleep(2000);
enableJob(jobName);
Thread.sleep(2000);
runAtOnce(jobName);
Thread.sleep(2000);
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
Collection<LongtimeJavaJob.JobStatus> values = LongtimeJavaJob.statusMap.values();
for (LongtimeJavaJob.JobStatus status : values) {
if (!status.running) {
return false;
}
}
return true;
}
}, 40);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
stopZkServer();
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
Collection<LongtimeJavaJob.JobStatus> values = LongtimeJavaJob.statusMap.values();
for (LongtimeJavaJob.JobStatus status : values) {
if (!status.finished) {
return false;
}
}
return true;
}
}, 40);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
LongtimeJavaJob.statusMap.clear();
}
use of com.vip.saturn.it.base.FinishCheck in project Saturn by vipshop.
the class TimeoutJobIT method test_A_JavaJob.
@Test
public void test_A_JavaJob() throws Exception {
final int shardCount = 3;
final String jobName = "test_A_JavaJob";
for (int i = 0; i < shardCount; i++) {
String key = jobName + "_" + i;
LongtimeJavaJob.JobStatus status = new LongtimeJavaJob.JobStatus();
status.runningCount = 0;
status.sleepSeconds = 30;
status.finished = false;
status.timeout = false;
status.beforeTimeout = false;
LongtimeJavaJob.statusMap.put(key, status);
}
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setCron("9 9 9 9 9 ? 2099");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(LongtimeJavaJob.class.getCanonicalName());
jobConfig.setTimeoutSeconds(3);
jobConfig.setShardingTotalCount(shardCount);
jobConfig.setShardingItemParameters("0=0,1=1,2=2");
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobConfig.getJobName());
Thread.sleep(1000);
runAtOnce(jobName);
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
Collection<LongtimeJavaJob.JobStatus> values = LongtimeJavaJob.statusMap.values();
for (LongtimeJavaJob.JobStatus status : values) {
if (!status.finished || !status.timeout || !status.beforeTimeout) {
return false;
}
}
return true;
}
}, 30);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
try {
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
for (int j = 0; j < shardCount; j++) {
if (!regCenter.isExisted(JobNodePath.getNodeFullPath(jobName, ExecutionNode.getTimeoutNode(j)))) {
return false;
}
}
return true;
}
}, 10);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
Thread.sleep(1000);
for (int j = 0; j < shardCount; j++) {
String key = jobName + "_" + j;
LongtimeJavaJob.JobStatus status = LongtimeJavaJob.statusMap.get(key);
assertThat(status.runningCount).isEqualTo(0);
assertThat(regCenter.isExisted(JobNodePath.getNodeFullPath(jobName, ExecutionNode.getTimeoutNode(j)))).isEqualTo(true);
assertThat(regCenter.isExisted(JobNodePath.getNodeFullPath(jobName, ExecutionNode.getCompletedNode(j)))).isEqualTo(true);
}
disableJob(jobConfig.getJobName());
Thread.sleep(1000);
removeJob(jobConfig.getJobName());
LongtimeJavaJob.statusMap.clear();
}
Aggregations