public void TestClearCacheScope() { CacheManager cacheManager = new CacheManager("3.5"); CacheScope cacheScope = cacheManager.GetCacheScope("test.proj", new BuildPropertyGroup(), null, CacheContentType.BuildResults); cacheScope.AddCacheEntry(new PropertyCacheEntry(Constants.defaultTargetCacheName, "Target1;Target2")); cacheScope.AddCacheEntry(new PropertyCacheEntry(Constants.initialTargetCacheName, "Initial1")); cacheManager.ClearCacheScope("test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.BuildResults); Assert.AreNotEqual(cacheScope, cacheManager.GetCacheScope("test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.BuildResults), "Expected to get different scopes"); }
public void TestRequestCachingDefaultInitialTargets() { CacheManager cacheManager = new CacheManager("3.5"); ArrayList actuallyBuiltTargets; CacheScope cacheScope = cacheManager.GetCacheScope("test.proj", new BuildPropertyGroup(), null, CacheContentType.BuildResults); cacheScope.AddCacheEntry(new PropertyCacheEntry(Constants.defaultTargetCacheName, "Target1;Target2")); cacheScope.AddCacheEntry(new PropertyCacheEntry(Constants.initialTargetCacheName, "Initial1")); cacheScope.AddCacheEntry(new PropertyCacheEntry(Constants.projectIdCacheName, "5")); CacheEntry cacheEntry = new BuildResultCacheEntry("Initial1", null, true); cacheManager.SetCacheEntries(new CacheEntry[] { cacheEntry }, "test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.BuildResults); cacheEntry = new BuildResultCacheEntry("Target1", null, true); cacheManager.SetCacheEntries(new CacheEntry[] { cacheEntry }, "test.proj", new BuildPropertyGroup(), null, CacheContentType.BuildResults); cacheEntry = new BuildResultCacheEntry("Target2", null, false); cacheManager.SetCacheEntries(new CacheEntry[] { cacheEntry }, "test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.BuildResults); cacheEntry = new BuildResultCacheEntry("Target3", null, true); cacheManager.SetCacheEntries(new CacheEntry[] { cacheEntry }, "test.proj", new BuildPropertyGroup(), null, CacheContentType.BuildResults); // Default target BuildRequest defaultRequest = new BuildRequest(1, "test.proj", null, new BuildPropertyGroup(), null, 1, true, false); BuildResult buildResult = cacheManager.GetCachedBuildResult(defaultRequest, out actuallyBuiltTargets); Assert.IsNotNull(buildResult, "Expect a cached value if scope contains data"); Assert.AreEqual(3, actuallyBuiltTargets.Count); Assert.AreEqual("Initial1", actuallyBuiltTargets[0]); Assert.AreEqual("Target1", actuallyBuiltTargets[1]); Assert.AreEqual("Target2", actuallyBuiltTargets[2]); Assert.AreEqual(3, buildResult.ResultByTarget.Count); Assert.AreEqual(Target.BuildState.CompletedSuccessfully, buildResult.ResultByTarget["Initial1"]); Assert.AreEqual(Target.BuildState.CompletedSuccessfully, buildResult.ResultByTarget["Target1"]); Assert.AreEqual(Target.BuildState.CompletedUnsuccessfully, buildResult.ResultByTarget["Target2"]); Assert.AreEqual(false, buildResult.EvaluationResult); Assert.AreEqual(5, buildResult.ProjectId); // Specific target BuildRequest specificRequest = new BuildRequest(1, "test.proj", new string[] { "Target3" }, new BuildPropertyGroup(), null, 1, true, false); buildResult = cacheManager.GetCachedBuildResult(specificRequest, out actuallyBuiltTargets); Assert.IsNotNull(buildResult, "Expect a cached value if scope contains data"); Assert.AreEqual(2, actuallyBuiltTargets.Count); Assert.AreEqual("Initial1", actuallyBuiltTargets[0]); Assert.AreEqual("Target3", actuallyBuiltTargets[1]); Assert.AreEqual(2, buildResult.ResultByTarget.Count); Assert.AreEqual(Target.BuildState.CompletedSuccessfully, buildResult.ResultByTarget["Initial1"]); Assert.AreEqual(Target.BuildState.CompletedSuccessfully, buildResult.ResultByTarget["Target3"]); Assert.AreEqual(true, buildResult.EvaluationResult); Assert.AreEqual(5, buildResult.ProjectId); }
public void BasicCacheOperation() { BuildPropertyGroup default_scope = new BuildPropertyGroup(); CacheScope testScope = new CacheScope("Test.proj", new BuildPropertyGroup(), "2.0"); // First add a single entry and verify that it is in the cache CacheEntry cacheEntry = new BuildResultCacheEntry("TestEntry", null, true); testScope.AddCacheEntry(cacheEntry); Assert.IsTrue(testScope.ContainsCacheEntry("TestEntry"), "Expect entry in the cache"); CacheEntry inCacheEntry = testScope.GetCacheEntry("TestEntry"); Assert.IsNotNull(inCacheEntry, "Cache should have an entry"); Assert.IsTrue(inCacheEntry.IsEquivalent(cacheEntry), "Expect entry to be the same"); // Add a second entry and then remove the first entry. Verify that the first entry // is not in the cache while the second entry is still there cacheEntry = new BuildResultCacheEntry("TestEntry2", null, true); testScope.AddCacheEntry(cacheEntry); testScope.ClearCacheEntry("TestEntry"); Assert.IsFalse(testScope.ContainsCacheEntry("TestEntry"), "Didn't expect entry in the cache"); Assert.IsTrue(testScope.ContainsCacheEntry("TestEntry2"), "Expected entry in the cache"); Assert.IsNull(testScope.GetCacheEntry("TestEntry"), "Cache should not have an entry"); Assert.IsNotNull(testScope.GetCacheEntry("TestEntry2"), "Cache should have an entry"); }
public void TestRequestCaching() { CacheManager cacheManager = new CacheManager("3.5"); ArrayList actuallyBuiltTargets; // Test the case where we pass in null targets Dictionary <string, string> dictionary = new Dictionary <string, string>(); BuildRequest emptyRequest = new BuildRequest(1, "test.proj", null, dictionary, null, 1, true, false); Assert.IsNull(cacheManager.GetCachedBuildResult(emptyRequest, out actuallyBuiltTargets), "Expect a null return value if T=null"); // Test the case where we pass in length 0 targets BuildRequest length0Request = new BuildRequest(1, "test.proj", new string[0], dictionary, null, 1, true, false); Assert.IsNull(cacheManager.GetCachedBuildResult(length0Request, out actuallyBuiltTargets), "Expect a null return value if T.Length=0"); // Test the case when the scope doesn't exist string[] targets = new string[1]; targets[0] = "Target1"; BuildRequest length1Request = new BuildRequest(1, "test.proj", targets, new BuildPropertyGroup(), null, 1, true, false); Assert.IsNull(cacheManager.GetCachedBuildResult(length1Request, out actuallyBuiltTargets), "Expect a null return value if no scope"); // Test the case when the scope exists but is empty CacheScope cacheScope = cacheManager.GetCacheScope("test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.BuildResults); Assert.IsNull(cacheManager.GetCachedBuildResult(length1Request, out actuallyBuiltTargets), "Expect a null return value if scope is empty"); // Test the case when the scope exists but contains wrong data CacheEntry cacheEntry = new BuildResultCacheEntry("Target2", null, true); cacheManager.SetCacheEntries(new CacheEntry[] { cacheEntry }, "test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.BuildResults); Assert.IsNull(cacheManager.GetCachedBuildResult(length1Request, out actuallyBuiltTargets), "Expect a null return value if scope contains wrong data"); // Test the case when everything is correct cacheScope.AddCacheEntry(new PropertyCacheEntry(Constants.defaultTargetCacheName, string.Empty)); cacheScope.AddCacheEntry(new PropertyCacheEntry(Constants.initialTargetCacheName, string.Empty)); cacheScope.AddCacheEntry(new PropertyCacheEntry(Constants.projectIdCacheName, "1")); cacheEntry = new BuildResultCacheEntry("Target1", null, true); cacheManager.SetCacheEntries(new CacheEntry[] { cacheEntry }, "test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.BuildResults); BuildResult buildResult = cacheManager.GetCachedBuildResult(length1Request, out actuallyBuiltTargets); Assert.IsNotNull(buildResult, "Expect a cached value if scope contains data"); Assert.AreEqual(1, actuallyBuiltTargets.Count); Assert.AreEqual("Target1", actuallyBuiltTargets[0]); Assert.AreEqual(1, buildResult.ResultByTarget.Count); Assert.AreEqual(Target.BuildState.CompletedSuccessfully, buildResult.ResultByTarget["Target1"]); // Test the case when the scope contains partially correct data targets = new string[2]; targets[0] = "Target2"; targets[1] = "Target3"; BuildRequest length2Request = new BuildRequest(1, "test.proj", targets, new BuildPropertyGroup(), null, 1, true, false); Assert.IsNull(cacheManager.GetCachedBuildResult(length2Request, out actuallyBuiltTargets), "Expect a null return value if partial data in the scope"); // Test the correctness case for multiple targets cacheEntry = new BuildResultCacheEntry("Target3", null, true); cacheManager.SetCacheEntries(new CacheEntry[] { cacheEntry }, "test.proj", new BuildPropertyGroup(), "3.5", CacheContentType.BuildResults); buildResult = cacheManager.GetCachedBuildResult(length2Request, out actuallyBuiltTargets); Assert.IsNotNull(buildResult, "Expect a cached value if scope contains data"); Assert.AreEqual(2, actuallyBuiltTargets.Count); Assert.AreEqual("Target2", actuallyBuiltTargets[0]); Assert.AreEqual("Target3", actuallyBuiltTargets[1]); Assert.AreEqual(2, buildResult.ResultByTarget.Count); Assert.AreEqual(Target.BuildState.CompletedSuccessfully, buildResult.ResultByTarget["Target2"]); Assert.AreEqual(Target.BuildState.CompletedSuccessfully, buildResult.ResultByTarget["Target3"]); Assert.AreEqual(1, buildResult.ProjectId); }