Search in sources :

Example 1 with ExtractZooKeeperArbitrateEvent

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

the class ExtractArbitrateEventTest method test_extract.

@Test
public void test_extract() {
    Mockit.setUpMock(ArbitrateConfigUtils.class, new Object() {

        @Mock
        public int getParallelism(Long pipelineId) {
            //并行度
            return 2;
        }
    });
    selectEvent = new SelectZooKeeperArbitrateEvent();
    extractEvent = new ExtractZooKeeperArbitrateEvent();
    final List<Long> initProcessIds = new ArrayList<Long>();
    try {
        //获取数据
        //select stage
        EtlEventData sdata1 = selectEvent.await(pipelineId);
        EtlEventData sdata2 = selectEvent.await(pipelineId);
        initProcessIds.add(sdata1.getProcessId());
        initProcessIds.add(sdata2.getProcessId());
        selectEvent.single(sdata1);
        selectEvent.single(sdata2);
        // extract stage
        EtlEventData edata1 = extractEvent.await(pipelineId);
        EtlEventData edata2 = extractEvent.await(pipelineId);
        extractEvent.single(edata1);
        extractEvent.single(edata2);
        ArbitrateFactory.destory(pipelineId);
    } catch (InterruptedException e) {
        want.fail();
    } finally {
        for (Long processId : initProcessIds) {
            destoryStage(processId, ArbitrateConstants.NODE_SELECTED);
            destoryStage(processId, ArbitrateConstants.NODE_EXTRACTED);
            destoryProcess(processId);
        }
    }
}
Also used : SelectZooKeeperArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.SelectZooKeeperArbitrateEvent) ArrayList(java.util.ArrayList) ExtractZooKeeperArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.ExtractZooKeeperArbitrateEvent) Mock(mockit.Mock) EtlEventData(com.alibaba.otter.shared.arbitrate.model.EtlEventData) BaseArbitrateEventTest(com.alibaba.otter.shared.arbitrate.setl.event.BaseArbitrateEventTest) Test(org.testng.annotations.Test)

Example 2 with ExtractZooKeeperArbitrateEvent

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

the class LoadArbitrateEventTest method test_load.

@Test
public void test_load() {
    Mockit.setUpMock(ArbitrateConfigUtils.class, new Object() {

        @Mock
        public int getParallelism(Long pipelineId) {
            // 并行度
            return 2;
        }
    });
    selectEvent = new SelectZooKeeperArbitrateEvent();
    extractEvent = new ExtractZooKeeperArbitrateEvent();
    transformEvent = new TransformZooKeeperArbitrateEvent();
    loadEvent = new LoadZooKeeperArbitrateEvent();
    terminEvent = (TerminZooKeeperArbitrateEvent) this.getBeanFactory().getBean("terminZooKeeperEvent");
    loadEvent.setTerminEvent(terminEvent);
    final List<Long> initProcessIds = new ArrayList<Long>();
    try {
        // 获取数据
        // select stage
        EtlEventData sdata1 = selectEvent.await(pipelineId);
        EtlEventData sdata2 = selectEvent.await(pipelineId);
        initProcessIds.add(sdata1.getProcessId());
        initProcessIds.add(sdata2.getProcessId());
        selectEvent.single(sdata1);
        selectEvent.single(sdata2);
        // extract stage
        EtlEventData edata1 = extractEvent.await(pipelineId);
        EtlEventData edata2 = extractEvent.await(pipelineId);
        extractEvent.single(edata1);
        extractEvent.single(edata2);
        // transform stage
        EtlEventData tdata1 = transformEvent.await(pipelineId);
        EtlEventData tdata2 = transformEvent.await(pipelineId);
        transformEvent.single(tdata1);
        transformEvent.single(tdata2);
        SelectStageListener selectStageListener = ArbitrateFactory.getInstance(pipelineId, SelectStageListener.class);
        selectStageListener.destory();
        // load stage
        EtlEventData ldata1 = loadEvent.await(pipelineId);
        loadEvent.single(ldata1);
        Long p1 = ldata1.getProcessId();
        TerminEventData terminData1 = new TerminEventData();
        terminData1.setPipelineId(pipelineId);
        terminData1.setProcessId(p1);
        // 发送ack信号,删除termin节点
        terminEvent.ack(terminData1);
        EtlEventData ldata2 = loadEvent.await(pipelineId);
        want.bool(ldata1.getProcessId() < ldata2.getProcessId()).is(true);
        loadEvent.single(ldata2);
        Long p2 = ldata2.getProcessId();
        TerminEventData terminData2 = new TerminEventData();
        terminData2.setPipelineId(pipelineId);
        terminData2.setProcessId(p2);
        // 发送ack信号,删除termin节点
        terminEvent.ack(terminData2);
        sleep(2000L);
        ArbitrateFactory.destory(pipelineId);
    } catch (InterruptedException e) {
        want.fail();
    } finally {
    }
}
Also used : SelectZooKeeperArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.SelectZooKeeperArbitrateEvent) ArrayList(java.util.ArrayList) TransformZooKeeperArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.TransformZooKeeperArbitrateEvent) ExtractZooKeeperArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.ExtractZooKeeperArbitrateEvent) Mock(mockit.Mock) EtlEventData(com.alibaba.otter.shared.arbitrate.model.EtlEventData) TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) LoadZooKeeperArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.LoadZooKeeperArbitrateEvent) SelectStageListener(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.SelectStageListener) Test(org.testng.annotations.Test) BaseArbitrateEventTest(com.alibaba.otter.shared.arbitrate.setl.event.BaseArbitrateEventTest)

