Пример #1
0
        public void ScopeWithCompositeComponent_ScopeNestedWorkspaceWrapperTearDownTest()
        {
            MockProgress progress = new MockProgress();

            string     testExperimentFilepath = System.IO.Path.Combine(AppContext.BaseTestDirectory, "Decision Scope with composite component.teml");
            Experiment experiment             = ExperimentManager.Load(testExperimentFilepath, AppContext.Components);

            using (var dispatcher = ExperimentRunnerHelper.CreateExperimentRunner(experiment, AppContext.WorkspaceInstance, AppContext.Components))
            {
                dispatcher.ExecuteExperiment(progress);
            }

            Assert.AreEqual(3, AppContext.WorkspaceInstance.Units.Count);

            HashSet <string> expectedUnitNames = new HashSet <string>();

            expectedUnitNames.Add("targetArtifacts");
            expectedUnitNames.Add("sourceArtifacts");
            expectedUnitNames.Add("similarityMatrix");

            foreach (WorkspaceUnit unit in AppContext.WorkspaceInstance.Units)
            {
                bool isCorrect = false;
                if (expectedUnitNames.Contains(unit.FriendlyUnitName))
                {
                    isCorrect = true;
                }
                Assert.IsTrue(isCorrect);
            }
        }
Пример #2
0
        public void ScopeNestedWorkspaceWrapperTearDownTest()
        {
            MockProgress progress = new MockProgress();

            Experiment experiment = ExperimentManager.Load("DecisionScopeTest.teml", AppContext.Components);

            using (var dispatcher = ExperimentRunnerHelper.CreateExperimentRunner(experiment, AppContext.WorkspaceInstance, AppContext.Components))
            {
                dispatcher.ExecuteExperiment(progress);
            }

            Assert.AreEqual(2, AppContext.WorkspaceInstance.Units.Count);
            foreach (WorkspaceUnit unit in AppContext.WorkspaceInstance.Units)
            {
                bool isCorrect = false;
                if (unit.FriendlyUnitName.Equals("a") && (int)unit.Data == 1)
                {
                    isCorrect = true;
                }
                else if (unit.FriendlyUnitName.Equals("b") && (int)unit.Data == 7)
                {
                    isCorrect = true;
                }

                Assert.IsTrue(isCorrect);
            }
        }
Пример #3
0
        public void OpenExperimentWithNonExistingCompositeComponentTest()
        {
            // load the experiment to be exported
            string     experimentFilename = System.IO.Path.Combine(AppContext.BaseTestDirectory, "experiment_with_non_existing_composite_component_bug_75.gml");
            Experiment experiment         = ExperimentManager.Load(experimentFilename, AppContext.Components);

            experiment.Settings = AppContext.Settings;

            Assert.IsNotNull(experiment);
            Assert.AreEqual(3, experiment.VertexCount);

            //find the composite component node
            CompositeComponentNode compositeComponentNode = null;

            foreach (ExperimentNode node in experiment.Vertices)
            {
                compositeComponentNode = node as CompositeComponentNode;
                if (compositeComponentNode != null)
                {
                    break;
                }
            }

            Assert.IsNotNull(compositeComponentNode); //if fails composite component node has not been found
            //once found check if it has error
            Assert.IsTrue(compositeComponentNode.HasError);

            //Also try to create ExperimentViewModel for the experiment. Assure that it does not crash
            var experimentViewModel = new TraceLab.UI.WPF.ViewModels.ExperimentViewModel_Accessor(experiment);
        }
Пример #4
0
        public void AddCompositeComponent_Bug77()
        {
            // load the experiment to be exported
            string     experimentFilename = System.IO.Path.Combine(AppContext.BaseTestDirectory, "experiment_to_test_bug77.gml");
            Experiment experiment         = ExperimentManager.Load(experimentFilename, AppContext.Components);

            experiment.Settings = AppContext.Settings;

            //create ExperimentViewModel for the experiment - the crash happen in the experiment view model, so it has to be initialized
            var experimentViewModel = new TraceLab.UI.WPF.ViewModels.ExperimentViewModel_Accessor(experiment);

            CompositeComponentMetadataDefinition compositeComponentDefinition = null;

            //find the composite component to test bug 77
            foreach (MetadataDefinition definition in AppContext.Components.Components)
            {
                if (definition.Classname.Equals("Component to test bug 77"))
                {
                    compositeComponentDefinition = definition as CompositeComponentMetadataDefinition;
                    break;
                }
            }

            //check if definition has been found in library
            Assert.IsNotNull(compositeComponentDefinition);

            Assert.AreEqual(3, experiment.VertexCount);
            ExperimentNode node = ((IEditableExperiment)experiment).AddComponentFromDefinition(compositeComponentDefinition, -5, 5);

            Assert.IsNotNull(node);
            Assert.AreEqual(4, experiment.VertexCount);
            Assert.IsTrue(experiment.IsModified);
        }
