use of org.apache.hadoop.io.Writable in project hadoop by apache.
the class TestTupleWritable method makeRandomWritables.
private Writable[] makeRandomWritables() {
Random r = new Random();
Writable[] writs = { new BooleanWritable(r.nextBoolean()), new FloatWritable(r.nextFloat()), new FloatWritable(r.nextFloat()), new IntWritable(r.nextInt()), new LongWritable(r.nextLong()), new BytesWritable("dingo".getBytes()), new LongWritable(r.nextLong()), new IntWritable(r.nextInt()), new BytesWritable("yak".getBytes()), new IntWritable(r.nextInt()) };
return writs;
}
use of org.apache.hadoop.io.Writable in project hadoop by apache.
the class TestTupleWritable method testWideTuple.
@Test
public void testWideTuple() throws Exception {
Text emptyText = new Text("Should be empty");
Writable[] values = new Writable[64];
Arrays.fill(values, emptyText);
values[42] = new Text("Number 42");
TupleWritable tuple = new TupleWritable(values);
tuple.setWritten(42);
for (int pos = 0; pos < tuple.size(); pos++) {
boolean has = tuple.has(pos);
if (pos == 42) {
assertTrue(has);
} else {
assertFalse("Tuple position is incorrectly labelled as set: " + pos, has);
}
}
}
use of org.apache.hadoop.io.Writable in project hadoop by apache.
the class TestTupleWritable method testWideWritable2.
@Test
public void testWideWritable2() throws Exception {
Writable[] manyWrits = makeRandomWritables(71);
TupleWritable sTuple = new TupleWritable(manyWrits);
for (int i = 0; i < manyWrits.length; i++) {
sTuple.setWritten(i);
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
sTuple.write(new DataOutputStream(out));
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
TupleWritable dTuple = new TupleWritable();
dTuple.readFields(new DataInputStream(in));
assertTrue("Failed to write/read tuple", sTuple.equals(dTuple));
assertEquals("All tuple data has not been read from the stream", -1, in.read());
}
use of org.apache.hadoop.io.Writable in project hadoop by apache.
the class TestTupleWritable method testNestedIterable.
@Test
public void testNestedIterable() throws Exception {
Random r = new Random();
Writable[] writs = { new BooleanWritable(r.nextBoolean()), new FloatWritable(r.nextFloat()), new FloatWritable(r.nextFloat()), new IntWritable(r.nextInt()), new LongWritable(r.nextLong()), new BytesWritable("dingo".getBytes()), new LongWritable(r.nextLong()), new IntWritable(r.nextInt()), new BytesWritable("yak".getBytes()), new IntWritable(r.nextInt()) };
TupleWritable sTuple = makeTuple(writs);
assertTrue("Bad count", writs.length == verifIter(writs, sTuple, 0));
}
use of org.apache.hadoop.io.Writable in project hadoop by apache.
the class TestTupleWritable method testWideTupleBoundary.
/**
* Tests that we can write more than 64 values.
*/
@Test
public void testWideTupleBoundary() throws Exception {
Text emptyText = new Text("Should not be set written");
Writable[] values = new Writable[65];
Arrays.fill(values, emptyText);
values[64] = new Text("Should be the only value set written");
TupleWritable tuple = new TupleWritable(values);
tuple.setWritten(64);
for (int pos = 0; pos < tuple.size(); pos++) {
boolean has = tuple.has(pos);
if (pos == 64) {
assertTrue(has);
} else {
assertFalse("Tuple position is incorrectly labelled as set: " + pos, has);
}
}
}
Aggregations