Esempio n. 1
0
        private void ExpectGraph(GraphReloadResult reloadResult, Pip[] oldPips, string expectedPipIndexesAsString, string expectedEdgesAsString)
        {
            int[] expectedPipIndexes = expectedPipIndexesAsString.Split(',').Select(i => int.Parse(i)).ToArray();
            var   graph = SimpleGraph.Parse(oldPips.Length, expectedEdgesAsString);

            var newPipGraph = reloadResult.PipGraph;
            var newPipTable = newPipGraph.PipTable;
            var newGraph    = newPipGraph.DirectedGraph;

            // check that the new pip table contains expected number of relevant pips
            var allPipTypes = new HashSet <PipType>(oldPips.Select(pip => pip.PipType).Distinct());
            IEnumerable <Pip> newRelevantPips = HydratePipsByType(newPipTable, relevantTypes: allPipTypes);

            Assert.Equal(expectedPipIndexes.Length, newRelevantPips.Count());

            // check that for all expected pips there is a node in the new graph
            XAssert.All(
                expectedPipIndexes,
                idx =>
            {
                Assert.True(newGraph.ContainsNode(oldPips[idx].PipId.ToNodeId()), $"No graph node found for Pip{idx}");
            });

            // check edges
            var newRelevantPipIdValues = new HashSet <uint>(newRelevantPips.Select(pip => pip.PipId.Value));

            XAssert.All(
                expectedPipIndexes,
                idx =>
            {
                var nodeId = oldPips[idx].PipId.ToNodeId();
                var expectedOutgoingEdges = graph
                                            .Edges
                                            .Where(e => e.Src == idx)
                                            .Select(e => oldPips[e.Dest].PipId.ToNodeId().Value)
                                            .OrderBy(v => v)
                                            .ToArray();
                var actualOutgoingEdges = newGraph
                                          .GetOutgoingEdges(nodeId)
                                          .Select(e => e.OtherNode.Value)
                                          .Where(v => newRelevantPipIdValues.Contains(v))
                                          .OrderBy(v => v)
                                          .ToArray();
                XAssert.AreArraysEqual(expectedOutgoingEdges, actualOutgoingEdges, expectedResult: true);
            });

            // check stats
            Assert.Equal(expectedPipIndexes.Length, reloadResult.Stats.NumPipsReloaded);
        }
Esempio n. 2
0
        private Pip[] CreateGraph(int numNodes, string graphAsString)
        {
            // parse edges
            var graph = SimpleGraph.Parse(numNodes, graphAsString);

            // for each node create a single output file
            var outFiles = Enumerable
                           .Range(0, numNodes)
                           .Select(_ => CreateOutputFileArtifact())
                           .ToArray();

            // for each node create a Process pip with a single output file and dependencies according to 'edges'
            var processes = Enumerable
                            .Range(0, numNodes)
                            .Select(procIdx =>
            {
                var dependencies = graph
                                   .Edges
                                   .Where(e => e.Dest == procIdx)
                                   .Select(e => outFiles[e.Src])
                                   .ToArray();
                var processBuilder = new ProcessBuilder();
                var arguments      = SchedulerTestBase.CreateCmdArguments(
                    stringTable: Context.StringTable,
                    dependencies: dependencies,
                    outputs: new[] { outFiles[procIdx] });
                return(processBuilder
                       .WithContext(Context)
                       .WithWorkingDirectory(GetWorkingDirectory())
                       .WithStandardDirectory(GetStandardDirectory())
                       .WithExecutable(CmdExecutable)
                       .WithArguments(arguments)
                       .WithDependencies(dependencies)
                       .WithOutputs(outFiles[procIdx])
                       .WithProvenance(CreateProvenance())
                       .Build());
            })
                            .ToArray();

            // add created processes to PipGraphBuilder
            foreach (var proc in processes)
            {
                PipGraphBuilder.AddProcess(proc);
            }

            // return created processes
            return(processes);
        }