Пример #1
0
        /// <exception cref="System.IO.IOException"/>
        private void DoTestReceiveAndMirror(PacketReceiver pr, int dataLen, int checksumsLen
                                            )
        {
            byte[] Data              = AppendTestUtil.InitBuffer(dataLen);
            byte[] Checksums         = AppendTestUtil.InitBuffer(checksumsLen);
            byte[] packet            = PrepareFakePacket(Data, Checksums);
            ByteArrayInputStream @in = new ByteArrayInputStream(packet);

            pr.ReceiveNextPacket(@in);
            ByteBuffer parsedData = pr.GetDataSlice();

            Assert.AssertArrayEquals(Data, RemainingAsArray(parsedData));
            ByteBuffer parsedChecksums = pr.GetChecksumSlice();

            Assert.AssertArrayEquals(Checksums, RemainingAsArray(parsedChecksums));
            PacketHeader header = pr.GetHeader();

            NUnit.Framework.Assert.AreEqual(Seqno, header.GetSeqno());
            NUnit.Framework.Assert.AreEqual(OffsetInBlock, header.GetOffsetInBlock());
            NUnit.Framework.Assert.AreEqual(dataLen + checksumsLen + Ints.Bytes, header.GetPacketLen
                                                ());
            // Mirror the packet to an output stream and make sure it matches
            // the packet we sent.
            ByteArrayOutputStream mirrored = new ByteArrayOutputStream();

            mirrored = Org.Mockito.Mockito.Spy(mirrored);
            pr.MirrorPacketTo(new DataOutputStream(mirrored));
            // The write should be done in a single call. Otherwise we may hit
            // nasty interactions with nagling (eg HDFS-4049).
            Org.Mockito.Mockito.Verify(mirrored, Org.Mockito.Mockito.Times(1)).Write(Org.Mockito.Mockito
                                                                                     .Any <byte[]>(), Org.Mockito.Mockito.AnyInt(), Org.Mockito.Mockito.Eq(packet.Length
                                                                                                                                                           ));
            Org.Mockito.Mockito.VerifyNoMoreInteractions(mirrored);
            Assert.AssertArrayEquals(packet, mirrored.ToByteArray());
        }
Пример #2
0
        public virtual void TestHSyncBlockBoundary()
        {
            Configuration  conf    = new HdfsConfiguration();
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).Build();
            FileSystem     fs      = cluster.GetFileSystem();
            Path           p       = new Path("/testHSyncBlockBoundary/foo");
            int            len     = 1 << 16;

            byte[]             fileContents = AppendTestUtil.InitBuffer(len);
            FSDataOutputStream @out         = fs.Create(p, FsPermission.GetDefault(), EnumSet.Of(CreateFlag
                                                                                                 .Create, CreateFlag.Overwrite, CreateFlag.SyncBlock), 4096, (short)1, len, null);

            // fill exactly one block (tests the SYNC_BLOCK case) and flush
            @out.Write(fileContents, 0, len);
            @out.Hflush();
            // the full block should have caused a sync
            CheckSyncMetric(cluster, 1);
            @out.Hsync();
            // first on block again
            CheckSyncMetric(cluster, 1);
            // write one more byte and sync again
            @out.Write(1);
            @out.Hsync();
            CheckSyncMetric(cluster, 2);
            @out.Close();
            CheckSyncMetric(cluster, 3);
            cluster.Shutdown();
        }