public static void TestStorageManager_CheckAsset_DoubleNoExist_CallsServerRequestOnlyOnce() { LOG.Info($"Executing {nameof(TestStorageManager_CheckAsset_DoubleNoExist_CallsServerRequestOnlyOnce)}"); // Tests the existence of a negative cache. var server = Substitute.For <IAssetServer>(); var config = new ChattelConfiguration(TestAssetLocalStorageLmdbPartitionedLRUCtor.DATABASE_FOLDER_PATH, WRITE_CACHE_FILE_PATH, WRITE_CACHE_MAX_RECORD_COUNT, server); using (var localStorage = new AssetLocalStorageLmdbPartitionedLRU( config, TestAssetLocalStorageLmdbPartitionedLRUCtor.DATABASE_MAX_SIZE_BYTES, TestAssetLocalStorageLmdbPartitionedLRUCtor.DATABASE_PARTITION_INTERVAL )) { var reader = new ChattelReader(config, localStorage, false); var writer = new ChattelWriter(config, localStorage, false); var assetId = Guid.NewGuid(); var mgr = new StorageManager( localStorage, TimeSpan.FromMinutes(2), reader, writer ); mgr.CheckAsset(assetId, result => { }); mgr.CheckAsset(assetId, result => { }); server.Received(1).RequestAssetSync(assetId); } }
public static void TestStorageManager_StoreAsset_AbleToFindAssetAfterFailure() { LOG.Info($"Executing {nameof(TestStorageManager_StoreAsset_AbleToFindAssetAfterFailure)}"); var mgr = new StorageManager( _readerLocalStorage, TimeSpan.FromMinutes(2), _chattelReader, _chattelWriter ); var asset = new StratusAsset { Id = Guid.NewGuid(), }; var wait = new AutoResetEvent(false); mgr.CheckAsset(asset.Id, foundResult => wait.Set()); wait.WaitOne(); wait.Reset(); mgr.StoreAsset(asset, result => wait.Set()); wait.WaitOne(); var found = false; wait.Reset(); mgr.CheckAsset(asset.Id, foundResult => { found = foundResult; wait.Set(); }); wait.WaitOne(); Assert.IsTrue(found); }
public static void TestStorageManager_PurgeAllLocalAsset_NonEmptyLocalStorage_DidntRemoveNonLocal() { LOG.Info($"Executing {nameof(TestStorageManager_PurgeAllLocalAsset_NonEmptyLocalStorage_DidntRemoveNonLocal)}"); var mgr = new StorageManager( _readerLocalStorage, TimeSpan.FromMinutes(2), _chattelReader, _chattelWriter ); var asset = new StratusAsset { Id = Guid.NewGuid(), Local = false, }; var wait = new AutoResetEvent(false); mgr.StoreAsset(asset, result => wait.Set()); wait.WaitOne(); mgr.PurgeAllLocalAssets(); var foundAsset = false; // Put in opposite state to what is expected. wait.Reset(); mgr.CheckAsset(asset.Id, found => { foundAsset = found; wait.Set(); }); wait.WaitOne(); Assert.True(foundAsset); }
public static void TestStorageManager_CheckAsset_Known_CallsCallback() { LOG.Info($"Executing {nameof(TestStorageManager_CheckAsset_Known_CallsCallback)}"); var mgr = new StorageManager( _readerLocalStorage, TimeSpan.FromMinutes(2), _chattelReader, _chattelWriter ); var id = Guid.NewGuid(); mgr.StoreAsset(new StratusAsset { Id = id, }, result => { }); var callbackWasCalled = false; var stopWaitHandle = new AutoResetEvent(false); mgr.CheckAsset(id, result => { callbackWasCalled = true; stopWaitHandle.Set(); }); stopWaitHandle.WaitOne(); Assert.True(callbackWasCalled); }
public static void TestStorageManager_CheckAsset_Unknown_IsFalse() { LOG.Info($"Executing {nameof(TestStorageManager_CheckAsset_Unknown_IsFalse)}"); var mgr = new StorageManager( _readerLocalStorage, TimeSpan.FromMinutes(2), _chattelReader, _chattelWriter ); mgr.CheckAsset(Guid.NewGuid(), Assert.False); }
public static void TestStorageManager_CheckAsset_Unknown_DoesntThrow() { LOG.Info($"Executing {nameof(TestStorageManager_CheckAsset_Unknown_DoesntThrow)}"); var mgr = new StorageManager( _readerLocalStorage, TimeSpan.FromMinutes(2), _chattelReader, _chattelWriter ); Assert.DoesNotThrow(() => mgr.CheckAsset(Guid.NewGuid(), result => { })); }
public static void TestStorageManager_CheckAsset_EmptyId_ArgumentException() { LOG.Info($"Executing {nameof(TestStorageManager_CheckAsset_EmptyId_ArgumentException)}"); var mgr = new StorageManager( _readerLocalStorage, TimeSpan.FromMinutes(2), _chattelReader, _chattelWriter ); Assert.Throws <ArgumentException>(() => mgr.CheckAsset(Guid.Empty, result => { })); }
public static void TestStorageManager_CheckAsset_Known_IsTrue() { LOG.Info($"Executing {nameof(TestStorageManager_CheckAsset_Known_IsTrue)}"); var mgr = new StorageManager( _readerLocalStorage, TimeSpan.FromMinutes(2), _chattelReader, _chattelWriter ); var id = Guid.NewGuid(); mgr.StoreAsset(new StratusAsset { Id = id, }, result => { }); mgr.CheckAsset(id, Assert.IsTrue); }