Пример #5
0
        public void SaveExperimentTest()
        {
            IExperiment experiment = ExperimentManager.New();

            Assert.IsNotNull(experiment);
            Assert.AreEqual(2, experiment.VertexCount);
            Assert.IsTrue(string.IsNullOrEmpty(experiment.ExperimentInfo.FilePath));

            string filename = System.IO.Path.Combine(AppContext.BaseTestDirectory, "testSave.gml");

            try
            {
                bool success = ExperimentManager.Save(experiment, filename);

                Assert.IsTrue(success);
                Assert.IsTrue(File.Exists(filename));

                IExperiment loadedExperiment = ExperimentManager.Load(filename, AppContext.Components);

                Assert.AreEqual(experiment.ExperimentInfo, loadedExperiment.ExperimentInfo);
            }
            finally
            {
                if (File.Exists(filename))
                {
                    //cleanup
                    File.Delete(filename);
                }
            }
        }
Пример #6
0
        public void ExperimentClone()
        {
            IExperiment loadedExperiment = ExperimentManager.Load(ExperimentFile, AppContext.Components);

            ValidateData(loadedExperiment);

            Experiment clone = (Experiment)((BaseExperiment)loadedExperiment).Clone();

            ValidateData(clone);
            Assert.IsFalse(clone.IsModified);

            Dictionary <string, ExperimentNode> clonedNodes = new Dictionary <string, ExperimentNode>();

            foreach (ExperimentNode clonedNode in clone.Vertices)
            {
                clonedNodes[clonedNode.ID] = clonedNode;
            }

            // Ensure that none of the vertices from the source experiment are in the clone experiment.
            // This checks references, since obviously the clone is supposed to have nodes with the same ID.
            foreach (ExperimentNode node in loadedExperiment.Vertices)
            {
                ExperimentNode clonedNode = null;
                Assert.IsTrue(clonedNodes.TryGetValue(node.ID, out clonedNode));
                Assert.IsFalse(object.ReferenceEquals(node, clonedNode));
                Assert.IsFalse(object.ReferenceEquals(node.Data, clonedNode.Data));
                Assert.IsFalse(object.ReferenceEquals(node.Data.Metadata, clonedNode.Data.Metadata));
            }
        }
Пример #7
0
        public void DefineCompositeComponentBasicTestSelectSubraphWithNoEndAndStart()
        {
            // load the experiment to be exported
            string     experimentFilename = System.IO.Path.Combine(AppContext.BaseTestDirectory, "experiment_define_composite_component_basic_test.teml");
            Experiment experiment         = ExperimentManager.Load(experimentFilename, AppContext.Components);

            experiment.Settings = AppContext.Settings; //assure that we apply global settings

            //select just one node
            foreach (ExperimentNode node in experiment.Vertices)
            {
                if (node.ID == TestImporterID)
                {
                    node.IsSelected = true;
                }
            }

            DefiningCompositeComponentSetup setup = new DefiningCompositeComponentSetup(experiment);

            Assert.IsNotNull(setup);

            Assert.AreEqual(1, setup.InputSettings.Count);
            Assert.AreEqual(1, setup.OutputSettings.Count);
            Assert.AreEqual(0, setup.ConfigSettings.Count);
            Assert.IsTrue(setup.InputSettings["test1"].Include);
            Assert.IsTrue(setup.OutputSettings["test2"].Include);

            //rescan library to be sure it is fresh scan
            int numberOfComponentsInLibrary = GetCountOfComponentsInLibrary();

            //let's export the experiment as composite component
            setup.CompositeComponentLocationFilePath = exportFile;

            Assert.IsFalse(File.Exists(exportFile));
            setup.DefineComponent();

            Assert.IsTrue(File.Exists(exportFile));

            int updatedNumberOfComponents = GetCountOfComponentsInLibrary();

            //after rescan there should be one more component in the library
            Assert.AreEqual(numberOfComponentsInLibrary + 1, updatedNumberOfComponents);

            //iterate through all components until find new composite component
            CompositeComponentMetadataDefinition compositeComponentDefinition = FindCompositeComponent(exportFile);

            //assure that composite component definition has been found
            Assert.IsNotNull(compositeComponentDefinition); //if fails, composite component has not been found

            Assert.AreEqual(setup.Name, compositeComponentDefinition.Label);
            Assert.AreEqual(setup.Description, compositeComponentDefinition.Description);
            Assert.AreEqual(setup.Author, compositeComponentDefinition.Author);
            Assert.IsNotNull(compositeComponentDefinition.ComponentGraph);

            //the number of configuration properties should be the same
            Assert.AreEqual(setup.ConfigSettings.Count, compositeComponentDefinition.ConfigurationWrapperDefinition.Properties.Count);

            Assert.AreEqual(1, compositeComponentDefinition.IOSpecDefinition.Input.Count);  //one input was included
            Assert.AreEqual(1, compositeComponentDefinition.IOSpecDefinition.Output.Count); //one output was included
        }
