Search in sources :

Example 26 with PermitMonitor

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

the class PermitMonitorTest method testPermit_init_ok.

@Test
public void testPermit_init_ok() {
    // 测试下permit的初始化内容
    channelEvent.start(channelId);
    updateMainStem(pipelineId, MainStemEventData.Status.OVERTAKE);
    updateMainStem(oppositePipelineId, MainStemEventData.Status.OVERTAKE);
    permitMonitor = new PermitMonitor(pipelineId);
    boolean isPermit = permitMonitor.isPermit();
    want.bool(isPermit).is(true);
}
Also used : PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) Test(org.testng.annotations.Test) BaseEventTest(com.alibaba.otter.shared.arbitrate.BaseEventTest)

Example 27 with PermitMonitor

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

the class PermitMonitorTest method testPermit_wait.

@Test
public void testPermit_wait() {
    channelEvent.start(channelId);
    updateMainStem(pipelineId, MainStemEventData.Status.OVERTAKE);
    updateMainStem(oppositePipelineId, MainStemEventData.Status.OVERTAKE);
    permitMonitor = new PermitMonitor(pipelineId);
    boolean isPermit = permitMonitor.isPermit();
    want.bool(isPermit).is(true);
    try {
        // 当前为permit=true,立马返回
        permitMonitor.waitForPermit();
    } catch (InterruptedException e) {
        want.fail();
    }
    // 一个节点挂起
    updateMainStem(pipelineId, MainStemEventData.Status.TAKEING);
    sleep();
    isPermit = permitMonitor.isPermit();
    want.bool(isPermit).is(false);
    // 提交一个异步更新状态任务
    final CountDownLatch count = new CountDownLatch(1);
    ExecutorService executor = Executors.newCachedThreadPool();
    executor.submit(new Runnable() {

        public void run() {
            // sleep一下后再触发
            sleep();
            // 一个节点挂起
            updateMainStem(pipelineId, MainStemEventData.Status.OVERTAKE);
            count.countDown();
        }
    });
    try {
        // 当前为permit=false,阻塞,等待信号
        permitMonitor.waitForPermit();
    } catch (InterruptedException e) {
        want.fail();
    }
    try {
        count.await();
        executor.shutdown();
    } catch (InterruptedException e) {
        want.fail();
    }
}
Also used : PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) ExecutorService(java.util.concurrent.ExecutorService) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test) BaseEventTest(com.alibaba.otter.shared.arbitrate.BaseEventTest)

Example 28 with PermitMonitor

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

the class TerminMemoryArbitrateEventTest method test_Restart.

@Test
public void test_Restart() {
    normalProcess();
    // 发送restart信号
    TerminEventData rollback = new TerminEventData();
    rollback.setPipelineId(pipelineId);
    rollback.setType(TerminType.RESTART);
    terminEvent.single(rollback);
    sleep(4000L);
    PermitMonitor monitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    want.bool(monitor.getChannelPermit(true).isStart()).is(true);
    sleep(4000L);
    // 发送shutdown信号
    TerminEventData shutdown = new TerminEventData();
    shutdown.setPipelineId(pipelineId);
    shutdown.setType(TerminType.SHUTDOWN);
    terminEvent.single(shutdown);
    want.bool(monitor.getChannelPermit(true).isStop()).is(true);
    // 删除对应的错误节点
    destoryTermin();
    ArbitrateFactory.destory(pipelineId);
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) Test(org.testng.annotations.Test) BaseArbitrateEventTest(com.alibaba.otter.shared.arbitrate.setl.event.BaseArbitrateEventTest)

Example 29 with PermitMonitor

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

the class TerminArbitrateEventTest method test_Restart.

@Test
public void test_Restart() {
    normalProcess();
    // 发送restart信号
    TerminEventData rollback = new TerminEventData();
    rollback.setPipelineId(pipelineId);
    rollback.setType(TerminType.RESTART);
    terminEvent.single(rollback);
    PermitMonitor monitor = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
    sleep(4000L);
    want.bool(monitor.getChannelPermit().isStart()).is(true);
    // 发送shutdown信号
    TerminEventData shutdown = new TerminEventData();
    shutdown.setPipelineId(pipelineId);
    shutdown.setType(TerminType.SHUTDOWN);
    terminEvent.single(shutdown);
    want.bool(monitor.getChannelPermit().isStop()).is(true);
    // 删除对应的错误节点
    destoryTermin();
    ArbitrateFactory.destory(pipelineId);
}
Also used : TerminEventData(com.alibaba.otter.shared.arbitrate.model.TerminEventData) PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) Test(org.testng.annotations.Test) BaseArbitrateEventTest(com.alibaba.otter.shared.arbitrate.setl.event.BaseArbitrateEventTest)

Example 30 with PermitMonitor

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

the class MainStemArbitrateEventTest method test_mainStem.

@Test
public void test_mainStem() {
    // 启动
    channelEvent.start(channelId);
    mainStemEvent = new MainStemArbitrateEvent();
    try {
        mainStemEvent.await(pipelineId);
        MainStemEventData eventData = new MainStemEventData();
        eventData.setPipelineId(pipelineId);
        eventData.setStatus(MainStemEventData.Status.OVERTAKE);
        mainStemEvent.single(eventData);
        PermitMonitor permit = ArbitrateFactory.getInstance(pipelineId, PermitMonitor.class);
        // 阻塞等待授权
        permit.waitForPermit();
    } catch (InterruptedException e) {
        want.fail();
    }
    boolean check = mainStemEvent.check(pipelineId);
    want.bool(check).is(true);
    // 删除mainStem节点
    mainStemEvent.release(pipelineId);
}
Also used : PermitMonitor(com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor) MainStemEventData(com.alibaba.otter.shared.arbitrate.model.MainStemEventData) MainStemArbitrateEvent(com.alibaba.otter.shared.arbitrate.impl.setl.MainStemArbitrateEvent) Test(org.testng.annotations.Test) BaseEventTest(com.alibaba.otter.shared.arbitrate.BaseEventTest)

Aggregations

PermitMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.PermitMonitor)30 Test (org.testng.annotations.Test)14 ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)13 TerminEventData (com.alibaba.otter.shared.arbitrate.model.TerminEventData)9 BaseEventTest (com.alibaba.otter.shared.arbitrate.BaseEventTest)8 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)7 ZkException (org.I0Itec.zkclient.exception.ZkException)7 ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)6 BaseArbitrateEventTest (com.alibaba.otter.shared.arbitrate.setl.event.BaseArbitrateEventTest)6 ZkNoNodeException (org.I0Itec.zkclient.exception.ZkNoNodeException)5 MainStemEventData (com.alibaba.otter.shared.arbitrate.model.MainStemEventData)4 Node (com.alibaba.otter.shared.common.model.config.node.Node)4 Date (java.util.Date)3 ProcessNodeEventData (com.alibaba.otter.shared.arbitrate.model.ProcessNodeEventData)2 IOException (java.io.IOException)2 MainStemArbitrateEvent (com.alibaba.otter.shared.arbitrate.impl.setl.MainStemArbitrateEvent)1 MainstemMonitor (com.alibaba.otter.shared.arbitrate.impl.setl.monitor.MainstemMonitor)1 SelectProcessListener (com.alibaba.otter.shared.arbitrate.impl.setl.rpc.monitor.SelectProcessListener)1 ExtractStageListener (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.ExtractStageListener)1 LoadStageListener (com.alibaba.otter.shared.arbitrate.impl.setl.zookeeper.monitor.LoadStageListener)1