Beispiel #1
0
        public void TryAddContentTest()
        {
            var numberOfPages = 1;

            // generate test pages
            byte[] testArray = new byte[Constants.PAGE_SIZE_INCL_HEADER * numberOfPages];

            Memory <byte> memory = new Memory <byte>(testArray);

            // create dummy headers for the 5 pages
            for (uint i = 0; i < numberOfPages; i++)
            {
                var slice = memory.Slice((int)(Constants.PAGE_SIZE_INCL_HEADER * i));
                SpanExtensions.WriteBytes(slice, 0, UnitTestHelper.GetPageHeader(i, PageType.Data));
            }

            string testContent  = "Hello World!!!";
            var    bytesContent = Encoding.UTF8.GetBytes(testContent);

            var dataPageManager = new DataPageManager(memory);
            var page            = (DataPage)dataPageManager.GetPageById(0);

            page.Should().NotBeNull();
            var id = page.TryAddContent(bytesContent, 0);

            id.Id.Should().NotBe(0);

            var document = page.FindById(id.Id);

            document.Should().NotBeNull();
        }
Beispiel #2
0
        public void GetBytesTest()
        {
            string s = "askljr3489ur34fojirejdresg";

            byte[] testArray = Encoding.UTF8.GetBytes(s);

            Memory <byte> target = new byte[500];

            SpanExtensions.WriteBytes(target, 0, testArray);

            var span   = target.Span;
            var bytes  = span.ReadBytes(0, testArray.Length);
            var result = Encoding.UTF8.GetString(bytes);

            result.Should().Be(s);
        }
        private Memory <byte> GenerateTestPages()
        {
            var numberOfPages = 5;

            // generate test pages
            byte[] testArray = new byte[Constants.PAGE_SIZE_INCL_HEADER * numberOfPages];

            Memory <byte> memory = new Memory <byte>(testArray);

            // create dummy headers for the 5 pages
            for (uint i = 0; i < numberOfPages; i++)
            {
                var slice = memory.Slice((int)(Constants.PAGE_SIZE_INCL_HEADER * i));
                SpanExtensions.WriteBytes(slice, 0, UnitTestHelper.GetPageHeader(i, PageType.Data));
            }

            return(new Memory <byte>(testArray));
        }
        public void Setup()
        {
            var numberOfPages = 1;

            // generate test pages
            byte[] testArray = new byte[Constants.PAGE_SIZE_INCL_HEADER * numberOfPages];

            Memory <byte> memory = new Memory <byte>(testArray);

            // create dummy headers for the 5 pages
            for (uint i = 0; i < numberOfPages; i++)
            {
                var slice = memory.Slice((int)(Constants.PAGE_SIZE_INCL_HEADER * i));
                SpanExtensions.WriteBytes(slice, 0, UnitTestHelper.GetPageHeader(i, PageType.Data));
            }

            string testContent = "Hello World!!!";

            bytesContent = Encoding.UTF8.GetBytes(testContent);

            var _dataPageManager = new DataPageManager(memory);

            _page  = (DataPage)_dataPageManager.GetPageById(0);
            _guids = new ushort[100];
            for (int i = 0; i < 100; i++)
            {
                var res = _page.TryAddContent(bytesContent, 0);
                _guids[i] = res.Id;
            }

            Random random = new Random();

            for (int i = 0; i < Int16.MaxValue * 10; i++)
            {
                _indexes.Add(random.Next(0, 99));
            }
        }