Skip to content

Commit

Permalink
Merge pull request LinkedInAttic#21 from RallySoftware/hadoop-version…
Browse files Browse the repository at this point in the history
…-agnostic-test

Make the EtlMultiOutputCommitterTest use reflection for the Api change from hadoop-1.0.3 to cdh4
  • Loading branch information
kengoodhope committed Aug 5, 2013
2 parents 90ed421 + ef6d404 commit d4ee695
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
import com.linkedin.camus.etl.kafka.common.DateUtils;
import com.linkedin.camus.etl.kafka.common.EtlKey;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapred.TaskAttemptID;
import org.apache.hadoop.mapreduce.TaskAttemptID;
import org.apache.hadoop.mapreduce.JobContext;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
Expand All @@ -27,10 +29,19 @@ public class EtlMultiOutputCommitterTest implements Partitioner {
Configuration configuration;

@Before
public void setup() throws IOException {
public void setup() throws Exception {
configuration = new Configuration();
configuration.set(EtlMultiOutputFormat.ETL_DEFAULT_PARTITIONER_CLASS, "com.linkedin.camus.etl.kafka.coders.DefaultPartitioner");
taskAttemptContext = new TaskAttemptContext(configuration, new TaskAttemptID());

Constructor taskAttemptContextConstructor;
Class taskAttemptClass = Class.forName("org.apache.hadoop.mapreduce.TaskAttemptContext");
if (taskAttemptClass.isInterface()) {
Class taskAttamptImplClass = Class.forName("org.apache.hadoop.mapreduce.task.TaskAttemptContextImpl");
taskAttemptContextConstructor = taskAttamptImplClass.getConstructor(Configuration.class, TaskAttemptID.class);
} else
taskAttemptContextConstructor = taskAttemptClass.getConstructor(Configuration.class, TaskAttemptID.class);

taskAttemptContext = (TaskAttemptContext) taskAttemptContextConstructor.newInstance(configuration, new TaskAttemptID());
etlMultiOutputFormat = new EtlMultiOutputFormat();
committer = (EtlMultiOutputFormat.EtlMultiOutputCommitter) etlMultiOutputFormat.getOutputCommitter(taskAttemptContext);
}
Expand Down

0 comments on commit d4ee695

Please sign in to comment.