public void CreateWithNoMagicDataError() { // Arrange using (var inputStream = System.IO.File.OpenRead(@"Data\empty.avro")) { var inputReader = AvroUtil.GetReaderFromStream(new NonSeekableStream(inputStream)); // Act // Assert Assert.Throws <ArgumentException>(() => AvroDataFileReaderStream.OpenStream(inputReader)); } }
public void GetStartPositionOfMagicStream() { // Arrange using (var inputStream = System.IO.File.OpenRead(@"Data\twitter.avro")) { var inputReader = AvroUtil.GetReaderFromStream(new NonSeekableStream(inputStream)); var baseStream = AvroDataFileReaderStream.OpenStream(inputReader); // Act // Assert Assert.Equal(0, baseStream.Position); } }
public void WriteError() { // Arrange using (var inputStream = System.IO.File.OpenRead(@"Data\twitter.avro")) { var inputReader = AvroUtil.GetReaderFromStream(new NonSeekableStream(inputStream)); var baseStream = AvroDataFileReaderStream.OpenStream(inputReader); // Act // Assert Assert.Throws <NotSupportedException>(() => baseStream.Write(new byte[0], 0, 0)); } }
public void BadReadByteOnMagicStringBeforeRead() { // Arrange using (var inputStream = System.IO.File.OpenRead(@"Data\twitter.avro")) { var inputReader = AvroUtil.GetReaderFromStream(new NonSeekableStream(inputStream)); var baseStream = AvroDataFileReaderStream.OpenStream(inputReader); // Act // Assert Assert.Throws <InvalidOperationException>(() => baseStream.ReadByte()); } }
public void CanWrite() { // Arrange using (var inputStream = System.IO.File.OpenRead(@"Data\twitter.avro")) { var inputReader = AvroUtil.GetReaderFromStream(new NonSeekableStream(inputStream)); var baseStream = AvroDataFileReaderStream.OpenStream(inputReader); // Act // Assert Assert.Equal(false, baseStream.CanWrite); } }
public void BadReadByteOnMagicStringAfterRead() { // Arrange using (var inputStream = System.IO.File.OpenRead(@"Data\twitter.avro")) { var inputReader = AvroUtil.GetReaderFromStream(new NonSeekableStream(inputStream)); var baseStream = AvroDataFileReaderStream.OpenStream(inputReader); var buffer = new byte[DataFileConstants.Magic.Length]; // Act // Assert baseStream.Read(buffer, 0, buffer.Length); Assert.Throws <InvalidOperationException>(() => baseStream.ReadByte()); } }
public void ReadMagicStreamBadOffset() { // Arrange using (var inputStream = System.IO.File.OpenRead(@"Data\twitter.avro")) { var inputReader = AvroUtil.GetReaderFromStream(new NonSeekableStream(inputStream)); var baseStream = AvroDataFileReaderStream.OpenStream(inputReader); var buffer = new byte[DataFileConstants.Magic.Length]; // Act // Assert var error = Assert.Throws <InvalidOperationException>(() => baseStream.Read(buffer, 1, buffer.Length)); Assert.Equal("Can only read the entire magic stream!", error.Message); } }
public void SeekMagicStreamBadOrigin() { // Arrange using (var inputStream = System.IO.File.OpenRead(@"Data\twitter.avro")) { var inputReader = AvroUtil.GetReaderFromStream(new NonSeekableStream(inputStream)); var baseStream = AvroDataFileReaderStream.OpenStream(inputReader); var buffer = new byte[DataFileConstants.Magic.Length]; // Act // Assert baseStream.Read(buffer, 0, buffer.Length); var error = Assert.Throws <InvalidOperationException>(() => baseStream.Seek(0, SeekOrigin.Current)); Assert.Equal("Can only seek the magic stream from the beginning!", error.Message); } }
public void SeekMagicStream() { // Arrange using (var inputStream = System.IO.File.OpenRead(@"Data\twitter.avro")) { var inputReader = AvroUtil.GetReaderFromStream(new NonSeekableStream(inputStream)); var baseStream = AvroDataFileReaderStream.OpenStream(inputReader); var buffer = new byte[DataFileConstants.Magic.Length]; // Act baseStream.Read(buffer, 0, buffer.Length); var seek = baseStream.Seek(0, SeekOrigin.Begin); // Assert Assert.Equal(0, seek); } }
public void ReadMagicStream() { // Arrange using (var inputStream = System.IO.File.OpenRead(@"Data\twitter.avro")) { var inputReader = AvroUtil.GetReaderFromStream(new NonSeekableStream(inputStream)); var baseStream = AvroDataFileReaderStream.OpenStream(inputReader); var buffer = new byte[DataFileConstants.Magic.Length]; // Act var read = baseStream.Read(buffer, 0, buffer.Length); // Assert Assert.Equal(buffer.Length, read); Assert.Equal(DataFileConstants.Magic, buffer); } }
public void GetPositionOfLastByteInvalidLastByte() { // Arrange using (var inputStream = System.IO.File.OpenRead(@"Data\twitter.avro")) { var inputReader = AvroUtil.GetReaderFromStream(new NonSeekableStream(inputStream)); var baseStream = AvroDataFileReaderStream.OpenStream(inputReader); var buffer = new byte[DataFileConstants.Magic.Length]; // Act baseStream.Read(buffer, 0, buffer.Length); baseStream.Seek(0, SeekOrigin.Begin); baseStream.Read(buffer, 0, buffer.Length); // Assert var error = Assert.Throws <InvalidOperationException>(() => { baseStream.Position = baseStream.Position - 1; }); Assert.Equal("There is no last byte to read!", error.Message); } }
public void SetAndGetPositionOfLastByte() { // Arrange using (var inputStream = System.IO.File.OpenRead(@"Data\twitter.avro")) { var inputReader = AvroUtil.GetReaderFromStream(new NonSeekableStream(inputStream)); var baseStream = AvroDataFileReaderStream.OpenStream(inputReader); var buffer = new byte[DataFileConstants.Magic.Length]; // Act baseStream.Read(buffer, 0, buffer.Length); baseStream.Seek(0, SeekOrigin.Begin); baseStream.Read(buffer, 0, buffer.Length); var currentPosition = baseStream.Position; baseStream.ReadByte(); baseStream.Position = currentPosition; // Assert Assert.Equal(currentPosition, baseStream.Position); } }