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);
}
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();
}
}
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);
}
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);
}
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);
}
Aggregations