Esempio n. 1
0
 internal Harness(DataChecksum checksum, int dataLength, bool useDirect)
 {
     this.checksum   = checksum;
     this.dataLength = dataLength;
     numSums         = (dataLength - 1) / checksum.GetBytesPerChecksum() + 1;
     sumsLength      = numSums * checksum.GetChecksumSize();
     byte[] data = new byte[dataLength + DataOffsetInBuffer + DataTrailerInBuffer];
     new Random().NextBytes(data);
     dataBuf = ByteBuffer.Wrap(data, DataOffsetInBuffer, dataLength);
     byte[] checksums = new byte[SumsOffsetInBuffer + sumsLength];
     checksumBuf = ByteBuffer.Wrap(checksums, SumsOffsetInBuffer, sumsLength);
     // Swap out for direct buffers if requested.
     if (useDirect)
     {
         dataBuf     = Directify(dataBuf);
         checksumBuf = Directify(checksumBuf);
     }
 }
Esempio n. 2
0
 /// <exception cref="Org.Apache.Hadoop.FS.ChecksumException"/>
 internal virtual void TestCorrectness()
 {
     // calculate real checksum, make sure it passes
     checksum.CalculateChunkedSums(dataBuf, checksumBuf);
     checksum.VerifyChunkedSums(dataBuf, checksumBuf, "fake file", 0);
     // Change a byte in the header and in the trailer, make sure
     // it doesn't affect checksum result
     CorruptBufferOffset(checksumBuf, 0);
     checksum.VerifyChunkedSums(dataBuf, checksumBuf, "fake file", 0);
     CorruptBufferOffset(dataBuf, 0);
     dataBuf.Limit(dataBuf.Limit() + 1);
     CorruptBufferOffset(dataBuf, dataLength + DataOffsetInBuffer);
     dataBuf.Limit(dataBuf.Limit() - 1);
     checksum.VerifyChunkedSums(dataBuf, checksumBuf, "fake file", 0);
     // Make sure bad checksums fail - error at beginning of array
     CorruptBufferOffset(checksumBuf, SumsOffsetInBuffer);
     try
     {
         checksum.VerifyChunkedSums(dataBuf, checksumBuf, "fake file", 0);
         NUnit.Framework.Assert.Fail("Did not throw on bad checksums");
     }
     catch (ChecksumException ce)
     {
         Assert.Equal(0, ce.GetPos());
     }
     // Make sure bad checksums fail - error at end of array
     UncorruptBufferOffset(checksumBuf, SumsOffsetInBuffer);
     CorruptBufferOffset(checksumBuf, SumsOffsetInBuffer + sumsLength - 1);
     try
     {
         checksum.VerifyChunkedSums(dataBuf, checksumBuf, "fake file", 0);
         NUnit.Framework.Assert.Fail("Did not throw on bad checksums");
     }
     catch (ChecksumException ce)
     {
         int expectedPos = checksum.GetBytesPerChecksum() * (numSums - 1);
         Assert.Equal(expectedPos, ce.GetPos());
         Assert.True(ce.Message.Contains("fake file"));
     }
 }