use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class ShardingIT method testJobAverageWithPreferList.
private void testJobAverageWithPreferList(String jobPrefix, boolean useDispreferList) throws Exception {
if (!AbstractAsyncShardingTask.ENABLE_JOB_BASED_SHARDING) {
return;
}
// 启动第1台executor
Main executor1 = startOneNewExecutorList();
// 添加第1个作业,设置preferList
final String job1 = jobPrefix + "_job1";
{
final JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(job1);
jobConfig.setCron("0/1 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(2);
jobConfig.setShardingItemParameters("0=0,1=1");
jobConfig.setPreferList(executor1.getExecutorName());
jobConfig.setUseDispreferList(useDispreferList);
addJob(jobConfig);
Thread.sleep(1000);
}
// 添加第2个作业
final String job2 = jobPrefix + "_job2";
{
final JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(job2);
jobConfig.setCron("0/1 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(2);
jobConfig.setShardingItemParameters("0=0,1=1");
addJob(jobConfig);
Thread.sleep(1000);
}
// 启用job1
enableJob(job1);
Thread.sleep(2000);
// 校验
Map<String, List<Integer>> shardingItems = namespaceShardingContentService.getShardingItems(job1);
assertThat(shardingItems.get(executor1.getExecutorName())).hasSize(2).contains(0, 1);
shardingItems = namespaceShardingContentService.getShardingItems(job2);
assertThat(shardingItems.get(executor1.getExecutorName())).isEmpty();
List<Integer> items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job1, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).hasSize(2).contains(0, 1);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job2, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).isEmpty();
// 启动第2台executor
Main executor2 = startOneNewExecutorList();
// 等待作业执行获取分片
Thread.sleep(2000);
// 校验
shardingItems = namespaceShardingContentService.getShardingItems(job1);
assertThat(shardingItems.get(executor1.getExecutorName())).hasSize(2).contains(0, // 由于设置了preferList为executor1
1);
assertThat(shardingItems.get(executor2.getExecutorName())).isEmpty();
shardingItems = namespaceShardingContentService.getShardingItems(job2);
assertThat(shardingItems.get(executor1.getExecutorName())).isEmpty();
assertThat(shardingItems.get(executor2.getExecutorName())).isEmpty();
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job1, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).hasSize(2).contains(0, 1);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job1, ShardingNode.getShardingNode(executor2.getExecutorName()))));
assertThat(items).isEmpty();
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job2, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).isEmpty();
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job2, ShardingNode.getShardingNode(executor2.getExecutorName()))));
assertThat(items).isEmpty();
// 启用job2
enableJob(job2);
Thread.sleep(2000);
// 校验
shardingItems = namespaceShardingContentService.getShardingItems(job1);
assertThat(shardingItems.get(executor1.getExecutorName())).hasSize(2).contains(0, 1);
assertThat(shardingItems.get(executor2.getExecutorName())).isEmpty();
shardingItems = namespaceShardingContentService.getShardingItems(job2);
assertThat(shardingItems.get(executor1.getExecutorName())).hasSize(1).contains(1);
assertThat(shardingItems.get(executor2.getExecutorName())).hasSize(1).contains(0);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job1, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).hasSize(2).contains(0, 1);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job1, ShardingNode.getShardingNode(executor2.getExecutorName()))));
assertThat(items).isEmpty();
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job2, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).hasSize(1).contains(1);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job2, ShardingNode.getShardingNode(executor2.getExecutorName()))));
// 由于优先放回总负荷最小的,所以executor2首先被分配0
assertThat(items).hasSize(1).contains(0);
// 禁用job1
disableJob(job1);
Thread.sleep(2000);
// 校验
shardingItems = namespaceShardingContentService.getShardingItems(job1);
assertThat(shardingItems.get(executor1.getExecutorName())).isEmpty();
assertThat(shardingItems.get(executor2.getExecutorName())).isEmpty();
shardingItems = namespaceShardingContentService.getShardingItems(job2);
assertThat(shardingItems.get(executor1.getExecutorName())).hasSize(1).contains(1);
assertThat(shardingItems.get(executor2.getExecutorName())).hasSize(1).contains(0);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job1, ShardingNode.getShardingNode(executor1.getExecutorName()))));
// 由于禁用的作业没有被notify,所以这个节点的内容还是原来的
assertThat(items).hasSize(2).contains(0, 1);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job1, ShardingNode.getShardingNode(executor2.getExecutorName()))));
assertThat(items).isEmpty();
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job2, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).hasSize(1).contains(1);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job2, ShardingNode.getShardingNode(executor2.getExecutorName()))));
assertThat(items).hasSize(1).contains(0);
// 下线executor1
stopExecutorGracefully(0);
Thread.sleep(2000);
// 校验
shardingItems = namespaceShardingContentService.getShardingItems(job1);
assertThat(shardingItems.get(executor1.getExecutorName())).isNull();
assertThat(shardingItems.get(executor2.getExecutorName())).isEmpty();
shardingItems = namespaceShardingContentService.getShardingItems(job2);
assertThat(shardingItems.get(executor1.getExecutorName())).isNull();
assertThat(shardingItems.get(executor2.getExecutorName())).hasSize(2).contains(0, 1);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job1, ShardingNode.getShardingNode(executor2.getExecutorName()))));
assertThat(items).isEmpty();
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job2, ShardingNode.getShardingNode(executor2.getExecutorName()))));
assertThat(items).hasSize(2).contains(0, 1);
// 启用job1
enableJob(job1);
Thread.sleep(2000);
// 校验
shardingItems = namespaceShardingContentService.getShardingItems(job1);
assertThat(shardingItems.get(executor1.getExecutorName())).isNull();
if (useDispreferList) {
// 由于useDispreferList为true,所以分片被executor2接管
assertThat(shardingItems.get(executor2.getExecutorName())).hasSize(2).contains(0, 1);
} else {
assertThat(shardingItems.get(executor2.getExecutorName())).isEmpty();
}
shardingItems = namespaceShardingContentService.getShardingItems(job2);
assertThat(shardingItems.get(executor1.getExecutorName())).isNull();
assertThat(shardingItems.get(executor2.getExecutorName())).hasSize(2).contains(0, 1);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job1, ShardingNode.getShardingNode(executor2.getExecutorName()))));
if (useDispreferList) {
assertThat(items).hasSize(2).contains(0, 1);
} else {
assertThat(items).isEmpty();
}
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job2, ShardingNode.getShardingNode(executor2.getExecutorName()))));
assertThat(items).hasSize(2).contains(0, 1);
// 关闭
disableJob(job1);
Thread.sleep(1000);
removeJob(job1);
Thread.sleep(1000);
disableJob(job2);
Thread.sleep(1000);
removeJob(job2);
stopExecutorListGracefully();
}
use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class ShardingIT method test_J_ContainerWithLocalModeAndOnlyPreferList.
/**
* preferList配置了容器资源,并且是本地模式,useDispreferList为false。当该容器有executor在线,则得到分片,并且分片数为1;当该容器全部executor下线,则其他executor也得不到分片
*/
@Test
public void test_J_ContainerWithLocalModeAndOnlyPreferList() throws Exception {
// 启动一个非容器executor
Main executor1 = startOneNewExecutorList();
boolean cleanOld = SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN;
String taskOld = SystemEnvProperties.VIP_SATURN_CONTAINER_DEPLOYMENT_ID;
try {
String taskId = "test1";
SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN = true;
SystemEnvProperties.VIP_SATURN_CONTAINER_DEPLOYMENT_ID = taskId;
// 启动一个容器executor
Main executor2 = startOneNewExecutorList();
int shardCount = 2;
final String jobName = "test_J_ContainerWithLocalModeAndOnlyPreferList";
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("*=a");
// 设置localMode为true
jobConfig.setLocalMode(true);
// 设置preferList为@taskId
jobConfig.setPreferList("@" + taskId);
// 设置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);
// executor2获取到0分片,executor1获取不到分片
List<Integer> items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor2.getExecutorName()))));
assertThat(items).hasSize(1).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(1000L);
// 等待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();
} finally {
SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN = cleanOld;
SystemEnvProperties.VIP_SATURN_CONTAINER_DEPLOYMENT_ID = taskOld;
}
}
use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class ShardingIT method test_H_ContainerWithOnlyPreferList.
/**
* preferList配置了容器资源,并且useDispreferList为false。当该容器有executor在线,则得到分片;当该容器全部executor下线,则其他executor可以得不到分片
*/
@Test
public void test_H_ContainerWithOnlyPreferList() throws Exception {
// 启动一个非容器executor
Main executor1 = startOneNewExecutorList();
boolean cleanOld = SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN;
String taskOld = SystemEnvProperties.VIP_SATURN_CONTAINER_DEPLOYMENT_ID;
try {
String taskId = "test1";
SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN = true;
SystemEnvProperties.VIP_SATURN_CONTAINER_DEPLOYMENT_ID = taskId;
// 启动一个容器executor
Main executor2 = startOneNewExecutorList();
int shardCount = 2;
final String jobName = "test_H_ContainerWithOnlyPreferList";
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");
jobConfig.setLocalMode(false);
// 设置preferList为@taskId
jobConfig.setPreferList("@" + taskId);
// 设置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);
// executor2获取到0、1分片,executor1获取不到分片
List<Integer> items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor2.getExecutorName()))));
assertThat(items).contains(0, 1);
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(1000L);
// 等待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();
} finally {
SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN = cleanOld;
SystemEnvProperties.VIP_SATURN_CONTAINER_DEPLOYMENT_ID = taskOld;
}
}
use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class ShardingIT method test_L_ContainerWithUseDispreferList_ButInvalidTaskId_ContainerFirst.
/**
* preferList配置了无效容器资源,并且useDispreferList为true。先添加作业,启用作业,再启动容器,再启动物理机。则非容器资源会得到分片。
*/
@Test
public void test_L_ContainerWithUseDispreferList_ButInvalidTaskId_ContainerFirst() throws Exception {
boolean cleanOld = SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN;
String taskOld = SystemEnvProperties.VIP_SATURN_CONTAINER_DEPLOYMENT_ID;
try {
int shardCount = 2;
final String jobName = "test_L_ContainerWithUseDispreferList_ButInvalidTaskId_ContainerFirst";
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");
jobConfig.setLocalMode(false);
// 设置preferList为@haha
jobConfig.setPreferList("@haha");
// 设置useDispreferList为true
jobConfig.setUseDispreferList(true);
addJob(jobConfig);
Thread.sleep(1000);
enableJob(jobName);
// 启动一个容器executor
String taskId = "test1";
SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN = true;
SystemEnvProperties.VIP_SATURN_CONTAINER_DEPLOYMENT_ID = taskId;
Main vdosExecutor = startOneNewExecutorList();
// 启动一个非容器executor
SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN = false;
SystemEnvProperties.VIP_SATURN_CONTAINER_DEPLOYMENT_ID = null;
Main logicExecutor = startOneNewExecutorList();
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return isNeedSharding(jobName);
}
}, 10);
runAtOnce(jobName);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return !isNeedSharding(jobName);
}
}, 10);
// vdosExecutor获取不到分片,logicExecutor获取到0、1分片
List<Integer> items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(vdosExecutor.getExecutorName()))));
assertThat(items).isEmpty();
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(logicExecutor.getExecutorName()))));
assertThat(items).contains(0, 1);
// wait running completed
Thread.sleep(1000);
// vdosExecutor下线
stopExecutorGracefully(0);
Thread.sleep(1000L);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return isNeedSharding(jobName);
}
}, 10);
runAtOnce(jobName);
waitForFinish(new FinishCheck() {
@Override
public boolean isOk() {
return !isNeedSharding(jobName);
}
}, 10);
// logicExecutor仍然获取0、1分片
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(logicExecutor.getExecutorName()))));
assertThat(items).contains(0, 1);
disableJob(jobName);
Thread.sleep(1000);
removeJob(jobName);
stopExecutorListGracefully();
} finally {
SystemEnvProperties.VIP_SATURN_EXECUTOR_CLEAN = cleanOld;
SystemEnvProperties.VIP_SATURN_CONTAINER_DEPLOYMENT_ID = taskOld;
}
}
use of com.vip.saturn.job.executor.Main in project Saturn by vipshop.
the class ShardingIT method test_C_JobAverageWithLocalMode.
@Test
public void test_C_JobAverageWithLocalMode() throws Exception {
if (!AbstractAsyncShardingTask.ENABLE_JOB_BASED_SHARDING) {
return;
}
// 启动第1台executor
Main executor1 = startOneNewExecutorList();
Main executor2 = startOneNewExecutorList();
// 添加第1个作业,设置preferList
final String job1 = "test_C_JobAverageWithLocalMode_job1";
{
final JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(job1);
jobConfig.setCron("0/1 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
jobConfig.setShardingTotalCount(2);
jobConfig.setShardingItemParameters("0=0,1=1");
// 设置preferList
jobConfig.setPreferList(executor1.getExecutorName());
addJob(jobConfig);
Thread.sleep(1000);
}
// 启用作业
enableJob(job1);
Thread.sleep(2000);
// 校验
Map<String, List<Integer>> shardingItems = namespaceShardingContentService.getShardingItems(job1);
assertThat(shardingItems.get(executor1.getExecutorName())).hasSize(2).contains(0, 1);
assertThat(shardingItems.get(executor2.getExecutorName())).isEmpty();
List<Integer> items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job1, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).hasSize(2).contains(0, 1);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job1, ShardingNode.getShardingNode(executor2.getExecutorName()))));
assertThat(items).isEmpty();
// 添加第2个作业,设置本地模式
final String job2 = "test_C_JobAverageWithLocalMode_job2";
{
final JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(job2);
jobConfig.setCron("0/1 * * * * ?");
jobConfig.setJobType(JobType.JAVA_JOB.toString());
jobConfig.setJobClass(SimpleJavaJob.class.getCanonicalName());
// 注意,设置1
jobConfig.setShardingTotalCount(1);
jobConfig.setShardingItemParameters("*=0");
// 设置本地模式
jobConfig.setLocalMode(true);
addJob(jobConfig);
Thread.sleep(1000);
}
// 启用job2
enableJob(job2);
Thread.sleep(2000);
// 校验
shardingItems = namespaceShardingContentService.getShardingItems(job1);
assertThat(shardingItems.get(executor1.getExecutorName())).hasSize(2).contains(0, 1);
assertThat(shardingItems.get(executor2.getExecutorName())).isEmpty();
// 由于job2为本地模式,所以仍然是每台机一个分片
shardingItems = namespaceShardingContentService.getShardingItems(job2);
assertThat(shardingItems.get(executor1.getExecutorName())).hasSize(1).contains(1);
assertThat(shardingItems.get(executor2.getExecutorName())).hasSize(1).contains(// 由于优先分配给总负荷最小的机器,所以executor2被分配0
0);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job1, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).hasSize(2).contains(0, 1);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job1, ShardingNode.getShardingNode(executor2.getExecutorName()))));
assertThat(items).isEmpty();
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job2, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).hasSize(1).contains(1);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job2, ShardingNode.getShardingNode(executor2.getExecutorName()))));
assertThat(items).hasSize(1).contains(0);
// 下线executor2
stopExecutorGracefully(1);
Thread.sleep(2000);
// 校验
shardingItems = namespaceShardingContentService.getShardingItems(job1);
assertThat(shardingItems.get(executor1.getExecutorName())).hasSize(2).contains(0, 1);
assertThat(shardingItems.get(executor2.getExecutorName())).isNull();
// 由于job2为本地模式,所以仍然是每台机一个分片
shardingItems = namespaceShardingContentService.getShardingItems(job2);
// 不会改变为0分片
assertThat(shardingItems.get(executor1.getExecutorName())).hasSize(1).contains(1);
assertThat(shardingItems.get(executor2.getExecutorName())).isNull();
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job1, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).hasSize(2).contains(0, 1);
items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(job2, ShardingNode.getShardingNode(executor1.getExecutorName()))));
assertThat(items).hasSize(1).contains(1);
// 关闭
disableJob(job1);
Thread.sleep(1000);
removeJob(job1);
Thread.sleep(1000);
disableJob(job2);
Thread.sleep(1000);
removeJob(job2);
stopExecutorListGracefully();
}
Aggregations