예제 #1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestPreVersion21CompatibilityEmptyTuple()
        {
            Writable[] manyWrits = new Writable[0];
            TestTupleWritable.PreVersion21TupleWritable oldTuple = new TestTupleWritable.PreVersion21TupleWritable
                                                                       (manyWrits);
            // don't set any values written
            ByteArrayOutputStream @out = new ByteArrayOutputStream();

            oldTuple.Write(new DataOutputStream(@out));
            ByteArrayInputStream @in    = new ByteArrayInputStream(@out.ToByteArray());
            TupleWritable        dTuple = new TupleWritable();

            dTuple.ReadFields(new DataInputStream(@in));
            NUnit.Framework.Assert.IsTrue("Tuple writable is unable to read pre-0.21 versions of TupleWritable"
                                          , oldTuple.IsCompatible(dTuple));
            NUnit.Framework.Assert.AreEqual("All tuple data has not been read from the stream"
                                            , -1, @in.Read());
        }
예제 #2
0
        /// <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)
                                          );
        }
예제 #3
0
        /// <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());
        }
예제 #4
0
        /// <summary>Tests compatibility with pre-0.21 versions of TupleWritable</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestPreVersion21Compatibility()
        {
            Writable[] manyWrits = MakeRandomWritables(64);
            TestTupleWritable.PreVersion21TupleWritable oldTuple = new TestTupleWritable.PreVersion21TupleWritable
                                                                       (manyWrits);
            for (int i = 0; i < manyWrits.Length; i++)
            {
                if (i % 3 == 0)
                {
                    oldTuple.SetWritten(i);
                }
            }
            ByteArrayOutputStream @out = new ByteArrayOutputStream();

            oldTuple.Write(new DataOutputStream(@out));
            ByteArrayInputStream @in    = new ByteArrayInputStream(@out.ToByteArray());
            TupleWritable        dTuple = new TupleWritable();

            dTuple.ReadFields(new DataInputStream(@in));
            NUnit.Framework.Assert.IsTrue("Tuple writable is unable to read pre-0.21 versions of TupleWritable"
                                          , oldTuple.IsCompatible(dTuple));
            NUnit.Framework.Assert.AreEqual("All tuple data has not been read from the stream"
                                            , -1, @in.Read());
        }