Exemplo n.º 1
0
 public void Test1CacheSetup(string folder)
 {
     using (var fc = FileCacheStore.Load(folder))
     {
         Assert.IsTrue(Directory.Exists(fc.FolderPath));
     }
 }
Exemplo n.º 2
0
        public void ThreadyHashIncludeFiles()
        {
            using (var ic = FileCacheStore.Load("testincs"))
            {
                var ht = new HashUtil(ic);

                var hashes = ht.ThreadyDigestFiles(Directory.GetFiles(IncludeDir), true);
                Assert.IsTrue(hashes.Count > 0);
            }
        }
Exemplo n.º 3
0
 public void HashIncludeFiles(int threads)
 {
     using (var ic = FileCacheStore.Load("testincs"))
     {
         var ht = new HashUtil(ic);
         ht.HashingThreadCount = threads;
         var files = Directory.GetFiles(IncludeDir);
         foreach (var f in files)
         {
             var hr = ht.DigestSourceFile(f);
             Assert.IsNotNull(hr.Hash);
         }
     }
 }
Exemplo n.º 4
0
        public void ReadTest <T>() where T : FileCacheBase, IFileCacheStore, new()
        {
            int nfiles   = 100;
            int filesize = 1024 * 1024 * 2;
            var ms       = new MemoryStream(filesize);

            using (var db = FileCacheStore.Load <T>(TempFolder))
            {
                for (int i = 0; i < nfiles; i++)
                {
                    string fname = "populate" + i.ToString();
                    using (var ws = db.OpenFileStream("cdef", fname, FileMode.Open, FileAccess.Read))
                    {
                        ws.CopyTo(ms);
                    }
                }
            }
        }
Exemplo n.º 5
0
 public void TestTextFileAddRemove()
 {
     using (var fc = FileCacheStore.Load("clcachetest_text"))
     {
         fc.WaitOne();
         try
         {
             fc.AddTextFileContent("aa12345", "test.txt", "hello");
             Assert.IsTrue(fc.ContainsEntry("aa12345", "test.txt"));
             fc.Remove("aa12345");
             Assert.IsFalse(fc.ContainsEntry("aa12345", "test.txt"));
         }
         finally
         {
             fc.ReleaseMutex();
         }
     }
 }
Exemplo n.º 6
0
 public void TestTextFileAddRemove()
 {
     using (var fc = FileCacheStore.Load("clcachetest_text"))
     {
         fc.WaitOne();
         try
         {
             fc.AddTextFileContent("aa12345", "test.txt", "hello");
             Assert.IsTrue(File.Exists(fc.MakePath("aa12345", "test.txt")));
             fc.Remove("aa12345");
             Assert.IsFalse(File.Exists(fc.MakePath("aa12345", "test.txt")));
             Assert.IsTrue(Directory.Exists(Path.Combine(fc.FolderPath, "aa")));
         }
         finally
         {
             fc.ReleaseMutex();
         }
     }
 }
Exemplo n.º 7
0
        public void ThreadyHashIncludeFilesCacheTest()
        {
            using (var ic = FileCacheStore.Load("testincs"))
            {
                var ht = new HashUtil(ic);

                var hashes = ht.DigestFiles(Directory.GetFiles(IncludeDir), IncludeDir);
                Assert.IsTrue(hashes.Count > 0);
                System.Threading.Thread.Sleep(500);
                var hashes2 = ht.DigestFiles(Directory.GetFiles(IncludeDir), IncludeDir);
                foreach (var h in hashes2)
                {
                    if (hashes.ContainsKey(h.Key))
                    {
                        Assert.IsTrue(h.Value.Cached);
                    }
                }
            }
        }
Exemplo n.º 8
0
        public void HashesMatch()
        {
            var files = Directory.GetFiles(IncludeDir);

            using (var ic = FileCacheStore.Load("testincs"))
            {
                var ht     = new HashUtil(ic);
                var hashes = ht.ThreadyDigestFiles(files, true);
                foreach (var f in files)
                {
                    var hash = ht.DigestSourceFile(f);

                    if (hash.Result == DataHashResult.Ok)
                    {
                        Assert.AreEqual(hash.Hash, hashes[f.ToLower()].Hash);
                    }
                }

                Assert.AreEqual(files.Length, hashes.Count);
            }
        }