public void TestWriteError() { ODataError odataError = new ODataError() { ErrorCode = "404", Message = "Not Found", }; MemoryStream ms = new MemoryStream(); using (var omw = TestHelper.CreateMessageWriter(ms, "avro/binary", AvroMediaTypeResolver.Instance)) { omw.WriteError(odataError, false); } ms.Seek(0, SeekOrigin.Begin); Error error; IAvroReader <Error> reader = null; using (reader = AvroContainer.CreateReader <Error>(ms)) using (var seqReader = new SequentialReader <Error>(reader)) { error = seqReader.Objects.First(); } Assert.IsNotNull(error); Assert.AreEqual("404", error.ErrorCode); Assert.AreEqual("Not Found", error.Message); }
public IEnumerable <T> AsEnumerable <T>(object source, Func <object, bool?> filterFunc = null) { if (source == null) { yield break; } IAvroReader <T> sr = source as IAvroReader <T>; ChoGuard.ArgumentNotNull(sr, "AvroReader"); InitializeRecordConfiguration(Configuration); if (!RaiseBeginLoad(sr)) { yield break; } foreach (var item in AsEnumerable(ReadObjects <T>(sr).OfType <object>(), TraceSwitch, filterFunc)) { yield return((T)item); } RaiseEndLoad(sr); }
public void Dispose() { if (this.reader != null) { this.reader.Dispose(); this.reader = null; } }
public void Dispose() { if (this.reader != null) { this.reader.Dispose(); this.reader = null; } }
public FileReader(Header header, IAvroReader <T> reader) { if (header.Schema.ToAvroCanonical() != reader.WriterSchema.ToAvroCanonical()) { throw new ArgumentException("Incompatible DatumReader"); } _fileHeader = header; _reader = reader; }
protected ChoAvroReader(IAvroReader <Dictionary <string, object> > avroReader, ChoAvroRecordConfiguration configuration = null) { ChoGuard.ArgumentNotNull(avroReader, "AvroReader"); Configuration = configuration; Init(); _avroReader = avroReader; }
/// <summary> /// Initializes a new instance of the <see cref="SequentialReader{T}" /> class. /// </summary> /// <param name="reader">The reader.</param> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="reader"/> is null.</exception> public SequentialReader(IAvroReader <T> reader) { if (reader == null) { throw new ArgumentNullException("reader"); } this.reader = reader; }
public ChoAvroReader(IAvroReader <T> avroReader, ChoAvroRecordConfiguration configuration = null) { ChoGuard.ArgumentNotNull(avroReader, "AvroReader"); Configuration = configuration; Init(); _avroReader = avroReader; }
private IEnumerable <T> ReadObjects <T>(IAvroReader <T> sr, Func <object, bool?> filterFunc = null) { using (var streamReader = new SequentialReader <T>(sr)) { foreach (var item in streamReader.Objects) { yield return(item); } } }
public virtual ChoAvroReader <T> Load(IAvroReader <T> avroReader) { ChoGuard.ArgumentNotNull(avroReader, "AvroReader"); Close(); Init(); _avroReader = avroReader; _closeStreamOnDispose = false; return(this); }
public override void CompareToAvroFile(Stream stream) { using (IAvroReader <object> streamReader = AvroContainer.CreateGenericReader(stream)) { using (var sequentialReader = new SequentialReader <object>(streamReader)) { IEnumerable <LargeClass> actual = sequentialReader.Objects.Select(o => (AvroRecord)o).Select(LargeClass.Create); Assert.IsTrue(this.Expected.SequenceEqual(actual)); } } }
public void TestWriteParameterWithFeed() { MemoryStream ms = new MemoryStream(); using (var omw = TestHelper.CreateMessageWriter(ms, "avro/binary", AvroMediaTypeResolver.Instance, new EdmModel(), false)) { var opw = omw.CreateODataParameterWriter(GetMaxId); var ew = opw.CreateFeedWriter("Products"); ew.WriteStart(new ODataFeed()); ew.WriteStart(entry0); ew.WriteEnd(); ew.WriteStart(entry1); ew.WriteEnd(); ew.WriteEnd(); ew.Flush(); opw.WriteEnd(); opw.Flush(); } ms.Seek(0, SeekOrigin.Begin); GetMaxIdParameter parameter; IAvroReader <GetMaxIdParameter> reader = null; try { reader = AvroContainer.CreateReader <GetMaxIdParameter>(ms); using (var seqReader = new SequentialReader <GetMaxIdParameter>(reader)) { reader = null; parameter = seqReader.Objects.First(); } } finally { if (reader != null) { reader.Dispose(); } } Assert.IsNotNull(parameter); var products = parameter.Products as IList <Product>; Assert.IsNotNull(products); Assert.AreEqual(product0, products[0]); Assert.AreEqual(product1, products[1]); }
public void WriteEntryAsAvroTest() { MemoryStream ms = new MemoryStream(); var ctx = this.CreateOutputContext(ms); ODataAvroWriter aw = new ODataAvroWriter(ctx, value => ctx.AvroWriter.Write(value), ctx.AvroWriter.UpdateSchema(null, TestEntityType), false); aw.WriteStart(entry0); aw.WriteStart(nestedResource0); aw.WriteStart(complex0); aw.WriteEnd(); aw.WriteEnd(); aw.WriteEnd(); aw.Flush(); ms.Seek(0, SeekOrigin.Begin); IEnumerable <object> results; IAvroReader <object> reader = null; try { reader = AvroContainer.CreateGenericReader(ms); using (var seqReader = new SequentialReader <object>(reader)) { reader = null; results = seqReader.Objects; } } finally { if (reader != null) { reader.Dispose(); } } dynamic record = results.Single() as AvroRecord; Assert.IsNotNull(record); Assert.AreEqual(true, record.TBoolean); Assert.AreEqual(32, record.TInt32); var col = record.TCollection as object[]; Assert.IsNotNull(col); Assert.IsTrue(longCollection0.SequenceEqual(col)); dynamic cpx = record.TComplex as AvroRecord; Assert.IsNotNull(cpx); Assert.IsTrue(binary0.SequenceEqual((byte[])cpx.TBinary)); Assert.AreEqual("iamstr", cpx.TString); }
public override void CompareToAvroFile(Stream stream) { IAvroReader <LargeClass> avroReader = AvroContainer.CreateReader <LargeClass>( stream, true, new AvroSerializerSettings { UsePosixTime = true }, new CodecFactory()); using (var reader = new SequentialReader <LargeClass>(avroReader)) { Assert.IsTrue(this.Expected.SequenceEqual(reader.Objects)); } }
public void TestWriteFeed() { MemoryStream ms = new MemoryStream(); using (var omw = TestHelper.CreateMessageWriter(ms, "avro/binary", AvroMediaTypeResolver.Instance)) { var entryWriter = omw.CreateODataFeedWriter(null, EntryType); entryWriter.WriteStart(new ODataFeed()); entryWriter.WriteStart(entry0); entryWriter.WriteEnd(); entryWriter.WriteStart(entry1); entryWriter.WriteEnd(); entryWriter.WriteStart(entry2); entryWriter.WriteEnd(); entryWriter.WriteStart(entry3); entryWriter.WriteEnd(); entryWriter.WriteEnd(); entryWriter.Flush(); } ms.Seek(0, SeekOrigin.Begin); Product[] products; IAvroReader <Product[]> reader = null; try { reader = AvroContainer.CreateReader <Product[]>(ms); using (var seqReader = new SequentialReader <Product[]>(reader)) { reader = null; products = seqReader.Objects.ToList().Single(); } } finally { if (reader != null) { reader.Dispose(); } } Assert.AreEqual(product0, products[0]); Assert.AreEqual(product1, products[1]); Assert.AreEqual(product2, products[2]); Assert.AreEqual(product3, products[3]); }
public void TestWriteParameter() { MemoryStream ms = new MemoryStream(); using (var omw = TestHelper.CreateMessageWriter(ms, container, "avro/binary", new EdmModel(), false)) { var opw = omw.CreateODataParameterWriter(AddProduct); var ew = opw.CreateResourceWriter("Product"); ew.WriteStart(entry0); ew.WriteEnd(); ew.Flush(); var ew1 = opw.CreateResourceWriter("Location"); ew1.WriteStart(complexResource); ew1.WriteEnd(); ew1.Flush(); opw.WriteEnd(); opw.Flush(); } ms.Seek(0, SeekOrigin.Begin); AddProductParameter parameter; IAvroReader <AddProductParameter> reader = null; try { reader = AvroContainer.CreateReader <AddProductParameter>(ms); using (var seqReader = new SequentialReader <AddProductParameter>(reader)) { reader = null; parameter = seqReader.Objects.First(); } } finally { if (reader != null) { reader.Dispose(); } } Assert.IsNotNull(parameter); Assert.AreEqual(product0, parameter.Product); Assert.AreEqual(address0, parameter.Location); }
public void TestWriteProperty() { ODataProperty prop = new ODataProperty() { Name = "prop1", Value = complexValue0 }; MemoryStream ms = new MemoryStream(); using (var omw = TestHelper.CreateMessageWriter(ms, "avro/binary", AvroMediaTypeResolver.Instance)) { omw.WriteProperty(prop); } ms.Seek(0, SeekOrigin.Begin); Address addr; IAvroReader <Address> reader = null; try { reader = AvroContainer.CreateReader <Address>(ms); using (var seqReader = new SequentialReader <Address>(reader)) { reader = null; addr = seqReader.Objects.First(); } } finally { if (reader != null) { reader.Dispose(); } } Assert.AreEqual(address0, addr); }
public void TestWriteProperty() { ODataProperty prop = new ODataProperty { Name = "Road", Value = "Road1" }; MemoryStream ms = new MemoryStream(); using (var omw = TestHelper.CreateMessageWriter(ms, container, "avro/binary")) { omw.WriteProperty(prop); } ms.Seek(0, SeekOrigin.Begin); string road; IAvroReader <string> reader = null; try { reader = AvroContainer.CreateReader <string>(ms); using (var seqReader = new SequentialReader <string>(reader)) { reader = null; road = seqReader.Objects.First(); } } finally { if (reader != null) { reader.Dispose(); } } Assert.AreEqual("Road1", road); }
public void TestWriteComplexResource() { MemoryStream ms = new MemoryStream(); using (var omw = TestHelper.CreateMessageWriter(ms, container, "avro/binary")) { var entryWriter = omw.CreateODataResourceWriter(null, ComplexType); entryWriter.WriteStart(complexResource); entryWriter.WriteEnd(); entryWriter.Flush(); } ms.Seek(0, SeekOrigin.Begin); Address addr; IAvroReader <Address> reader = null; try { reader = AvroContainer.CreateReader <Address>(ms); using (var seqReader = new SequentialReader <Address>(reader)) { reader = null; addr = seqReader.Objects.First(); } } finally { if (reader != null) { reader.Dispose(); } } Assert.AreEqual(address0, addr); }
public void TestWriteEntry() { MemoryStream ms = new MemoryStream(); using (var omw = TestHelper.CreateMessageWriter(ms, "avro/binary", AvroMediaTypeResolver.Instance)) { var entryWriter = omw.CreateODataEntryWriter(null, EntryType); entryWriter.WriteStart(entry0); entryWriter.WriteEnd(); entryWriter.Flush(); } ms.Seek(0, SeekOrigin.Begin); Product prd; IAvroReader <Product> reader = null; try { reader = AvroContainer.CreateReader <Product>(ms); using (var seqReader = new SequentialReader <Product>(reader)) { reader = null; prd = seqReader.Objects.First(); } } finally { if (reader != null) { reader.Dispose(); } } Assert.AreEqual(product0, prd); }
public IAvroFileReader <T> OpenRead <T>(IAvroReader <T> datumReader) { return(new FileReader <T>(this, datumReader)); }
public AvroReader(IAvroReader<object> innerReader) { this.reader = innerReader; }
public AvroReader(IAvroReader <object> innerReader) { this.reader = innerReader; }
public void WriteFeedAsAvroTest() { ODataResource entry1 = new ODataResource { Properties = new[] { new ODataProperty { Name = "TBoolean", Value = true, }, new ODataProperty { Name = "TInt32", Value = 32, }, }, TypeName = "NS.SimpleEntry" }; ODataResource entry2 = new ODataResource { Properties = new[] { new ODataProperty { Name = "TBoolean", Value = false, }, new ODataProperty { Name = "TInt32", Value = 325, }, }, TypeName = "NS.SimpleEntry" }; MemoryStream ms = new MemoryStream(); var ctx = this.CreateOutputContext(ms); ODataAvroWriter aw = new ODataAvroWriter(ctx, value => ctx.AvroWriter.Write(value), null, true); aw.WriteStart(new ODataResourceSet()); aw.WriteStart(entry1); aw.WriteEnd(); aw.WriteStart(entry2); aw.WriteEnd(); aw.WriteEnd(); aw.Flush(); ms.Seek(0, SeekOrigin.Begin); IEnumerable <object> results; IAvroReader <object> reader = null; try { reader = AvroContainer.CreateGenericReader(ms); using (var seqReader = new SequentialReader <object>(reader)) { reader = null; results = seqReader.Objects; } } finally { if (reader != null) { reader.Dispose(); } } var records = results.Cast <object[]>().Single(); Assert.AreEqual(2, records.Count()); dynamic record = records[0]; Assert.AreEqual(true, record.TBoolean); Assert.AreEqual(32, record.TInt32); record = records[1]; Assert.AreEqual(false, record.TBoolean); Assert.AreEqual(325, record.TInt32); }