private static void ConfigureDitto() { try { var container = new DestinationConfigurationContainer(null, new TestConfigurationFactory()); container.Map <BenchDestinationProps.Int1>().From <BenchSourceProps.Int1>(); container.Map <BenchDestinationProps.Int2>().From <BenchSourceProps.Int2>(); container.Map <BenchDestinationProps>().From <BenchSourceProps>(); var bindable = container.ToBinding(); bindable.Bind(); bindable.Assert(); var contextualizer = new TestContextualizer(); var cacher = new CacheInitializer(contextualizer); bindable.Accept(cacher); dittoMapCommand = bindable.CreateCommand(typeof(BenchSourceProps), typeof(BenchDestinationProps)); } catch (Exception ex) { Console.WriteLine(ex); throw; } }
/// <summary> /// Returns a cache initializer to a real instance of the cache /// </summary> protected CacheInitializer GetRealCacheInitializerForTests() { var tempDir = OperatingSystemHelper.IsUnixOS ? "/tmp/buildxl-temp" : TemporaryDirectory; string cacheDirectory = Path.Combine(tempDir, "cache"); AbsolutePath cacheConfigPath = WriteTestCacheConfigToDisk(cacheDirectory); var translator = new RootTranslator(); if (TryGetSubstSourceAndTarget(out var substSource, out var substTarget)) { translator.AddTranslation(substTarget, substSource); } translator.Seal(); Configuration.Cache.CacheConfigFile = cacheConfigPath; Configuration.Cache.CacheLogFilePath = AbsolutePath.Create(Context.PathTable, tempDir).Combine(Context.PathTable, "cache.log"); var maybeCacheInitializer = CacheInitializer.GetCacheInitializationTask( LoggingContext, Context.PathTable, cacheDirectory, Configuration.Cache, translator, recoveryStatus: false, cancellationToken: CancellationToken.None).GetAwaiter().GetResult(); if (!maybeCacheInitializer.Succeeded) { throw new BuildXLException("Unable to initialize the real cache: " + maybeCacheInitializer.Failure.DescribeIncludingInnerFailures()); } return(maybeCacheInitializer.Result); }
public SharedOpaqueEngineTests(ITestOutputHelper output) : base(output) { // These tests validate the right ACLs are set on particular files. We need the real cache for that. m_cacheInitializer = GetRealCacheInitializerForTests(); ConfigureCache(m_cacheInitializer); Configuration.Schedule.DisableProcessRetryOnResourceExhaustion = true; }
private void DisposeRealCache() { if (m_cacheInitializer != null) { var closeResult = m_cacheInitializer.Close(); if (!closeResult.Succeeded) { throw new BuildXLException("Unable to close the cache session: " + closeResult.Failure.DescribeIncludingInnerFailures()); } m_cacheInitializer.Dispose(); m_cacheInitializer = null; } }
private void InitializeCollections() { var collectionsToInitialize = GetType().GetProperties() .Where(p => p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(IUQCollection <>)) .Select(p => new { Property = p, Attribute = p.GetCustomAttributes(typeof(DataAccessObjectAttribute), false).FirstOrDefault() as DataAccessObjectAttribute }) .Where(p => p.Attribute != null); var relations = new Dictionary <Type, IList <Type> >(); foreach (var item in collectionsToInitialize) { var entityType = item.Property.PropertyType.GenericTypeArguments[0]; var newCollection = Activator.CreateInstance(typeof(UQCollection <>).MakeGenericType(entityType), true); var dao = Activator.CreateInstance(item.Attribute.DataAccessObjectType); if (dao is INeedDataSourceProperties dataSourcePropertiesRequestor) { dataSourcePropertiesRequestor.SetProperties(_properties); } var cacheConfig = ((CacheConfigurationAttribute)Attribute.GetCustomAttribute(GetType(), typeof(CacheConfigurationAttribute))) ?.Configuration; var cacheConfigEx = cacheConfig != null ? new InCodeCacheConfiguration(cacheConfig) : UQConfiguration.Instance.HorizontalCacheConfiguration as IHorizontalCacheConfigurationInternal; var persistentCache = item.Attribute.DisableCache ? null : CacheInitializer.GetCachedDataProvider(entityType, _dataStoreSetId, cacheConfigEx, dao); (newCollection as IUQCollectionInitializer).Initialize(dao, persistentCache); item.Property.SetValue(this, newCollection); // get 'parent' entities: var entityRelations = entityType.GetProperties() .Select(p => p.GetCustomAttribute(typeof(EntityIdentifierAttribute))) .Where(a => a != null) .OfType <EntityIdentifierAttribute>() .Select(x => x.EntityType) .Where(x => x != entityType) // exclude self references .ToList(); relations[entityType] = entityRelations.ToList(); } BuildRelationsOrder(relations); }
protected override void Dispose(bool disposing) { if (m_cacheInitializer != null) { var closeResult = m_cacheInitializer.Close(); if (!closeResult.Succeeded) { throw new BuildXLException("Unable to close the cache session: " + closeResult.Failure.DescribeIncludingInnerFailures()); } m_cacheInitializer.Dispose(); m_cacheInitializer = null; } base.Dispose(disposing); }
private void ConfigureRealCache(string cacheId = null) { try { if (!HasCacheInitializer) { // These tests validate the right ACLs are set on particular files. We need the real cache for that. m_cacheInitializer = GetRealCacheInitializerForTests(cacheId: cacheId); ConfigureCache(m_cacheInitializer); } } catch (Exception ex) { TestOutput.WriteLine($"Could not initialize cache initializer: {ex.ToStringDemystified()}"); } }
public LazyMaterializationBuildVfsTests(ITestOutputHelper output) : base(output) { Logger.Log.AddObserver(this); EtwOnlyTextLogger.EnableGlobalEtwLogging(LoggingContext); Configuration.Cache.VfsCasRoot = Combine(Configuration.Layout.CacheDirectory, "vfs"); try { // These tests validate the right ACLs are set on particular files. We need the real cache for that. m_cacheInitializer = GetRealCacheInitializerForTests(); ConfigureCache(m_cacheInitializer); } catch (Exception ex) { TestOutput.WriteLine($"Could not initialize cache initializer: {ex.ToStringDemystified()}"); } }
[TestMethod] // tests parameters in the test project app.config file public void TestConfiguration() { // Arrange - Act var config = UQConfiguration.Instance; // Assert Assert.IsTrue(config.HorizontalCacheConfiguration.IsEnabled); Assert.AreEqual(typeof(TextFileCacheProvider <>), config.HorizontalCacheConfiguration.ProviderType); var data = CacheInitializer.GetCachedDataProvider(typeof(DummyEntity), "db1", config.HorizontalCacheConfiguration as IHorizontalCacheConfigurationInternal, new DummyEntityDAO2()); var memCache = typeof(CachedDataProviderBase <DummyEntity>).GetField("_memoryCacheService", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(data); var provider = typeof(MemoryCacheService <DummyEntity>).GetField("_cacheProvider", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(memCache); var folder = typeof(TextFileCacheProvider <DummyEntity>).GetField("_folder", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(provider); Assert.AreEqual(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\UQFramework", folder); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var cache = services.GetRequiredService <IDistributedCache>(); CacheInitializer.Seed(cache); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the cache."); } } host.Run(); }
private static async Task <ICacheFacade <K, V> > CreateCohortAsync <K, V>(int cohortNumber, CacheConfiguration <K, V> cacheConfiguration) { // Force loads assemblies in directory and registers to global serializer. new RyuFactory().Create(); AssertTrue(cohortNumber >= 0 && cohortNumber < 15); var cohortId = Guid.Parse("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".Replace('x', (cohortNumber + 1).ToString("x")[0])); var courier = await CourierBuilder.Create() .ForceIdentity(cohortId) .UseUdpTransport( UdpTransportConfigurationBuilder.Create() .WithUnicastReceivePort(21338 + cohortNumber) .Build()) .UseTcpServerTransport(21337 + cohortNumber) .BuildAsync().ConfigureAwait(false); var cacheInitializer = new CacheInitializer(courier); var myCacheFacade = cacheInitializer.CreateLocal <K, V>(cacheConfiguration); return(myCacheFacade); }
protected void ConfigureCache(CacheInitializer cacheInitializer) { HasCacheInitializer = true; TestHooks.CacheFactory = () => cacheInitializer.CreateCacheForContext(); }
protected void ConfigureCache(CacheInitializer cacheInitializer) { TestHooks.CacheFactory = (context) => cacheInitializer.CreateCacheForContext(context); }
public void TestProperLogMessageOnCacheLockAcquisitionFailure() { var tempDir = Path.Combine( OperatingSystemHelper.IsUnixOS ? "/tmp/bxl-temp" : TemporaryDirectory, Guid.NewGuid().ToString()); string cacheDirectory = Path.Combine(tempDir, "cache"); string cacheConfigJson = $@"{{ ""MaxCacheSizeInMB"": 1024, ""CacheId"": ""TestCache"", ""Assembly"": ""BuildXL.Cache.MemoizationStoreAdapter"", ""CacheLogPath"": ""[BuildXLSelectedLogPath]"", ""Type"": ""BuildXL.Cache.MemoizationStoreAdapter.MemoizationStoreCacheFactory"", ""CacheRootPath"": ""{cacheDirectory.Replace("\\", "\\\\")}"", ""UseStreamCAS"": false, ""SingleInstanceTimeoutInSeconds"" : 5 }}"; AbsolutePath cacheConfigPath = WriteTestCacheConfigToDisk(cacheDirectory, cacheConfigJson); var translator = new RootTranslator(); translator.Seal(); var possibleFirstCacheInitializer = CacheInitializer.GetCacheInitializationTask( LoggingContext, Context.PathTable, cacheDirectory, new CacheConfiguration { CacheLogFilePath = AbsolutePath.Create(Context.PathTable, tempDir).Combine(Context.PathTable, "cache.log"), CacheConfigFile = cacheConfigPath }, translator, recoveryStatus: false, cancellationToken: CancellationToken.None).GetAwaiter().GetResult(); if (!possibleFirstCacheInitializer.Succeeded) { AssertTrue(false, "Failed to initialize the cache: " + possibleFirstCacheInitializer.Failure.DescribeIncludingInnerFailures()); } var possibleSecondCacheInitializer = CacheInitializer.GetCacheInitializationTask( LoggingContext, Context.PathTable, cacheDirectory, new CacheConfiguration { // need a different name for the log file (due to the order in which the things are initialized) CacheLogFilePath = AbsolutePath.Create(Context.PathTable, tempDir).Combine(Context.PathTable, "cache_2.log"), CacheConfigFile = cacheConfigPath, }, translator, recoveryStatus: false, cancellationToken: CancellationToken.None).GetAwaiter().GetResult(); // close and dispose the first cache (must be done before the assert block bellow) var firstCacheInitializer = possibleFirstCacheInitializer.Result; AssertSuccess(firstCacheInitializer.Close()); firstCacheInitializer.Dispose(); AssertErrorEventLogged(global::BuildXL.Engine.Tracing.LogEventId.FailedToAcquireDirectoryLock); AssertTrue(!possibleSecondCacheInitializer.Succeeded, "Initialization of the second cache should have failed."); }