Пример #8
0
        public void ExperimentLoad()
        {
            IExperiment loadedExperiment = ExperimentManager.Load(ExperimentFile, AppContext.Components);

            Assert.IsNotNull(loadedExperiment);
            ValidateData(loadedExperiment);
            Assert.IsFalse(loadedExperiment.IsModified);
        }
Пример #9
0
        /// <summary>
        /// Loads the test experiment file
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <returns></returns>
        private Experiment LoadExperiment(string filename)
        {
            filename = System.IO.Path.Combine(AppContext.BaseTestDirectory, filename);
            if (System.IO.File.Exists(filename) == false)
            {
                throw new System.IO.FileNotFoundException("Graph file not found", filename);
            }

            Experiment currentExperiment = ExperimentManager.Load(filename, AppContext.Components);

            return(currentExperiment);
        }
Пример #10
0
        public void DefineCompositeComponentSerializeDeserializeTest()
        {
            // load the experiment to be exported
            string     experimentFilename = System.IO.Path.Combine(AppContext.BaseTestDirectory, "Preprocessor.gml");
            Experiment experiment         = ExperimentManager.Load(experimentFilename, AppContext.Components);

            experiment.Settings = AppContext.Settings; //applying these settings was causing the bug #74

            //select all nodes
            foreach (ExperimentNode node in experiment.Vertices)
            {
                node.IsSelected = true;
            }

            DefiningCompositeComponentSetup setup = new DefiningCompositeComponentSetup(experiment);

            setup.CompositeComponentLocationFilePath = exportFile;

            var tmpCompositeComponentDefinition = setup.GenerateCompositeComponentDefinition();

            XmlSerializer serializer = new XmlSerializer(typeof(TraceLab.Core.Components.CompositeComponentMetadataDefinition));

            Assert.IsFalse(File.Exists(exportFile));

            using (TextWriter writer = new StreamWriter(exportFile))
            {
                serializer.Serialize(writer, tmpCompositeComponentDefinition);
                writer.Close();
            }

            //check if file has been created
            Assert.IsTrue(System.IO.File.Exists(exportFile));

            //deserialize the file to CompositeComponentMetadataDefinition
            CompositeComponentMetadataDefinition compositeComponentDefinition;

            using (XmlReader reader = XmlReader.Create(exportFile))
            {
                compositeComponentDefinition = (CompositeComponentMetadataDefinition)serializer.Deserialize(reader);
                compositeComponentDefinition.PostProcessReadXml(AppContext.Components, AppContext.BaseTestDirectory);
            }
            Assert.IsNotNull(compositeComponentDefinition);
            Assert.AreEqual(compositeComponentDefinition.ID, tmpCompositeComponentDefinition.ID);
            Assert.AreEqual(compositeComponentDefinition.Version, tmpCompositeComponentDefinition.Version);
            Assert.AreEqual(compositeComponentDefinition.Classname, tmpCompositeComponentDefinition.Classname); //NAME
            Assert.AreEqual(compositeComponentDefinition.Author, tmpCompositeComponentDefinition.Author);
            Assert.AreEqual(compositeComponentDefinition.Label, tmpCompositeComponentDefinition.Label);
            Assert.AreEqual(compositeComponentDefinition.Description, tmpCompositeComponentDefinition.Description);
            Assert.AreEqual(compositeComponentDefinition.IOSpecDefinition, tmpCompositeComponentDefinition.IOSpecDefinition);
            Assert.AreEqual(compositeComponentDefinition.ConfigurationWrapperDefinition.Properties.Count, tmpCompositeComponentDefinition.ConfigurationWrapperDefinition.Properties.Count);
            Assert.AreEqual(compositeComponentDefinition.ComponentGraph.VertexCount, tmpCompositeComponentDefinition.ComponentGraph.VertexCount);
            Assert.AreEqual(compositeComponentDefinition.ComponentGraph.EdgeCount, tmpCompositeComponentDefinition.ComponentGraph.EdgeCount);
        }