Example 3 with ExtractZooKeeperArbitrateEvent

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

the class TerminArbitrateEventTest method normalProcess.

private void normalProcess() {
    Mockit.setUpMock(ArbitrateConfigUtils.class, new Object() {

        @Mock
        public int getParallelism(Long pipelineId) {
            // 并行度
            return 2;
        }

        @Mock
        public Long getCurrentNid() {
            return nid;
        }
    });
    selectEvent = new SelectZooKeeperArbitrateEvent();
    extractEvent = new ExtractZooKeeperArbitrateEvent();
    transformEvent = new TransformZooKeeperArbitrateEvent();
    loadEvent = new LoadZooKeeperArbitrateEvent();
    terminEvent = (TerminZooKeeperArbitrateEvent) this.getBeanFactory().getBean("terminZooKeeperEvent");
    loadEvent.setTerminEvent(terminEvent);
    final List<Long> initProcessIds = new ArrayList<Long>();
    try {
        // 获取数据
        // select stage
        EtlEventData sdata1 = selectEvent.await(pipelineId);
        EtlEventData sdata2 = selectEvent.await(pipelineId);
        initProcessIds.add(sdata1.getProcessId());
        initProcessIds.add(sdata2.getProcessId());
        selectEvent.single(sdata1);
        selectEvent.single(sdata2);
        // extract stage
        EtlEventData edata1 = extractEvent.await(pipelineId);
        EtlEventData edata2 = extractEvent.await(pipelineId);
        extractEvent.single(edata1);
        extractEvent.single(edata2);
        // transform stage
        EtlEventData tdata1 = transformEvent.await(pipelineId);
        EtlEventData tdata2 = transformEvent.await(pipelineId);
        transformEvent.single(tdata1);
        transformEvent.single(tdata2);
        // SelectStageListener selectStageListener =
        // ArbitrateFactory.getInstance(pipelineId,
        // SelectStageListener.class);
        // selectStageListener.destory();
        // load stage
        EtlEventData ldata1 = loadEvent.await(pipelineId);
        loadEvent.single(ldata1);
        Long p1 = ldata1.getProcessId();
        TerminEventData terminData1 = new TerminEventData();
        terminData1.setPipelineId(pipelineId);
        terminData1.setProcessId(p1);
        // 发送ack信号,删除termin节点
        terminEvent.ack(terminData1);
    } catch (InterruptedException e) {
        want.fail();
    }
}
Also used : SelectZooKeeperArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.SelectZooKeeperArbitrateEvent) TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) LoadZooKeeperArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.LoadZooKeeperArbitrateEvent) ArrayList(java.util.ArrayList) TransformZooKeeperArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.TransformZooKeeperArbitrateEvent) ExtractZooKeeperArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.ExtractZooKeeperArbitrateEvent) Mock(mockit.Mock) EtlEventData(com.alibaba.otter.shared.arbitrate.model.EtlEventData)

