JUnit测试Hadoop Writable

时间:2012-02-10 22:32:10

标签: java hadoop

我正在编写一些自定义的Hadoop Writable类。我想使用JUnit来测试readFields()和write()函数。

有没有办法将write(DataOutput out)重定向到readFields(DataInput in)?我想做点什么:

CustomWritable writeable1 = new CustomWritable();
CustomWritable writeable2 = new CustomWritable();

//build writable1 with some data.
DataInputAndOutput io = ...

writeable1.write(io);
writable2.read(io);

assertEquals(writable1,writable2);

思想?

1 个答案:

答案 0 :(得分:2)

使用ByteArrayOutputStream byteout = ...和ByteArrayInputStream(byteout.toByteArray())来完成此任务。

我尝试使用:

http://docs.oracle.com/javase/7/docs/api/java/io/PipedOutputStream.html http://docs.oracle.com/javase/7/docs/api/java/io/PipedInputStream.html

但发现如果从同一个线程运行,这些有时会死锁。