/// <exception cref="System.Exception"/> public virtual void TestWritable() { Random r = new Random(); Writable[] writs = new Writable[] { new BooleanWritable(r.NextBoolean()), new FloatWritable (r.NextFloat()), new FloatWritable(r.NextFloat()), new IntWritable(r.Next()), new LongWritable(r.NextLong()), new BytesWritable(Sharpen.Runtime.GetBytesForString( "dingo")), new LongWritable(r.NextLong()), new IntWritable(r.Next()), new BytesWritable (Sharpen.Runtime.GetBytesForString("yak")), new IntWritable(r.Next()) }; TupleWritable sTuple = MakeTuple(writs); ByteArrayOutputStream @out = new ByteArrayOutputStream(); sTuple.Write(new DataOutputStream(@out)); ByteArrayInputStream @in = new ByteArrayInputStream(@out.ToByteArray()); TupleWritable dTuple = new TupleWritable(); dTuple.ReadFields(new DataInputStream(@in)); NUnit.Framework.Assert.IsTrue("Failed to write/read tuple", sTuple.Equals(dTuple) ); }
/// <exception cref="System.Exception"/> public virtual void TestWideWritable2() { 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)); NUnit.Framework.Assert.IsTrue("Failed to write/read tuple", sTuple.Equals(dTuple) ); NUnit.Framework.Assert.AreEqual("All tuple data has not been read from the stream" , -1, @in.Read()); }