Search in sources :

Example 26 with FinishCheck

use of com.vip.saturn.it.base.FinishCheck in project Saturn by vipshop.

the class RunAtOnceJobIT method test_C_normalTrigger.

/**
 * 作业STOPPING时立即强制终止
 */
@Test
public void test_C_normalTrigger() throws Exception {
    final int shardCount = 3;
    final String jobName = "test_C_normalTrigger";
    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.setTimeoutSeconds(0);
    jobConfig.setShardingItemParameters("0=0,1=1,2=2");
    addJob(jobConfig);
    Thread.sleep(1000);
    enableJob(jobName);
    Thread.sleep(1000);
    runAtOnce(jobName);
    try {
        waitForFinish(new FinishCheck() {

            @Override
            public boolean isOk() {
                for (int i = 0; i < shardCount; i++) {
                    String key = jobName + "_" + i;
                    if (SimpleJavaJob.statusMap.get(key) != 1) {
                        return false;
                    }
                }
                return true;
            }
        }, 30);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    disableJob(jobName);
    Thread.sleep(1000);
    removeJob(jobName);
    SimpleJavaJob.statusMap.clear();
}
Also used : FinishCheck(com.vip.saturn.it.base.FinishCheck) SimpleJavaJob(com.vip.saturn.it.job.SimpleJavaJob) JobConfig(com.vip.saturn.job.console.domain.JobConfig)

Example 27 with FinishCheck

use of com.vip.saturn.it.base.FinishCheck in project Saturn by vipshop.

the class ShardingIT method test_G_ContainerWithUseDispreferList.

/**
 * preferList配置了容器资源,并且useDispreferList为true。当该容器有executor在线,则得到分片;当该容器全部executor下线,则其他executor得到分片
 */
@Test
public void test_G_ContainerWithUseDispreferList() 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();
        final int shardCount = 2;
        final String jobName = "test_G_ContainerWithUseDispreferList";
        for (int i = 0; i < shardCount; i++) {
            String key = jobName + "_" + i;
            SimpleJavaJob.statusMap.put(key, 0);
        }
        final 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为true
        jobConfig.setUseDispreferList(true);
        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();
        waitForFinish(new FinishCheck() {

            @Override
            public boolean isOk() {
                return hasCompletedZnodeForAllShards(jobName, shardCount);
            }
        }, 10);
        // 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仍然获取0、1分片
        items = ItemUtils.toItemList(regCenter.getDirectly(JobNodePath.getNodeFullPath(jobName, ShardingNode.getShardingNode(executor1.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;
    }
}
Also used : FinishCheck(com.vip.saturn.it.base.FinishCheck) SimpleJavaJob(com.vip.saturn.it.job.SimpleJavaJob) Main(com.vip.saturn.job.executor.Main) JobConfig(com.vip.saturn.job.console.domain.JobConfig) Test(org.junit.Test)

Example 28 with FinishCheck

use of com.vip.saturn.it.base.FinishCheck in project Saturn by vipshop.

the class ShardingIT method test_K_ContainerWithUseDispreferList_ButInvalidTaskId.

/**
 * preferList配置了无效容器资源,并且useDispreferList为true。则非容器资源会得到分片。
 */
@Test
public void test_K_ContainerWithUseDispreferList_ButInvalidTaskId() throws Exception {
    // 启动一个非容器executor
    Main logicExecutor = 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 vdosExecutor = startOneNewExecutorList();
        int shardCount = 2;
        final String jobName = "test_K_ContainerWithUseDispreferList_ButInvalidTaskId";
        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为@hahataskId
        jobConfig.setPreferList("@haha" + taskId);
        // 设置useDispreferList为true
        jobConfig.setUseDispreferList(true);
        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);
        // 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(1);
        Thread.sleep(1000);
        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;
    }
}
Also used : FinishCheck(com.vip.saturn.it.base.FinishCheck) SimpleJavaJob(com.vip.saturn.it.job.SimpleJavaJob) Main(com.vip.saturn.job.executor.Main) JobConfig(com.vip.saturn.job.console.domain.JobConfig) Test(org.junit.Test)

Example 29 with FinishCheck

use of com.vip.saturn.it.base.FinishCheck 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;
    }
}
Also used : FinishCheck(com.vip.saturn.it.base.FinishCheck) SimpleJavaJob(com.vip.saturn.it.job.SimpleJavaJob) Main(com.vip.saturn.job.executor.Main) JobConfig(com.vip.saturn.job.console.domain.JobConfig) Test(org.junit.Test)

Example 30 with FinishCheck

use of com.vip.saturn.it.base.FinishCheck 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;
    }
}
Also used : FinishCheck(com.vip.saturn.it.base.FinishCheck) SimpleJavaJob(com.vip.saturn.it.job.SimpleJavaJob) Main(com.vip.saturn.job.executor.Main) JobConfig(com.vip.saturn.job.console.domain.JobConfig) Test(org.junit.Test)

Aggregations

FinishCheck (com.vip.saturn.it.base.FinishCheck)45 JobConfig (com.vip.saturn.job.console.domain.JobConfig)45 SimpleJavaJob (com.vip.saturn.it.job.SimpleJavaJob)28 Main (com.vip.saturn.job.executor.Main)26 Test (org.junit.Test)23 LongtimeJavaJob (com.vip.saturn.it.job.LongtimeJavaJob)12 Collection (java.util.Collection)5 Random (java.util.Random)2 Signal (sun.misc.Signal)2 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 IThrowableProxy (ch.qos.logback.classic.spi.IThrowableProxy)1 UpdateCronJob (com.vip.saturn.it.job.UpdateCronJob)1 JobA (com.vip.saturn.it.job.downStream.JobA)1 JobB (com.vip.saturn.it.job.downStream.JobB)1 LogbackListAppender (com.vip.saturn.it.utils.LogbackListAppender)1 UpdateJobConfigVo (com.vip.saturn.job.console.vo.UpdateJobConfigVo)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1