/// <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(); } }
/// <exception cref="System.IO.IOException"/> private void CheckSort(FileSystem fs, int count, int seed, Path file) { Log.Info("sorting " + count + " records in memory for debug"); RandomDatum.Generator generator = new RandomDatum.Generator(seed); SortedDictionary <RandomDatum, RandomDatum> map = new SortedDictionary <RandomDatum , RandomDatum>(); for (int i = 0; i < count; i++) { generator.Next(); RandomDatum key = generator.GetKey(); RandomDatum value = generator.GetValue(); map[key] = value; } Log.Debug("checking order of " + count + " records"); RandomDatum k = new RandomDatum(); RandomDatum v = new RandomDatum(); IEnumerator <KeyValuePair <RandomDatum, RandomDatum> > iterator = map.GetEnumerator( ); SequenceFile.Reader reader = new SequenceFile.Reader(fs, file.Suffix(".sorted"), conf); for (int i_1 = 0; i_1 < count; i_1++) { KeyValuePair <RandomDatum, RandomDatum> entry = iterator.Next(); RandomDatum key = entry.Key; RandomDatum value = entry.Value; reader.Next(k, v); if (!k.Equals(key)) { throw new RuntimeException("wrong key at " + i_1); } if (!v.Equals(value)) { throw new RuntimeException("wrong value at " + i_1); } } reader.Close(); Log.Debug("sucessfully checked " + count + " records"); }
/// <exception cref="System.IO.IOException"/> private void ReadTest(FileSystem fs, int count, int seed, Path file) { Log.Debug("reading " + count + " records"); SequenceFile.Reader reader = new SequenceFile.Reader(fs, file, conf); RandomDatum.Generator generator = new RandomDatum.Generator(seed); RandomDatum k = new RandomDatum(); RandomDatum v = new RandomDatum(); DataOutputBuffer rawKey = new DataOutputBuffer(); SequenceFile.ValueBytes rawValue = reader.CreateValueBytes(); for (int i = 0; i < count; i++) { generator.Next(); RandomDatum key = generator.GetKey(); RandomDatum value = generator.GetValue(); try { if ((i % 5) == 0) { // Testing 'raw' apis rawKey.Reset(); reader.NextRaw(rawKey, rawValue); } else { // Testing 'non-raw' apis if ((i % 2) == 0) { reader.Next(k); reader.GetCurrentValue(v); } else { reader.Next(k, v); } // Check if (!k.Equals(key)) { throw new RuntimeException("wrong key at " + i); } if (!v.Equals(value)) { throw new RuntimeException("wrong value at " + i); } } } catch (IOException ioe) { Log.Info("Problem on row " + i); Log.Info("Expected key = " + key); Log.Info("Expected len = " + key.GetLength()); Log.Info("Actual key = " + k); Log.Info("Actual len = " + k.GetLength()); Log.Info("Expected value = " + value); Log.Info("Expected len = " + value.GetLength()); Log.Info("Actual value = " + v); Log.Info("Actual len = " + v.GetLength()); Log.Info("Key equals: " + k.Equals(key)); Log.Info("value equals: " + v.Equals(value)); throw; } } reader.Close(); }