Example #1
0
        public virtual void CommonUsagePerfTest()
        {
            int          NumRuns  = 5;
            DataChecksum checksum = DataChecksum.NewDataChecksum(DataChecksum.Type.Crc32c, 512
                                                                 );
            int dataLength = 512 * 1024 * 1024;

            TestDataChecksum.Harness h = new TestDataChecksum.Harness(checksum, dataLength, true
                                                                      );
            for (int i = 0; i < NumRuns; i++)
            {
                StopWatch s = new StopWatch().Start();
                // calculate real checksum, make sure it passes
                checksum.CalculateChunkedSums(h.dataBuf, h.checksumBuf);
                s.Stop();
                System.Console.Error.WriteLine("Calculate run #" + i + ": " + s.Now(TimeUnit.Microseconds
                                                                                    ) + "us");
                s = new StopWatch().Start();
                // calculate real checksum, make sure it passes
                checksum.VerifyChunkedSums(h.dataBuf, h.checksumBuf, "fake file", 0);
                s.Stop();
                System.Console.Error.WriteLine("Verify run #" + i + ": " + s.Now(TimeUnit.Microseconds
                                                                                 ) + "us");
            }
        }
Example #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"));
     }
 }