Пример #1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestWithWritable()
        {
            conf.Set("io.serializations", "org.apache.hadoop.io.serializer.WritableSerialization"
                     );
            Log.Info("Testing DefaultStringifier with Text");
            Random random = new Random();

            //test with a Text
            for (int i = 0; i < 10; i++)
            {
                //generate a random string
                StringBuilder builder = new StringBuilder();
                int           strLen  = random.Next(40);
                for (int j = 0; j < strLen; j++)
                {
                    builder.Append(alphabet[random.Next(alphabet.Length)]);
                }
                Org.Apache.Hadoop.IO.Text text = new Org.Apache.Hadoop.IO.Text(builder.ToString()
                                                                               );
                DefaultStringifier <Org.Apache.Hadoop.IO.Text> stringifier = new DefaultStringifier
                                                                             <Org.Apache.Hadoop.IO.Text>(conf, typeof(Org.Apache.Hadoop.IO.Text));
                string str = stringifier.ToString(text);
                Org.Apache.Hadoop.IO.Text claimedText = stringifier.FromString(str);
                Log.Info("Object: " + text);
                Log.Info("String representation of the object: " + str);
                Assert.Equal(text, claimedText);
            }
        }
Пример #2
0
        /// <exception cref="System.Exception"/>
        public virtual void TestWithJavaSerialization()
        {
            conf.Set("io.serializations", "org.apache.hadoop.io.serializer.JavaSerialization"
                     );
            Log.Info("Testing DefaultStringifier with Serializable Integer");
            //Integer implements Serializable
            int testInt = Extensions.ValueOf(42);
            DefaultStringifier <int> stringifier = new DefaultStringifier <int>(conf, typeof(int
                                                                                             ));
            string str        = stringifier.ToString(testInt);
            int    claimedInt = stringifier.FromString(str);

            Log.Info("String representation of the object: " + str);
            Assert.Equal(testInt, claimedInt);
        }