/// <exception cref="System.IO.IOException"/> private static void CreateFiles(int length, int numFiles, Random random) { TestCombineSequenceFileInputFormat.Range[] ranges = CreateRanges(length, numFiles , random); for (int i = 0; i < numFiles; i++) { Path file = new Path(workDir, "test_" + i + ".seq"); // create a file with length entries SequenceFile.Writer writer = SequenceFile.CreateWriter(localFs, conf, file, typeof( IntWritable), typeof(BytesWritable)); TestCombineSequenceFileInputFormat.Range range = ranges[i]; try { for (int j = range.start; j < range.end; j++) { IntWritable key = new IntWritable(j); byte[] data = new byte[random.Next(10)]; random.NextBytes(data); BytesWritable value = new BytesWritable(data); writer.Append(key, value); } } finally { writer.Close(); } } }
private static TestCombineSequenceFileInputFormat.Range[] CreateRanges(int length , int numFiles, Random random) { // generate a number of files with various lengths TestCombineSequenceFileInputFormat.Range[] ranges = new TestCombineSequenceFileInputFormat.Range [numFiles]; for (int i = 0; i < numFiles; i++) { int start = i == 0 ? 0 : ranges[i - 1].end; int end = i == numFiles - 1 ? length : (length / numFiles) * (2 * i + 1) / 2 + random .Next(length / numFiles) + 1; ranges[i] = new TestCombineSequenceFileInputFormat.Range(start, end); } return(ranges); }