/// <exception cref="System.Exception"/> public virtual void TestEmptyFile() { Configuration conf = new Configuration(); FileSystem fs = FileSystem.GetLocal(conf); WriteTest(fs, new RandomDatum[0], TestFile); ArrayFile.Reader reader = new ArrayFile.Reader(fs, TestFile, conf); NUnit.Framework.Assert.IsNull(reader.Get(0, new RandomDatum())); reader.Close(); }
/// <exception cref="System.IO.IOException"/> private static void ReadTest(FileSystem fs, RandomDatum[] data, string file, Configuration conf) { RandomDatum v = new RandomDatum(); if (Log.IsDebugEnabled()) { Log.Debug("reading " + data.Length + " debug"); } ArrayFile.Reader reader = new ArrayFile.Reader(fs, file, conf); try { for (int i = 0; i < data.Length; i++) { // try forwards reader.Get(i, v); if (!v.Equals(data[i])) { throw new RuntimeException("wrong value at " + i); } } for (int i_1 = data.Length - 1; i_1 >= 0; i_1--) { // then backwards reader.Get(i_1, v); if (!v.Equals(data[i_1])) { throw new RuntimeException("wrong value at " + i_1); } } if (Log.IsDebugEnabled()) { Log.Debug("done reading " + data.Length + " debug"); } } finally { reader.Close(); } }
/// <summary> /// test on /// <see cref="Reader"/> /// iteration methods /// <pre> /// <c>next(), seek()</c> /// in and out of range. /// </pre> /// </summary> public virtual void TestArrayFileIteration() { int Size = 10; Configuration conf = new Configuration(); try { FileSystem fs = FileSystem.Get(conf); ArrayFile.Writer writer = new ArrayFile.Writer(conf, fs, TestFile, typeof(LongWritable ), SequenceFile.CompressionType.Record, defaultProgressable); NUnit.Framework.Assert.IsNotNull("testArrayFileIteration error !!!", writer); for (int i = 0; i < Size; i++) { writer.Append(new LongWritable(i)); } writer.Close(); ArrayFile.Reader reader = new ArrayFile.Reader(fs, TestFile, conf); LongWritable nextWritable = new LongWritable(0); for (int i_1 = 0; i_1 < Size; i_1++) { nextWritable = (LongWritable)reader.Next(nextWritable); Assert.Equal(nextWritable.Get(), i_1); } Assert.True("testArrayFileIteration seek error !!!", reader.Seek (new LongWritable(6))); nextWritable = (LongWritable)reader.Next(nextWritable); Assert.True("testArrayFileIteration error !!!", reader.Key() == 7); Assert.True("testArrayFileIteration error !!!", nextWritable.Equals (new LongWritable(7))); NUnit.Framework.Assert.IsFalse("testArrayFileIteration error !!!", reader.Seek(new LongWritable(Size + 5))); reader.Close(); } catch (Exception) { Fail("testArrayFileWriterConstruction error !!!"); } }