public void Container_SerializeHugeObject()
        {
            var single = new SimpleFlatClass
            {
                StringField        = new string('a', 16254),
                ByteArrayField     = Encoding.ASCII.GetBytes(new string('b', 65666)),
                ZeroByteArrayField = Encoding.ASCII.GetBytes(new string('c', 128344))
            };

            var expected = new List <SimpleFlatClass>
            {
                single,
                single,
                single,
            };

            var writer = AvroContainer.CreateWriter <SimpleFlatClass>(this.resultStream, new AvroSerializerSettings {
                Resolver = new AvroDataContractResolver(true)
            }, Codec.Null);

            var block = writer.CreateBlockAsync().Result;

            expected.ForEach(block.Write);
            writer.WriteBlockAsync(block).Wait();
            writer.Dispose();

            this.resultStream.Seek(0, SeekOrigin.Begin);
            var reader = AvroContainer.CreateReader <SimpleFlatClass>(this.resultStream, true, new AvroSerializerSettings {
                Resolver = new AvroDataContractResolver(true)
            }, new CodecFactory());

            reader.MoveNext();
            Assert.True(expected.SequenceEqual(reader.Current.Objects));
        }
Exemple #2
0
        public void SequentialReaderWriter_SerializeHugeObject()
        {
            var single = new SimpleFlatClass
            {
                StringField        = new string('a', 16254),
                ByteArrayField     = Encoding.ASCII.GetBytes(new string('b', 65666)),
                ZeroByteArrayField = Encoding.ASCII.GetBytes(new string('c', 128344))
            };

            var expected = new List <SimpleFlatClass>
            {
                single,
                single,
                single,
            };

            var w = AvroContainer.CreateWriter <SimpleFlatClass>(this.resultStream, new AvroSerializerSettings {
                Resolver = new AvroDataContractResolver(true)
            }, Codec.Null);

            using (var writer = new SequentialWriter <SimpleFlatClass>(w, 24))
            {
                expected.ForEach(writer.Write);
            }

            this.resultStream.Seek(0, SeekOrigin.Begin);
            var r = AvroContainer.CreateReader <SimpleFlatClass>(this.resultStream, true, new AvroSerializerSettings {
                Resolver = new AvroDataContractResolver(true)
            }, new CodecFactory());

            using (var reader = new SequentialReader <SimpleFlatClass>(r))
            {
                Assert.IsTrue(expected.SequenceEqual(reader.Objects));
            }
        }
Exemple #3
0
        public void Performance_SimpleFlatClass()
        {
            var serializationTime   = new Stopwatch();
            var deserializationTime = new Stopwatch();
            var expected            = SimpleFlatClass.Create();
            var serializer          = AvroSerializer.Create <SimpleFlatClass>(new AvroSerializerSettings {
                Resolver = new AvroDataContractResolver(true)
            });

            using (var stream = new MemoryStream())
            {
                serializationTime.Start();
                for (var i = 0; i < NumberOfRuns; i++)
                {
                    serializer.Serialize(stream, expected);
                }
                serializationTime.Stop();

                stream.Seek(0, SeekOrigin.Begin);

                deserializationTime.Start();
                for (var i = 0; i < NumberOfRuns; i++)
                {
                    var deserialized = serializer.Deserialize(stream);
                }
                deserializationTime.Stop();

                Console.WriteLine(serializationTime.ElapsedTicks);
                Console.WriteLine(deserializationTime.ElapsedTicks);
            }
        }
Exemple #4
0
 public static ComplexNestedClass Create()
 {
     return(new ComplexNestedClass
     {
         NestedField = SimpleFlatClass.Create(),
         IntNestedField = R.Next(),
         RecursiveField = Recursive.Create()
     });
 }