Search in sources :

Example 1 with ShuffleConsumerPlugin

use of org.apache.hadoop.mapred.ShuffleConsumerPlugin in project hadoop by apache.

the class TestShufflePlugin method testPluginAbility.

@Test
public /**
   * A testing method instructing core hadoop to load an external ShuffleConsumerPlugin
   * as if it came from a 3rd party.
   */
void testPluginAbility() {
    try {
        // create JobConf with mapreduce.job.shuffle.consumer.plugin=TestShuffleConsumerPlugin
        JobConf jobConf = new JobConf();
        jobConf.setClass(MRConfig.SHUFFLE_CONSUMER_PLUGIN, TestShufflePlugin.TestShuffleConsumerPlugin.class, ShuffleConsumerPlugin.class);
        ShuffleConsumerPlugin shuffleConsumerPlugin = null;
        Class<? extends ShuffleConsumerPlugin> clazz = jobConf.getClass(MRConfig.SHUFFLE_CONSUMER_PLUGIN, Shuffle.class, ShuffleConsumerPlugin.class);
        assertNotNull("Unable to get " + MRConfig.SHUFFLE_CONSUMER_PLUGIN, clazz);
        // load 3rd party plugin through core's factory method
        shuffleConsumerPlugin = ReflectionUtils.newInstance(clazz, jobConf);
        assertNotNull("Unable to load " + MRConfig.SHUFFLE_CONSUMER_PLUGIN, shuffleConsumerPlugin);
    } catch (Exception e) {
        assertTrue("Threw exception:" + e, false);
    }
}
Also used : ShuffleConsumerPlugin(org.apache.hadoop.mapred.ShuffleConsumerPlugin) JobConf(org.apache.hadoop.mapred.JobConf) Test(org.junit.Test)

Example 2 with ShuffleConsumerPlugin

use of org.apache.hadoop.mapred.ShuffleConsumerPlugin in project hadoop by apache.

the class TestShufflePlugin method testConsumerApi.

@Test
public /**
   * A testing method verifying availability and accessibility of API that is needed
   * for sub-classes of ShuffleConsumerPlugin
   */
void testConsumerApi() {
    JobConf jobConf = new JobConf();
    ShuffleConsumerPlugin<K, V> shuffleConsumerPlugin = new TestShuffleConsumerPlugin<K, V>();
    //mock creation
    ReduceTask mockReduceTask = mock(ReduceTask.class);
    TaskUmbilicalProtocol mockUmbilical = mock(TaskUmbilicalProtocol.class);
    Reporter mockReporter = mock(Reporter.class);
    FileSystem mockFileSystem = mock(FileSystem.class);
    Class<? extends org.apache.hadoop.mapred.Reducer> combinerClass = jobConf.getCombinerClass();
    // needed for mock with generic
    @SuppressWarnings("unchecked") CombineOutputCollector<K, V> mockCombineOutputCollector = (CombineOutputCollector<K, V>) mock(CombineOutputCollector.class);
    org.apache.hadoop.mapreduce.TaskAttemptID mockTaskAttemptID = mock(org.apache.hadoop.mapreduce.TaskAttemptID.class);
    LocalDirAllocator mockLocalDirAllocator = mock(LocalDirAllocator.class);
    CompressionCodec mockCompressionCodec = mock(CompressionCodec.class);
    Counter mockCounter = mock(Counter.class);
    TaskStatus mockTaskStatus = mock(TaskStatus.class);
    Progress mockProgress = mock(Progress.class);
    MapOutputFile mockMapOutputFile = mock(MapOutputFile.class);
    Task mockTask = mock(Task.class);
    try {
        String[] dirs = jobConf.getLocalDirs();
        // verify that these APIs are available through super class handler
        ShuffleConsumerPlugin.Context<K, V> context = new ShuffleConsumerPlugin.Context<K, V>(mockTaskAttemptID, jobConf, mockFileSystem, mockUmbilical, mockLocalDirAllocator, mockReporter, mockCompressionCodec, combinerClass, mockCombineOutputCollector, mockCounter, mockCounter, mockCounter, mockCounter, mockCounter, mockCounter, mockTaskStatus, mockProgress, mockProgress, mockTask, mockMapOutputFile, null);
        shuffleConsumerPlugin.init(context);
        shuffleConsumerPlugin.run();
        shuffleConsumerPlugin.close();
    } catch (Exception e) {
        assertTrue("Threw exception:" + e, false);
    }
    // verify that these APIs are available for 3rd party plugins
    mockReduceTask.getTaskID();
    mockReduceTask.getJobID();
    mockReduceTask.getNumMaps();
    mockReduceTask.getPartition();
    mockReporter.progress();
}
Also used : ReduceTask(org.apache.hadoop.mapred.ReduceTask) Task(org.apache.hadoop.mapred.Task) ShuffleConsumerPlugin(org.apache.hadoop.mapred.ShuffleConsumerPlugin) Counter(org.apache.hadoop.mapred.Counters.Counter) FileSystem(org.apache.hadoop.fs.FileSystem) CompressionCodec(org.apache.hadoop.io.compress.CompressionCodec) JobConf(org.apache.hadoop.mapred.JobConf) MapOutputFile(org.apache.hadoop.mapred.MapOutputFile) Progress(org.apache.hadoop.util.Progress) Reporter(org.apache.hadoop.mapred.Reporter) TaskStatus(org.apache.hadoop.mapred.TaskStatus) CombineOutputCollector(org.apache.hadoop.mapred.Task.CombineOutputCollector) TaskUmbilicalProtocol(org.apache.hadoop.mapred.TaskUmbilicalProtocol) ReduceTask(org.apache.hadoop.mapred.ReduceTask) LocalDirAllocator(org.apache.hadoop.fs.LocalDirAllocator) Test(org.junit.Test)

Aggregations

JobConf (org.apache.hadoop.mapred.JobConf)2 ShuffleConsumerPlugin (org.apache.hadoop.mapred.ShuffleConsumerPlugin)2 Test (org.junit.Test)2 FileSystem (org.apache.hadoop.fs.FileSystem)1 LocalDirAllocator (org.apache.hadoop.fs.LocalDirAllocator)1 CompressionCodec (org.apache.hadoop.io.compress.CompressionCodec)1 Counter (org.apache.hadoop.mapred.Counters.Counter)1 MapOutputFile (org.apache.hadoop.mapred.MapOutputFile)1 ReduceTask (org.apache.hadoop.mapred.ReduceTask)1 Reporter (org.apache.hadoop.mapred.Reporter)1 Task (org.apache.hadoop.mapred.Task)1 CombineOutputCollector (org.apache.hadoop.mapred.Task.CombineOutputCollector)1 TaskStatus (org.apache.hadoop.mapred.TaskStatus)1 TaskUmbilicalProtocol (org.apache.hadoop.mapred.TaskUmbilicalProtocol)1 Progress (org.apache.hadoop.util.Progress)1