public virtual void TestRandomSeeks() { int limit = GetContract().GetLimit(TestRandomSeekCount, DefaultRandomSeekCount); Describe("Testing " + limit + " random seeks"); int filesize = 10 * 1024; byte[] buf = ContractTestUtils.Dataset(filesize, 0, 255); Path randomSeekFile = Path("testrandomseeks.bin"); ContractTestUtils.CreateFile(GetFileSystem(), randomSeekFile, false, buf); Random r = new Random(); FSDataInputStream stm = GetFileSystem().Open(randomSeekFile); // Record the sequence of seeks and reads which trigger a failure. int[] seeks = new int[10]; int[] reads = new int[10]; try { for (int i = 0; i < limit; i++) { int seekOff = r.Next(buf.Length); int toRead = r.Next(Math.Min(buf.Length - seekOff, 32000)); seeks[i % seeks.Length] = seekOff; reads[i % reads.Length] = toRead; ContractTestUtils.VerifyRead(stm, buf, seekOff, toRead); } } catch (Exception afe) { StringBuilder sb = new StringBuilder(); sb.Append("Sequence of actions:\n"); for (int j = 0; j < seeks.Length; j++) { sb.Append("seek @ ").Append(seeks[j]).Append(" ").Append("read ").Append(reads[j ]).Append("\n"); } Log.Error(sb.ToString()); throw; } finally { stm.Close(); } }