public static void TestChattelConfiguration_CtorDirect_GoodLocalStoragePath_LocalStorageEnabledTrue() { LOCAL_STORAGE_DIR_INFO.Create(); var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName); Assert.True(config.LocalStorageEnabled); }
public static void TestChattelConfiguration_CtorDirect_GoodLocalStoragePath_WriteCacheRecordCount_Correct() { LOCAL_STORAGE_DIR_INFO.Create(); var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName, WRITE_CACHE_FILE_INFO.FullName, WRITE_CACHE_MAX_RECORD_COUNT, ASSET_SERVERS); Assert.AreEqual(WRITE_CACHE_MAX_RECORD_COUNT, config.WriteCacheRecordCount); }
public static void TestChattelConfiguration_CtorDirect_GoodLocalStoragePath_LocalStorageFolderNotNull() { LOCAL_STORAGE_DIR_INFO.Create(); var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName); Assert.IsNotNull(config.LocalStorageFolder); }
public static void TestStorageManager_StoreAsset_CallsServerPutAsset() { LOG.Info($"Executing {nameof(TestStorageManager_StoreAsset_CallsServerPutAsset)}"); var server = Substitute.For <IAssetServer>(); var config = new ChattelConfiguration(TestAssetLocalStorageLmdbPartitionedLRUCtor.DATABASE_FOLDER_PATH, server); using (var readerLocalStorage = new AssetLocalStorageLmdbPartitionedLRU( config, uint.MaxValue, TestAssetLocalStorageLmdbPartitionedLRUCtor.DATABASE_PARTITION_INTERVAL )) { var reader = new ChattelReader(config, readerLocalStorage); var writer = new ChattelWriter(config, readerLocalStorage); var mgr = new StorageManager( readerLocalStorage, TimeSpan.FromMinutes(2), reader, writer ); var asset = new StratusAsset { Id = Guid.NewGuid(), }; var wait = new AutoResetEvent(false); mgr.StoreAsset(asset, result => wait.Set()); wait.WaitOne(); server.Received(1).StoreAssetSync(asset); } }
public static void TestStorageManager_GetAsset_DoubleNoExist_CallsServerRequestOnlyOnce() { LOG.Info($"Executing {nameof(TestStorageManager_GetAsset_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.GetAsset(assetId, result => { }, () => { }); mgr.GetAsset(assetId, result => { }, () => { }); server.Received(1).RequestAssetSync(assetId); } }
public static void TestChattelWriter_PutAssetSync_FullWriteCache_HitsRemote() { var server = Substitute.For <IAssetServer>(); var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName, WRITE_CACHE_FILE_INFO.FullName, 4, server); var localStorage = Substitute.For <IChattelLocalStorage>(); var writer = new ChattelWriter(config, localStorage); var testAsset = new StratusAsset { Id = Guid.NewGuid(), }; try { writer.PutAssetSync(testAsset); } catch (AggregateException) { // moving right along. } try { writer.PutAssetSync(testAsset); } catch (AggregateException) { // moving right along. } try { writer.PutAssetSync(testAsset); } catch (WriteCacheFullException) { // moving right along. } // Write cache currently requires one left empty. server.Received(3).StoreAssetSync(testAsset); }
public static void Startup() { // Folder has to be there or the config fails. TestAssetLocalStorageLmdbPartitionedLRUCtor.RebuildLocalStorageFolder(TestAssetLocalStorageLmdbPartitionedLRUCtor.DATABASE_FOLDER_PATH, WRITE_CACHE_FILE_PATH); _chattelConfigRead = new ChattelConfiguration(TestAssetLocalStorageLmdbPartitionedLRUCtor.DATABASE_FOLDER_PATH, WRITE_CACHE_FILE_PATH, WRITE_CACHE_MAX_RECORD_COUNT, (IAssetServer)null); _chattelConfigWrite = new ChattelConfiguration(TestAssetLocalStorageLmdbPartitionedLRUCtor.DATABASE_FOLDER_PATH, WRITE_CACHE_FILE_PATH, WRITE_CACHE_MAX_RECORD_COUNT, (IAssetServer)null); }
public static void TestChattelWriter_PutAssetSync_ServerError_AggregateException_ContainsCorrectException() { var server = Substitute.For <IAssetServer>(); var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName, WRITE_CACHE_FILE_INFO.FullName, 4, server); var localStorage = Substitute.For <IChattelLocalStorage>(); var writer = new ChattelWriter(config, localStorage); server .WhenForAnyArgs(x => x.StoreAssetSync(Arg.Any <StratusAsset>())) .Do(x => { throw new DriveNotFoundException(); // Just needs an error to cause remote storage failure. }) ; var testAsset = new StratusAsset { Id = Guid.NewGuid(), }; try { writer.PutAssetSync(testAsset); } catch (AggregateException e) { Assert.IsInstanceOf(typeof(DriveNotFoundException), e.InnerException); return; } Assert.Fail(); }
public static void TestChattelWriter_PutAssetSync_FullWriteCache_BadServer_AggregateException() { var server = Substitute.For <IAssetServer>(); var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName, WRITE_CACHE_FILE_INFO.FullName, 4, server); var localStorage = Substitute.For <IChattelLocalStorage>(); var writer = new ChattelWriter(config, localStorage); server .WhenForAnyArgs(x => x.StoreAssetSync(Arg.Any <StratusAsset>())) .Do(x => { throw new Exception(); // Just needs an error to cause remote storage failure. }) ; var testAsset = new StratusAsset { Id = Guid.NewGuid(), }; try { writer.PutAssetSync(testAsset); } catch (AggregateException) { // moving right along. } try { writer.PutAssetSync(testAsset); } catch (AggregateException) { // moving right along. } // Write cache currenlty requires one left empty. Assert.Throws <AggregateException>(() => writer.PutAssetSync(testAsset)); }
public static void TestChattelWriter_PutAssetSync_MultipleParallel_AllReceived() { var server = Substitute.For <IAssetServer>(); var config = new ChattelConfiguration(server); var localStorage = Substitute.For <IChattelLocalStorage>(); var writer = new ChattelWriter(config, localStorage); var testAsset1 = new StratusAsset { Id = Guid.NewGuid(), }; var testAsset2 = new StratusAsset { Id = Guid.NewGuid(), }; var testAsset3 = new StratusAsset { Id = Guid.NewGuid(), }; Parallel.Invoke( () => writer.PutAssetSync(testAsset1), () => writer.PutAssetSync(testAsset2), () => writer.PutAssetSync(testAsset3) ); server.Received(1).StoreAssetSync(testAsset1); server.Received(1).StoreAssetSync(testAsset2); server.Received(1).StoreAssetSync(testAsset3); }
public static void TestChattelWriter_PutAssetSync_WritesBackupRemoteParallel_WithLocalStorage() { var server1 = Substitute.For <IAssetServer>(); var server2 = Substitute.For <IAssetServer>(); var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName, new List <List <IAssetServer> > { new List <IAssetServer> { server1, }, new List <IAssetServer> { server2, }, }); var localStorage = Substitute.For <IChattelLocalStorage>(); var writer = new ChattelWriter(config, localStorage); var testAsset = new StratusAsset { Id = Guid.NewGuid(), }; server1.WhenForAnyArgs(x => x.StoreAssetSync(testAsset)).Do(x => throw new AssetWriteException(testAsset.Id)); writer.PutAssetSync(testAsset); server2.Received(1).StoreAssetSync(testAsset); }
public static void TestChattelWriter_PutAssetSync_WritesRemoteSeries_CorrectOrder() { var server1 = Substitute.For <IAssetServer>(); var server2 = Substitute.For <IAssetServer>(); var config = new ChattelConfiguration(new List <List <IAssetServer> > { new List <IAssetServer> { server1, }, new List <IAssetServer> { server2, }, }); var writer = new ChattelWriter(config); var testAsset = new StratusAsset { Id = Guid.NewGuid(), }; server1.WhenForAnyArgs(x => x.StoreAssetSync(testAsset)).Do(x => throw new AssetWriteException(testAsset.Id)); writer.PutAssetSync(testAsset); Received.InOrder(() => { server1.StoreAssetSync(testAsset); server2.StoreAssetSync(testAsset); }); }
public static void TestChattelConfiguration_CtorDirect_NullWriteCachePath_WriteCacheFileNull() { LOCAL_STORAGE_DIR_INFO.Create(); var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName, null, WRITE_CACHE_MAX_RECORD_COUNT, ASSET_SERVERS); Assert.Null(config.WriteCacheFile); }
public static void TestChattelConfiguration_CtorDirect_ZeroWriteCacheRecordCount_WriteCacheFileNull() { LOCAL_STORAGE_DIR_INFO.Create(); var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName, WRITE_CACHE_FILE_INFO.FullName, 0, ASSET_SERVERS); Assert.Null(config.WriteCacheFile); }
[Timeout(900)] // Must be less than 2x the delay of the server. public static void TestChattelReader_GetAssetAsync2_UncachedAsset_SingleSlowServer_ParallelReads_SingleServerCall() { var server = Substitute.For <IAssetServer>(); var config = new ChattelConfiguration(server); var asset = new StratusAsset { Id = Guid.NewGuid(), Name = "Avengers", }; server .RequestAssetSync(asset.Id) .Returns(x => { Thread.Sleep(500); // Slow server call. return(asset); }) ; var reader = new ChattelReader(config); Parallel.Invoke( () => { reader.GetAssetAsync(asset.Id, resultAsset => { }); }, () => { reader.GetAssetAsync(asset.Id, resultAsset => { }); }, () => { reader.GetAssetAsync(asset.Id, resultAsset => { }); } ); // The server should only be hit once for multiple parallel calls for the same asset ID. server.Received(1).RequestAssetSync(asset.Id); }
public static void TestChattelReader_GetAssetAsync2_UncachedAsset_SerialServer_ReturnsEqualAsset() { var server1 = Substitute.For <IAssetServer>(); var server2 = Substitute.For <IAssetServer>(); var config = new ChattelConfiguration(new List <List <IAssetServer> > { new List <IAssetServer> { server1 }, new List <IAssetServer> { server2 } }); var asset = new StratusAsset { Id = Guid.NewGuid(), Name = "Avengers", }; server1.WhenForAnyArgs(x => x.StoreAssetSync(asset)).Do(x => throw new AssetWriteException(asset.Id)); server2.RequestAssetSync(asset.Id).Returns(asset); var reader = new ChattelReader(config); var wait = new AutoResetEvent(false); reader.GetAssetAsync(asset.Id, resultAsset => { Assert.AreEqual(asset, resultAsset); wait.Set(); }); wait.WaitOne(); }
public static void BeforeEveryTest() { #pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body try { Directory.Delete(TestAssetLocalStorageLmdbPartitionedLRUCtor.DATABASE_FOLDER_PATH, true); } catch { } #pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body Directory.CreateDirectory(TestAssetLocalStorageLmdbPartitionedLRUCtor.DATABASE_FOLDER_PATH); var chattelConfigRead = new ChattelConfiguration(TestAssetLocalStorageLmdbPartitionedLRUCtor.DATABASE_FOLDER_PATH); var chattelConfigWrite = new ChattelConfiguration(TestAssetLocalStorageLmdbPartitionedLRUCtor.DATABASE_FOLDER_PATH); _readerLocalStorage = new AssetLocalStorageLmdbPartitionedLRU( chattelConfigRead, TestAssetLocalStorageLmdbPartitionedLRUCtor.DATABASE_MAX_SIZE_BYTES, TestAssetLocalStorageLmdbPartitionedLRUCtor.DATABASE_PARTITION_INTERVAL ); _chattelReader = new ChattelReader(chattelConfigRead, _readerLocalStorage); _chattelWriter = new ChattelWriter(chattelConfigWrite, _readerLocalStorage); _storageManager = new StorageManager( _readerLocalStorage, TimeSpan.FromMinutes(2), _chattelReader, _chattelWriter ); }
public static void TestChattelReader_GetAssetAsync2_CachedAsset_ReturnsEqualAsset() { var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName); var localStorage = Substitute.For <IChattelLocalStorage>(); var asset = new StratusAsset { Id = Guid.NewGuid(), Name = "Avengers", }; localStorage .TryGetAsset(asset.Id, out var junk) .Returns(x => { x[1] = asset; return(true); }) ; var reader = new ChattelReader(config, localStorage); var wait = new AutoResetEvent(false); reader.GetAssetAsync(asset.Id, resultAsset => { Assert.AreEqual(asset, resultAsset); wait.Set(); }); wait.WaitOne(); }
public static void TestAssetStorageSimpleFolderTree_PurgeAll_SingleFilter_OneMatch_OneMismatch_Correct() { var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName); var localStorage = new AssetStorageSimpleFolderTree(config); var assetId1 = Guid.NewGuid(); var assetId2 = Guid.NewGuid(); CreateLocalStorageEntry(LOCAL_STORAGE_DIR_INFO, new StratusAsset { Id = assetId1, Local = false, }); CreateLocalStorageEntry(LOCAL_STORAGE_DIR_INFO, new StratusAsset { Id = assetId2, Local = true, }); localStorage.PurgeAll(new List <AssetFilter> { new AssetFilter { LocalFilter = true, } }); Assert.IsTrue(LocalStorageEntryExists(LOCAL_STORAGE_DIR_INFO, assetId1)); Assert.IsFalse(LocalStorageEntryExists(LOCAL_STORAGE_DIR_INFO, assetId2)); }
public static void TestAssetStorageSimpleFolderTree_PurgeAll_Null_EmptyLocalStorage_DoesntThrow() { var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName); var localStorage = new AssetStorageSimpleFolderTree(config); Assert.DoesNotThrow(() => localStorage.PurgeAll(null)); }
public static void TestAssetStorageSimpleFolderTree_TryGetAsset_Unknown_ReturnsFalse() { var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName); var localStorage = new AssetStorageSimpleFolderTree(config); Assert.False(localStorage.TryGetAsset(Guid.NewGuid(), out var asset)); }
public static void TestAssetStorageSimpleFolderTree_TryGetAsset_EmptyLocalStorage_DoesntThrow() { var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName); var localStorage = new AssetStorageSimpleFolderTree(config); Assert.DoesNotThrow(() => localStorage.TryGetAsset(Guid.NewGuid(), out var asset)); }
public static void TestChattelWriter_PutAssetSync_Null_ArgumentNullException() { var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName); var writer = new ChattelWriter(config); Assert.Throws <ArgumentNullException>(() => writer.PutAssetSync(null)); }
public static void TestChattelReader_HasUpstream_None_False() { var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName); var reader = new ChattelReader(config); Assert.False(reader.HasUpstream); }
public static void TestChattelConfiguration_DisableLocalStorage_LocalStorageEnabled_False() { LOCAL_STORAGE_DIR_INFO.Create(); var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName); config.DisableLocalStorage(); Assert.False(config.LocalStorageEnabled); }
public static void TestChattelReader_HasUpstream_Mocked_True() { var server = Substitute.For <IAssetServer>(); var config = new ChattelConfiguration(server); var reader = new ChattelReader(config); Assert.True(reader.HasUpstream); }
public static void TestAssetStorageSimpleFolderTree_Purge_Unknown_AssetNotFoundException() { var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName); var localStorage = new AssetStorageSimpleFolderTree(config); var assetId = Guid.NewGuid(); Assert.Throws <AssetNotFoundException>(() => localStorage.Purge(assetId)); }
public static void TestChattelWriter_PutAssetSync_EmptyId_ArgumentException() { var config = new ChattelConfiguration(LOCAL_STORAGE_DIR_INFO.FullName); var writer = new ChattelWriter(config); Assert.Throws <ArgumentException>(() => writer.PutAssetSync(new StratusAsset { Id = Guid.Empty, })); }
public void Init() { // Configure Log4Net XmlConfigurator.Configure(new FileInfo(Constants.LOG_CONFIG_PATH)); // Set CWD so that native libs are found. Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory); // Load INI stuff var configSource = new ArgvConfigSource(new string[] { }); // Configure nIni aliases and locale Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US", true); configSource.Alias.AddAlias("On", true); configSource.Alias.AddAlias("Off", false); configSource.Alias.AddAlias("True", true); configSource.Alias.AddAlias("False", false); configSource.Alias.AddAlias("Yes", true); configSource.Alias.AddAlias("No", false); // Read in the ini file configSource.Merge(new IniConfigSource(Constants.INI_PATH)); // Prep cache folder try { Directory.Delete(Constants.TEST_CACHE_PATH, true); } catch (DirectoryNotFoundException) { // Skip. } Directory.CreateDirectory(Constants.TEST_CACHE_PATH); // Start booting server var pidFileManager = new PIDFileManager(Constants.PID_FILE_PATH); var chattelConfigRead = new ChattelConfiguration(Constants.TEST_CACHE_PATH); LocalStorage = new AssetStorageSimpleFolderTree(chattelConfigRead); var chattelReader = new ChattelReader(chattelConfigRead, LocalStorage); _service = new F_Stop( Constants.SERVICE_URI, Constants.SERVICE_ADMIN_TOKEN, TimeSpan.FromSeconds(Constants.SERVICE_NC_LIFETIME_SECONDS), chattelReader, new List <sbyte> { 0, 12, /*18, 19,*/ 49 } ); _service.Start(); }
public static void TestAssetLocalStorageLmdb_Ctor2_DBPathBlank_DoesntThrow() { var chattelConfigRead = new ChattelConfiguration("", assetServer: null); Assert.DoesNotThrow(() => { using (new AssetLocalStorageLmdb( _chattelConfigRead, DATABASE_MAX_SIZE_BYTES )) { } }); }