Exemple #1
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);
        }
Exemple #2
0
        public void RootTranslation()
        {
            var rootTranslator = new RootTranslator();
            var pathTable      = Context.PathTable;

            // Source is shorter than target
            var shortCaseSourceTranslatedRootPath = GetFullPath(pathTable, "ShortSource").Expand(pathTable);
            var shortCaseTargetTranslatedRootPath = GetFullPath(pathTable, "Short___Target").Expand(pathTable);

            rootTranslator.AddTranslation(
                shortCaseSourceTranslatedRootPath.ExpandedPath,
                shortCaseTargetTranslatedRootPath.ExpandedPath);

            // Source is longer than target
            var longCaseSourceTranslatedRootPath = GetFullPath(pathTable, "LongSourceSource").Expand(pathTable);
            var longCaseTargetTranslatedRootPath = GetFullPath(pathTable, "LongTarget").Expand(pathTable);

            rootTranslator.AddTranslation(
                longCaseSourceTranslatedRootPath.ExpandedPath,
                longCaseTargetTranslatedRootPath.ExpandedPath);

            rootTranslator.Seal();

            var cache = new CacheCoreArtifactContentCache(Session, rootTranslator);

            // SHORTER SOURCE, SAME ROOT: Path should NOT be translated
            VerifyExpandedPathForCacheEquals(cache, shortCaseSourceTranslatedRootPath, shortCaseSourceTranslatedRootPath);

            // LONGER SOURCE, SAME ROOT: Path SHOULD be translated
            VerifyExpandedPathForCacheEquals(cache, longCaseSourceTranslatedRootPath, longCaseTargetTranslatedRootPath);
        }
        public void TestRootTranslator()
        {
            AddTranslation(ToAbsolutePath(new string[] { "D" }), ToAbsolutePath(new string[] { "X", "underD", "" }));
            AddTranslation(ToAbsolutePath(new string[] { "D", "root2" }), ToAbsolutePath(new string[] { "J", "R3" }));
            AddTranslation(ToAbsolutePath(new string[] { "C", "test", "folder0" }), ToAbsolutePath(new string[] { "M", "" }));
            AddTranslation(ToAbsolutePath(new string[] { "F", "prefix" }), ToAbsolutePath(new string[] { "N", "" }));
            AddTranslation(ToAbsolutePath(new string[] { "K", "root2", "subroot", "phase2", "folder" }), ToAbsolutePath(new string[] { "B", "" }));
            AddTranslation(ToAbsolutePath(new string[] { "D", "root1" }), ToAbsolutePath(new string[] { "K", "root2", "subroot" }));
            m_translator.Seal();

            // Generic translation
            TestRootTranslation(ToAbsolutePath(new string[] { "D", "fromRoot", "root.SLN" }), ToAbsolutePath(new string[] { "X", "underD", "fromRoot", "root.SLN" }));

            // Test NOT translated
            TestNotTranslated(ToAbsolutePath(new string[] { "F", "prefix folder", "file.bin" }));
            TestNotTranslated(ToAbsolutePath(new string[] { "F", "prefixbefore", "file.bin" }));
            TestNotTranslated(ToAbsolutePath(new string[] { "F", "pref", "file.bin" }));

            // More specific translation takes precedence
            TestRootTranslation(ToAbsolutePath(new string[] { "D", "root1", "files.txt" }), ToAbsolutePath(new string[] { "K", "root2", "subroot", "files.txt" }));
            TestRootTranslation(ToAbsolutePath(new string[] { "D", "root2", "nested", "files.txt" }), ToAbsolutePath(new string[] { "J", "R3", "nested", "files.txt" }));
            TestRootTranslation(ToAbsolutePath(new string[] { "D", "root1", "files2.txt" }), ToAbsolutePath(new string[] { "K", "root2", "subroot", "files2.txt" }));

            // Nested folder translation
            TestRootTranslation(ToAbsolutePath(new string[] { "C", "test", "folder0", "nested", "files.txt" }), ToAbsolutePath(new string[] { "M", "nested", "files.txt" }));

            // Test that have chains of translations are translated appropriately
            // 1. D:\root1\phase2\folder\test\BLAH.blob -> K:\root2\subroot\phase2\folder\test\BLAH.blob
            // 2. K:\root2\subroot\phase2\folder\test\BLAH.blob -> B:\test\BLAH.blob
            TestRootTranslation(ToAbsolutePath(new string[] { "D", "root1", "phase2", "folder", "test", "BLAH.blob" }), ToAbsolutePath(new string[] { "B", "test", "BLAH.blob" }));
        }
Exemple #4
0
        public void RootTranslationDifferentRoots()
        {
            var rootTranslator = new RootTranslator();
            var pathTable      = Context.PathTable;

            // Source is shorter than target but has different root
            var shortCaseChangeRootSourceTranslatedRootPath = ChangeRoot(GetFullPath(pathTable, "ShortChangeRootSrc"), pathTable, newRoot: 'A');
            var shortCaseChangeRootTargetTranslatedRootPath = ChangeRoot(GetFullPath(pathTable, "ShortChangeRootTarget"), pathTable, newRoot: 'B');

            rootTranslator.AddTranslation(
                shortCaseChangeRootSourceTranslatedRootPath.ExpandedPath,
                shortCaseChangeRootTargetTranslatedRootPath.ExpandedPath);

            rootTranslator.Seal();

            var cache = new CacheCoreArtifactContentCache(Session, rootTranslator);

            // SHORTER SOURCE, DIFFERENT ROOT: Path SHOULD be translated
            VerifyExpandedPathForCacheEquals(cache, shortCaseChangeRootSourceTranslatedRootPath, shortCaseChangeRootTargetTranslatedRootPath);
        }
Exemple #5
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.");
        }