public void TransitiveReduceThreeNodes() { var graph = new DependencyGraph<char>(); graph.AddDependency('a', 'b'); graph.AddDependency('b', 'c'); graph.AddDependency('a', 'c'); graph.TransitiveReduce(); CollectionAssert.AreEqual(new[] { 'a', 'b', 'c' }, graph.Nodes); CollectionAssert.AreEqual(new[] { 'b' }, graph.GetDependenciesForNode('a')); CollectionAssert.AreEqual(new[] { 'c' }, graph.GetDependenciesForNode('b')); }
public void TransitiveReduceCycles() { var graph = new DependencyGraph<char>(); graph.AddDependency('a', 'b'); // a <--> b graph.AddDependency('b', 'a'); graph.AddDependency('a', 'c'); // a --> c graph.AddDependency('b', 'c'); // b --> c graph.TransitiveReduce(); // NOTE result here depends upon order of enumeration from HashSet<char>, making this test potentially fragile CollectionAssert.AreEqual(new[] { 'b' }, graph.GetDependenciesForNode('a')); CollectionAssert.AreEqual(new[] { 'a', 'c' }, graph.GetDependenciesForNode('b')); }
public void AddDependencyTest() { var graph = new DependencyGraph<string>(); graph.AddDependency("A", "B"); CollectionAssert.AreEqual(new[] { "A", "B" }, graph.Nodes); CollectionAssert.AreEqual(new[] { "B" }, graph.GetDependenciesForNode("A")); }
protected override IEnumerable<IComponent> GetComponentsToRun(string action, ComponentRunContext runContext) { var graph = new DependencyGraph<IComponent>(); var prerequisites = new PrerequisitesComponent(mReleaseInfo); var tplComponent = new TemplatesComponent(mReleaseInfo); var reportsComponent = new ReportsComponent(mReleaseInfo); var scriptsComponent = new ScriptsComponent(mReleaseInfo, mDbConnection); graph.AddDependency(prerequisites, tplComponent); graph.AddDependency(prerequisites, reportsComponent); graph.AddDependency(prerequisites, scriptsComponent); graph.AddDependency(tplComponent, scriptsComponent); graph.AddDependency(reportsComponent, scriptsComponent); return graph.GetPath(); }
public void AddDependencyTest() { var graph = new DependencyGraph<string>(); graph.AddDependency("A", "B"); TestHelper.AssertEqualArrays(new[] { "A", "B" }, graph.GetNodes().ToArray()); TestHelper.AssertEqualArrays(new[] { "B" }, graph.GetDependenciesForNode("A").ToArray()); }
public void GenerateDotCommand_ExclusionList() { var graph = new DependencyGraph<string>(); graph.AddDependency("A", "B"); graph.AddDependency("B", "C"); graph.AddDependency("C", "A"); var filterPreferences = new AssemblyFilterPreferences(); filterPreferences.SetAssemblyNames(graph.GetNodes()); filterPreferences.Exclude("C"); var command = new DotCommandBuilder().GenerateDotCommand(graph, filterPreferences); const string expected = @"digraph G { 1 -> 2; 1 [label=""A""]; 2 [label=""B""]; }"; Assertion.AssertEquals(expected, command); }
public void CircularReferences2() { var dependencies = new DependencyGraph<string>(); dependencies.AddDependency("A", "A"); var allNodes = dependencies.Nodes; var startNodes = allNodes.Where(x => !allNodes.Any(y => dependencies.GetDependenciesForNode(y).Contains(x))); var endNodes = allNodes.Where(x => dependencies.GetDependenciesForNode(x).Count() == 0); var circularReferences = CircularReferencesHelper.FindCircularReferences(dependencies, startNodes, endNodes); Assert.IsTrue(circularReferences.Count() > 0); }
public void TransitiveReduceCascade() { var graph = new DependencyGraph<char>(); for (var c1 = 'a'; c1 < 'f'; c1++) for (var c2 = (char)(c1 + 1); c2 < 'f'; c2++) graph.AddDependency(c1, c2); graph.TransitiveReduce(); for (var c = 'a'; c < 'f' - 1; c++) CollectionAssert.AreEqual(new[] { (char)(c + 1) }, graph.GetDependenciesForNode(c), $"Dep of {c} should be {(char)(c+1)}"); }
public void GenerateDotCommand() { var graph = new DependencyGraph<string>(); graph.AddDependency("A", "B"); var filterPreferences = new AssemblyFilterPreferences(); filterPreferences.SetAssemblyNames(graph.Nodes); var command = DotCommandBuilder.Generate(graph, filterPreferences); const string expected = @"digraph G { 1 -> 2; 1 [label=""A""]; 2 [label=""B""]; }"; Assert.AreEqual(expected, command); }
public void Init() { var teamCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://logpmtfs01v:8080/tfs/Logitravel")); var buildServer = teamCollection.GetService<IBuildServer>(); var commonStructureService = teamCollection.GetService<Microsoft.TeamFoundation.Server.ICommonStructureService>(); var buildDefinitionResults = Helpers.QueryBuildDefinitions(commonStructureService, buildServer, buildName: ""); var buildDefinition = buildDefinitionResults.FirstOrDefault().Definitions.FirstOrDefault(bd => bd != null && bd.QueueStatus == DefinitionQueueStatus.Enabled); Graph = new DependencyGraph<ProjectInfo>(); var ti = new TeamCollectionInfo(teamCollection); var bi = new BuildDefinitionInfo(ti, buildDefinition); var si = new SolutionInfo(bi, "S1"); var pA = new ProjectInfo(si) { ProjectGuid = Guid.Empty, GeneratedAssembly = "A", ReferencedProjects = new System.Collections.Generic.HashSet<Guid>() }; var pB = new ProjectInfo(si) { ProjectGuid = Guid.Empty, GeneratedAssembly = "B", ReferencedProjects = new System.Collections.Generic.HashSet<Guid>() }; var pC = new ProjectInfo(si) { ProjectGuid = Guid.Empty, GeneratedAssembly = "C", ReferencedProjects = new System.Collections.Generic.HashSet<Guid>() }; var pD = new ProjectInfo(si) { ProjectGuid = Guid.Empty, GeneratedAssembly = "D", ReferencedProjects = new System.Collections.Generic.HashSet<Guid>() }; var pE = new ProjectInfo(si) { ProjectGuid = Guid.Empty, GeneratedAssembly = "E", ReferencedProjects = new System.Collections.Generic.HashSet<Guid>() }; var pF = new ProjectInfo(si) { ProjectGuid = Guid.Empty, GeneratedAssembly = "F", ReferencedProjects = new System.Collections.Generic.HashSet<Guid>() }; var pG = new ProjectInfo(si) { ProjectGuid = Guid.Empty, GeneratedAssembly = "G", ReferencedProjects = new System.Collections.Generic.HashSet<Guid>() }; var pH = new ProjectInfo(si) { ProjectGuid = Guid.Empty, GeneratedAssembly = "H", ReferencedProjects = new System.Collections.Generic.HashSet<Guid>() }; Graph.Nodes.Add(pA); Graph.Nodes.Add(pB); Graph.Nodes.Add(pC); Graph.Nodes.Add(pD); Graph.Nodes.Add(pE); Graph.Nodes.Add(pF); Graph.Nodes.Add(pG); Graph.Nodes.Add(pH); Graph.AddDependency(pA, pC); Graph.AddDependency(pA, pF); Graph.AddDependency(pA, pD); Graph.AddDependency(pD, pF); Graph.AddDependency(pD, pG); Graph.AddDependency(pB, pD); Graph.AddDependency(pB, pG); Graph.AddDependency(pE, pG); Graph.AddDependency(pG, pF); Graph.AddDependency(pG, pH); }
private IDependencyGraph<BranchInfo> CreateBranchGraph(Configuration config) { var branchesByName = config.Branches.ToDictionary(x => x.Name); var graph = new DependencyGraph<BranchInfo>(); foreach (var branchInfo in config.Branches) { if (branchInfo.Parent != null) { var source = branchesByName[branchInfo.Parent]; var target = branchesByName[branchInfo.Name]; graph.AddDependency(source, target); } else { graph.AddNode(branchesByName[branchInfo.Name]); } } return graph; }
internal DependencyGraph<ProjectInfo> GetProjectsDependencies() { DependencyGraph<ProjectInfo> dependencyGraph = new DependencyGraph<ProjectInfo>(); foreach (TeamCollectionInfo current in this.TeamCollections) { foreach (BuildDefinitionInfo current2 in current.BuildDefinitions) { foreach (SolutionInfo current3 in current2.Solutions) { foreach (ProjectInfo current4 in current3.Projects) { dependencyGraph.Nodes.Add(current4); current4.DependentProjects = new List<ProjectInfo>(); foreach (TeamCollectionInfo current5 in this.TeamCollections) { foreach (BuildDefinitionInfo current6 in current5.BuildDefinitions) { foreach (SolutionInfo current7 in current6.Solutions) { foreach (ProjectInfo current8 in current7.Projects) { if (current8.ReferencedAssemblies.Contains(current4.GeneratedAssembly)) { dependencyGraph.AddDependency(current8, current4); current8.DependentProjects.Add(current4); } } } } } } } } } return dependencyGraph; }
public void StressTest15() { // Dependency graph DependencyGraph t = new DependencyGraph(); // A bunch of strings to use const int SIZE = 800; string[] letters = new string[SIZE]; for (int i = 0; i < SIZE; i++) { letters[i] = ("" + (char)('a' + i)); } // The correct answers HashSet <string>[] dents = new HashSet <string> [SIZE]; HashSet <string>[] dees = new HashSet <string> [SIZE]; for (int i = 0; i < SIZE; i++) { dents[i] = new HashSet <string>(); dees[i] = new HashSet <string>(); } // Add a bunch of dependencies for (int i = 0; i < SIZE; i++) { for (int j = i + 1; j < SIZE; j++) { t.AddDependency(letters[i], letters[j]); dents[i].Add(letters[j]); dees[j].Add(letters[i]); } } // Remove a bunch of dependencies for (int i = 0; i < SIZE; i++) { for (int j = i + 2; j < SIZE; j += 3) { t.RemoveDependency(letters[i], letters[j]); dents[i].Remove(letters[j]); dees[j].Remove(letters[i]); } } // Replace a bunch of dependees for (int i = 0; i < SIZE; i += 2) { HashSet <string> newDees = new HashSet <String>(); for (int j = 0; j < SIZE; j += 9) { newDees.Add(letters[j]); } t.ReplaceDependees(letters[i], newDees); foreach (string s in dees[i]) { dents[s[0] - 'a'].Remove(letters[i]); } foreach (string s in newDees) { dents[s[0] - 'a'].Add(letters[i]); } dees[i] = newDees; } // Make sure everything is right for (int i = 0; i < SIZE; i++) { Assert.IsTrue(dents[i].SetEquals(new HashSet <string>(t.GetDependents(letters[i])))); Assert.IsTrue(dees[i].SetEquals(new HashSet <string>(t.GetDependees(letters[i])))); } }
public void AddToEmpty() { DependencyGraph t = new DependencyGraph(); t.AddDependency("a", "b"); }
public void EmptyTest8() { DependencyGraph t = new DependencyGraph(); t.AddDependency("a", "b"); }
public void SpecTest() { DependencyGraph g = new DependencyGraph(); g.AddDependency("a", "b"); g.AddDependency("a", "c"); g.AddDependency("b", "d"); g.AddDependency("d", "d"); Assert.IsTrue(g.HasDependents("a")); Assert.IsTrue(g.HasDependents("b")); Assert.IsFalse(g.HasDependents("c")); Assert.IsTrue(g.HasDependents("d")); Assert.IsFalse(g.HasDependees("a")); Assert.IsTrue(g.HasDependees("b")); Assert.IsTrue(g.HasDependees("c")); Assert.IsTrue(g.HasDependees("d")); // Test "a" HashSet <string> aDependents = new HashSet <string>(); aDependents.Add("b"); aDependents.Add("c"); HashSet <string> aDependees = new HashSet <string>(); foreach (string aDependent in g.GetDependents("a")) { Assert.IsTrue(aDependents.Remove(aDependent)); } Assert.AreEqual(aDependents.Count, 0); foreach (string aDependee in g.GetDependees("a")) { Assert.IsTrue(aDependees.Remove(aDependee)); } Assert.AreEqual(aDependees.Count, 0); // Test "b" HashSet <string> bDependents = new HashSet <string>(); bDependents.Add("d"); HashSet <string> bDependees = new HashSet <string>(); bDependees.Add("a"); foreach (string bDependent in g.GetDependents("b")) { Assert.IsTrue(bDependents.Remove(bDependent)); } Assert.AreEqual(bDependents.Count, 0); foreach (string bDependee in g.GetDependees("b")) { Assert.IsTrue(bDependees.Remove(bDependee)); } Assert.AreEqual(bDependees.Count, 0); // Test "c" HashSet <string> cDependents = new HashSet <string>(); HashSet <string> cDependees = new HashSet <string>(); cDependees.Add("a"); foreach (string cDependent in g.GetDependents("c")) { Assert.IsTrue(cDependents.Remove(cDependent)); } Assert.AreEqual(cDependents.Count, 0); foreach (string cDependee in g.GetDependees("c")) { Assert.IsTrue(cDependees.Remove(cDependee)); } Assert.AreEqual(cDependees.Count, 0); // Test "d" HashSet <string> dDependents = new HashSet <string>(); dDependents.Add("d"); HashSet <string> dDependees = new HashSet <string>(); dDependees.Add("d"); dDependees.Add("b"); foreach (string dDependent in g.GetDependents("d")) { Assert.IsTrue(dDependents.Remove(dDependent)); } Assert.AreEqual(dDependents.Count, 0); foreach (string dDependee in g.GetDependees("d")) { Assert.IsTrue(dDependees.Remove(dDependee)); } Assert.AreEqual(dDependees.Count, 0); }
public void TestMethod13() { DependencyGraph graph = new DependencyGraph(); graph.AddDependency(null, null); }
public void NullTest1() { DependencyGraph dependencyGraph = new DependencyGraph(); dependencyGraph.AddDependency(null, "1"); }
/// <summary> /// Builds join tuple composer. /// </summary> /// <param name="statementName">Name of the statement.</param> /// <param name="statementId">The statement identifier.</param> /// <param name="outerJoinDescList">list of descriptors for outer join criteria</param> /// <param name="optionalFilterNode">filter tree for analysis to build indexes for fast access</param> /// <param name="streamTypes">types of streams</param> /// <param name="streamNames">names of streams</param> /// <param name="streamJoinAnalysisResult">The stream join analysis result.</param> /// <param name="queryPlanLogging">if set to <c>true</c> [query plan logging].</param> /// <param name="statementContext">The statement context.</param> /// <param name="historicalViewableDesc">The historical viewable desc.</param> /// <param name="exprEvaluatorContext">The expr evaluator context.</param> /// <param name="selectsRemoveStream">if set to <c>true</c> [selects remove stream].</param> /// <param name="hasAggregations">if set to <c>true</c> [has aggregations].</param> /// <param name="tableService">The table service.</param> /// <param name="isOnDemandQuery">if set to <c>true</c> [is on demand query].</param> /// <param name="allowIndexInit">if set to <c>true</c> [allow index initialize].</param> /// <returns> /// composer implementation /// </returns> /// <throws>com.espertech.esper.epl.expression.core.ExprValidationException is thrown to indicate thatvalidation of view use in joins failed. /// {D255958A-8513-4226-94B9-080D98F904A1}</throws> public static JoinSetComposerPrototype MakeComposerPrototype(string statementName, int statementId, OuterJoinDesc[] outerJoinDescList, ExprNode optionalFilterNode, EventType[] streamTypes, string[] streamNames, StreamJoinAnalysisResult streamJoinAnalysisResult, bool queryPlanLogging, StatementContext statementContext, HistoricalViewableDesc historicalViewableDesc, ExprEvaluatorContext exprEvaluatorContext, bool selectsRemoveStream, bool hasAggregations, TableService tableService, bool isOnDemandQuery, bool allowIndexInit) { // Determine if there is a historical stream, and what dependencies exist var historicalDependencyGraph = new DependencyGraph(streamTypes.Length, false); for (var i = 0; i < streamTypes.Length; i++) { if (historicalViewableDesc.Historical[i]) { var streamsThisStreamDependsOn = historicalViewableDesc.DependenciesPerHistorical[i]; historicalDependencyGraph.AddDependency(i, streamsThisStreamDependsOn); } } if (log.IsDebugEnabled) { log.Debug("Dependency graph: " + historicalDependencyGraph); } // Handle a join with a database or other historical data source for 2 streams if ((historicalViewableDesc.HasHistorical) && (streamTypes.Length == 2)) { return(MakeComposerHistorical2Stream(outerJoinDescList, optionalFilterNode, streamTypes, historicalViewableDesc, queryPlanLogging, exprEvaluatorContext, statementContext, streamNames, allowIndexInit)); } var isOuterJoins = !OuterJoinDesc.ConsistsOfAllInnerJoins(outerJoinDescList); // Query graph for graph relationships between streams/historicals // For outer joins the query graph will just contain outer join relationships var hint = ExcludePlanHint.GetHint(streamNames, statementContext); var queryGraph = new QueryGraph(streamTypes.Length, hint, false); if (outerJoinDescList.Length > 0) { OuterJoinAnalyzer.Analyze(outerJoinDescList, queryGraph); if (log.IsDebugEnabled) { log.Debug(".makeComposer After outer join queryGraph=\n" + queryGraph); } } // Let the query graph reflect the where-clause if (optionalFilterNode != null) { // Analyze relationships between streams using the optional filter expression. // Relationships are properties in AND and EQUALS nodes of joins. FilterExprAnalyzer.Analyze(optionalFilterNode, queryGraph, isOuterJoins); if (log.IsDebugEnabled) { log.Debug(".makeComposer After filter expression queryGraph=\n" + queryGraph); } // Add navigation entries based on key and index property equivalency (a=b, b=c follows a=c) QueryGraph.FillEquivalentNav(streamTypes, queryGraph); if (log.IsDebugEnabled) { log.Debug(".makeComposer After fill equiv. nav. queryGraph=\n" + queryGraph); } } // Historical index lists var historicalStreamIndexLists = new HistoricalStreamIndexList[streamTypes.Length]; var queryPlan = QueryPlanBuilder.GetPlan(streamTypes, outerJoinDescList, queryGraph, streamNames, historicalViewableDesc, historicalDependencyGraph, historicalStreamIndexLists, streamJoinAnalysisResult, queryPlanLogging, statementContext.Annotations, exprEvaluatorContext); // remove unused indexes - consider all streams or all unidirectional var usedIndexes = new HashSet <TableLookupIndexReqKey>(); var indexSpecs = queryPlan.IndexSpecs; for (var streamNum = 0; streamNum < queryPlan.ExecNodeSpecs.Length; streamNum++) { var planNode = queryPlan.ExecNodeSpecs[streamNum]; if (planNode != null) { planNode.AddIndexes(usedIndexes); } } foreach (var indexSpec in indexSpecs) { if (indexSpec == null) { continue; } var items = indexSpec.Items; var indexNames = items.Keys.ToArray(); foreach (var indexName in indexNames) { if (!usedIndexes.Contains(indexName)) { items.Remove(indexName); } } } var hook = QueryPlanIndexHookUtil.GetHook(statementContext.Annotations); if (queryPlanLogging && (QueryPlanLog.IsInfoEnabled || hook != null)) { QueryPlanLog.Info("Query plan: " + queryPlan.ToQueryPlan()); if (hook != null) { hook.Join(queryPlan); } } // register index-use references for tables if (!isOnDemandQuery) { foreach (var usedIndex in usedIndexes) { if (usedIndex.TableName != null) { tableService.GetTableMetadata(usedIndex.TableName).AddIndexReference(usedIndex.Name, statementName); } } } var joinRemoveStream = selectsRemoveStream || hasAggregations; return(new JoinSetComposerPrototypeImpl( statementName, statementId, outerJoinDescList, optionalFilterNode, streamTypes, streamNames, streamJoinAnalysisResult, statementContext.Annotations, historicalViewableDesc, exprEvaluatorContext, indexSpecs, queryPlan, historicalStreamIndexLists, joinRemoveStream, isOuterJoins, tableService, statementContext.EventTableIndexService)); }
private static JoinSetComposerPrototype MakeComposerHistorical2Stream(OuterJoinDesc[] outerJoinDescList, ExprNode optionalFilterNode, EventType[] streamTypes, HistoricalViewableDesc historicalViewableDesc, bool queryPlanLogging, ExprEvaluatorContext exprEvaluatorContext, StatementContext statementContext, string[] streamNames, bool allowIndexInit) { var polledViewNum = 0; var streamViewNum = 1; if (historicalViewableDesc.Historical[1]) { streamViewNum = 0; polledViewNum = 1; } // if all-historical join, check dependency var isAllHistoricalNoSubordinate = false; if ((historicalViewableDesc.Historical[0]) && historicalViewableDesc.Historical[1]) { var graph = new DependencyGraph(2, false); graph.AddDependency(0, historicalViewableDesc.DependenciesPerHistorical[0]); graph.AddDependency(1, historicalViewableDesc.DependenciesPerHistorical[1]); if (graph.FirstCircularDependency != null) { throw new ExprValidationException("Circular dependency detected between historical streams"); } // if both streams are independent if (graph.RootNodes.Count == 2) { isAllHistoricalNoSubordinate = true; // No parameters used by either historical } else { if ((graph.GetDependenciesForStream(0).Count == 0)) { streamViewNum = 0; polledViewNum = 1; } else { streamViewNum = 1; polledViewNum = 0; } } } // Build an outer join expression node var isOuterJoin = false; var isInnerJoinOnly = false; ExprNode outerJoinEqualsNode = null; if (outerJoinDescList.Length > 0) { var outerJoinDesc = outerJoinDescList[0]; isInnerJoinOnly = outerJoinDesc.OuterJoinType == OuterJoinType.INNER; if (outerJoinDesc.OuterJoinType.Equals(OuterJoinType.FULL)) { isOuterJoin = true; } else if ((outerJoinDesc.OuterJoinType.Equals(OuterJoinType.LEFT)) && (streamViewNum == 0)) { isOuterJoin = true; } else if ((outerJoinDesc.OuterJoinType.Equals(OuterJoinType.RIGHT)) && (streamViewNum == 1)) { isOuterJoin = true; } outerJoinEqualsNode = outerJoinDesc.MakeExprNode(exprEvaluatorContext); } // Determine filter for indexing purposes ExprNode filterForIndexing = null; if ((outerJoinEqualsNode != null) && (optionalFilterNode != null) && isInnerJoinOnly) // both filter and outer join, add { filterForIndexing = new ExprAndNodeImpl(); filterForIndexing.AddChildNode(optionalFilterNode); filterForIndexing.AddChildNode(outerJoinEqualsNode); } else if ((outerJoinEqualsNode == null) && (optionalFilterNode != null)) { filterForIndexing = optionalFilterNode; } else if (outerJoinEqualsNode != null) { filterForIndexing = outerJoinEqualsNode; } var indexStrategies = DetermineIndexing(filterForIndexing, streamTypes[polledViewNum], streamTypes[streamViewNum], polledViewNum, streamViewNum, statementContext, streamNames); var hook = QueryPlanIndexHookUtil.GetHook(statementContext.Annotations); if (queryPlanLogging && (QueryPlanLog.IsInfoEnabled || hook != null)) { QueryPlanLog.Info("historical lookup strategy: " + indexStrategies.First.ToQueryPlan()); QueryPlanLog.Info("historical index strategy: " + indexStrategies.Second.ToQueryPlan()); if (hook != null) { hook.Historical(new QueryPlanIndexDescHistorical(indexStrategies.First.GetType().Name, indexStrategies.Second.GetType().Name)); } } return(new JoinSetComposerPrototypeHistorical2StreamImpl( optionalFilterNode, streamTypes, exprEvaluatorContext, polledViewNum, streamViewNum, isOuterJoin, outerJoinEqualsNode, indexStrategies, isAllHistoricalNoSubordinate, outerJoinDescList, allowIndexInit)); }
public void CircularReferences3() { var dependencies = new DependencyGraph<string>(); dependencies.AddDependency("1", "2"); dependencies.AddDependency("1", "3"); dependencies.AddDependency("3", "2"); dependencies.AddDependency("3", "10"); dependencies.AddDependency("3", "1"); dependencies.AddDependency("4", "2"); dependencies.AddDependency("4", "3"); dependencies.AddDependency("4", "1"); dependencies.AddDependency("5", "3"); dependencies.AddDependency("5", "2"); dependencies.AddDependency("6", "2"); dependencies.AddDependency("7", "2"); dependencies.AddDependency("8", "2"); dependencies.AddDependency("8", "8"); dependencies.AddDependency("9", "2"); dependencies.AddDependency("9", "3"); dependencies.AddDependency("10", "2"); dependencies.AddDependency("11", "2"); dependencies.AddDependency("12", "2"); var allNodes = dependencies.Nodes; var startNodes = allNodes.Where(x => !allNodes.Any(y => dependencies.GetDependenciesForNode(y).Contains(x))); var endNodes = allNodes.Where(x => dependencies.GetDependenciesForNode(x).Count() == 0); var circularReferences = CircularReferencesHelper.FindCircularReferences(dependencies, startNodes, endNodes); Assert.IsTrue(circularReferences.Count() == 1); Assert.IsTrue(circularReferences[0][0] == "1"); Assert.IsTrue(circularReferences[0][1] == ""); }
public void ComplexTest() { DependencyGraph t = new DependencyGraph(); t.AddDependency("a", "a"); t.AddDependency("a", "b"); t.AddDependency("a", "c"); t.AddDependency("a", "d"); t.AddDependency("b", "a"); t.AddDependency("b", "c"); t.AddDependency("b", "d"); t.AddDependency("c", "c"); t.AddDependency("c", "d"); t.AddDependency("c", "e"); t.AddDependency("d", "a"); t.AddDependency("d", "b"); t.AddDependency("d", "c"); t.AddDependency("d", "k"); t.AddDependency("f", "a"); t.AddDependency("g", "a"); t.AddDependency("x", "g"); HashSet <string> newDependents = new HashSet <string>() { "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; HashSet <string> newDependees = new HashSet <string>() { "a", "b", "c", "d", "e", "f", "g", "h", "i" }; t.ReplaceDependents("d", newDependents); t.ReplaceDependents("f", newDependents); t.ReplaceDependents("g", newDependents); t.ReplaceDependees("g", newDependees); HashSet <String> aDents = new HashSet <string>() { "a", "b", "c", "d", "g" }; HashSet <String> bDents = new HashSet <string>() { "a", "c", "d", "g" }; HashSet <String> cDents = new HashSet <string>() { "c", "d", "e", "g" }; HashSet <string> dDents = new HashSet <string>() { "g", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; HashSet <string> gDents = new HashSet <string>() { "g", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; HashSet <string> gDees = new HashSet <string>() { "a", "b", "c", "d", "e", "f", "g", "h", "i" }; HashSet <string> kDees = new HashSet <string>() { "d", "f", "g" }; HashSet <string> aDees = new HashSet <string>() { "a", "b" }; Assert.IsTrue(aDents.SetEquals(t.GetDependents("a"))); Assert.IsTrue(bDents.SetEquals(t.GetDependents("b"))); Assert.IsTrue(cDents.SetEquals(t.GetDependents("c"))); Assert.IsTrue(dDents.SetEquals(t.GetDependents("d"))); Assert.IsTrue(gDents.SetEquals(t.GetDependents("g"))); Assert.IsTrue(gDees.SetEquals(t.GetDependees("g"))); Assert.IsTrue(kDees.SetEquals(t.GetDependees("k"))); Assert.IsTrue(aDees.SetEquals(t.GetDependees("a"))); }
public void ABunchOfTiming() { DependencyGraph dg = new DependencyGraph(); List <String> cellList = GetListOfCells(1, 26, 1, 200); //A1:Z200 Random r = new Random(); Stopwatch stopWatch = new Stopwatch(); TimeSpan t = stopWatch.Elapsed; //add 50,000 for (int i = 0; i < 50000; i++) { int first = r.Next(0, 1299); int second = r.Next(0, 1299); if (cellList[first] != cellList[second]) { String s = ("(" + cellList[first] + "), (" + cellList[second] + ")"); dg.AddDependency(cellList[first], cellList[second]); } } //Add known value dg.AddDependency("Z8", "A5"); dg.AddDependency("Z8", "A6"); dg.AddDependency("Z8", "A7"); dg.AddDependency("Z9", "A7"); dg.AddDependency("Z10", "A7"); //add 50,000 more while (dg.Size <= 100000) { //add 50,000 more(if they don't exist) int first = r.Next(0, 1299); int second = r.Next(0, 1299); if (cellList[first] != cellList[second]) { String s = ("(" + cellList[first] + "), (" + cellList[second] + ")"); dg.AddDependency(cellList[first], cellList[second]); } } //Test removing stopWatch.Start(); dg.RemoveDependency("Z8", "A5"); stopWatch.Stop(); double elapsed = t.Milliseconds; Assert.IsTrue(elapsed < 1000); //Test Getting dependents stopWatch = new Stopwatch(); t = stopWatch.Elapsed; stopWatch.Start(); var nl = dg.GetDependents("Z8"); stopWatch.Stop(); elapsed = t.Milliseconds; Assert.IsTrue(elapsed < 1000); //Test replacing dependants stopWatch = new Stopwatch(); t = stopWatch.Elapsed; stopWatch.Start(); dg.ReplaceDependees("A3", nl); stopWatch.Stop(); elapsed = t.Milliseconds; Assert.IsTrue(elapsed < 1000); //Test Getting dependees stopWatch = new Stopwatch(); t = stopWatch.Elapsed; stopWatch.Start(); nl = dg.GetDependees("A7"); stopWatch.Stop(); elapsed = t.Milliseconds; Assert.IsTrue(elapsed < 1000); //Test replacing dependees stopWatch = new Stopwatch(); t = stopWatch.Elapsed; stopWatch.Start(); dg.ReplaceDependees("A7", nl); stopWatch.Stop(); elapsed = t.Milliseconds; Assert.IsTrue(elapsed < 1000); }
public void NullTest() { DependencyGraph t = new DependencyGraph(); t.AddDependency("", ""); }
public void NullTest2() { DependencyGraph test = new DependencyGraph(); test.AddDependency(null, null); }
public void SizeTest3() { DependencyGraph t = new DependencyGraph(); t.AddDependency("b", "a"); t.AddDependency("c", "a"); t.AddDependency("d", "a"); t.AddDependency("e", "a"); t.AddDependency("g", "a"); t.AddDependency("j", "a"); t.AddDependency("t", "a"); t.AddDependency("z", "a"); t.AddDependency("u", "a"); t.AddDependency("i", "a"); t.AddDependency("m", "a"); t.AddDependency("q", "a"); t.ReplaceDependees("a", new HashSet <string>() { "t", "u" }); Assert.AreEqual(2, t.Size); }
private void UndeployAllInternal(UndeploymentOptions options) { if (options == null) { options = new UndeploymentOptions(); } var deploymentSvc = _services.DeploymentLifecycleService; var deployments = _services.DeploymentLifecycleService.DeploymentIds; if (deployments.Length == 0) { return; } if (deployments.Length == 1) { Undeploy(deployments[0]); return; } if (deployments.Length == 2) { var zero = deploymentSvc.GetDeploymentById(deployments[0]); var zeroDependsOn = zero.DeploymentIdDependencies; if (zeroDependsOn != null && zeroDependsOn.Length > 0) { Undeploy(deployments[0]); Undeploy(deployments[1]); } else { Undeploy(deployments[1]); Undeploy(deployments[0]); } return; } // build map of deployment-to-index var deploymentIndexes = new Dictionary <string, int>(); var count = 0; foreach (var deployment in deployments) { deploymentIndexes.Put(deployment, count++); } var graph = new DependencyGraph(deployments.Length, false); foreach (var deploymentId in deployments) { var deployment = deploymentSvc.GetDeploymentById(deploymentId); var dependentOn = deployment.DeploymentIdDependencies; if (dependentOn == null || dependentOn.Length == 0) { continue; } foreach (var target in dependentOn) { int fromIndex = deploymentIndexes.Get(deploymentId); int targetIndex = deploymentIndexes.Get(target); graph.AddDependency(targetIndex, fromIndex); } } var undeployed = new HashSet <string>(); foreach (var rootIndex in graph.RootNodes) { RecursiveUndeploy(rootIndex, deployments, graph, undeployed, options); } }
public void NullTest2() { DependencyGraph dependencyGraph = new DependencyGraph(); dependencyGraph.AddDependency("A", null); }
public void StressTest() { // Dependency graph DependencyGraph t = new DependencyGraph(); // A bunch of strings to use const int SIZE = 400; string[] letters = new string[SIZE]; for (int i = 0; i < SIZE; i++) { letters[i] = ("" + (char)('a' + i)); } // The correct answers HashSet <string>[] dents = new HashSet <string> [SIZE]; HashSet <string>[] dees = new HashSet <string> [SIZE]; for (int i = 0; i < SIZE; i++) { dents[i] = new HashSet <string>(); dees[i] = new HashSet <string>(); } // Add a bunch of dependencies for (int i = 0; i < SIZE; i++) { for (int j = i + 1; j < SIZE; j++) { t.AddDependency(letters[i], letters[j]); dents[i].Add(letters[j]); dees[j].Add(letters[i]); } } // Remove a bunch of dependencies for (int i = 0; i < SIZE; i++) { for (int j = i + 4; j < SIZE; j += 4) { t.RemoveDependency(letters[i], letters[j]); dents[i].Remove(letters[j]); dees[j].Remove(letters[i]); } } // Add some back for (int i = 0; i < SIZE; i++) { for (int j = i + 1; j < SIZE; j += 2) { t.AddDependency(letters[i], letters[j]); dents[i].Add(letters[j]); dees[j].Add(letters[i]); } } // Remove some more for (int i = 0; i < SIZE; i += 2) { for (int j = i + 3; j < SIZE; j += 3) { t.RemoveDependency(letters[i], letters[j]); dents[i].Remove(letters[j]); dees[j].Remove(letters[i]); } } // Make sure everything is right for (int i = 0; i < SIZE; i++) { Assert.IsTrue(dents[i].SetEquals(new HashSet <string>(t.GetDependents(letters[i])))); Assert.IsTrue(dees[i].SetEquals(new HashSet <string>(t.GetDependees(letters[i])))); } }
public void NullTest8() { DependencyGraph d = new DependencyGraph(); d.AddDependency("test", null); }
public void NullException1() { DependencyGraph G = new DependencyGraph(); G.AddDependency("a", null); }
public DeploymentOrder GetDeploymentOrder(ICollection <Module> modules, DeploymentOrderOptions options) { using (_iLock.Acquire()) { if (options == null) { options = new DeploymentOrderOptions(); } var deployments = _deploymentStateService.Deployments; var proposedModules = new List <Module>(); proposedModules.AddAll(modules); ICollection <String> availableModuleNames = new HashSet <String>(); foreach (var proposedModule in proposedModules) { if (proposedModule.Name != null) { availableModuleNames.Add(proposedModule.Name); } } // Collect all uses-dependencies of existing modules IDictionary <String, ICollection <String> > usesPerModuleName = new Dictionary <String, ICollection <String> >(); foreach (var deployment in deployments) { var info = _deploymentStateService.GetDeployment(deployment); if (info == null) { continue; } if ((info.Module.Name == null) || (info.Module.Uses == null)) { continue; } var usesSet = usesPerModuleName.Get(info.Module.Name); if (usesSet == null) { usesSet = new HashSet <String>(); usesPerModuleName.Put(info.Module.Name, usesSet); } usesSet.AddAll(info.Module.Uses); } // Collect uses-dependencies of proposed modules foreach (var proposedModule in proposedModules) { // check uses-dependency is available if (options.IsCheckUses) { if (proposedModule.Uses != null) { foreach (var uses in proposedModule.Uses) { if (availableModuleNames.Contains(uses)) { continue; } if (IsDeployed(uses)) { continue; } var message = "Module-dependency not found"; if (proposedModule.Name != null) { message += " as declared by module '" + proposedModule.Name + "'"; } message += " for uses-declaration '" + uses + "'"; throw new DeploymentOrderException(message); } } } if ((proposedModule.Name == null) || (proposedModule.Uses == null)) { continue; } var usesSet = usesPerModuleName.Get(proposedModule.Name); if (usesSet == null) { usesSet = new HashSet <String>(); usesPerModuleName.Put(proposedModule.Name, usesSet); } usesSet.AddAll(proposedModule.Uses); } var proposedModuleNames = new HashMap <String, SortedSet <int> >(); var count = 0; foreach (var proposedModule in proposedModules) { var moduleNumbers = proposedModuleNames.Get(proposedModule.Name); if (moduleNumbers == null) { moduleNumbers = new SortedSet <int>(); proposedModuleNames.Put(proposedModule.Name, moduleNumbers); } moduleNumbers.Add(count); count++; } var graph = new DependencyGraph(proposedModules.Count, false); var fromModule = 0; foreach (var proposedModule in proposedModules) { if ((proposedModule.Uses == null) || (proposedModule.Uses.IsEmpty())) { fromModule++; continue; } var dependentModuleNumbers = new SortedSet <int>(); foreach (var use in proposedModule.Uses) { var moduleNumbers = proposedModuleNames.Get(use); if (moduleNumbers == null) { continue; } dependentModuleNumbers.AddAll(moduleNumbers); } dependentModuleNumbers.Remove(fromModule); graph.AddDependency(fromModule, dependentModuleNumbers); fromModule++; } if (options.IsCheckCircularDependency) { var circular = graph.FirstCircularDependency; if (circular != null) { var message = ""; var delimiter = ""; foreach (var i in circular) { message += delimiter; message += "module '" + proposedModules[i].Name + "'"; delimiter = " uses (depends on) "; } throw new DeploymentOrderException( "Circular dependency detected in module uses-relationships: " + message); } } var reverseDeployList = new List <Module>(); var ignoreList = new HashSet <int>(); while (ignoreList.Count < proposedModules.Count) { // seconardy sort according to the order of listing ICollection <int> rootNodes = new SortedSet <int>( new StandardComparer <int>((o1, o2) => - 1 * o1.CompareTo(o2))); rootNodes.AddAll(graph.GetRootNodes(ignoreList)); if (rootNodes.IsEmpty()) { // circular dependency could cause this for (var i = 0; i < proposedModules.Count; i++) { if (!ignoreList.Contains(i)) { rootNodes.Add(i); break; } } } foreach (var root in rootNodes) { ignoreList.Add(root); reverseDeployList.Add(proposedModules[root]); } } reverseDeployList.Reverse(); return(new DeploymentOrder(reverseDeployList)); } }
public void MyTest() { DependencyGraph t = new DependencyGraph(); t.AddDependency("a", "b"); t.AddDependency("a", "c"); t.AddDependency("b", "d"); t.AddDependency("d", "d"); Assert.IsTrue(t.GetDependents("a").ToHashSet().SetEquals(new HashSet <string>() { "b", "c" })); Assert.IsTrue(t.GetDependents("b").ToHashSet().SetEquals(new HashSet <string>() { "d" })); Assert.IsTrue(t.GetDependents("c").ToHashSet().SetEquals(new HashSet <string>() { })); Assert.IsTrue(t.GetDependents("d").ToHashSet().SetEquals(new HashSet <string>() { "d" })); Assert.IsTrue(t.GetDependees("a").ToHashSet().SetEquals(new HashSet <string>() { })); Assert.IsTrue(t.GetDependees("b").ToHashSet().SetEquals(new HashSet <string>() { "a" })); Assert.AreEqual(1, t["b"]); Assert.IsTrue(t.GetDependees("c").ToHashSet().SetEquals(new HashSet <string>() { "a" })); Assert.IsTrue(t.GetDependees("d").ToHashSet().SetEquals(new HashSet <string>() { "b", "d" })); Assert.AreEqual(2, t["d"]); Assert.AreEqual(0, t["h"]); Assert.AreEqual(0, t["a"]); Assert.IsFalse(t.HasDependees("a")); Assert.IsFalse(t.HasDependees("f")); Assert.IsFalse(t.HasDependents("c")); Assert.IsTrue(t.HasDependents("a")); Assert.IsFalse(t.HasDependents("h")); Assert.IsTrue(t.HasDependents("d")); Assert.IsTrue(t.HasDependees("b")); Assert.IsTrue(t.HasDependees("c")); Assert.IsTrue(t.HasDependees("d")); Assert.AreEqual(4, t.Size); t.RemoveDependency("a", "b"); Assert.IsTrue(t.GetDependents("a").ToHashSet().SetEquals(new HashSet <string>() { "c" })); Assert.IsTrue(t.GetDependees("b").ToHashSet().SetEquals(new HashSet <string>() { })); t.AddDependency("a", "b"); t.AddDependency("a", "b"); t.ReplaceDependents("a", new HashSet <string>() { "x", "y", "x", "y", "z" }); Assert.IsTrue(t.GetDependents("a").ToHashSet().SetEquals(new HashSet <string>() { "x", "y", "z" })); Assert.AreEqual(5, t.Size); t.ReplaceDependees("b", new HashSet <string>() { "x", "y", "x", "y" }); Assert.IsTrue(t.GetDependees("b").ToHashSet().SetEquals(new HashSet <string>() { "x", "y" })); Assert.AreEqual(7, t.Size); Assert.AreEqual(2, t["b"]); //Assert.AreEqual(4, t.Size); }
public void StressTest15() { // Dependency graph var graph = new DependencyGraph(); // A bunch of strings to use const int size = 100; var letters = new string[size]; for (var i = 0; i < size; i++) { letters[i] = ("" + (char)('a' + i)); } // The correct answers var dents = new HashSet <string> [size]; var dees = new HashSet <string> [size]; for (var i = 0; i < size; i++) { dents[i] = new HashSet <string>(); dees[i] = new HashSet <string>(); } // Add a bunch of dependencies for (var i = 0; i < size; i++) { for (var j = i + 1; j < size; j++) { graph.AddDependency(letters[i], letters[j]); dents[i].Add(letters[j]); dees[j].Add(letters[i]); } } // Remove a bunch of dependencies for (var i = 0; i < size; i++) { for (var j = i + 2; j < size; j += 2) { graph.RemoveDependency(letters[i], letters[j]); dents[i].Remove(letters[j]); dees[j].Remove(letters[i]); } } // Replace a bunch of dependees for (var i = 0; i < size; i += 4) { var newDees = new HashSet <string>(); for (var j = 0; j < size; j += 7) { newDees.Add(letters[j]); } graph.ReplaceDependees(letters[i], newDees); foreach (var s in dees[i]) { dents[s[0] - 'a'].Remove(letters[i]); } foreach (var s in newDees) { dents[s[0] - 'a'].Add(letters[i]); } dees[i] = newDees; } // Make sure everything is right for (var i = 0; i < size; i++) { Assert.IsTrue(dents[i].SetEquals(new HashSet <string>(graph.GetDependents(letters[i])))); Assert.IsTrue(dees[i].SetEquals(new HashSet <string>(graph.GetDependees(letters[i])))); } }
public void EqualDependents() { DependencyGraph t = new DependencyGraph(); t.AddDependency("a", "a"); t.AddDependency("a", "b"); t.AddDependency("a", "c"); t.AddDependency("a", "d"); t.AddDependency("a", "e"); t.AddDependency("a", "f"); t.AddDependency("a", "g"); t.AddDependency("b", "a"); t.AddDependency("b", "b"); t.AddDependency("b", "c"); t.AddDependency("b", "d"); t.AddDependency("b", "e"); t.AddDependency("b", "f"); t.AddDependency("b", "g"); HashSet <String> aDents = new HashSet <String>(t.GetDependents("a")); HashSet <String> bDents = new HashSet <String>(t.GetDependents("b")); Assert.IsTrue(aDents.Count == bDents.Count); }
public void StressTestCombinedLargeSize() { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); // Dependency graph DependencyGraph t = new DependencyGraph(); // A bunch of strings to use const int SIZE = 2000; string[] letters = new string[SIZE]; for (int i = 0; i < SIZE; i++) { letters[i] = ("" + (char)('a' + i)); } // The correct answers HashSet <string>[] dents = new HashSet <string> [SIZE]; HashSet <string>[] dees = new HashSet <string> [SIZE]; for (int i = 0; i < SIZE; i++) { dents[i] = new HashSet <string>(); dees[i] = new HashSet <string>(); } // Add a bunch of dependencies for (int i = 0; i < SIZE; i++) { for (int j = i + 1; j < SIZE; j++) { t.AddDependency(letters[i], letters[j]); dents[i].Add(letters[j]); dees[j].Add(letters[i]); } } // Remove a bunch of dependencies for (int i = 0; i < SIZE; i++) { for (int j = i + 2; j < SIZE; j += 2) { t.RemoveDependency(letters[i], letters[j]); dents[i].Remove(letters[j]); dees[j].Remove(letters[i]); } } // Replace a bunch of dependents for (int i = 0; i < SIZE; i += 4) { HashSet <string> newDents = new HashSet <String>(); for (int j = 0; j < SIZE; j += 7) { newDents.Add(letters[j]); } t.ReplaceDependents(letters[i], newDents); foreach (string s in dents[i]) { dees[s[0] - 'a'].Remove(letters[i]); } foreach (string s in newDents) { dees[s[0] - 'a'].Add(letters[i]); } dents[i] = newDents; } // Replace a bunch of dependees for (int i = 0; i < SIZE; i += 4) { HashSet <string> newDees = new HashSet <String>(); for (int j = 0; j < SIZE; j += 7) { newDees.Add(letters[j]); } t.ReplaceDependees(letters[i], newDees); foreach (string s in dees[i]) { dents[s[0] - 'a'].Remove(letters[i]); } foreach (string s in newDees) { dents[s[0] - 'a'].Add(letters[i]); } dees[i] = newDees; } // Make sure everything is right for (int i = 0; i < SIZE; i++) { Assert.IsTrue(dents[i].SetEquals(new HashSet <string>(t.GetDependents(letters[i])))); Assert.IsTrue(dees[i].SetEquals(new HashSet <string>(t.GetDependees(letters[i])))); } stopWatch.Stop(); TimeSpan time = stopWatch.Elapsed; Assert.IsTrue(time.Seconds < 10); }
public void EqualDependees() { DependencyGraph t = new DependencyGraph(); t.AddDependency("a", "a"); t.AddDependency("a", "b"); t.AddDependency("a", "c"); t.AddDependency("a", "d"); t.AddDependency("a", "e"); t.AddDependency("a", "f"); t.AddDependency("a", "g"); t.AddDependency("b", "a"); t.AddDependency("b", "b"); t.AddDependency("b", "c"); t.AddDependency("b", "d"); t.AddDependency("b", "e"); t.AddDependency("b", "f"); t.AddDependency("b", "g"); HashSet <String> aDees = new HashSet <String>(t.GetDependees("a")); HashSet <String> bDees = new HashSet <String>(t.GetDependees("b")); HashSet <String> cDees = new HashSet <String>(t.GetDependees("c")); HashSet <String> dDees = new HashSet <String>(t.GetDependees("d")); HashSet <String> eDees = new HashSet <String>(t.GetDependees("e")); HashSet <String> fDees = new HashSet <String>(t.GetDependees("f")); HashSet <String> gDees = new HashSet <String>(t.GetDependees("g")); Assert.IsTrue(aDees.Count == 2); Assert.IsTrue(bDees.Count == 2); Assert.IsTrue(cDees.Count == 2); Assert.IsTrue(dDees.Count == 2); Assert.IsTrue(eDees.Count == 2); Assert.IsTrue(fDees.Count == 2); Assert.IsTrue(gDees.Count == 2); }
public void TestMethod13() { DependencyGraph dg = new DependencyGraph(); dg.AddDependency(null, "b"); }
public void TestSize3() { DependencyGraph t = new DependencyGraph(); t.AddDependency("a", "a"); t.AddDependency("a", "b"); t.AddDependency("a", "c"); t.AddDependency("a", "d"); t.AddDependency("f", "d"); t.AddDependency("e", "c"); t.AddDependency("r", "m"); t.AddDependency("a", "d"); t.AddDependency("a", "d"); t.AddDependency("m", "r"); t.AddDependency("m", "r"); t.AddDependency("m", "r"); t.AddDependency("e", "c"); t.AddDependency("m", "r"); t.RemoveDependency("m", "r"); t.RemoveDependency("a", "b"); t.RemoveDependency("a", "b"); Assert.AreEqual(6, t.Size); }
public void NullTest7() { DependencyGraph d = new DependencyGraph(); d.AddDependency(null, null); }
public void TestMethod3() { DependencyGraph dg = new DependencyGraph(); dg.AddDependency("a", "b"); }
public void Null1() { DependencyGraph d = new DependencyGraph(); d.AddDependency("a", null); }
public void TestMethod6() { DependencyGraph dg = new DependencyGraph(); dg.AddDependency("a", null); }