Example 4 with ExtractZooKeeperArbitrateEvent

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

the class TransformArbitrateEventTest method test_transform.

@Test
public void test_transform() {
    Mockit.setUpMock(ArbitrateConfigUtils.class, new Object() {

        @Mock
        public int getParallelism(Long pipelineId) {
            // 并行度
            return 2;
        }
    });
    selectEvent = new SelectZooKeeperArbitrateEvent();
    extractEvent = new ExtractZooKeeperArbitrateEvent();
    transformEvent = new TransformZooKeeperArbitrateEvent();
    final List<Long> initProcessIds = new ArrayList<Long>();
    try {
        // 获取数据
        // select stage
        EtlEventData sdata1 = selectEvent.await(pipelineId);
        EtlEventData sdata2 = selectEvent.await(pipelineId);
        initProcessIds.add(sdata1.getProcessId());
        initProcessIds.add(sdata2.getProcessId());
        selectEvent.single(sdata1);
        selectEvent.single(sdata2);
        // extract stage
        EtlEventData edata1 = extractEvent.await(pipelineId);
        EtlEventData edata2 = extractEvent.await(pipelineId);
        extractEvent.single(edata1);
        extractEvent.single(edata2);
        // transform stage
        EtlEventData tdata1 = transformEvent.await(pipelineId);
        EtlEventData tdata2 = transformEvent.await(pipelineId);
        transformEvent.single(tdata1);
        transformEvent.single(tdata2);
        ArbitrateFactory.destory(pipelineId);
    } catch (InterruptedException e) {
        want.fail();
    } finally {
        for (Long processId : initProcessIds) {
            destoryStage(processId, ArbitrateConstants.NODE_SELECTED);
            destoryStage(processId, ArbitrateConstants.NODE_EXTRACTED);
            destoryStage(processId, ArbitrateConstants.NODE_TRANSFORMED);
            destoryProcess(processId);
        }
    }
}
Also used : SelectZooKeeperArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.SelectZooKeeperArbitrateEvent) ArrayList(java.util.ArrayList) TransformZooKeeperArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.TransformZooKeeperArbitrateEvent) ExtractZooKeeperArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.ExtractZooKeeperArbitrateEvent) Mock(mockit.Mock) EtlEventData(com.alibaba.otter.shared.arbitrate.model.EtlEventData) Test(org.testng.annotations.Test) BaseArbitrateEventTest(com.alibaba.otter.shared.arbitrate.setl.event.BaseArbitrateEventTest)

Aggregations

ExtractZooKeeperArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.ExtractZooKeeperArbitrateEvent)4 SelectZooKeeperArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.SelectZooKeeperArbitrateEvent)4 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)4 ArrayList (java.util.ArrayList)4 Mock (mockit.Mock)4 TransformZooKeeperArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.TransformZooKeeperArbitrateEvent)3 BaseArbitrateEventTest (com.alibaba.otter.shared.arbitrate.setl.event.BaseArbitrateEventTest)3 Test (org.testng.annotations.Test)3 LoadZooKeeperArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.LoadZooKeeperArbitrateEvent)2 TerminEventData (com.alibaba.otter.shared.arbitrate.model.TerminEventData)2 SelectStageListener (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.SelectStageListener)1