public void TestResultsCacheTranslation(object obj) { var resultsCache = (ResultsCache)obj; resultsCache.Translate(TranslationHelpers.GetWriteTranslator()); var copy = new ResultsCache(TranslationHelpers.GetReadTranslator()); copy.ResultsDictionary.Keys.ToHashSet().SetEquals(resultsCache.ResultsDictionary.Keys.ToHashSet()).ShouldBeTrue(); foreach (var configId in copy.ResultsDictionary.Keys) { var copiedBuildResult = copy.ResultsDictionary[configId]; var initialBuildResult = resultsCache.ResultsDictionary[configId]; copiedBuildResult.SubmissionId.ShouldBe(initialBuildResult.SubmissionId); copiedBuildResult.ConfigurationId.ShouldBe(initialBuildResult.ConfigurationId); copiedBuildResult.ResultsByTarget.Keys.ToHashSet().SetEquals(initialBuildResult.ResultsByTarget.Keys.ToHashSet()).ShouldBeTrue(); foreach (var targetKey in copiedBuildResult.ResultsByTarget.Keys) { var copiedTargetResult = copiedBuildResult.ResultsByTarget[targetKey]; var initialTargetResult = initialBuildResult.ResultsByTarget[targetKey]; copiedTargetResult.WorkUnitResult.ResultCode.ShouldBe(initialTargetResult.WorkUnitResult.ResultCode); copiedTargetResult.WorkUnitResult.ActionCode.ShouldBe(initialTargetResult.WorkUnitResult.ActionCode); } } }
public void RejectCachesWithMismatchedIds() { // one entry in each cache but different config ids var configCache = new ConfigCache(); configCache.AddConfiguration(new BuildRequestConfiguration(configId: 1, new BuildRequestData("path", new Dictionary <string, string>() { ["p"] = "v" }, "13", new [] { "a", "b" }, null), "13")); var resultsCache = new ResultsCache(); var buildResult = new BuildResult(new BuildRequest(1, 2, configurationId: 2, new List <string>() { "a", "b" }, null, BuildEventContext.Invalid, null)); buildResult.AddResultsForTarget("a", GetNonEmptySucceedingTargetResult()); resultsCache.AddResult(buildResult); aggregator.Add(configCache, resultsCache); using (var env = TestEnvironment.Create()) { env.SetEnvironmentVariable("MSBUILDDONOTLAUNCHDEBUGGER", "1"); var e = Should.Throw <InternalErrorException>(() => aggregator.Aggregate()); e.Message.ShouldContain("Each result should have a corresponding configuration. Otherwise the caches are not consistent"); } }
public void RejectCachesWithMoreConfigEntriesThanResultEntries() { var configCache = new ConfigCache(); configCache.AddConfiguration(new BuildRequestConfiguration(configId: 1, new BuildRequestData("path", new Dictionary <string, string>() { ["p"] = "v" }, "13", new [] { "a", "b" }, null), "13")); configCache.AddConfiguration(new BuildRequestConfiguration(configId: 2, new BuildRequestData("path2", new Dictionary <string, string>() { ["p"] = "v" }, "13", new [] { "c", "d" }, null), "13")); var resultsCache = new ResultsCache(); var buildResult = new BuildResult(new BuildRequest(1, 2, configurationId: 1, new List <string>() { "a", "b" }, null, BuildEventContext.Invalid, null)); buildResult.AddResultsForTarget("a", GetNonEmptySucceedingTargetResult()); resultsCache.AddResult(buildResult); aggregator.Add(configCache, resultsCache); using (var env = TestEnvironment.Create()) { env.SetEnvironmentVariable("MSBUILDDONOTLAUNCHDEBUGGER", "1"); var e = Should.Throw <InternalErrorException>(() => aggregator.Aggregate()); e.Message.ShouldContain("Assuming 1-to-1 mapping between configs and results. Otherwise it means the caches are either not minimal or incomplete"); } }
public void TestCleansUpOldItems() { ResultsCache<int, int> cache = new ResultsCache<int, int>(new TimeSpan(0, 0, 1)); for (int i = 0; i < 100; i++) cache.InsertResult(i, i * i); Assert.AreEqual(cache.ItemCount, 100); // query the cache 100 times, which should trigger the periodic cleanup at some point int result; for (int i = 0; i < 100; i++) cache.LookupResult(i, out result); //however, since insufficient time has passed, all records still there Assert.AreEqual(cache.ItemCount, 100); System.Threading.Thread.Sleep(1100); for (int i = 0; i < 100; i++) cache.LookupResult(i, out result); // this time round the periodic cleanup will dump all records since >1sec passed Assert.AreEqual(cache.ItemCount, 0); }
static CachingEngine() { m_AddressInfoCache = new ResultsCache<string, IAddress>(); m_MembersCache = new ResultsCache<string, IAddress[]>(); m_MemberOfCache = new ResultsCache<KeyValuePair<IAddress, IAddress>, bool>(); m_MembersByFieldCache = new ResultsCache<KeyValuePair<FieldType, KeyValuePair<string, string>>, IAddress[]>(); }
public static (IConfigCache ConfigCache, IResultsCache ResultsCache, Exception exception) DeserializeCaches(string inputCacheFile) { try { ConfigCache configCache = null; ResultsCache resultsCache = null; using (var fileStream = File.OpenRead(inputCacheFile)) { using var translator = BinaryTranslator.GetReadTranslator(fileStream, null); translator.Translate(ref configCache); translator.Translate(ref resultsCache); } ErrorUtilities.VerifyThrowInternalNull(configCache, nameof(configCache)); ErrorUtilities.VerifyThrowInternalNull(resultsCache, nameof(resultsCache)); return(configCache, resultsCache, null); } catch (Exception e) { return(null, null, e); } }
public void CacheCanBeEnumerated() { ResultsCache cache = new ResultsCache(); BuildRequest request = new BuildRequest(submissionId: 1, nodeRequestId: 0, configurationId: 1, new string[1] { "testTarget" }, null, BuildEventContext.Invalid, null); BuildResult result = new BuildResult(request); result.AddResultsForTarget("result1target1", BuildResultUtilities.GetEmptyFailingTargetResult()); cache.AddResult(result); request = new BuildRequest(1 /* submissionId */, 0, 1, new string[1] { "otherTarget" }, null, BuildEventContext.Invalid, null); result = new BuildResult(request); result.AddResultsForTarget("result1target2", BuildResultUtilities.GetEmptySucceedingTargetResult()); cache.AddResult(result); BuildResult result2 = new BuildResult(new BuildRequest(submissionId: 1, nodeRequestId: 0, configurationId: 2, new string[1] { "testTarget" }, null, BuildEventContext.Invalid, null)); result2.AddResultsForTarget("result2target1", BuildResultUtilities.GetEmptyFailingTargetResult()); cache.AddResult(result2); var results = cache.GetEnumerator().ToArray(); results.Length.ShouldBe(2); Assert.True(results[0].HasResultsForTarget("result1target1")); Assert.True(results[0].HasResultsForTarget("result1target2")); Assert.True(results[1].HasResultsForTarget("result2target1")); }
/// <summary> /// Setup the object /// </summary> public Integration_Tests() { _commonTests = new Common_Tests(this.GetComponent, true); _resultsCache = null; _tempPath = System.IO.Path.GetTempPath(); _assemblyPath = Path.GetDirectoryName( new Uri(System.Reflection.Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath); _assemblyPath = Path.Combine(_assemblyPath, "Microsoft.Build.Unittest.dll"); }
public void SingleEmpty() { var configCache = new ConfigCache(); var resultsCache = new ResultsCache(); aggregator.Add(configCache, resultsCache); var results = aggregator.Aggregate(); AssertAggregation(new[] { (configCache, resultsCache) }, results);
public void TestMissingResults() { ResultsCache cache = new ResultsCache(); BuildRequest request = new BuildRequest(1 /* submissionId */, 0, 1, new string[1] { "testTarget" }, null, BuildEventContext.Invalid, null); BuildResult retrievedResult = cache.GetResultForRequest(request); Assert.Null(retrievedResult); }
public void TestCachedItemExpiry() { ResultsCache<int, int> cache = new ResultsCache<int, int>(new TimeSpan(0,0,1)); cache.InsertResult(5, 25); System.Threading.Thread.Sleep(600); cache.InsertResult(6, 36); System.Threading.Thread.Sleep(600); int result; Assert.IsFalse(cache.LookupResult(5, out result)); Assert.IsTrue(cache.LookupResult(6, out result)); Assert.AreEqual(result, 36); }
public void TestRetrieveIncompleteResults() { ResultsCache cache = new ResultsCache(); BuildRequest request = new BuildRequest(1 /* submissionId */, 0, 1, new string[2] { "testTarget", "testTarget2" }, null, BuildEventContext.Invalid, null); BuildResult result = new BuildResult(request); result.AddResultsForTarget("testTarget", TestUtilities.GetEmptyFailingTargetResult()); cache.AddResult(result); BuildResult retrievedResult = cache.GetResultForRequest(request); }
public void last_counts() { var c = new ResultsCache(); var result1 = new SpecExecutionCompleted("foo", new SpecResults(), new Specification()); c.Store(result1); var result2 = new SpecExecutionCompleted("bar", new SpecResults(), new Specification()); c.Store(result2); var result3 = new SpecExecutionCompleted("foo", new SpecResults{Counts = new Counts()}, new Specification()); c.Store(result3); c.LastResultFor("foo") .ShouldBe(result3); }
public void TestAddAndRetrieveResults() { ResultsCache cache = new ResultsCache(); BuildRequest request = new BuildRequest(1 /* submissionId */, 0, 1, new string[1] { "testTarget" }, null, BuildEventContext.Invalid, null); BuildResult result = new BuildResult(request); result.AddResultsForTarget("testTarget", TestUtilities.GetEmptyFailingTargetResult()); cache.AddResult(result); BuildResult retrievedResult = cache.GetResultForRequest(request); Assert.True(AreResultsIdentical(result, retrievedResult)); }
public void write_initial_model() { // You need to compile everything before trying to use this var input = new ProjectInput { Path = AppDomain.CurrentDomain.BaseDirectory.ParentDirectory() .ParentDirectory() .ParentDirectory() .AppendPath("Storyteller.Samples"), ProfileFlag = "Safari" }; using (var controller = input.BuildRemoteController()) { controller.Start(EngineMode.Batch).Wait(30.Seconds()); var hierarchy = HierarchyLoader.ReadHierarchy(input.Path.AppendPath("Specs")); var request = new BatchRunRequest { SpecPath = input.SpecPath }; var response = controller.Send(request).AndWaitFor <BatchRunResponse>(); var cache = new ResultsCache(); response.Result.records.Each( x => { var completed = new SpecExecutionCompleted(x.specification.id, x.results, x.specification); cache.Store(completed); }); response.Result.fixtures = controller.LatestSystemRecycled.fixtures; var hierarchyLoaded = new HierarchyLoaded(hierarchy, cache); var initialization = new InitialModel(controller.LatestSystemRecycled, hierarchyLoaded) { wsAddress = "ws://localhost:" + 8200 }; writeResponse(response.Result); //writeInitialization(initialization); } }
private IEnumerable <Result <T> > CreateConsumerEnumerable() { int nextResultIndex = 0; ResultsCache <T> unsafeResults = this.results; foreach (Result <T> result in unsafeResults.Skip(nextResultIndex)) { yield return(result); } nextResultIndex = unsafeResults.Count; if (!unsafeResults.IsComplete) { ResultsCache <T> currentResults; do { lock (this.producerLock) { if (nextResultIndex == this.results.Count) { if (this.producer == null) { this.producer = this.CreateProducerEnumerator(); } try { if (!this.producer.MoveNext()) { yield break; } } catch (Exception inner) { base.CancelAnalysis(new CriticalException(this, inner)); } } currentResults = this.results; } foreach (Result <T> result2 in currentResults.Skip(nextResultIndex)) { yield return(result2); } nextResultIndex = currentResults.Count; }while (!currentResults.IsComplete); } yield break; }
public void TestMergeResultsWithException() { ResultsCache cache = new ResultsCache(); BuildRequest request = new BuildRequest(1 /* submissionId */, 0, 1, new string[] { "testTarget" }, null, BuildEventContext.Invalid, null); BuildResult result = new BuildResult(request); result.AddResultsForTarget("testTarget", TestUtilities.GetEmptyFailingTargetResult()); cache.AddResult(result); BuildResult result2 = new BuildResult(request, new Exception("Test exception")); cache.AddResult(result2); BuildResult retrievedResult = cache.GetResultForRequest(request); Assert.NotNull(retrievedResult.Exception); }
public override List <ExtractResult> Extract(string source) { List <ExtractResult> results; if ((this.Options & NumberOptions.NoProtoCache) != 0) { results = base.Extract(source); } else { var key = GenKey(source); results = ResultsCache.GetOrCreate(key, () => base.Extract(source)); } return(results); }
public void TestPairAsQueryType() { ResultsCache<KeyValuePair<string, string>, int> cache = new ResultsCache<KeyValuePair<string, string>, int>(); cache.InsertResult(new KeyValuePair<string, string>("one", "two"), 12); cache.InsertResult(new KeyValuePair<string, string>("two", "two"), 22); cache.InsertResult(new KeyValuePair<string, string>("one", "one"), 11); int iRetVal; Assert.IsTrue(cache.LookupResult(new KeyValuePair<string, string>("one", "two"), out iRetVal)); Assert.AreEqual(iRetVal, 12); Assert.IsTrue(cache.LookupResult(new KeyValuePair<string, string>("two", "two"), out iRetVal)); Assert.AreEqual(iRetVal, 22); Assert.IsTrue(cache.LookupResult(new KeyValuePair<string, string>("one", "one"), out iRetVal)); Assert.AreEqual(iRetVal, 11); Assert.IsFalse(cache.LookupResult(new KeyValuePair<string, string>("two", "one"), out iRetVal)); Assert.AreEqual(0, iRetVal); }
public void RejectCollidingConfigurationsFromSeparateCaches() { // collides with the config id from configCache2 var configCache1 = new ConfigCache(); configCache1.AddConfiguration(new BuildRequestConfiguration(configId: 1, new BuildRequestData("path", new Dictionary <string, string>() { ["p"] = "v" }, "13", new [] { "a", "b" }, null), "13")); var resultsCache1 = new ResultsCache(); var buildResult11 = new BuildResult(new BuildRequest(1, 2, configurationId: 1, new List <string>() { "a", "b" }, null, BuildEventContext.Invalid, null)); buildResult11.AddResultsForTarget("a", GetNonEmptySucceedingTargetResult()); resultsCache1.AddResult(buildResult11); var configCache2 = new ConfigCache(); configCache2.AddConfiguration(new BuildRequestConfiguration(configId: 1, new BuildRequestData("path", new Dictionary <string, string>() { ["p"] = "v" }, "13", new [] { "a", "b" }, null), "13")); var resultsCache2 = new ResultsCache(); var buildResult21 = new BuildResult(new BuildRequest(1, 2, configurationId: 1, new List <string>() { "e", "f" }, null, BuildEventContext.Invalid, null)); buildResult21.AddResultsForTarget("a", GetNonEmptySucceedingTargetResult()); resultsCache2.AddResult(buildResult21); aggregator.Add(configCache1, resultsCache1); aggregator.Add(configCache2, resultsCache2); using (var env = TestEnvironment.Create()) { env.SetEnvironmentVariable("MSBUILDDONOTLAUNCHDEBUGGER", "1"); var e = Should.Throw <InternalErrorException>(() => aggregator.Aggregate()); e.Message.ShouldContain("Input caches should not contain entries for the same configuration"); } }
public void TestClearResultsCache() { ResultsCache cache = new ResultsCache(); cache.ClearResults(); BuildRequest request = new BuildRequest(1 /* submissionId */, 0, 1, new string[1] { "testTarget2" }, null, BuildEventContext.Invalid, null); BuildResult result = new BuildResult(request); result.AddResultsForTarget("testTarget", TestUtilities.GetEmptyFailingTargetResult()); cache.AddResult(result); cache.ClearResults(); Assert.Null(cache.GetResultForRequest(request)); }
public void last_counts() { var c = new ResultsCache(); var result1 = new SpecExecutionCompleted("foo", new SpecResults(), new Specification()); c.Store(result1); var result2 = new SpecExecutionCompleted("bar", new SpecResults(), new Specification()); c.Store(result2); var result3 = new SpecExecutionCompleted("foo", new SpecResults { Counts = new Counts() }, new Specification()); c.Store(result3); c.LastResultFor("foo") .ShouldBe(result3); }
public void write_initial_model() { // You need to compile everything before trying to use this var input = new ProjectInput { Path = AppDomain.CurrentDomain.BaseDirectory.ParentDirectory() .ParentDirectory() .ParentDirectory() .AppendPath("Storyteller.Samples"), ProfileFlag = "Safari" }; using (var controller = input.BuildRemoteController()) { controller.Start(EngineMode.Batch).Wait(30.Seconds()); var hierarchy = HierarchyLoader.ReadHierarchy(input.Path.AppendPath("Specs")); var request = new BatchRunRequest(); var response = controller.Send(request).AndWaitFor<BatchRunResponse>(); var cache = new ResultsCache(); response.Result.records.Each( x => { var completed = new SpecExecutionCompleted(x.specification.id, x.results, x.specification); cache.Store(completed); }); response.Result.fixtures = controller.LatestSystemRecycled.fixtures; var hierarchyLoaded = new HierarchyLoaded(hierarchy, cache); var initialization = new InitialModel(controller.LatestSystemRecycled, hierarchyLoaded) { wsAddress = "ws://localhost:" + 8200 }; writeResponse(response.Result); //writeInitialization(initialization); } }
public void TestRetrieveSubsetTargetsFromResult() { ResultsCache cache = new ResultsCache(); BuildRequest request = new BuildRequest(1 /* submissionId */, 0, 1, new string[1] { "testTarget2" }, null, BuildEventContext.Invalid, null); BuildResult result = new BuildResult(request); result.AddResultsForTarget("testTarget", TestUtilities.GetEmptyFailingTargetResult()); result.AddResultsForTarget("testTarget2", TestUtilities.GetEmptySucceedingTargetResult()); cache.AddResult(result); ResultsCacheResponse response = cache.SatisfyRequest(request, new List <string>(), new List <string>(new string[] { "testTarget2" }), new List <string>(new string[] { "testTarget" }), skippedResultsAreOK: false); Assert.Equal(ResultsCacheResponseType.Satisfied, response.Type); Assert.True(AreResultsIdenticalForTarget(result, response.Results, "testTarget2")); Assert.False(response.Results.HasResultsForTarget("testTarget")); Assert.Equal(BuildResultCode.Failure, response.Results.OverallResult); }
//[Fact] public void write_initial_model() { // You need to compile everything before trying to use this var input = new ProjectInput(EngineMode.Batch) { Path = samplesFolder, ProfileFlag = "Safari" }; using (var controller = input.BuildEngine()) { controller.Start().Wait(30.Seconds()); var hierarchy = HierarchyLoader.ReadHierarchy(input.Path.AppendPath("Specs")); var request = new BatchRunRequest { SpecPath = input.SpecPath }; var response = controller.Send(request).AndWaitFor <BatchRunResponse>(); var cache = new ResultsCache(); response.Result.records.Each( x => { var completed = new SpecExecutionCompleted(x.specification.id, x.results, x.specification); cache.Store(completed); }); response.Result.fixtures = controller.LatestSystemRecycled.fixtures; var hierarchyLoaded = new HierarchyLoaded(hierarchy, cache); writeResponse(response.Result); //writeInitialization(initialization); } }
public void TestAddAndRetrieveResultsByConfiguration() { ResultsCache cache = new ResultsCache(); BuildRequest request = new BuildRequest(1 /* submissionId */, 0, 1, new string[1] { "testTarget" }, null, BuildEventContext.Invalid, null); BuildResult result = new BuildResult(request); result.AddResultsForTarget("testTarget", TestUtilities.GetEmptyFailingTargetResult()); cache.AddResult(result); request = new BuildRequest(1 /* submissionId */, 0, 1, new string[1] { "otherTarget" }, null, BuildEventContext.Invalid, null); result = new BuildResult(request); result.AddResultsForTarget("otherTarget", TestUtilities.GetEmptySucceedingTargetResult()); cache.AddResult(result); BuildResult retrievedResult = cache.GetResultsForConfiguration(1); Assert.True(retrievedResult.HasResultsForTarget("testTarget")); Assert.True(retrievedResult.HasResultsForTarget("otherTarget")); }
/// <summary> /// Setup the object /// </summary> public TargetBuilder_Tests() { _commonTests = new Common_Tests(this.GetComponent, true); _tempPath = System.IO.Path.GetTempPath(); _resultsCache = null; }
public void Setup() { this.resultsCache = new ResultsCache(); this.commonTests.Setup(); }
public void TearDown() { this.commonTests.TearDown(); this.resultsCache = null; }
public void Setup() { _resultsCache = new ResultsCache(); _commonTests.Setup(); }
public void TearDown() { _commonTests.TearDown(); _resultsCache = null; }
public void TestConstructor() { ResultsCache cache = new ResultsCache(); }
public void SetUp() { theCache = new ResultsCache(); }
/// <summary> /// Initializes a new instance of the ResultsCacheTestExtension class. /// </summary> /// <param name="resultsCache">Instance of the result cache created by the build manager.</param> internal ResultsCacheTestExtension(ResultsCache resultsCache) : base() { this.ResultsCache = resultsCache; }
public ResultsCacheWithOverride(IResultsCache @override) { _override = @override; CurrentCache = new ResultsCache(); }
public static string SerializeCaches(IConfigCache configCache, IResultsCache resultsCache, string outputCacheFile) { ErrorUtilities.VerifyThrowInternalNull(outputCacheFile, nameof(outputCacheFile)); try { if (string.IsNullOrWhiteSpace(outputCacheFile)) { return(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("EmptyOutputCacheFile")); } var fullPath = FileUtilities.NormalizePath(outputCacheFile); Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); // Use FileStream constructor (File.OpenWrite should not be used as it doesn't reset the length of the file!) using (var fileStream = new FileStream(fullPath, FileMode.Create, FileAccess.Write, FileShare.None)) { var translator = BinaryTranslator.GetWriteTranslator(fileStream); ConfigCache configCacheToSerialize = null; ResultsCache resultsCacheToSerialize = null; switch (configCache) { case ConfigCache asConfigCache: configCacheToSerialize = asConfigCache; break; case ConfigCacheWithOverride configCacheWithOverride: configCacheToSerialize = configCacheWithOverride.CurrentCache; break; default: ErrorUtilities.ThrowInternalErrorUnreachable(); break; } switch (resultsCache) { case ResultsCache asResultsCache: resultsCacheToSerialize = asResultsCache; break; case ResultsCacheWithOverride resultsCacheWithOverride: resultsCacheToSerialize = resultsCacheWithOverride.CurrentCache; break; default: ErrorUtilities.ThrowInternalErrorUnreachable(); break; } translator.Translate(ref configCacheToSerialize); translator.Translate(ref resultsCacheToSerialize); } } catch (Exception e) { return(ResourceUtilities.FormatResourceStringIgnoreCodeAndKeyword("ErrorWritingCacheFile", outputCacheFile, e.Message)); } return(null); }