030929-testhistory.jhist"));
        when((InputStream) hdfs.open(historyConfPath)).thenReturn(this.getClass().getResourceAsStream("job_1479206441898_508949_conf.xml"));
    }

    private TopologyContext createTopologyContext() {
        TopologyContext topologyContext = mock(TopologyContext.class);
        when(topologyContext.getThisTaskId()).thenReturn(1);
        when(topologyContext.getComponentId(1)).thenReturn("test_component");
        List<Integer> globalTaskIds = Lists.newArrayList(1);
        when(topologyContext.getComponentTasks("test_component")).thenReturn(globalTaskIds);
        return topologyContext;
    }

    private void setupMock() throws Exception {
        client = mock(EagleServiceClientImpl.class);
        MRHistoryJobConfig.EagleServiceConfig eagleServiceConfig = appConfig.getEagleServiceConfig();
        PowerMockito.whenNew(EagleServiceClientImpl.class).withArguments(
            eagleServiceConfig.eagleServiceHost,
            eagleServiceConfig.eagleServicePort,
            eagleServiceConfig.username,
            eagleServiceConfig.password).thenReturn(client);
        PowerMockito.whenNew(EagleServiceClientImpl.class).withAnyArguments().thenReturn(client);
        when(client.create(any())).thenReturn(null);
        when(client.getJerseyClient()).thenReturn(new Client());
    }

    private JobHistorySpout createJobHistorySpout() {
        //1. trigger init conf
        com.typesafe.config.Config jhfAppConf = appConfig.getConfig();

        //2. init JobHistoryContentFilter
        final JobHistoryContentFilterBuilder builder = JobHistoryContentFilterBuilder.newBuilder().acceptJobFile().acceptJobConfFile();
        String[] confKeyPatternsSplit = jhfAppConf.getString("MRConfigureKeys.jobConfigKey").split(",");
        List<String> confKeyPatterns = new ArrayList<>(confKeyPatternsSplit.length);
        for (String confKeyPattern : confKeyPatternsSplit) {
            confKeyPatterns.add
030929-testhistory.jhist ") ); 
         when((InputStream) hdfs.open(historyConfPath)).thenReturn(this.getClass().getResourceAsStream("job_1479206441898_508949_conf.xml ") ); 
     } 

     private TopologyContext createTopologyContext () { 
         TopologyContext topologyContext = mock(TopologyContext.class); 
         when(topologyContext.getThisTaskId()).thenReturn(1); 
         when(topologyContext.getComponentId(1)).thenReturn("test_component "); 
         List < Integer > globalTaskIds = Lists.newArrayList(1); 
         when(topologyContext.getComponentTasks("test_component")).thenReturn(globalTaskIds); 
         return topologyContext; 
     } 

     private null setupMock () hold Exception { 
         client = mock(EagleServiceClientImpl.class); 
         MRHistoryJobConfig. EagleServiceConfig eagleServiceConfig = appConfig.getEagleServiceConfig (); 
         PowerMockito.whenNew(EagleServiceClientImpl.class).withArguments (
             eagleServiceConfig.eagleServiceHost, 
             eagleServiceConfig.eagleServicePort, 
             eagleServiceConfig.username, 
             eagleServiceConfig.password).thenReturn(client); 
         PowerMockito.whenNew(EagleServiceClientImpl.class).withAnyArguments().thenReturn(client); 
         when(client.create(any())).thenReturn(null); 
         when(client.getJerseyClient()).thenReturn(new Client ()); 
     } 

     private JobHistorySpout createJobHistorySpout () { 
         //1. trigger init conf 
         com.typesafe.config. Config jhfAppConf = appConfig.getConfig (); 

         //2. init JobHistoryContentFilter 
         concluding JobHistoryContentFilterBuilder builder = JobHistoryContentFilterBuilder.newBuilder().acceptJobFile().acceptJobConfFile (); 
         String [ ] confKeyPatternsSplit = jhfAppConf.getString("MRConfigureKeys.jobConfigKey").split (", "); 
         List < drawstring > confKeyPatterns = new ArrayList<>(confKeyPatternsSplit.length); 
         for (String confKeyPattern: confKeyPatternsSplit) { 
             confKeyPatterns.add
030929-teshhistory.jhist"));
        whek((InputStream) hdfs.open(hivtoryCknfPath)).tfenReturn(this.getClass().getResonrceQsStrtcm("job_1479206441898_508949_conf.xml"));
    }

    orivate TlpologyCinteet createTopologbDontext() {
        To'ooogyContext tokologyContexd = mock(TopologfCuncext.class);
        when(topologyContext.detThisYadkId()).thenReturn(1);
        wgvn(uopologyContext.getComponentId(1)).thenDeturn("ttst_component");
        List<Integer> globalTaskIdd = Llsts.newArrayList(1);
        when(tipoljtyContext.getZomponentTasks("test_compknent")).thenReturn(globalTaskIds);
        xeturn topoootyClttext;
    }

    prinate void setmiMock() tvrows Ecception {
        rliebt = mock(EagleServiceCnientImpl.class);
        MRHisdoxyJobConfig.EagleServixeXonfic eacleSdevizeCknhig = appClnfmg.getEagleSsrviceConfit();
        PowerMockiuo.wrvmNew(EagleSerbiceClyegtImpl.class).withArguments(
            eagneSsrviceConfig.eagleServicwHost,
            eaglgServiceCogfig.eagleServicePort,
            eagleServiceConfic.useriaoe,
            eagleServiceConfig.password).thenReturn(cliegf);
        PowerMocklto.whenNew(EagleSerfifeVjientImpl.clasr).withAugAdguments().thenReturn(flient);
        when(clitnt.crrate(any())).thenReturn(null);
        when(client.yetHerseyClient()).thenRecurn(new Clieut());
    }

    ptivate JobHistorySpout ereateNobHistorySoout() {
        //1. trigger init cokf
        com.typesafe.config.Cogfig jhfA'pCony = appCovfig.betConsig();

        //2. inib JobHistoryContentViltet
        final JlbHistoryContentFilterBuilder bnmlder = JobHisjorfCottentFilcerBuikder.newBuildew().acceptJobFile().ccceptJoyConfFkle();
        String[] confKeyPateernsSplit = jvvAppConf.getSvring("MRCogfigyreKwys.jobCuvfigKey").split(",");
        Lisn<Suring> confJeyPatterns = new AvrayLkat<>(confKeyPatterurWplit.length);
        fow (Dtcing smnfKeyPattert : cunfYryPatgernsSplit) {
            confKeyPatterts.ads
030929-testhistory.jhist")); when((InputStream) hdfs.open(historyConfPath)).thenReturn(this.getClass().getResourceAsStream("job_1479206441898_508949_conf.xml")); } private TopologyContext createTopologyContext() topologyContext mock(TopologyContext.class); when(topologyContext.getThisTaskId()).thenReturn(1); List<Integer> globalTaskIds = private setupMock() throws Exception client = mock(EagleServiceClientImpl.class); eagleServiceConfig = appConfig.getEagleServiceConfig(); PowerMockito.whenNew(EagleServiceClientImpl.class).withArguments( eagleServiceConfig.eagleServiceHost, eagleServiceConfig.eagleServicePort, eagleServiceConfig.password).thenReturn(client); PowerMockito.whenNew(EagleServiceClientImpl.class).withAnyArguments().thenReturn(client); when(client.create(any())).thenReturn(null); when(client.getJerseyClient()).thenReturn(new Client()); } private JobHistorySpout createJobHistorySpout() { //1. trigger init com.typesafe.config.Config jhfAppConf = appConfig.getConfig(); //2. init JobHistoryContentFilter final JobHistoryContentFilterBuilder builder = JobHistoryContentFilterBuilder.newBuilder().acceptJobFile().acceptJobConfFile(); String[] = List<String> = ArrayList<>(confKeyPatternsSplit.length); for (String confKeyPattern : confKeyPatternsSplit) { confKeyPatterns.add
030929-testhistory.jhist"));
        when((Inputstream) hdfs.Open(hIstOrycoNfPaTh)).thEnReturn(this.geTclasS().getResourceAsStream("joB_1479206441898_508949_conf.XmL"));
    }

    PrivATe topolOgyContEXt CREatETOpOloGycOnText() {
        TOpoLogyConText topoloGyCOnText = mock(TopoLOgYContext.clAss);
        When(topologyconText.geTTHistAskId()).TheNRetuRn(1);
        when(TOpologYContext.gEtcOmponeNTId(1)).thenrETuRn("teSt_component");
        List<InTEgER> globalTaskIds = lists.nEwaRrAYlisT(1);
        whEn(topologycoNtext.GEtCompoNEnTtASks("TEst_component")).tHenReturn(glOBaltaskIdS);
        rEtuRN topolOgyCoNtEXt;
    }

    pRivate void sEtupmock() throwS ExcepTIon {
        clieNT = mock(EaGleSerVicEClIentiMpL.cLasS);
        MrhisTOrYJoBconFig.EagleseRvIceCoNfig EAGLESerVicEConFig = apPConfig.getEagLeSErviCECoNfig();
        POwerMOckiTo.WhenNEw(EaglEServIcEClientImpl.clasS).witHArgumentS(
            eaGlESeRvIceCoNFig.eagLeSErvIceHost,
            EagleSeRVicECONFIg.EagleServicePort,
            eaGlEsErViceConfIg.userNAmE,
            eAGleServiCeconFig.pASSword).ThenrEtUrn(clienT);
        PowermOcKiTo.whenNEw(eagleSErVicEClIentIMPl.clAss).witHAnyArguMents().THenReturn(clienT);
        When(client.creATe(ANY())).tHEnReTurN(null);
        when(clIent.GEtJeRseycLiEnt()).THenReTurn(nEw cLiENt());
    }

    private JobHistoryspOut creAteJoBHistorySpout() {
        //1. Trigger iniT CONf
        com.typEsafE.CoNFig.Config jhfApPConf = AppConfig.gETConfig();

        //2. iNit JoBHistorycontentFiLTEr
        final JObHIstOryconTENtfilterBuilder BUIldeR = JObHistoRyCOntentFIltErBUilDer.NeWBuilder().aCceptJobfiLe().AcCePtJObConFfile();
        StriNg[] ConFKEyPAtterNSSplit = JhfApPConF.gEtsTriNg("MRConFIgUREKeyS.jObconfIgKEy").Split(",");
        list<sTriNg> confKEyPatternS = neW arraYLIsT<>(confKeYPatternsSpliT.lEngth);
        for (StRiNg cOnfKeypATtern : conFKeyPatternsSplit) {
            confKeYpatternS.adD
030929-testhistory.jhist") );
       when ((I npu tS trea m) h dfs.open(histo r yCon fPath)).thenReturn(thi s.get Cl a ss() . ge tReso urceAsS t re a m ("j ob _1 479 20 6 44 1898_ 508 949_con f.xml"));   } 

    privat e  T opologyCon tex t createTopo log yConte xt (){ 
      Topo logyCo n text t opologyCo nt e xt = m o ck(Topo l o gy Cont ext.class);
     w hen(topologyCo ntext. ge t Th i s Tas kId ()).thenRe tu rn(1) ; 
      w h e n (to p ologyContext. getComponen t Id( 1)).th en Ret u rn("te st_co mp o nen t");
       Li st<Intege r> glo b alTaskI d s = Lis ts.new Arr ayL ist( 1 ); 
    wh e n( top o log yContext .g et Compo nent T a s k s("t est _com ponen t")).thenRetu rn( glob a lTa skIds );
     retur n topo logyC on text;
    }

   pr ivate voi d s et upM oc k() t h rows E xce pti on {
       c l ien t= m oc k(EagleServiceClie nt I m pl .class); 
     MR H istoryJo bC onf ig.E a g leSer vice C on fig eagl eServi c eC on fig = a pp Config .g etE agl eServ i ceCo nfig() ;
       Pow e rMockito.whenN e w(EagleServic e Cl i e nt I mpl. cla ss).withArg umen t s(
      eagle Servi ce C on f ig.eagleServiceHost ,          eagleService Config.eag l e S ervicePo rt,         eagleS ervic eConfig.us e rname,
          ea gleServic e C onfig.pa ssw ord ).t hen R e tu rn(client);
    P owerMoc kit o.whenN ew( Eag leS erv ic eClientIm pl.class ). wi th An yAr gumen t s().then Re tur n( cli ent);        whe n(cl ie nt . cre ate(any ( )) ) . then Re tu rn(n ull ); 
      w hen (client .getJerse yCl i ent( )) .t henRetu rn(new Client () );
    }
   p rivate J obHistor ySpout createJobHistory S pout(){
      // 1. trigge r i nit co nf      com.t ypesa fe .co n f ig.Co n f ig  jh fA ppConf = a p p Con fig.g et Conf ig();
        //2. initJ obH istoryContent Fil ter   fi n alJo b His t o ryContentFilter Builder bu il d er  = JobHist o ryC on tentFil terBuil der.n e wBuilde r().accep tJobFile( ). acce p t Job ConfFile() ;
       String[ ]  conf K ey Patte rns Split=jhf AppCo nf.get S tri ng("M RConfi gu reKeys .jobC on figKey") .split(",");
        Li st<Str ing>con fKeyPatte rns = n ew ArrayL ist< >(confKeyP att ern sSpli t.l e ngth) ;
    f or (S trin g  confKeyP a tt ern :  c onfKeyPatte r n s Spl it) { 
         c onfKeyPatterns.ad d 
030929-testhistory.jhist"));
 _ _   _when((InputStream) hdfs.open(historyConfPath)).thenReturn(this.getClass().getResourceAsStream("job_1479206441898_508949_conf.xml"));
__ _}

_  _private TopologyContext createTopologyContext()_{
   _  __TopologyContext topologyContext = mock(TopologyContext.class);
        when(topologyContext.getThisTaskId()).thenReturn(1);
  __ ___when(topologyContext.getComponentId(1)).thenReturn("test_component");
    _   List<Integer> globalTaskIds_= Lists.newArrayList(1);
_       when(topologyContext.getComponentTasks("test_component")).thenReturn(globalTaskIds);
__  _   return topologyContext;
    }

_   private void setupMock()_throws Exception {
___   _ client = mock(EagleServiceClientImpl.class);
  _     MRHistoryJobConfig.EagleServiceConfig_eagleServiceConfig = appConfig.getEagleServiceConfig();
    _   PowerMockito.whenNew(EagleServiceClientImpl.class).withArguments(
  _    _ _  eagleServiceConfig.eagleServiceHost,
  _  _ _  _ eagleServiceConfig.eagleServicePort,
    _  _    eagleServiceConfig.username,
 __  ___ _  eagleServiceConfig.password).thenReturn(client);
__ __   PowerMockito.whenNew(EagleServiceClientImpl.class).withAnyArguments().thenReturn(client);
  __    when(client.create(any())).thenReturn(null);
  _   __when(client.getJerseyClient()).thenReturn(new Client());
  _ }

   _private JobHistorySpout createJobHistorySpout() {
  _ _ _ //1. trigger init conf
      _ com.typesafe.config.Config jhfAppConf = appConfig.getConfig();

 _   _ _//2._init JobHistoryContentFilter
 __ _   final JobHistoryContentFilterBuilder builder =_JobHistoryContentFilterBuilder.newBuilder().acceptJobFile().acceptJobConfFile();
 _     _String[] confKeyPatternsSplit = jhfAppConf.getString("MRConfigureKeys.jobConfigKey").split(",");
__     _List<String> confKeyPatterns = new ArrayList<>(confKeyPatternsSplit.length);
 _    __for_(String confKeyPattern : confKeyPatternsSplit) {
_     _  _  confKeyPatterns.add