Package com.taobao.top.analysis.node.component

Source Code of com.taobao.top.analysis.node.component.DefaultAnalysisEngineTestBig

package com.taobao.top.analysis.node.component;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.junit.Test;

import com.taobao.top.analysis.node.component.FileJobBuilder;
import com.taobao.top.analysis.node.component.FileJobExporter;
import com.taobao.top.analysis.node.component.JobResultMerger;
import com.taobao.top.analysis.node.io.FileInputAdaptor;
import com.taobao.top.analysis.node.io.FileOutputAdaptor;
import com.taobao.top.analysis.node.io.HttpInputAdaptor;
import com.taobao.top.analysis.node.io.IInputAdaptor;
import com.taobao.top.analysis.node.job.Job;
import com.taobao.top.analysis.node.job.JobTask;
import com.taobao.top.analysis.node.job.JobTaskResult;
import com.taobao.top.analysis.statistics.StatisticsEngine;


/**
* @author fangweng
* @Email fangweng@taobao.com
* 2011-11-26
*
* 测试整个分析统计抽象层的测试用例子,analysis-job-config.properties中的一个数据来源
* 需要通过http本地获得数据,因此首先跑这个用例以前先运行TestServer,然后再跑这个例子
*
*/
public class DefaultAnalysisEngineTestBig {

  @Test
  public void testDoAnalysis() throws Exception {
    StatisticsEngine defaultAnalysisEngine = new StatisticsEngine();
    defaultAnalysisEngine.init();
   
    IInputAdaptor fileInputAdaptor =  new FileInputAdaptor();
    IInputAdaptor httpInputAdaptor = new HttpInputAdaptor();
    FileOutputAdaptor fileOutAdaptor = new FileOutputAdaptor();
   
    FileJobExporter fileJobExporter = new FileJobExporter();
    fileJobExporter.setMaxCreateReportWorker(2);
    fileJobExporter.init();
   
    fileOutAdaptor.setJobExporter(fileJobExporter);
   
    JobResultMerger jobResultMerger = new JobResultMerger();
    jobResultMerger.init();
   
    defaultAnalysisEngine.addInputAdaptor(fileInputAdaptor);
    defaultAnalysisEngine.addInputAdaptor(httpInputAdaptor);
    defaultAnalysisEngine.addOutputAdaptor(fileOutAdaptor);
     
    FileJobBuilder jobBuilder = new FileJobBuilder();
    Map<String,Job> jobs = jobBuilder.build("jobs-config-engine-big.properties");
   
    for(int i =0 ; i < 100; i++)
    {
   
      for(Job job : jobs.values())
      {
        List<JobTask> tasks = job.getJobTasks();
       
        List<JobTaskResult> taskResults = new ArrayList<JobTaskResult>();
       
        for(JobTask jobtask : tasks)
        {
          taskResults.add(defaultAnalysisEngine.doAnalysis(jobtask));
        }
       
        JobTaskResult jobTaskResult = jobResultMerger.merge(tasks.get(0), taskResults,true,true);
       
        defaultAnalysisEngine.doExport(tasks.get(0), jobTaskResult);
      }
    }

    fileJobExporter.releaseResource();
    jobResultMerger.releaseResource();
    defaultAnalysisEngine.releaseResource();
   
    Thread.sleep(100);
   
  }

}
TOP

Related Classes of com.taobao.top.analysis.node.component.DefaultAnalysisEngineTestBig

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.