/// <exception cref="System.Exception"/> public virtual void TestFindAfterUpdatingContents() { Org.Apache.Hadoop.IO.Text text = new Org.Apache.Hadoop.IO.Text("abcd"); text.Set(Runtime.GetBytesForString("a")); Assert.Equal(text.GetLength(), 1); Assert.Equal(text.Find("a"), 0); Assert.Equal(text.Find("b"), -1); }
/// <exception cref="CharacterCodingException"/> public virtual void TestTextText() { Org.Apache.Hadoop.IO.Text a = new Org.Apache.Hadoop.IO.Text("abc"); Org.Apache.Hadoop.IO.Text b = new Org.Apache.Hadoop.IO.Text("a"); b.Set(a); Assert.Equal("abc", b.ToString()); a.Append(Runtime.GetBytesForString("xdefgxxx"), 1, 4); Assert.Equal("modified aliased string", "abc", b.ToString()); Assert.Equal("appended string incorrectly", "abcdefg", a.ToString ()); // add an extra byte so that capacity = 14 and length = 8 a.Append(new byte[] { (byte)('d') }, 0, 1); Assert.Equal(14, a.GetBytes().Length); Assert.Equal(8, a.CopyBytes().Length); }
/// <exception cref="System.IO.IOException"/> internal static long WriteBench(JobConf conf) { // OutputFormat instantiation long filelen = conf.GetLong("filebench.file.bytes", 5 * 1024 * 1024 * 1024); Org.Apache.Hadoop.IO.Text key = new Org.Apache.Hadoop.IO.Text(); Org.Apache.Hadoop.IO.Text val = new Org.Apache.Hadoop.IO.Text(); string fn = conf.Get("test.filebench.name", string.Empty); Path outd = FileOutputFormat.GetOutputPath(conf); conf.Set("mapred.work.output.dir", outd.ToString()); OutputFormat outf = conf.GetOutputFormat(); RecordWriter <Org.Apache.Hadoop.IO.Text, Org.Apache.Hadoop.IO.Text> rw = outf.GetRecordWriter (outd.GetFileSystem(conf), conf, fn, Reporter.Null); try { long acc = 0L; DateTime start = new DateTime(); for (int i = 0; acc < filelen; ++i) { i %= keys.Length; key.Set(keys[i]); val.Set(values[i]); rw.Write(key, val); acc += keys[i].Length; acc += values[i].Length; } DateTime end = new DateTime(); return(end.GetTime() - start.GetTime()); } finally { rw.Close(Reporter.Null); } }