I’m writing some custom Hadoop Writable classes. I’d like to use JUnit to test the readFields() and write() functions.
Is there a way to redirect the write(DataOutput out) to the readFields(DataInput in)? I’d like to do something like:
CustomWritable writeable1 = new CustomWritable();
CustomWritable writeable2 = new CustomWritable();
//build writable1 with some data.
DataInputAndOutput io = ...
writeable1.write(io);
writable2.read(io);
assertEquals(writable1,writable2);
Thoughts?
Ended up using ByteArrayOutputStream byteout = … and ByteArrayInputStream(byteout.toByteArray()) to accomplish this.
I tried using:
http://docs.oracle.com/javase/7/docs/api/java/io/PipedOutputStream.html
http://docs.oracle.com/javase/7/docs/api/java/io/PipedInputStream.html
But found that these would sometimes deadlock if run from the same thread.