@Test
  public void testSuppressOwnConstructor() {
    Mockit.stubOutClass(ExampleWithEvilConstructor.class, "(String)");

    ExampleWithEvilConstructor tested = new ExampleWithEvilConstructor("test");

    assertNull(tested.getMessage());
  }
 @BeforeMethod
 public final void beforeBase() {
   assertEquals("REAL1", new RealClass1().getValue());
   Mockit.setUpMocks(MockClass1.class);
   assertEquals("TEST1", new RealClass1().getValue());
 }
  @BeforeMethod
  public void setUp() {
    // mock 配置信息数据
    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(one));
            pipeline.setExtractNodes(Arrays.asList(one));
            pipeline.setLoadNodes(Arrays.asList(two));
            channel.setPipelines(Arrays.asList(pipeline));
            return channel;
          }

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

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

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

          @SuppressWarnings("unused")
          @Mock
          public Pipeline getOppositePipeline(Long pipelineId) {
            Pipeline pipeline = new Pipeline();
            pipeline.setId(oppositePipelineId);
            pipeline.setSelectNodes(Arrays.asList(two));
            pipeline.setExtractNodes(Arrays.asList(two));
            pipeline.setLoadNodes(Arrays.asList(one));
            return pipeline;
          }

          @SuppressWarnings("unused")
          @Mock
          public Channel getChannel(Long pipelineId) {
            Channel channel = new Channel();
            channel.setId(channelId);

            Pipeline pipeline = new Pipeline();
            pipeline.setId(pipelineId);

            Pipeline oppositePipeline = new Pipeline();
            oppositePipeline.setId(oppositePipelineId);
            channel.setPipelines(Arrays.asList(pipeline, oppositePipeline));
            return channel;
          }
        });

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

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

    zookeeper = getZookeeper();

    one.setId(oneNid);
    two.setId(twoNid);
    nodeEvent = new NodeArbitrateEvent();
    channelEvent = new ChannelArbitrateEvent(); // 创建channel
    pipelineEvent = new PipelineArbitrateEvent();

    // 创建node节点
    nodeEvent.init(oneNid);

    // 创建pipeline节点
    try {
      channelEvent.init(channelId);
    } catch (Exception e) {
      // ignore
    }

    try {
      pipelineEvent.init(channelId, pipelineId);
    } catch (Exception e) {
      // ignore
    }

    arbitrateEventService =
        (ArbitrateEventService) getBeanFactory().getBean("arbitrateEventService");
    mainStem = new MainStemServiceDemo();
    autowire(mainStem);
    select = new SelectServiceDemo();
    autowire(select);
    extract = new ExtractServiceDemo();
    autowire(extract);
    transform = new TransformServiceDemo();
    autowire(transform);
    load = new LoadServiceDemo();
    autowire(load);
    view = new ProcessViewDemo();
    autowire(view);
    termin = new TerminProcessDemo();
    autowire(termin);
  }
Ejemplo n.º 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);
  }