コード例 #1
0
        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;
            }
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
 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;
 }
コード例 #4
0
 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;
     }
 }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
 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()}");
     }
 }
コード例 #8
0
        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()}");
            }
        }
コード例 #9
0
        [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);
        }
コード例 #10
0
        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();
        }
コード例 #11
0
        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);
        }
コード例 #12
0
 protected void ConfigureCache(CacheInitializer cacheInitializer)
 {
     HasCacheInitializer    = true;
     TestHooks.CacheFactory = () => cacheInitializer.CreateCacheForContext();
 }
コード例 #13
0
 protected void ConfigureCache(CacheInitializer cacheInitializer)
 {
     TestHooks.CacheFactory = (context) => cacheInitializer.CreateCacheForContext(context);
 }
コード例 #14
0
        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.");
        }