All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.mlk.junit.rules.HadoopYarnRule Maven / Gradle / Ivy

There is a newer version: 1.5.39
Show newest version
package com.github.mlk.junit.rules;

import org.apache.hadoop.hdfs.HdfsConfiguration;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.server.MiniYARNCluster;

/**
 * Starts and stops a local Hadoop DFS & YARN cluster for integration testing against Hadoop.
 * For an example of it in action see the tests for this
 * class.
 */
public class HadoopYarnRule extends HadoopDFSRule {

  private MiniYARNCluster yarnCluster;
  private final String name;

  /**
   * Creates a Yarn rule with the following test name.
   *
   * @param name The test name
   */
  public HadoopYarnRule(String name) {
    this.name = name;
  }

  protected HdfsConfiguration createConfiguration() {
    return new HdfsConfiguration(new YarnConfiguration());
  }

  @Override
  protected void before() throws Throwable {
    super.before();

    yarnCluster = new MiniYARNCluster(name, 1, 1, 1);
    yarnCluster.init(getConfiguration());
    yarnCluster.start();
  }

  @Override
  protected void after() {
    super.after();
    yarnCluster.stop();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy