public virtual void TestSerializerAvailability() { Configuration conf = new Configuration(); SerializationFactory factory = new SerializationFactory(conf); // Test that a valid serializer class is returned when its present NUnit.Framework.Assert.IsNotNull("A valid class must be returned for default Writable Serde" , factory.GetSerializer <Writable>()); NUnit.Framework.Assert.IsNotNull("A valid class must be returned for default Writable serDe" , factory.GetDeserializer <Writable>()); // Test that a null is returned when none can be found. NUnit.Framework.Assert.IsNull("A null should be returned if there are no serializers found." , factory.GetSerializer <TestSerializationFactory>()); NUnit.Framework.Assert.IsNull("A null should be returned if there are no deserializers found" , factory.GetDeserializer <TestSerializationFactory>()); }
public virtual void TestSerializationKeyIsTrimmed() { Configuration conf = new Configuration(); conf.Set(CommonConfigurationKeys.IoSerializationsKey, " org.apache.hadoop.io.serializer.WritableSerialization " ); SerializationFactory factory = new SerializationFactory(conf); NUnit.Framework.Assert.IsNotNull("Valid class must be returned", factory.GetSerializer <LongWritable>()); }
/// <summary>A utility that tests serialization/deserialization.</summary> /// <param name="conf"> /// configuration to use, "io.serializations" is read to /// determine the serialization /// </param> /// <?/> /// <param name="before">item to (de)serialize</param> /// <returns>deserialized item</returns> /// <exception cref="System.Exception"/> public static K TestSerialization <K>(Configuration conf, K before) { SerializationFactory factory = new SerializationFactory(conf); Org.Apache.Hadoop.IO.Serializer.Serializer <K> serializer = factory.GetSerializer( GenericsUtil.GetClass(before)); Deserializer <K> deserializer = factory.GetDeserializer(GenericsUtil.GetClass(before )); DataOutputBuffer @out = new DataOutputBuffer(); serializer.Open(@out); serializer.Serialize(before); serializer.Close(); DataInputBuffer @in = new DataInputBuffer(); @in.Reset(@out.GetData(), @out.GetLength()); deserializer.Open(@in); K after = deserializer.Deserialize(null); deserializer.Close(); return(after); }