Пример #11
0
 internal void OpenExperiment(string file)
 {
     try
     {
         var experiment = ExperimentManager.Load(file, (TraceLab.Core.Components.ComponentsLibrary)m_viewModel.ComponentLibraryViewModel);
         ApplicationViewModel newApplicationViewModel = ApplicationViewModel.CreateNewApplicationViewModel(m_viewModel, experiment);
         RecentExperimentsHelper.UpdateRecentExperimentList(TraceLab.Core.Settings.Settings.RecentExperimentsPath, file);
         OpenInWindow(newApplicationViewModel);
     }
     catch (TraceLab.Core.Exceptions.ExperimentLoadException ex)
     {
         string msg = String.Format("Unable to open the file {0}. Error: {1}", file, ex.Message);
         NLog.LogManager.GetCurrentClassLogger().ErrorException(msg, ex);
         MessageBox.Show(msg, "Failed to load experiment", MessageBoxButton.OK, MessageBoxImage.Exclamation);
     }
 }
Пример #12
0
        public void PrepareAndRunBenchmarkExperiment()
        {
            Assert.Fail("Test temporarily broken. Ignored till contest feature is going to be revisited.");

            List <Benchmark> benchmarks    = BenchmarkLoader.LoadBenchmarksInfo(BenchmarkDirectory);
            Benchmark        testBenchmark = benchmarks[0];

            // load the experiment to be run against benchmark
            string     experimentFilename        = System.IO.Path.Combine(AppContext.BaseTestDirectory, "experiment_to_be_benchmarked.gml");
            Experiment experimentToBeBenchmarked = ExperimentManager.Load(experimentFilename, AppContext.Components);

            //prepare matching io
            testBenchmark.PrepareMatchingIOByType(experimentToBeBenchmarked);
            Assert.AreEqual(2, testBenchmark.BenchmarkInputSetting.Count);
            Assert.AreEqual(1, testBenchmark.BenchmarkOutputsSetting.Count);

            //match benchmarkSourceArtifact with original source artifacts
            foreach (BenchmarkItemSetting <IOItem> pair in testBenchmark.BenchmarkInputSetting)
            {
                IOItem item = pair.Item;
                ItemSettingCollection candidates = pair.CandidateSettings;
                if (item.MappedTo.Equals("benchmarkSourceArtifacts"))
                {
                    //we found the item we want to remap
                    pair.SelectedSetting = candidates["originalSourceArtifacts"];
                }
            }

            //finally prepare benchmark experiment
            testBenchmark.PrepareBenchmarkExperiment(experimentToBeBenchmarked, AppContext.Components);

            //assert that only two inputs are included in the export settings and one output
            int includedInputs = 0;

            foreach (KeyValuePair <string, ItemSetting> pair in testBenchmark.Setup.InputSettings)
            {
                if (pair.Value.Include == true)
                {
                    includedInputs++;
                }
            }
            Assert.AreEqual(2, includedInputs);

            int includedOutputs = 0;

            foreach (KeyValuePair <string, ItemSetting> pair in testBenchmark.Setup.OutputSettings)
            {
                if (pair.Value.Include == true)
                {
                    includedOutputs++;
                }
            }
            Assert.AreEqual(1, includedOutputs);

            Assert.IsNotNull(testBenchmark.BenchmarkExperiment);

            //for debug output file
            // string path = System.IO.Path.Combine(AppContext.BaseTestDirectory, "benchmarkTest1.gml");
            // AppContext.ExperimentManager.Save(testBenchmark.BenchmarkExperiment, path);

            MockProgress progress = new MockProgress();

            using (var dispatcher = ExperimentRunnerHelper.CreateExperimentRunner(testBenchmark.BenchmarkExperiment, AppContext.WorkspaceInstance, AppContext.Components))
            {
                dispatcher.ExecuteExperiment(progress);
                Assert.AreEqual(7, progress.NumSteps);
                Assert.IsFalse(progress.HasError);
            }
        }
