Example #1
0
        /// <summary>
        /// If valueClass is undefined, readFields should throw an exception indicating
        /// that the field is null.
        /// </summary>
        /// <remarks>
        /// If valueClass is undefined, readFields should throw an exception indicating
        /// that the field is null. Otherwise, readFields should succeed.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestThrowUndefinedValueException()
        {
            // Get a buffer containing a simple text array
            Text[] elements = new Text[] { new Text("zero"), new Text("one"), new Text("two") };
            TestArrayWritable.TextArrayWritable sourceArray = new TestArrayWritable.TextArrayWritable
                                                                  ();
            sourceArray.Set(elements);
            // Write it to a normal output buffer
            DataOutputBuffer @out = new DataOutputBuffer();
            DataInputBuffer  @in  = new DataInputBuffer();

            sourceArray.Write(@out);
            // Read the output buffer with TextReadable. Since the valueClass is defined,
            // this should succeed
            TestArrayWritable.TextArrayWritable destArray = new TestArrayWritable.TextArrayWritable
                                                                ();
            @in.Reset(@out.GetData(), @out.GetLength());
            destArray.ReadFields(@in);
            Writable[] destElements = destArray.Get();
            Assert.True(destElements.Length == elements.Length);
            for (int i = 0; i < elements.Length; i++)
            {
                Assert.Equal(destElements[i], elements[i]);
            }
        }
Example #2
0
        /// <summary>
        /// test
        /// <see cref="ArrayWritable"/>
        /// toArray() method
        /// </summary>
        public virtual void TestArrayWritableToArray()
        {
            Text[] elements = new Text[] { new Text("zero"), new Text("one"), new Text("two") };
            TestArrayWritable.TextArrayWritable arrayWritable = new TestArrayWritable.TextArrayWritable
                                                                    ();
            arrayWritable.Set(elements);
            object array = arrayWritable.ToArray();

            Assert.True("TestArrayWritable testArrayWritableToArray error!!! "
                        , array is Text[]);
            Text[] destElements = (Text[])array;
            for (int i = 0; i < elements.Length; i++)
            {
                Assert.Equal(destElements[i], elements[i]);
            }
        }