示例#1
0
 public FileServer(string pref, int maxParallelRequests,
     string destination, int numMaxDirNodes=50)
 {
     listener = new HttpListener();
     listener.Prefixes.Add(pref);
     numMaxParallelRequests = maxParallelRequests;
     concurrentAllowedRequests = numMaxParallelRequests;
     fileUploadsDestination = destination;
     Directory.CreateDirectory(fileUploadsDestination);
     fileStore = new FileStore(numMaxDirNodes, fileUploadsDestination);
 }
示例#2
0
        public void TestAddFile()
        {
            FileStore fStore = new FileStore(3, fileStoreDestination);
            string contents = "this is my text1.";
            string filename = MakeFile(contents);

            fStore.AddFile(filename);

            string[] dirs = Directory.GetDirectories(fileStoreDestination);
            Assert.AreEqual(1, dirs.Length);

            string[] files = Directory.GetFiles(dirs[0]);
            Assert.AreEqual(1, files.Length);

            string addedFileContents = File.ReadAllText(files[0]);
            Assert.AreEqual(contents, addedFileContents);
        }
示例#3
0
        public void TestAddManyFiles()
        {
            int b = 3;
            FileStore fStore = new FileStore(b, fileStoreDestination);
            string contents = "this is my text3.";
            string filename = MakeFile(contents);
            int numFiles = 89;
            int depth = (int) Math.Ceiling(Math.Log(numFiles, b)) + 2;

            for (int i=0; i<numFiles; i++)
            {
                filename = MakeFile(contents);
                fStore.AddFile(filename);
            }

            List<string> path = new List<string>();
            List<List<string>> files = DirSearch(fileStoreDestination, path);

            Assert.AreEqual(numFiles, files.Count);
            foreach (List<string> p in files)
            {
                Assert.AreEqual(depth, p.Count);
            }
        }
示例#4
0
        public void TestChangeRoot()
        {
            FileStore fStore = new FileStore(3, fileStoreDestination);
            string contents = "this is my text2.";
            string filename = MakeFile(contents);

            fStore.AddFile(filename);

            string[] dirs = Directory.GetDirectories(fileStoreDestination);
            Assert.AreEqual(1, dirs.Length);

            string[] files = Directory.GetFiles(dirs[0]);
            Assert.AreEqual(1, files.Length);

            filename = MakeFile(contents);
            fStore.AddFile(filename);
            filename = MakeFile(contents);
            fStore.AddFile(filename);

            files = Directory.GetFiles(dirs[0]);
            Assert.AreEqual(3, files.Length);

            filename = MakeFile(contents);
            fStore.AddFile(filename);

            // This call should have extended the tree height by 1
            // This means a new root with 2 children and the files are in the children
            dirs = Directory.GetDirectories(fileStoreDestination);
            Assert.AreEqual(1, dirs.Length);

            dirs = Directory.GetDirectories(dirs[0]);
            Assert.AreEqual(2, dirs.Length);

            int numFiles = 0;
            foreach(string dir in dirs)
            {
                files = Directory.GetFiles(dir);
                numFiles += files.Length;
            }

            Assert.AreEqual(4, numFiles);
        }
示例#5
0
 public void TestBaseStoreCreated()
 {
     FileStore fStore = new FileStore(3, fileStoreDestination);
     string[] dirs = Directory.GetDirectories(fileStoreDestination);
     Assert.AreEqual(1, dirs.Length);
 }