Пример #1
0
        public void BuiltContentSizeIsCorrect()
        {
            // When building records, the BuiltContentSize property must be carefully maintained
            var anyRec = new StdinRecord(1);

            anyRec.Contents.WriteByte(1);
            anyRec.Contents.WriteByte(2);

            var recFactory = new RecordFactory();

            Assert.AreEqual(0, recFactory.BuiltContentSize);

            foreach (var recData in anyRec.GetBytes())
            {
                recFactory.Read(recData).SingleOrDefault();
            }

            Assert.AreEqual(2, recFactory.BuiltContentSize);

            foreach (var recData in anyRec.GetBytes())
            {
                recFactory.Read(recData).SingleOrDefault();
            }

            Assert.AreEqual(4, recFactory.BuiltContentSize);
        }
Пример #2
0
        public void BuildingRecords()
        {
            // After supplying the factory with a record's bytes, the same record must come out
            var beginRec = new BeginRequestRecord(1);

            beginRec.Role = Role.Responder;
            var stdinRec = new StdinRecord(1);

            stdinRec.Contents.WriteByte(0);
            stdinRec.Contents.WriteByte(0);

            BeginRequestRecord builtBeginReqRecord = null;
            StdinRecord        builtStdinRecord    = null;

            var recFactory = new RecordFactory();

            foreach (var recData in beginRec.GetBytes())
            {
                builtBeginReqRecord = (BeginRequestRecord)recFactory.Read(recData).SingleOrDefault();
            }
            foreach (var recData in stdinRec.GetBytes())
            {
                builtStdinRecord = (StdinRecord)recFactory.Read(recData).SingleOrDefault();
            }

            Assert.AreEqual(beginRec, builtBeginReqRecord);
            Assert.AreEqual(stdinRec, builtStdinRecord);
        }
Пример #3
0
        public void MaximumInMemoryBuiltContentSizeIsRespectedWithInMemoryRecord()
        {
            // We need to know that the max in memory content size is respected. This time, one of the records
            // will be stored in memory
            var firstRec = new StdinRecord(1);

            firstRec.Contents.WriteByte(0);

            var secondRec = new StdinRecord(2);

            secondRec.Contents.WriteByte(0);
            secondRec.Contents.WriteByte(0);

            StdinRecord inMemoryBuiltRecord     = null;
            StdinRecord inSecStorageBuiltRecord = null;

            var secondaryStorageStream = new MemoryStream();
            var recFactory             = new RecordFactory(secondaryStorageStream, 2);

            foreach (var recData in firstRec.GetBytes())
            {
                inMemoryBuiltRecord = (StdinRecord)recFactory.Read(recData).SingleOrDefault();
            }
            foreach (var recData in secondRec.GetBytes())
            {
                inSecStorageBuiltRecord = (StdinRecord)recFactory.Read(recData).SingleOrDefault();
            }

            Assert.IsFalse(inMemoryBuiltRecord.Contents.InSecondaryStorage);
            Assert.IsTrue(inSecStorageBuiltRecord.Contents.InSecondaryStorage);
            Assert.AreEqual(firstRec, inMemoryBuiltRecord);
            Assert.AreEqual(secondRec, inSecStorageBuiltRecord);
        }
Пример #4
0
        public void ReceiveEmptyRecord()
        {
            using (var rec = new StdinRecord(1))
            {
                var allRecordBytes = rec.GetBytes().ToList();

                // Header first
                var recordHeader = allRecordBytes[0];

                int endOfRecord;

                using (var receivedRecord = (StdinRecord)RecordFactory.CreateRecordFromHeader(recordHeader.Array, recordHeader.Offset, recordHeader.Count, out endOfRecord))
                {
                    int i = 1;
                    while (endOfRecord == -1)
                    {
                        recordHeader = allRecordBytes[i];
                        receivedRecord.FeedBytes(recordHeader.Array, recordHeader.Offset, recordHeader.Count, out endOfRecord);
                    }

                    Assert.AreEqual(8 + receivedRecord.PaddingLength - 1, endOfRecord);
                    Assert.AreEqual(0, receivedRecord.ContentLength);
                    Assert.AreEqual(true, receivedRecord.EmptyContentData);
                    Assert.AreEqual(true, receivedRecord.IsByteStreamRecord);
                }
            }
        }
