Package eu.stratosphere.test.util

Source Code of eu.stratosphere.test.util.RecordAPITestBase

/***********************************************************************************************************************
* Copyright (C) 2010-2013 by the Stratosphere project (http://stratosphere.eu)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
**********************************************************************************************************************/

package eu.stratosphere.test.util;

import org.junit.Assert;
import org.junit.Test;

import eu.stratosphere.api.common.JobExecutionResult;
import eu.stratosphere.api.common.Plan;
import eu.stratosphere.compiler.DataStatistics;
import eu.stratosphere.compiler.PactCompiler;
import eu.stratosphere.compiler.plan.OptimizedPlan;
import eu.stratosphere.compiler.plandump.PlanJSONDumpGenerator;
import eu.stratosphere.compiler.plantranslate.NepheleJobGraphGenerator;
import eu.stratosphere.configuration.Configuration;
import eu.stratosphere.nephele.client.JobClient;
import eu.stratosphere.nephele.jobgraph.JobGraph;

public abstract class RecordAPITestBase extends AbstractTestBase {
 
  protected JobExecutionResult jobExecutionResult;
 
  protected boolean printPlan;
 
 
  public RecordAPITestBase() {
    this(new Configuration());
  }
 
  public RecordAPITestBase(Configuration config) {
    super(config);
  }
 
 
  // --------------------------------------------------------------------------------------------
  //  Methods to create the test program and for pre- and post- test work
  // --------------------------------------------------------------------------------------------

  protected void preSubmit() throws Exception {}

  protected void postSubmit() throws Exception {}
 
 
  public JobExecutionResult getJobExecutionResult() {
    return jobExecutionResult;
  }
 
 
  protected JobGraph getJobGraph() throws Exception {
    Plan p = getTestJob();
    if (p == null) {
      Assert.fail("Error: Cannot obtain Pact plan. Did the thest forget to override either 'getPactPlan()' or 'getJobGraph()' ?");
    }
   
    PactCompiler pc = new PactCompiler(new DataStatistics());
    OptimizedPlan op = pc.compile(p);
   
    if (printPlan) {
      System.out.println(new PlanJSONDumpGenerator().getOptimizerPlanAsJSON(op));
    }

    NepheleJobGraphGenerator jgg = new NepheleJobGraphGenerator();
    return jgg.compileJobGraph(op);
  }
 
  protected Plan getTestJob() {
    return null;
  }
 
  // --------------------------------------------------------------------------------------------
  //  Actual Test Entry Point
  // --------------------------------------------------------------------------------------------
 
  @Test
  public void testJob() throws Exception {
    // pre-submit
    try {
      preSubmit();
    }
    catch (Exception e) {
      System.err.println(e.getMessage());
      e.printStackTrace();
      Assert.fail("Pre-submit work caused an error: " + e.getMessage());
    }
   
    // submit job
    JobGraph jobGraph = null;
    try {
      jobGraph = getJobGraph();
    }
    catch(Exception e) {
      System.err.println(e.getMessage());
      e.printStackTrace();
      Assert.fail("Failed to obtain JobGraph!");
    }
   
    Assert.assertNotNull("Obtained null JobGraph", jobGraph);
   
    try {
      JobClient client = this.executor.getJobClient(jobGraph);
      client.setConsoleStreamForReporting(getNullPrintStream());
      this.jobExecutionResult = client.submitJobAndWait();
    }
    catch(Exception e) {
      System.err.println(e.getMessage());
      e.printStackTrace();
      Assert.fail("Job execution failed!");
    }
   
    // post-submit
    try {
      postSubmit();
    }
    catch (Exception e) {
      System.err.println(e.getMessage());
      e.printStackTrace();
      Assert.fail("Post-submit work caused an error: " + e.getMessage());
    }
  }
}
TOP

Related Classes of eu.stratosphere.test.util.RecordAPITestBase

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.