/// <summary> /// test /// <c>Text</c> /// readFields/write operations /// </summary> public virtual void TestReadWriteOperations() { string line = "adsawseeeeegqewgasddga"; byte[] inputBytes = Runtime.GetBytesForString(line); inputBytes = Bytes.Concat(new byte[] { unchecked ((byte)22) }, inputBytes); DataInputBuffer @in = new DataInputBuffer(); DataOutputBuffer @out = new DataOutputBuffer(); Org.Apache.Hadoop.IO.Text text = new Org.Apache.Hadoop.IO.Text(line); try { @in.Reset(inputBytes, inputBytes.Length); text.ReadFields(@in); } catch (Exception) { Fail("testReadFields error !!!"); } try { text.Write(@out); } catch (IOException) { } catch (Exception) { Fail("testReadWriteOperations error !!!"); } }
/// <exception cref="System.Exception"/> public virtual void TestCompare() { DataOutputBuffer out1 = new DataOutputBuffer(); DataOutputBuffer out2 = new DataOutputBuffer(); DataOutputBuffer out3 = new DataOutputBuffer(); Text.Comparator comparator = new Text.Comparator(); for (int i = 0; i < NumIterations; i++) { // reset output buffer out1.Reset(); out2.Reset(); out3.Reset(); // generate two random strings string str1 = GetTestString(); string str2 = GetTestString(); if (i == 0) { str1 = GetLongString(); str2 = GetLongString(); } else { str1 = GetTestString(); str2 = GetTestString(); } // convert to texts Org.Apache.Hadoop.IO.Text txt1 = new Org.Apache.Hadoop.IO.Text(str1); Org.Apache.Hadoop.IO.Text txt2 = new Org.Apache.Hadoop.IO.Text(str2); Org.Apache.Hadoop.IO.Text txt3 = new Org.Apache.Hadoop.IO.Text(str1); // serialize them txt1.Write(out1); txt2.Write(out2); txt3.Write(out3); // compare two strings by looking at their binary formats int ret1 = comparator.Compare(out1.GetData(), 0, out1.GetLength(), out2.GetData() , 0, out2.GetLength()); // compare two strings int ret2 = txt1.CompareTo(txt2); Assert.Equal(ret1, ret2); Assert.Equal("Equivalence of different txt objects, same content" , 0, txt1.CompareTo(txt3)); Assert.Equal("Equvalence of data output buffers", 0, comparator .Compare(out1.GetData(), 0, out3.GetLength(), out3.GetData(), 0, out3.GetLength( ))); } }