Search in sources :

Example 1 with StageMonitor

use of com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.StageMonitor in project otter by alibaba.

the class LoadStageListenerTest method testProcess_init.

@Test
public void testProcess_init() {
    final List<Long> initProcessIds = new ArrayList<Long>();
    final Map<Long, List<String>> stages = new HashMap<Long, List<String>>();
    try {
        // 准备数据
        Long p1 = initProcess();
        initStage(p1, ArbitrateConstants.NODE_SELECTED);
        initStage(p1, ArbitrateConstants.NODE_EXTRACTED);
        initStage(p1, ArbitrateConstants.NODE_TRANSFORMED, getData(nid));
        Long p2 = initProcess();
        initStage(p2, ArbitrateConstants.NODE_SELECTED);
        initStage(p2, ArbitrateConstants.NODE_EXTRACTED);
        initStage(p2, ArbitrateConstants.NODE_TRANSFORMED, getData(nid + 1));
        // 准备清理数据
        initProcessIds.add(p1);
        initProcessIds.add(p2);
        List<String> p1Stages = Arrays.asList(ArbitrateConstants.NODE_SELECTED, ArbitrateConstants.NODE_EXTRACTED, ArbitrateConstants.NODE_TRANSFORMED);
        stages.put(p1, p1Stages);
        List<String> p2Stages = Arrays.asList(ArbitrateConstants.NODE_SELECTED, ArbitrateConstants.NODE_EXTRACTED, ArbitrateConstants.NODE_TRANSFORMED);
        stages.put(p2, p2Stages);
        // 进行验证
        LoadStageListener load = new LoadStageListener(pipelineId);
        Long processId = load.waitForProcess();
        want.number(processId).isEqualTo(p1);
        // 验证下process信息
        StageMonitor monitor = ArbitrateFactory.getInstance(pipelineId, StageMonitor.class);
        List<Long> processIds = monitor.getCurrentProcessIds();
        // 获取下stage信息
        List<String> currentP1Stages = monitor.getCurrentStages(p1);
        List<String> currentP2Stages = monitor.getCurrentStages(p2);
        want.collection(processIds).isEqualTo(initProcessIds);
        want.collection(currentP1Stages).isEqualTo(stages.get(p1));
        want.collection(currentP2Stages).isEqualTo(stages.get(p2));
        load.destory();
        ArbitrateFactory.destory(pipelineId);
    } catch (InterruptedException e) {
        want.fail();
    } finally {
        for (Long processId : initProcessIds) {
            List<String> ss = stages.get(processId);
            for (String stage : ss) {
                destoryStage(processId, stage);
            }
            destoryProcess(processId);
        }
    }
}
Also used : LoadStageListener(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.LoadStageListener) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) StageMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.StageMonitor) Test(org.testng.annotations.Test) BaseStageTest(com.alibaba.otter.shared.arbitrate.setl.BaseStageTest)

Example 2 with StageMonitor

use of com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.StageMonitor in project otter by alibaba.

the class SelectStageListenerTest method testProcess_dymanic.

@Test
public void testProcess_dymanic() {
    final List<Long> initProcessIds = new ArrayList<Long>();
    try {
        initProcess();
        SelectStageListener select = new SelectStageListener(pipelineId);
        final Long p2 = select.waitForProcess();
        final Long p3 = select.waitForProcess();
        final CountDownLatch count = new CountDownLatch(1);
        ExecutorService executor = Executors.newCachedThreadPool();
        executor.submit(new Runnable() {

            public void run() {
                sleep();
                destoryProcess(p2);
                sleep();
                destoryProcess(p3);
                count.countDown();
            }
        });
        Long p4 = select.waitForProcess();
        Long p5 = select.waitForProcess();
        initProcessIds.add(p4);
        initProcessIds.add(p5);
        sleep();
        StageMonitor monitor = ArbitrateFactory.getInstance(pipelineId, StageMonitor.class);
        List<Long> processIds = monitor.getCurrentProcessIds();
        want.collection(processIds).isEqualTo(initProcessIds);
        count.await();
        select.destory();
        ArbitrateFactory.destory(pipelineId);
    } catch (InterruptedException e) {
        want.fail();
    } finally {
        for (Long processId : initProcessIds) {
            destoryProcess(processId);
        }
    }
}
Also used : SelectStageListener(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.SelectStageListener) ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) StageMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.StageMonitor) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test) BaseStageTest(com.alibaba.otter.shared.arbitrate.setl.BaseStageTest)

Example 3 with StageMonitor

use of com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.StageMonitor in project otter by alibaba.

the class SelectStageListenerTest method testProcess_init.

