我正在嘗試使用Cloudera hadoop distrubution開發mr-job。我正在使用api版本2. 我確實遇到了先生-單元。請建議做什麼。我使用了標準的arhetype並完全丟失,我不明白問題的根源在哪裏。 這裏是我的依賴關係:java.lang.NoSuchMethodError:運行MRUnit時的org.apache.hadoop.mapreduce.TaskAttemptID
<dependency>
<groupId>com.cloudera.hadoop</groupId>
<artifactId>hadoop-core</artifactId>
<version>0.20.2-320</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.cloudera.hadoop</groupId>
<artifactId>hadoop-mrunit</artifactId>
<version>0.20.2-320</version>
<scope>test</scope>
</dependency>
這裏是我的測試代碼:
@Test
public void testEmptyOutput() throws Exception{
for(String line : linesFromFlatFile){
//List<Pair<GetReq, IntWritable>> output =
driver.withInput(UNUSED_LONG_KEY, new Text(line))
// .withOutput(null, null)
.run();
//assertTrue("", output.isEmpty());
}
}
這裏是個例外:
> Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.283
> sec <<< FAILURE!
> testEmptyOutput(MapperTest)
> Time elapsed: 0.258 sec <<< ERROR! java.lang.NoSuchMethodError:
> org.apache.hadoop.mapreduce.TaskAttemptID.<init>(Ljava/lang/String;IZII)V
> at
> org.apache.hadoop.mrunit.mapreduce.mock.MockMapContextWrapper$MockMapContext.<init>(MockMapContextWrapper.java:71)
> at
> org.apache.hadoop.mrunit.mapreduce.mock.MockMapContextWrapper.getMockContext(MockMapContextWrapper.java:144)
> at
> org.apache.hadoop.mrunit.mapreduce.MapDriver.run(MapDriver.java:197)
> at
MapperTest.testEmptyOutput(ScoringCounterMapperTest.java:42)
package mypackage;
import java.util.Date;
import java.util.List;
import junit.framework.TestCase;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mrunit.mapreduce.MapDriver;
import org.apache.hadoop.mrunit.types.Pair;
import org.junit.Before;
import org.junit.Test;
import Sample;
import GetReq;
public class MapperTest extends TestCase {
private static final IntWritable ONE_OCCURANCE = new IntWritable(1);
private static final LongWritable UNUSED_LONG_KEY = new LongWritable(new Date().getTime());
private Mapper<LongWritable, Text, GetReq, IntWritable> mapper;
private MapDriver<LongWritable, Text, GetReq, IntWritable> driver;
List<String> linesFromFlatFileNoOutput = null;
List<String> linesFromFlatFileWithOutput = null;
@Before
public void setUp() {
mapper = newMapper();
driver = new MapDriver<LongWritable, Text, GetReq, IntWritable>(mapper);
Mapper.METADATA_CSV ="../../data/metadata.csv"; //ugly hook
linesFromFlatFileNoOutput = Sample.instance.getLinesFromFlatFileNoOutput();
linesFromFlatFileWithOutput = Sample.instance.getLinesFromFlatFileWithOutput();
}
@Test
public void testEmptyOutput() throws Exception{
for(String line : linesFromFlatFileNoOutput){
//List<Pair<GetReq, IntWritable>> output =
driver.withInput(UNUSED_LONG_KEY, new Text(line))
.withOutput(null, null)
.runTest();
//assertTrue("", output.isEmpty());
}
}
@Test
public void testResultOutput() throws Exception{
for(String line : linesFromFlatFileWithOutput){
driver.withInput(UNUSED_LONG_KEY, new Text(line))
//.withOutput(null, null)
.runTest();
}
}
}
嗯...我沒有改變什麼pom.xml 現在我得到輸出和相同的exeption。看起來像映射器運行一次。或者運行。我從mapper body得到調試輸出。
UPD:我已經添加了分類和改變依賴:
<dependency>
<groupId>org.apache.mrunit</groupId>
<artifactId>mrunit</artifactId>
<version>0.9.0-incubating</version>
<classifier>hadoop2</classifier>
<scope>test</scope>
</dependency>
現在我得到了另一個問題:
Found interface org.apache.hadoop.mapreduce.Counter, but class was expected
在線:
context.getCounter(EnumCounter.MATCHED_RECORDS).increment(1);
做什麼我又錯了嗎?
您正在使用哪種IDE? –
它有道理嗎?我在安裝了m2Eclipse的Eclipse Juno 4.2中運行mvn clean test,並從命令行獲取它 – Sergey
您可以發佈整個測試類源代碼嗎? –