Пример #13
0
        public void DefiningBenchmarkTest()
        {
            Assert.Fail("Test temporarily broken. Ignored till contest feature is going to be revisited.");

            string baseExperimentFilename  = "DefiningBenchmarkTestExperiment.teml";
            string testingSolutionFilename = "DefiningBenchmarkTestingSolution.teml";

            //create temporary directory for defining benchmark
            string benchmarkTemporaryDirectory = System.IO.Path.Combine(AppContext.BaseTestDirectory, "DefiningBenchmarkTest");

            System.IO.Directory.CreateDirectory(benchmarkTemporaryDirectory);

            string newBenchmarkFilePath = System.IO.Path.Combine(benchmarkTemporaryDirectory, "newDefinedBenchmark.tbml");

            //copy the test data into temporary benchmark directory
            string testData = System.IO.Path.Combine(AppContext.BaseTestDirectory, "DefiningBenchmarkTestData.xml");

            System.IO.File.Copy(testData, System.IO.Path.Combine(benchmarkTemporaryDirectory, "DefiningBenchmarkTestData.xml"));

            // load the experiment from which the benchmark is going to be defined from
            string     baseExperimentFilePath             = System.IO.Path.Combine(AppContext.BaseTestDirectory, baseExperimentFilename);
            Experiment baseExperimentForDefiningBenchmark = ExperimentManager.Load(baseExperimentFilePath, AppContext.Components);

            var benchmarkDefiner = new DefiningBenchmark(baseExperimentForDefiningBenchmark, AppContext.Components, AppContext.WorkspaceInstance, AppContext.PackageManager, AppContext.WorkspaceInstance.TypeDirectories, null);

            Assert.AreEqual(1, benchmarkDefiner.TemplatizableComponents.Count);
            Assert.AreEqual("Preprocessor", benchmarkDefiner.TemplatizableComponents[0].Data.Metadata.Label);

            //select preprocessor template as Component Template for benchmarking
            benchmarkDefiner.SelectedTemplateNode = benchmarkDefiner.TemplatizableComponents[0];

            //select new benchmark path
            benchmarkDefiner.BenchmarkInfo.FilePath = newBenchmarkFilePath;

            //set some values for benchmark info
            string   benchmarkName    = "Testing defining new benchmark";
            string   author           = "Re test author";
            string   contributors     = "Re test contributors";
            string   description      = "Re test description";
            string   shortDescription = "Re test short description";
            DateTime deadline         = DateTime.Now;
            string   fakeExperimentResultsUnitname = "fakeunitname";
            string   webpageLink = "test://test.webpage.link";

            benchmarkDefiner.BenchmarkInfo.Name                      = benchmarkName;
            benchmarkDefiner.BenchmarkInfo.Author                    = author;
            benchmarkDefiner.BenchmarkInfo.Contributors              = contributors;
            benchmarkDefiner.BenchmarkInfo.Description               = description;
            benchmarkDefiner.BenchmarkInfo.ShortDescription          = shortDescription;
            benchmarkDefiner.BenchmarkInfo.Deadline                  = deadline;
            benchmarkDefiner.BenchmarkInfo.ExperimentResultsUnitname = fakeExperimentResultsUnitname;
            benchmarkDefiner.BenchmarkInfo.WebPageLink               = new Uri(webpageLink);

            //assure file does not exists prior defining
            Assert.IsFalse(System.IO.File.Exists(benchmarkDefiner.BenchmarkInfo.FilePath));

            //set some mock experiment results as baseline
            TraceLabSDK.Types.Contests.TLExperimentResults fakeBaseline = CreateDummyExperimentResults("FAKE-BASELINE");

            benchmarkDefiner.SelectedExperimentResults = fakeBaseline;

            //call define benchmark
            benchmarkDefiner.Define();

            //check if new benchmark has been created
            Assert.IsTrue(System.IO.File.Exists(benchmarkDefiner.BenchmarkInfo.FilePath));

            //load newly defined benchmark
            List <Benchmark> benchmarks    = BenchmarkLoader.LoadBenchmarksInfo(benchmarkTemporaryDirectory);
            Benchmark        testBenchmark = benchmarks[0]; //there should be only 1, since the directory has been just created

            //check if new test benchmark has previously defined properties
            Assert.AreEqual(benchmarkName, testBenchmark.BenchmarkInfo.Name);
            Assert.AreEqual(author, testBenchmark.BenchmarkInfo.Author);
            Assert.AreEqual(contributors, testBenchmark.BenchmarkInfo.Contributors);
            Assert.AreEqual(description, testBenchmark.BenchmarkInfo.Description);
            Assert.AreEqual(shortDescription, testBenchmark.BenchmarkInfo.ShortDescription);
            Assert.AreEqual(deadline.ToString(), testBenchmark.BenchmarkInfo.Deadline.ToString());
            Assert.AreEqual(fakeExperimentResultsUnitname, testBenchmark.BenchmarkInfo.ExperimentResultsUnitname);

            //check if baseline results has been saved properly, by loading it from xml
            TraceLabSDK.Types.Contests.TLExperimentResults baseline = BenchmarkLoader.ReadBaseline(benchmarkDefiner.BenchmarkInfo.FilePath);
            Assert.AreEqual(fakeBaseline.TechniqueName, baseline.TechniqueName);
            Assert.AreEqual(fakeBaseline.Score, baseline.Score);
            Assert.AreEqual(fakeBaseline.AcrossAllDatasetsResults, baseline.AcrossAllDatasetsResults);
            Assert.IsTrue(fakeBaseline.DatasetsResults.SequenceEqual(baseline.DatasetsResults));

            // load the experiment to be run against new defined benchmark
            string     experimentFilename        = System.IO.Path.Combine(AppContext.BaseTestDirectory, testingSolutionFilename);
            Experiment testingSolutionExperiment = ExperimentManager.Load(experimentFilename, AppContext.Components);

            //finally prepare benchmark experiment
            testBenchmark.PrepareBenchmarkExperiment(testingSolutionExperiment, AppContext.Components);

            //run benchmark
            MockProgress progress = new MockProgress();

            using (var dispatcher = CreateExperiment(testBenchmark.BenchmarkExperiment, AppContext.WorkspaceInstance, AppContext.Components))
            {
                dispatcher.ExecuteExperiment(progress);
                Assert.AreEqual(5, progress.NumSteps);
                Assert.IsFalse(progress.HasError);
            }
        }
