Exemplo n.º 1
0
        public virtual void TestSizeChange()
        {
            var hadoop = GetBytesForString("hadoop");

            BytesWritable buf           = new BytesWritable(hadoop);
            int           size          = buf.Length;
            int           orig_capacity = buf.Capacity;

            buf.Size = (size * 2);
            int newCapacity = buf.Capacity;

            Array.Copy(buf.Bytes, 0, buf.Bytes, size, size);
            newCapacity.ShouldBeGreaterThanOrEqualTo(size * 2);
            (size * 2).ShouldEqual(buf.Length);

            Assert.True(newCapacity != orig_capacity);
            buf.Size = (size * 4);
            Assert.True(newCapacity != buf.Capacity);
            for (int i = 0; i < size * 2; ++i)
            {
                Assert.Equal(hadoop[i % size], buf.Bytes[i]);
            }
            // ensure that copyBytes is exactly the right length

            Assert.Equal(size * 4, buf.CopyBytes().Length);
            // shrink the buffer
            buf.Capacity = (1);
            // make sure the size has been cut down too
            Assert.Equal(1, buf.Length);
            // but that the data is still there
            Assert.Equal(hadoop[0], buf.Bytes[0]);
        }