Пример #5
0
        public void NewAllTypesOfRecords()
        {
            RecordBase rec = new BeginRequestRecord(1);

            Assert.AreEqual(RecordType.FCGIBeginRequest, rec.RecordType);

            rec = new EndRequestRecord(1);
            Assert.AreEqual(RecordType.FCGIEndRequest, rec.RecordType);

            rec = new StdinRecord(1);
            Assert.AreEqual(RecordType.FCGIStdin, rec.RecordType);

            rec = new StdoutRecord(1);
            Assert.AreEqual(RecordType.FCGIStdout, rec.RecordType);

            rec = new StderrRecord(1);
            Assert.AreEqual(RecordType.FCGIStderr, rec.RecordType);

            rec = new ParamsRecord(1);
            Assert.AreEqual(RecordType.FCGIParams, rec.RecordType);

            rec = new BeginRequestRecord(1);
            Assert.AreEqual(RecordType.FCGIBeginRequest, rec.RecordType);

            rec = new DataRecord(1);
            Assert.AreEqual(RecordType.FCGIData, rec.RecordType);
        }
Пример #6
0
        /// <summary>
        /// If you don't have a request body to send, don't write to <see cref="Stdin"/> and call this method. It will also dispose
        /// <see cref="Stdin"/>.
        /// </summary>
        public void SendEmptyStdin()
        {
            using (var emptyStdin = new StdinRecord(RequestId))
            {
                Send(emptyStdin);
            }

            Stdin.Dispose();
        }
Пример #7
0
        public void FirstSegmentIsHeader()
        {
            using (var rec = new StdinRecord(1))
            {
                // rec is just an empty record
                var header = rec.GetBytes().First();

                Assert.AreEqual(8, header.Count);
            }
        }
Пример #8
0
 public void EmptyStdinRecord()
 {
     using (var rec = new StdinRecord(1))
     {
         // rec is just an empty record
         var header = rec.GetBytes().First();
         int endOfRecord;
         using (var emptyRec = new StdinRecord(header.Array, header.Offset, header.Count, out endOfRecord))
         {
             Assert.AreEqual(7, endOfRecord);
         }
     }
 }
Пример #9
0
        public void NonEmptyStdinRecord()
        {
            using (var rec = new StdinRecord(1))
            {
                byte[] x = new byte[1];                 // The contents of the array don't really matter
                rec.Contents.Write(x, 0, 1);

                var blocks = rec.GetBytes().ToList();
                var header = blocks.First();
                int endOfRecord;
                using (var emptyRec = new StdinRecord(header.Array, header.Offset, header.Count, out endOfRecord))
                {
                    Assert.AreEqual(-1, endOfRecord);
                    emptyRec.FeedBytes(blocks[1].Array, blocks[1].Offset, blocks[1].Count, out endOfRecord);
                    Assert.AreEqual(0, endOfRecord);
                }
            }
        }
Пример #10
0
        public void MaximumInMemoryBuiltContentSizeIsRespected()
        {
            // We need to know that the max in memory content size is respected
            var record = new StdinRecord(1);

            record.Contents.WriteByte(0);

            StdinRecord inSecStorageBuiltRecord = null;

            var secondaryStorageStream = new MemoryStream();
            var recFactory             = new RecordFactory(secondaryStorageStream, 0);

            foreach (var recData in record.GetBytes())
            {
                inSecStorageBuiltRecord = (StdinRecord)recFactory.Read(recData).SingleOrDefault();
            }

            Assert.IsTrue(inSecStorageBuiltRecord.Contents.InSecondaryStorage);
            Assert.AreEqual(record, inSecStorageBuiltRecord);
        }
Пример #11
0
        public void BuildingRecordWithSecondaryStorage()
        {
            // After supplying the factory with a record's bytes, the same record must come out, even
            // when using secondary storage
            var anyRec = new StdinRecord(1);

            anyRec.Contents.WriteByte(1);
            anyRec.Contents.WriteByte(2);

            StdinRecord builtRecord = null;

            var secondaryStorageStream = new MemoryStream();
            var recFactory             = new RecordFactory(secondaryStorageStream, 0);

            foreach (var recData in anyRec.GetBytes())
            {
                builtRecord = (StdinRecord)recFactory.Read(recData).SingleOrDefault();
            }

            Assert.IsNull(builtRecord.Contents.MemoryBlocks);
            Assert.AreEqual(anyRec, builtRecord);
        }
Пример #12
0
        public void RecordsContentsInSecondaryStorage()
        {
            // All the record's contents must be written to the secondary storage ops object
            StdinRecord rec;

            using (var secondaryStorageStream = new MemoryStream())
            {
                rec = new StdinRecord(1, secondaryStorageStream);

                rec.Contents.WriteByte(1);
                rec.Contents.WriteByte(2);
                rec.Contents.WriteByte(3);
                rec.Contents.WriteByte(4);

                byte[] recordsContents = new byte[4];
                secondaryStorageStream.Position = 0;
                secondaryStorageStream.Read(recordsContents, 0, 4);
                for (int i = 1; i <= 4; i++)
                {
                    Assert.AreEqual((byte)i, recordsContents[i - 1]);
                }
            }
        }