Пример #14
0
 public void ExperimentLoadNull()
 {
     IExperiment loadedExperiment = ExperimentManager.Load(null, AppContext.Components);
 }
Пример #15
0
 public void ExperimentLoadStructureCorruptedFile()
 {
     string      filename         = System.IO.Path.Combine(AppContext.BaseTestDirectory, "tracingGraphStructureCorrupted.teml");
     IExperiment loadedExperiment = ExperimentManager.Load(filename, AppContext.Components);
 }
Пример #16
0
        public void DefineCompositeComponentFromExperimentWithAnotherCompositeComponentTest()
        {
            // load the experiment to be exported
            string     experimentFilename = System.IO.Path.Combine(AppContext.BaseTestDirectory, "experiment_with_composite_component.teml");
            Experiment experiment         = ExperimentManager.Load(experimentFilename, AppContext.Components);

            experiment.Settings = AppContext.Settings; //applying these settings was causing the bug #74

            //select all nodes
            foreach (ExperimentNode node in experiment.Vertices)
            {
                node.IsSelected = true;
            }

            DefiningCompositeComponentSetup setup = new DefiningCompositeComponentSetup(experiment);

            Assert.IsNotNull(experiment);
            Assert.AreEqual(3, experiment.VertexCount);
            Assert.IsNotNull(setup);

            Assert.AreEqual(0, setup.InputSettings.Count);
            Assert.AreEqual(2, setup.OutputSettings.Count);
            Assert.AreEqual(2, setup.ConfigSettings.Count);

            //check if default name is the same as experiment info
            Assert.IsTrue(setup.OutputSettings["test_x"].Include);
            Assert.IsTrue(setup.OutputSettings["test_y"].Include);
            Assert.IsTrue(setup.ConfigSettings["Composite Component Test writer Value"].Include);
            Assert.IsTrue(setup.ConfigSettings["Composite Component Test writer Value 2"].Include);

            //get real names of the config values
            string configName1 = setup.ConfigSettings["Composite Component Test writer Value"].PropertyObject.Name;
            string configName2 = setup.ConfigSettings["Composite Component Test writer Value 2"].PropertyObject.Name;

            //change settings to sth different values
            setup.Name        = "Complex Composite Component";
            setup.Author      = "Author XYZ";
            setup.Description = "Complex Composite Component to test export";

            //don't include following in the export
            setup.OutputSettings["test_y"].Include = false;

            //change alias
            setup.ConfigSettings["Composite Component Test writer Value"].Alias     = "Config 1";
            setup.ConfigSettings["Composite Component Test writer Value 2"].Alias   = "Config 2";
            setup.ConfigSettings["Composite Component Test writer Value 2"].Include = false;

            //rescan library to be sure it is fresh scan
            int numberOfComponentsInLibrary = GetCountOfComponentsInLibrary();

            //let's export the experiment as composite component
            Assert.IsFalse(File.Exists(exportFile));
            setup.CompositeComponentLocationFilePath = exportFile;

            setup.DefineComponent();

            Assert.IsTrue(File.Exists(exportFile));

            //rescan the library
            int updatedNumberOfComponents = GetCountOfComponentsInLibrary();

            //after rescan there should be one more component in the library
            Assert.AreEqual(numberOfComponentsInLibrary + 1, updatedNumberOfComponents);

            //iterate through all components until find new composite component
            CompositeComponentMetadataDefinition compositeComponentDefinition = FindCompositeComponent(exportFile);

            //assure that composite component definition has been found
            Assert.IsNotNull(compositeComponentDefinition); //if fails, composite component has not been found

            Assert.AreEqual(setup.Name, compositeComponentDefinition.Label);
            Assert.AreEqual(setup.Description, compositeComponentDefinition.Description);
            Assert.AreEqual(setup.Author, compositeComponentDefinition.Author);
            Assert.IsNotNull(compositeComponentDefinition.ComponentGraph);

            //the number of configuration properties should be the same
            Assert.AreEqual(setup.ConfigSettings.Count, compositeComponentDefinition.ConfigurationWrapperDefinition.Properties.Count);

            ConfigPropertyObject config1 = compositeComponentDefinition.ConfigurationWrapperDefinition.Properties[configName1];
            ConfigPropertyObject config2 = compositeComponentDefinition.ConfigurationWrapperDefinition.Properties[configName2];

            Assert.AreEqual("Config 1", config1.DisplayName);
            Assert.AreEqual("Config 2", config2.DisplayName);

            Assert.IsTrue(config1.Visible);
            Assert.IsFalse(config2.Visible);                                                //config1 should not be visible, because Include was set to false

            Assert.AreEqual(0, compositeComponentDefinition.IOSpecDefinition.Input.Count);  //none input value were included
            Assert.AreEqual(1, compositeComponentDefinition.IOSpecDefinition.Output.Count); //one output value was included
        }