@Test
public void testProcess_init() {
    final List<Long> initProcessIds = new ArrayList<Long>();
    try {
        initProcess();
        // initProcessIds.add(p1);
        SelectStageListener select = new SelectStageListener(pipelineId);
        sleep();
        Long p2 = select.waitForProcess();
        Long p3 = select.waitForProcess();
        Long p4 = select.waitForProcess();
        initProcessIds.add(p2);
        initProcessIds.add(p3);
        initProcessIds.add(p4);
        StageMonitor monitor = ArbitrateFactory.getInstance(pipelineId, StageMonitor.class);
        List<Long> processIds = monitor.getCurrentProcessIds();
        want.collection(processIds).isEqualTo(initProcessIds);
        select.destory();
        ArbitrateFactory.destory(pipelineId);
    } catch (InterruptedException e) {
        want.fail();
    } finally {
        for (Long processId : initProcessIds) {
            destoryProcess(processId);
        }
    }
}
Also used : SelectStageListener(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.SelectStageListener) ArrayList(java.util.ArrayList) StageMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.StageMonitor) Test(org.testng.annotations.Test) BaseStageTest(com.alibaba.otter.shared.arbitrate.setl.BaseStageTest)

Example 4 with StageMonitor

use of com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.StageMonitor in project otter by alibaba.

the class TransformStageListenerTest method testProcess_init.

@Test
public void testProcess_init() {
    final List<Long> initProcessIds = new ArrayList<Long>();
    final Map<Long, List<String>> stages = new HashMap<Long, List<String>>();
    try {
        Long p1 = initProcess();
        initStage(p1, ArbitrateConstants.NODE_SELECTED);
        initStage(p1, ArbitrateConstants.NODE_EXTRACTED);
        initStage(p1, ArbitrateConstants.NODE_TRANSFORMED);
        Long p2 = initProcess();
        initStage(p2, ArbitrateConstants.NODE_SELECTED);
        initStage(p2, ArbitrateConstants.NODE_EXTRACTED, getData(nid));
        Long p3 = initProcess();
        initStage(p3, ArbitrateConstants.NODE_SELECTED);
        initStage(p3, ArbitrateConstants.NODE_EXTRACTED);
        initStage(p3, ArbitrateConstants.NODE_TRANSFORMED);
        Long p4 = initProcess();
        initStage(p4, ArbitrateConstants.NODE_SELECTED);
        initStage(p4, ArbitrateConstants.NODE_EXTRACTED, getData(nid + 1));
        // 准备清理数据
        initProcessIds.add(p1);
        initProcessIds.add(p2);
        initProcessIds.add(p3);
        initProcessIds.add(p4);
        List<String> p1Stages = Arrays.asList(ArbitrateConstants.NODE_SELECTED, ArbitrateConstants.NODE_EXTRACTED, ArbitrateConstants.NODE_TRANSFORMED);
        stages.put(p1, p1Stages);
        List<String> p2Stages = Arrays.asList(ArbitrateConstants.NODE_SELECTED, ArbitrateConstants.NODE_EXTRACTED);
        stages.put(p2, p2Stages);
        List<String> p3Stages = Arrays.asList(ArbitrateConstants.NODE_SELECTED, ArbitrateConstants.NODE_EXTRACTED, ArbitrateConstants.NODE_TRANSFORMED);
        stages.put(p3, p3Stages);
        List<String> p4Stages = Arrays.asList(ArbitrateConstants.NODE_SELECTED, ArbitrateConstants.NODE_EXTRACTED);
        stages.put(p4, p4Stages);
        // 进行验证
        TransformStageListener transform = new TransformStageListener(pipelineId);
        Long processId = transform.waitForProcess();
        want.number(processId).isEqualTo(p2);
        // 验证下process信息
        StageMonitor monitor = ArbitrateFactory.getInstance(pipelineId, StageMonitor.class);
        List<Long> processIds = monitor.getCurrentProcessIds();
        // 获取下stage信息
        List<String> currentP1Stages = monitor.getCurrentStages(p1);
        List<String> currentP2Stages = monitor.getCurrentStages(p2);
        List<String> currentP3Stages = monitor.getCurrentStages(p3);
        List<String> currentP4Stages = monitor.getCurrentStages(p4);
        want.collection(processIds).isEqualTo(initProcessIds);
        want.collection(currentP1Stages).isEqualTo(stages.get(p1));
        want.collection(currentP2Stages).isEqualTo(stages.get(p2));
        want.collection(currentP3Stages).isEqualTo(stages.get(p3));
        want.collection(currentP4Stages).isEqualTo(stages.get(p4));
        transform.destory();
        ArbitrateFactory.destory(pipelineId);
    } catch (InterruptedException e) {
        want.fail();
    } finally {
        for (Long processId : initProcessIds) {
            List<String> ss = stages.get(processId);
            for (String stage : ss) {
                destoryStage(processId, stage);
            }
            destoryProcess(processId);
        }
    }
}
Also used : TransformStageListener(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.TransformStageListener) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) StageMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.StageMonitor) Test(org.testng.annotations.Test) BaseStageTest(com.alibaba.otter.shared.arbitrate.setl.BaseStageTest)

