Ejemplo n.º 1
0
        /// <summary>
        /// Returns a map of file path to the file data
        /// </summary>
        /// <param name="vfsroot"></param>
        /// <param name="vfsdatastore"></param>
        /// <param name="random"></param>
        /// <param name="regSizeFileCount"></param>
        /// <returns></returns>
        public static Dictionary <string, byte[]> AddStandardVFSFiles(
            MetadataNode vfsDirectory, BPlusTree <byte[]> vfsdatastore, Random?random = null, int regSizeFileCount = 100)
        {
            Dictionary <string, byte[]> verifyfilepaths = new();

            (byte[] hash, byte[] file) = MakeRandomFile(10_000_000, random); // 10 MB file
            AddFileToVFS("big", hash, file);

            (hash, file) = MakeRandomFile(0); // Empty file
            AddFileToVFS("empty", hash, file);

            (hash, file) = MakeRandomFile(1, random); // 1byte file
            AddFileToVFS("1b", hash, file);

            (hash, file) = MakeRandomFile(2, random); // 2byte file
            AddFileToVFS("2b", hash, file);

            foreach (var num in Enumerable.Range(0, regSizeFileCount))
            {
                (hash, file) = MakeRandomFile(5_000, random); // regular size file
                AddFileToVFS(String.Format("reg_{0}", num), hash, file);
            }

            return(verifyfilepaths);

            void AddFileToVFS(string path, byte[] filehash, byte[] filedata)
            {
                new BPlusTree <byte[]>(10).AddOrFind(filehash, filedata);
                verifyfilepaths[path] = filehash;
                vfsdatastore.AddOrFind(filehash, filedata);
                DateTime dateTime = RandomDateTime(random);
                string?  dirpath  = Path.GetDirectoryName(path);

                if (dirpath == null)
                {
                    throw new NullReferenceException();
                }
                vfsDirectory.AddFile(dirpath,
                                     new FileMetadata(Path.GetFileName(path), dateTime, dateTime, dateTime, FileAttributes.Normal, filedata.Length, filehash));
            }
        }
Ejemplo n.º 2
0
        public void TestAddRemoveFew()
        {
            var BPTree = new BPlusTree <BlobLocation>(100);

            var          testblob1 = new BlobLocation(null, "somewhere1", 0);
            BlobLocation bl2       = new BlobLocation(null, "somewhere2", 4);
            BlobLocation bl3       = new BlobLocation(new byte[][] { new byte[] { 1, 2 }, new byte[] { 1, 0 } }.ToList());
            BlobLocation bl4       = new BlobLocation();

            var rng = new Random();

            var testkey1 = new byte[20];

            rng.NextBytes(testkey1);
            byte[] key2 = new byte[20];
            rng.NextBytes(key2);
            byte[] key3 = new byte[20];
            rng.NextBytes(key3);
            byte[] key4 = new byte[20];
            rng.NextBytes(key4);
            byte[] key5 = new byte[20];
            rng.NextBytes(key5);

            BPTree.AddOrFind(testkey1, testblob1);
            BPTree.AddOrFind(key2, bl2);
            BPTree.AddOrFind(key3, bl3);
            BPTree.AddOrFind(key4, bl4);

            BPTree.AddOrFind(key5, bl4);
            BPTree.AddOrFind(testkey1, testblob1);

            List <KeyValuePair <byte[], BlobLocation> > treecontents1 = new List <KeyValuePair <byte[], BlobLocation> >(BPTree);

            BPTree.Remove(testkey1);
            List <KeyValuePair <byte[], BlobLocation> > treecontents2 = new List <KeyValuePair <byte[], BlobLocation> >(BPTree);

            BPTree.AddOrFind(testkey1, testblob1);
            List <KeyValuePair <byte[], BlobLocation> > treecontents3 = new List <KeyValuePair <byte[], BlobLocation> >(BPTree);

            Assert.IsFalse(TreeContentsMatch(treecontents1, treecontents2));
            Assert.IsTrue(TreeContentsMatch(treecontents1, treecontents3));
        }