Exemple #1
0
        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));
            }
        }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
        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));
            }
        }
Exemple #4
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());
            }
        }
Exemple #5
0
        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);
            }
        }
Exemple #6
0
        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());
            }
        }
Exemple #7
0
        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);
            }
        }
Exemple #8
0
        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);
            }
        }
Exemple #9
0
        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);
            }
        }
Exemple #10
0
        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);
            }
        }
Exemple #11
0
        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);
            }
        }
Exemple #12
0
        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);
            }
        }