Example 5 with StageMonitor

use of com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.StageMonitor in project otter by alibaba.

the class TransformStageListenerTest method testProcess_dynamic.

@Test
public void testProcess_dynamic() {
    final List<Long> initProcessIds = new ArrayList<Long>();
    final Map<Long, List<String>> stages = new HashMap<Long, List<String>>();
    try {
        // 准备数据,准备5个process,一个已经完成extracted,一个满足条件,一个出现error,一个出现end,一个stage满足但不是自己机器处理
        Long p1 = initProcess();
        initStage(p1, ArbitrateConstants.NODE_SELECTED);
        initStage(p1, ArbitrateConstants.NODE_EXTRACTED);
        initStage(p1, ArbitrateConstants.NODE_TRANSFORMED);
        Long p2 = initProcess();
        initStage(p2, ArbitrateConstants.NODE_SELECTED);
        initStage(p2, ArbitrateConstants.NODE_EXTRACTED, getData(nid + 1));
        // 初始化信息
        TransformStageListener transform = new TransformStageListener(pipelineId);
        // 开始变化
        destoryStage(p1, ArbitrateConstants.NODE_SELECTED);
        destoryStage(p1, ArbitrateConstants.NODE_EXTRACTED);
        destoryStage(p1, ArbitrateConstants.NODE_TRANSFORMED);
        destoryProcess(p1);
        Long p3 = initProcess();
        initStage(p3, ArbitrateConstants.NODE_SELECTED);
        initStage(p3, ArbitrateConstants.NODE_EXTRACTED, getData(nid));
        Long p4 = initProcess();
        // 准备清理数据
        initProcessIds.add(p2);
        initProcessIds.add(p3);
        initProcessIds.add(p4);
        List<String> p1Stages = Lists.newArrayList();
        stages.put(p1, p1Stages);
        List<String> p2Stages = Arrays.asList(ArbitrateConstants.NODE_SELECTED, ArbitrateConstants.NODE_EXTRACTED);
        stages.put(p2, p2Stages);
        List<String> p3Stages = Arrays.asList(ArbitrateConstants.NODE_SELECTED, ArbitrateConstants.NODE_EXTRACTED);
        stages.put(p3, p3Stages);
        List<String> p4Stages = Lists.newArrayList();
        stages.put(p4, p4Stages);
        // sleep一下,等待数据同步
        sleep();
        // 进行验证
        Long processId = transform.waitForProcess();
        want.number(processId).isEqualTo(p3);
        // 验证下process信息
        StageMonitor monitor = ArbitrateFactory.getInstance(pipelineId, StageMonitor.class);
        List<Long> processIds = monitor.getCurrentProcessIds();
        // 获取下stage信息
        List<String> currentP1Stages = monitor.getCurrentStages(p1);
        List<String> currentP2Stages = monitor.getCurrentStages(p2);
        List<String> currentP3Stages = monitor.getCurrentStages(p3);
        List<String> currentP4Stages = monitor.getCurrentStages(p4);
        want.collection(processIds).isEqualTo(initProcessIds);
        want.collection(currentP1Stages).isEqualTo(stages.get(p1));
        want.collection(currentP2Stages).isEqualTo(stages.get(p2));
        want.collection(currentP3Stages).isEqualTo(stages.get(p3));
        want.collection(currentP4Stages).isEqualTo(stages.get(p4));
        transform.destory();
        ArbitrateFactory.destory(pipelineId);
    } catch (InterruptedException e) {
        want.fail();
    } finally {
        for (Long processId : initProcessIds) {
            List<String> ss = stages.get(processId);
            for (String stage : ss) {
                destoryStage(processId, stage);
            }
            destoryProcess(processId);
        }
    }
}
Also used : TransformStageListener(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.TransformStageListener) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) StageMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.StageMonitor) Test(org.testng.annotations.Test) BaseStageTest(com.alibaba.otter.shared.arbitrate.setl.BaseStageTest)

Aggregations

StageMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.StageMonitor)9 BaseStageTest (com.alibaba.otter.shared.arbitrate.setl.BaseStageTest)9 ArrayList (java.util.ArrayList)9 Test (org.testng.annotations.Test)9 HashMap (java.util.HashMap)7 List (java.util.List)7 ExtractStageListener (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.ExtractStageListener)2 LoadStageListener (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.LoadStageListener)2 SelectStageListener (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.SelectStageListener)2 TransformStageListener (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.TransformStageListener)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1