public virtual void TestEmptyReport()
        {
            BlockListAsLongs blocks = CheckReport();

            Assert.AssertArrayEquals(new long[] { 0, 0, -1, -1, -1 }, blocks.GetBlockListAsLongs
                                         ());
        }
        public virtual void TestFinalized()
        {
            BlockListAsLongs blocks = CheckReport(new FinalizedReplica(b1, null, null));

            Assert.AssertArrayEquals(new long[] { 1, 0, 1, 11, 111, -1, -1, -1 }, blocks.GetBlockListAsLongs
                                         ());
        }
        private BlockListAsLongs CheckReport(params Replica[] replicas)
        {
            IDictionary <long, Replica> expectedReplicas = new Dictionary <long, Replica>();

            foreach (Replica replica in replicas)
            {
                expectedReplicas[replica.GetBlockId()] = replica;
            }
            expectedReplicas = Sharpen.Collections.UnmodifiableMap(expectedReplicas);
            // encode the blocks and extract the buffers
            BlockListAsLongs   blocks  = BlockListAsLongs.Encode(expectedReplicas.Values);
            IList <ByteString> buffers = blocks.GetBlocksBuffers();
            // convert to old-style list of longs
            IList <long> longs = new AList <long>();

            foreach (long value in blocks.GetBlockListAsLongs())
            {
                longs.AddItem(value);
            }
            // decode the buffers and verify its contents
            BlockListAsLongs decodedBlocks = BlockListAsLongs.DecodeBuffers(expectedReplicas.
                                                                            Count, buffers);

            CheckReplicas(expectedReplicas, decodedBlocks);
            // decode the long and verify its contents
            BlockListAsLongs decodedList = BlockListAsLongs.DecodeLongs(longs);

            CheckReplicas(expectedReplicas, decodedList);
            return(blocks);
        }
        public virtual void TestUc()
        {
            BlockListAsLongs blocks = CheckReport(new ReplicaBeingWritten(b1, null, null, null
                                                                          ));

            Assert.AssertArrayEquals(new long[] { 0, 1, -1, -1, -1, 1, 11, 111, HdfsServerConstants.ReplicaState
                                                  .Rbw.GetValue() }, blocks.GetBlockListAsLongs());
        }
        public virtual void TestMix()
        {
            BlockListAsLongs blocks = CheckReport(new FinalizedReplica(b1, null, null), new FinalizedReplica
                                                      (b2, null, null), new ReplicaBeingWritten(b3, null, null, null), new ReplicaWaitingToBeRecovered
                                                      (b4, null, null));

            Assert.AssertArrayEquals(new long[] { 2, 2, 1, 11, 111, 2, 22, 222, -1, -1, -1, 3
                                                  , 33, 333, HdfsServerConstants.ReplicaState.Rbw.GetValue(), 4, 44, 444, HdfsServerConstants.ReplicaState
                                                  .Rwr.GetValue() }, blocks.GetBlockListAsLongs());
        }