use of com.alibaba.otter.shared.arbitrate.model.TerminEventData in project otter by alibaba.
the class MemoryArbitrateEventTest method test_all.
@Test
public void test_all() {
Mockit.setUpMock(ArbitrateConfigUtils.class, new Object() {
@Mock
public int getParallelism(Long pipelineId) {
// 并行度
return 2;
}
});
selectEvent = new SelectMemoryArbitrateEvent();
extractEvent = new ExtractMemoryArbitrateEvent();
transformEvent = new TransformMemoryArbitrateEvent();
loadEvent = new LoadMemoryArbitrateEvent();
terminEvent = (TerminMemoryArbitrateEvent) this.getBeanFactory().getBean("terminMemoryEvent");
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);
// 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 {
}
}
use of com.alibaba.otter.shared.arbitrate.model.TerminEventData 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.model.TerminEventData in project otter by alibaba.
the class TerminMemoryArbitrateEventTest method destoryTermin.
private void destoryTermin() {
String path = StagePathUtils.getTerminRoot(pipelineId);
List<String> terminNodes = zookeeper.getChildren(path);
for (String node : terminNodes) {
// 删除对应的错误节点
TerminEventData termin = new TerminEventData();
termin.setPipelineId(pipelineId);
termin.setProcessId(StagePathUtils.getProcessId(node));
System.out.println("remove termin node: " + path + "/" + node);
// 发送ack信号,删除termin节点
terminEvent.ack(termin);
}
}
use of com.alibaba.otter.shared.arbitrate.model.TerminEventData in project otter by alibaba.
the class TerminMemoryArbitrateEventTest 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 SelectMemoryArbitrateEvent();
extractEvent = new ExtractMemoryArbitrateEvent();
transformEvent = new TransformMemoryArbitrateEvent();
loadEvent = new LoadMemoryArbitrateEvent();
terminEvent = (TerminMemoryArbitrateEvent) this.getBeanFactory().getBean("terminMemoryEvent");
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();
}
}
use of com.alibaba.otter.shared.arbitrate.model.TerminEventData in project otter by alibaba.
the class RpcArbitrateEventTest method test_all.
@Test
public void test_all() {
Mockit.setUpMock(ArbitrateConfigUtils.class, new Object() {
@Mock
public int getParallelism(Long pipelineId) {
// 并行度
return 2;
}
});
RpcStageEventDispatcher rpcStageEventDispatcher = (RpcStageEventDispatcher) this.getBeanFactory().getBean("rpcStageEventDispatcher");
terminEvent = (TerminRpcArbitrateEvent) this.getBeanFactory().getBean("terminRpcEvent");
selectEvent = new SelectRpcArbitrateEvent();
selectEvent.setRpcStageEventDispatcher(rpcStageEventDispatcher);
extractEvent = new ExtractRpcArbitrateEvent();
extractEvent.setRpcStageEventDispatcher(rpcStageEventDispatcher);
transformEvent = new TransformRpcArbitrateEvent();
transformEvent.setRpcStageEventDispatcher(rpcStageEventDispatcher);
loadEvent = new LoadRpcArbitrateEvent();
loadEvent.setRpcStageEventDispatcher(rpcStageEventDispatcher);
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);
// 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 {
}
}
Aggregations