Beispiel #1
0
        public void TestIsEnabled()
        {
            IDiskStorage     storage = CreateDiskStorage(TESTCACHE_CURRENT_VERSION);
            DiskStorageCache cache   = CreateDiskCache(storage, false);

            Assert.IsTrue(cache.IsEnabled);
        }
Beispiel #2
0
        public void TestVersioning()
        {
            // Define data that will be written to cache
            ICacheKey key = new SimpleCacheKey("version_test");

            byte[] value = new byte[32];
            value[0] = 118; // 'v'

            // Set up cache with version == 1
            IDiskStorage     storage1 = CreateDiskStorage(TESTCACHE_CURRENT_VERSION);
            DiskStorageCache cache1   = CreateDiskCache(storage1, false);

            // Write test data to cache 1
            cache1.Insert(key, WriterCallbacks.From(value));

            // Get cached file
            IBinaryResource resource1 = GetResource(storage1, key);

            Assert.IsNotNull(resource1);

            // Set up cache with version == 2
            IDiskStorage     storageSupplier2 = CreateDiskStorage(TESTCACHE_NEXT_VERSION);
            DiskStorageCache cache2           = CreateDiskCache(storageSupplier2, false);

            // Write test data to cache 2
            cache2.Insert(key, WriterCallbacks.From(value));

            // Get cached file
            IBinaryResource resource2 = GetResource(storageSupplier2, key);

            Assert.IsNotNull(resource2);

            // Make sure filenames of the two file are different
            Assert.IsFalse(resource2.Equals(resource1));
        }
Beispiel #3
0
        public void Initialize()
        {
            _clock = MockSystemClock.Get();
            _clock.SetDateTime(DateTime.Now);
            NoOpDiskTrimmableRegistry.Instance.ResetCounter();
            _diskTrimmableRegistry = NoOpDiskTrimmableRegistry.Instance;
            _cacheEventListener    = new DuplicatingCacheEventListener();

            // We know the directory will be this
            _cacheDirectory = new DirectoryInfo(
                Path.Combine(ApplicationData.Current.LocalCacheFolder.Path, CACHE_TYPE));
            _cacheDirectory.Create();
            if (!_cacheDirectory.Exists)
            {
                throw new Exception(
                          string.Format(
                              "Cannot create cache dir: {0}: directory {1}",
                              ApplicationData.Current.LocalCacheFolder.Path,
                              _cacheDirectory.Exists ? "already exists" : "does not exist"));
            }

            _storage = CreateDiskStorage(TESTCACHE_VERSION_START_OF_VERSIONING);
            _cache   = CreateDiskCache(_storage, false);
            Assert.IsTrue(((NoOpDiskTrimmableRegistry)_diskTrimmableRegistry).RegisterDiskTrimmableCount == 1);
        }
Beispiel #4
0
        public void TestGetResourceWithoutAwaitingIndex()
        {
            ICacheKey key = PutOneThingInCache();

            // A new cache object in the same directory. Equivalent to a process restart.
            // Index may not yet updated.
            DiskStorageCache cache2 = CreateDiskCache(_storage, false);

            Assert.IsNotNull(cache2.GetResource(key));
        }
Beispiel #5
0
        public void TestHasKeyWithPopulateAtStartupWithoutAwaitingIndex()
        {
            ICacheKey key = PutOneThingInCache();

            // A new cache object in the same directory. Equivalent to a process restart.
            // Index may not yet updated.
            DiskStorageCache cache2 = CreateDiskCache(_storage, true);

            Assert.IsTrue(cache2.HasKey(key));
            Assert.IsTrue(cache2.HasKeySync(key));
        }
Beispiel #6
0
        public void TestHasKeyWithPopulateAtStartupWithAwaitingIndex()
        {
            ICacheKey key = PutOneThingInCache();

            // A new cache object in the same directory. Equivalent to a process restart.
            // Index should be updated.
            DiskStorageCache cache2 = CreateDiskCache(_storage, true);

            // Wait for index populated in cache before use of cache
            cache2.AwaitIndex();
            Assert.IsTrue(cache2.HasKeySync(key));
            Assert.IsTrue(cache2.HasKey(key));
        }