Beispiel #1
0
        public void Read()
        {
            int position = 4096 * 11; //some random position

            using (var fs = _fixture.GetFileStream())
            {
                fs.Seek(position, SeekOrigin.Begin);
                fs.Write(_testArray, 0, _testArray.Length);
                fs.Close();
            }

            MemoryMappedFileSlim mapping = null;

            try
            {
                mapping = _fixture.GetMemoryMappedFileSlim();
                var tempSpan = mapping.GetSpan(position, BackFileFixture.BufferSize)
                               .Slice(0, _testArray.Length);
                Assert.True(tempSpan.SequenceEqual(_testArray.AsSpan()));
            }
            finally
            {
                mapping?.Dispose();
            }
        }
Beispiel #2
0
        public void Init(string tempFolder)
        {
            _tempFile = Path.Combine(tempFolder, "storage.st");

            using (var spanMmf = new MemoryMappedFileSlim(_tempFile, _length))
            {
                // just initialize file
            }
        }
Beispiel #3
0
        public void CreateStore()
        {
            var layers = new MemoryMappedFileSlim[_storesPath.Length];

            for (var i = 0; i < _storesPath.Length; ++i)
            {
                layers[i] = new MemoryMappedFileSlim(_storesPath[i], _sectorsSize[i] * 64);
            }

            var journal = new MemoryMappedFileSlim(_journalPath, Constants.CoinStoreJournalCapacity);

            _store = new PackStore(64, _sectorsSize, layers, journal, _genericStore);
            _store.Initialize();
        }
Beispiel #4
0
        public void WriteOverflow()
        {
            long position = _fixture.Length - _testArray.Length + 1;
            MemoryMappedFileSlim mapping = null;

            try
            {
                mapping = _fixture.GetMemoryMappedFileSlim();

                Assert.Throws <ArgumentOutOfRangeException>(() => mapping.GetSpan(position, _testArray.Length));
            }
            finally
            {
                mapping?.Dispose();
            }
        }
Beispiel #5
0
        /// <summary> Ctor. </summary>
        /// <param name="sectorCount">  Count number of sectors in a single layer. </param>
        /// <param name="sectorSizeInBytes"> Array of each layer sector size in bytes. </param>
        /// <param name="layerMmf"> Backing all layers but the bottom one. </param>
        /// <param name="journalMmf"> Backing the journal. </param>
        /// <param name="bottomLayer"> Backing the last layer, with a lazy sector allocation. </param>
        /// <param name="log"></param>
        public PackStore(
            int sectorCount,
            int[] sectorSizeInBytes,
            MemoryMappedFileSlim[] layerMmf,
            MemoryMappedFileSlim journalMmf,
            IKeyValueStore <uint> bottomLayer,
            ILog log = null)
        {
            if (sectorSizeInBytes.Length != layerMmf.Length)
            {
                throw new ArgumentException("Arguments length mismatch.",
                                            nameof(sectorSizeInBytes) + nameof(layerMmf));
            }

            _sectorSizeInBytes = sectorSizeInBytes;
            _sectorCount       = sectorCount;

            _layerMmf    = layerMmf;
            _journalMmf  = journalMmf;
            _bottomLayer = bottomLayer;
            _log         = log;
        }
Beispiel #6
0
        public void Write()
        {
            int position = 4096 * 10; //some random position
            MemoryMappedFileSlim mapping = null;

            try
            {
                mapping = _fixture.GetMemoryMappedFileSlim();
                _testArray.CopyTo(mapping.GetSpan(position, _testArray.Length));
            }
            finally
            {
                mapping?.Dispose();
            }

            using (var fs = _fixture.GetFileStream())
            {
                byte[] temp = new byte[_testArray.Length];
                fs.Seek(position, SeekOrigin.Begin);
                fs.Read(temp, 0, _testArray.Length);
                Assert.Equal(temp, _testArray);
                fs.Close();
            }
        }
Beispiel #7
0
 public ChainStore(MemoryMappedFileSlim file, ILog log = null)
 {
     _file = file;
     _log  = log;
 }