Пример #17
0
 public void ExperimentLoadEmpty()
 {
     IExperiment loadedExperiment = ExperimentManager.Load(string.Empty, AppContext.Components);
 }
Пример #18
0
        public void DefineCompositeComponentBasicTestSelectAllNodes()
        {
            // load the experiment to be exported
            string     experimentFilename = System.IO.Path.Combine(AppContext.BaseTestDirectory, "experiment_define_composite_component_basic_test.teml");
            Experiment experiment         = ExperimentManager.Load(experimentFilename, AppContext.Components);

            experiment.Settings = AppContext.Settings; //assure that we apply global settings

            //in first basic test select all nodes
            foreach (ExperimentNode node in experiment.Vertices)
            {
                node.IsSelected = true;
            }

            DefiningCompositeComponentSetup setup = new DefiningCompositeComponentSetup(experiment);

            Assert.IsNotNull(setup);

            Assert.AreEqual(1, setup.InputSettings.Count);
            Assert.AreEqual(2, setup.OutputSettings.Count);
            Assert.AreEqual(1, setup.ConfigSettings.Count);

            Assert.IsTrue(setup.InputSettings["test1"].Include);
            Assert.IsTrue(setup.OutputSettings["test1"].Include);
            Assert.IsTrue(setup.OutputSettings["test2"].Include);

            //note, if there are two components with the same label and same config name, the expected behaviour is to add
            Assert.IsTrue(setup.ConfigSettings["Test writer Value"].Include);

            //get real names of the config values
            string configName1 = setup.ConfigSettings["Test writer Value"].PropertyObject.Name;

            //change settings to sth different values
            setup.Name        = "Test Composite Component";
            setup.Author      = "Author XYZ";
            setup.Description = "Composite Component to test export";

            //don't include following in the export
            setup.InputSettings["test1"].Include  = false;
            setup.OutputSettings["test1"].Include = false;

            //rescan library to be sure it is fresh scan
            int numberOfComponentsInLibrary = GetCountOfComponentsInLibrary();

            //set file path to composite component
            setup.CompositeComponentLocationFilePath = exportFile;
            Assert.IsFalse(File.Exists(setup.CompositeComponentLocationFilePath));

            setup.DefineComponent();

            Assert.IsTrue(File.Exists(exportFile));

            //rescan the library
            int updatedNumberOfComponents = GetCountOfComponentsInLibrary();

            //after rescan there should be one more component in the library
            Assert.AreEqual(numberOfComponentsInLibrary + 1, updatedNumberOfComponents);

            //iterate through all components until find new composite component
            CompositeComponentMetadataDefinition compositeComponentDefinition = FindCompositeComponent(exportFile);

            //assure that composite component definition has been found
            Assert.IsNotNull(compositeComponentDefinition); //if fails, composite component has not been found

            Assert.AreEqual(setup.Name, compositeComponentDefinition.Label);
            Assert.AreEqual(setup.Description, compositeComponentDefinition.Description);
            Assert.AreEqual(setup.Author, compositeComponentDefinition.Author);
            Assert.IsNotNull(compositeComponentDefinition.ComponentGraph);

            //the number of configuration properties should be the same
            Assert.AreEqual(setup.ConfigSettings.Count, compositeComponentDefinition.ConfigurationWrapperDefinition.Properties.Count);

            ConfigPropertyObject config1 = compositeComponentDefinition.ConfigurationWrapperDefinition.Properties[configName1];

            Assert.AreEqual("Test writer Value", config1.DisplayName);

            Assert.IsTrue(config1.Visible);                                                 //config1 should  be visible, because Include was set to false

            Assert.AreEqual(0, compositeComponentDefinition.IOSpecDefinition.Input.Count);  //no input was included
            Assert.AreEqual(1, compositeComponentDefinition.IOSpecDefinition.Output.Count); //only one output was included
        }
