示例#1
0
  // 模拟创建一个process
  protected Long initProcess() {
    String path =
        zookeeper.create(processPath + "/", new byte[0], CreateMode.PERSISTENT_SEQUENTIAL);

    // 创建为顺序的节点
    String processNode = StringUtils.substringAfterLast(path, "/");
    return StagePathUtils.getProcessId(processNode); // 添加到当前的process列表
  }
示例#2
0
  // 模拟创建一个终结节点
  protected void initTermin(Long processId) {
    TerminEventData data = new TerminEventData();
    data.setPipelineId(pipelineId);
    data.setProcessId(processId);
    data.setType(TerminType.NORMAL);

    byte[] bytes = JsonUtils.marshalToByte(data);
    zookeeper.create(StagePathUtils.getTermin(pipelineId, processId), bytes, CreateMode.PERSISTENT);
  }
  @AfterMethod
  public void tearDown() {
    // 删除mainStem节点
    String path = StagePathUtils.getPipeline(pipelineId) + "/" + ArbitrateConstants.NODE_MAINSTEM;
    zookeeper.delete(path);

    nodeEvent.destory(one.getId());
    // 关闭pipeline
    pipelineEvent.destory(channelId, pipelineId);
    channelEvent.destory(channelId);
  }
示例#4
0
  @BeforeClass
  public void init() {
    // 初始化节点
    // mock 配置信息数据
    local.setStatus(NodeStatus.START);
    Mockit.setUpMock(
        ArbitrateConfigUtils.class,
        new Object() {

          @SuppressWarnings("unused")
          @Mock
          public Channel getChannelByChannelId(Long channelId) {
            Channel channel = new Channel();
            channel.setId(channelId);
            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);
            pipeline.setSelectNodes(Arrays.asList(local));
            pipeline.setExtractNodes(Arrays.asList(local));
            pipeline.setLoadNodes(Arrays.asList(local));
            channel.setPipelines(Arrays.asList(pipeline));
            return channel;
          }

          @SuppressWarnings("unused")
          @Mock
          public Channel getChannel(Long pipelineId) {
            Channel channel = new Channel();
            channel.setId(channelId);
            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);
            pipeline.setSelectNodes(Arrays.asList(local));
            pipeline.setExtractNodes(Arrays.asList(local));
            pipeline.setLoadNodes(Arrays.asList(local));
            channel.setPipelines(Arrays.asList(pipeline));
            return channel;
          }

          @SuppressWarnings("unused")
          @Mock
          public Pipeline getPipeline(Long pipelineId) {
            Pipeline pipeline = new Pipeline();
            pipeline.setSelectNodes(Arrays.asList(local));
            pipeline.setExtractNodes(Arrays.asList(local));
            pipeline.setLoadNodes(Arrays.asList(local));
            return pipeline;
          }

          @SuppressWarnings("unused")
          @Mock
          public Pipeline getOppositePipeline(Long pipelineId) {
            return null; // 没有反向同步
          }

          @SuppressWarnings("unused")
          @Mock
          public Long getCurrentNid() {
            return nid;
          }

          @SuppressWarnings("unused")
          @Mock
          public int getParallelism(Long pipelineId) {
            return 3; // 并行度
          }
        });

    Mockit.setUpMock(
        ArbitrateCommmunicationClient.class,
        new Object() {

          @SuppressWarnings("unused")
          @Mock
          public Object callManager(final Event event) {
            // do nothing
            return null;
          }

          @SuppressWarnings("unused")
          @Mock
          public void callManager(final Event event, final Callback callback) {
            // do nothing
          }
        });

    zookeeper = getZookeeper();
    local.setId(nid);
    nodeEvent = new NodeArbitrateEvent();
    channelEvent = new ChannelArbitrateEvent();
    pipelineEvent = new PipelineArbitrateEvent();

    pipelinePath = StagePathUtils.getPipeline(channelId, pipelineId);
    processPath = StagePathUtils.getProcessRoot(channelId, pipelineId);
    channelEvent.init(channelId);
    pipelineEvent.init(channelId, pipelineId);
    channelEvent.start(channelId);

    String path = pipelinePath + "/" + ArbitrateConstants.NODE_MAINSTEM;
    MainStemEventData eventData = new MainStemEventData();
    eventData.setStatus(MainStemEventData.Status.OVERTAKE);
    eventData.setNid(nid);
    byte[] bytes = JsonUtils.marshalToByte(eventData); // 初始化的数据对象

    zookeeper.create(path, bytes, CreateMode.EPHEMERAL);
  }
示例#5
0
 // 模拟删除一个终结节点
 protected void destoryTermin(Long processId) {
   zookeeper.delete(StagePathUtils.getTermin(pipelineId, processId));
 }
示例#6
0
  // 模拟创建一个带数据的stage节点
  protected void initStage(Long processId, String stageNode, EtlEventData event) {
    String path = processPath + "/" + StagePathUtils.getProcessNode(processId) + "/" + stageNode;

    byte[] datas = JsonUtils.marshalToByte(event);
    zookeeper.create(path, datas, CreateMode.PERSISTENT);
  }
示例#7
0
  // 模拟销毁一个stage节点
  protected void destoryStage(Long processId, String stageNode) {
    String path = processPath + "/" + StagePathUtils.getProcessNode(processId) + "/" + stageNode;

    zookeeper.delete(path);
  }
示例#8
0
 // 模拟创建一个stage节点
 protected void initStage(Long processId, String stageNode) {
   String path = processPath + "/" + StagePathUtils.getProcessNode(processId) + "/" + stageNode;
   zookeeper.create(path, new byte[0], CreateMode.PERSISTENT);
 }
示例#9
0
 // 模拟销毁一个process
 protected void destoryProcess(Long processId) {
   String path = processPath + "/" + StagePathUtils.getProcessNode(processId);
   zookeeper.delete(path);
 }