Пример #19
0
        /// <summary>
        /// Prepares the benchmark experiment.
        /// </summary>
        /// <param name="experimentToBeBenchmarked">The experiment to be benchmarked.</param>
        /// <exception cref="TraceLab.Core.Exceptions.ExperimentLoadException">throws if experiment load fails</exception>
        /// <param name="library">The library.</param>
        public void PrepareBenchmarkExperiment(Experiment experimentToBeBenchmarked, ComponentsLibrary library)
        {
            //load benchmark experiment
            Experiment benchmarkExperiment = ExperimentManager.Load(BenchmarkInfo.FilePath, library);

            //update benchmark experiment info, so that it refers to the same benchmark info (LoadExperiment would not read BenchmarkInfo, as it only reads ExperimentInfo)
            benchmarkExperiment.ExperimentInfo = BenchmarkInfo;

            //2. find template node to be replaced
            ExperimentNode templateNode = null;

            foreach (ExperimentNode node in benchmarkExperiment.Vertices)
            {
                if (node.Data.Metadata is ComponentTemplateMetadata)
                {
                    templateNode = node;
                    break;
                }
            }
            if (templateNode == null)
            {
                throw new TraceLab.Core.Exceptions.BenchmarkException("Template node has not been found in the benchmark experiment. The benchmark experiment is corrupted.");
            }

            //3. export current experiment into composite component
            foreach (BenchmarkItemSetting <IOItem> item in BenchmarkInputSetting)
            {
                item.SelectedSetting.Include = true;
            }

            foreach (BenchmarkItemSetting <IOItem> item in BenchmarkOutputsSetting)
            {
                item.SelectedSetting.Include = true;
            }

            //create temporary component source - note it is just a assembly source name file to satisfy Metadata Assembly requirement
            //the file is not going to be created (this is UGLY - do refactoring)
            string tempSource = System.IO.Path.Combine(BenchmarkInfo.FilePath, "temporary");

            m_setup.CompositeComponentLocationFilePath = tempSource;

            CompositeComponentMetadataDefinition definition = m_setup.GenerateCompositeComponentDefinition();

            //4. Replace template node by removing it from graph, adding the new node, and reconnecting new not

            //Add composite component node
            ExperimentNode replacementNode = benchmarkExperiment.AddComponentFromDefinition(definition, templateNode.Data.X, templateNode.Data.Y);

            //connect replacement node to the same outgoing nodes as template node
            foreach (ExperimentNodeConnection nodeConnection in benchmarkExperiment.OutEdges(templateNode))
            {
                benchmarkExperiment.AddConnection(replacementNode, nodeConnection.Target);
            }

            //connect replacement node to the same incoming nodes as template node
            foreach (ExperimentNodeConnection nodeConnection in benchmarkExperiment.InEdges(templateNode))
            {
                benchmarkExperiment.AddConnection(nodeConnection.Source, replacementNode);

                //if the predecessor is a decision node update its decision code so that it matches new label
                FixDecisionCode(templateNode.Data.Metadata.Label, replacementNode.Data.Metadata.Label, nodeConnection.Source as ExperimentDecisionNode);
            }

            //finally remove the template node
            benchmarkExperiment.RemoveVertex(templateNode);

            //now remap io according to settings
            CompositeComponentMetadata compositeComponentDefinition = (CompositeComponentMetadata)replacementNode.Data.Metadata;

            foreach (BenchmarkItemSetting <IOItem> item in BenchmarkInputSetting)
            {
                item.SelectedSetting.Include = true;
                compositeComponentDefinition.IOSpec.Input[item.SelectedSetting.ItemSettingName].MappedTo = item.Item.MappedTo;
            }

            foreach (BenchmarkItemSetting <IOItem> item in BenchmarkOutputsSetting)
            {
                item.SelectedSetting.Include = true;
                compositeComponentDefinition.IOSpec.Output[item.SelectedSetting.ItemSettingName].MappedTo = item.Item.MappedTo;
            }

            BenchmarkExperiment = benchmarkExperiment;
        }