예제 #1
0
        public void ToDeploymentModel_WithoutDependencies_Returns_Correctly()
        {
            var aFeature = new Feature(new FeatureIdentifier("a"), "a", new[]
            {
                new Property(new PropertyIdentifier("p1"), "p1")
            }
                                       );

            var bFeature = new Feature(new FeatureIdentifier("b"), "b", new[]
            {
                new Property(new PropertyIdentifier("p2"), "p2")
            }
                                       );

            var featureModel = new FeatureModel(new[] { aFeature, bFeature }, Enumerable.Empty <PropertyRelation>());

            var genes = new[]
            {
                new DeploymentGene(new FeatureIdentifier("a"), new MicroserviceIdentifier("a")),
                new DeploymentGene(new FeatureIdentifier("b"), new MicroserviceIdentifier("b"))
            };
            var sot = new DeploymentChromosome(featureModel, genes);

            var deploymentModel = new DeploymentModel(featureModel, new[]
            {
                new Microservice(new[] { new FeatureInstance(aFeature, new[] { new PropertyIdentifier("p1") }) }),
                new Microservice(new[] { new FeatureInstance(bFeature, new[] { new PropertyIdentifier("p2") }) }),
            });

            Assert.AreEqual(deploymentModel, sot.ToDeploymentModel());
        }
예제 #2
0
        public void ToDeploymentModel_WithRecursiveDependenciesInSingleMicroservice_Returns_Correctly()
        {
            var aFeature = new Feature(new FeatureIdentifier("a"), "a", new[]
            {
                new Property(new PropertyIdentifier("p1"), "p1"),
                new Property(new PropertyIdentifier("p2"), "p2")
            }
                                       );

            var bFeature = new Feature(new FeatureIdentifier("b"), "b", new[]
            {
                new Property(new PropertyIdentifier("p3"), "p3"),
                new Property(new PropertyIdentifier("p4"), "p4")
            }
                                       );

            var cFeature = new Feature(new FeatureIdentifier("c"), "c", new[]
            {
                new Property(new PropertyIdentifier("p5"), "p5"),
                new Property(new PropertyIdentifier("p6"), "p6"),
                new Property(new PropertyIdentifier("p7"), "p7")
            }
                                       );

            var featureModel = new FeatureModel(new[] { aFeature, bFeature, cFeature }, new[]
            {
                new PropertyRelation(new PropertyIdentifier("p6"), new PropertyIdentifier("p4")),
                new PropertyRelation(new PropertyIdentifier("p4"), new PropertyIdentifier("p2"))
            });

            var genes = new[]
            {
                new DeploymentGene(new FeatureIdentifier("a"), new MicroserviceIdentifier("a")),
                new DeploymentGene(new FeatureIdentifier("b"), new MicroserviceIdentifier("b")),
                new DeploymentGene(new FeatureIdentifier("c"), new MicroserviceIdentifier("c"))
            };

            var sot = new DeploymentChromosome(featureModel, genes);

            var deploymentModel = new DeploymentModel(featureModel, new[]
            {
                new Microservice(new[]
                {
                    new FeatureInstance(aFeature, new[] { new PropertyIdentifier("p1"), new PropertyIdentifier("p2") }),
                }),
                new Microservice(new []
                {
                    new FeatureInstance(aFeature, new[] { new PropertyIdentifier("p2") }, true),
                    new FeatureInstance(bFeature, new[] { new PropertyIdentifier("p3"), new PropertyIdentifier("p4") })
                }),
                new Microservice(new []
                {
                    new FeatureInstance(cFeature, new[] { new PropertyIdentifier("p5"), new PropertyIdentifier("p6"), new PropertyIdentifier("p7") }),
                    new FeatureInstance(bFeature, new[] { new PropertyIdentifier("p4") }, true),
                    new FeatureInstance(aFeature, new[] { new PropertyIdentifier("p2") }, true)
                }),
            });

            Assert.AreEqual(deploymentModel, sot.ToDeploymentModel());
        }
        public void Cross_WithMultipleGene_Returns_Correctly()
        {
            var featureModel = new FeatureModel(Enumerable.Empty <Feature>(), Enumerable.Empty <PropertyRelation>());
            var chromosome   = new DeploymentChromosome(featureModel, new[]
            {
                new DeploymentGene(new FeatureIdentifier("a"), new MicroserviceIdentifier("a")),
                new DeploymentGene(new FeatureIdentifier("b"), new MicroserviceIdentifier("b")),
                new DeploymentGene(new FeatureIdentifier("c"), new MicroserviceIdentifier("c")),
            });

            var randomProvider = A.Fake <IRandomProvider>();

            A.CallTo(() => randomProvider.GetRandom(0, 0)).WithAnyArguments().ReturnsNextFromSequence(0, 1, 0, 1);
            var sot    = new MergeMicroserviceCrossover(randomProvider);
            var result = sot.Cross(new[] { chromosome, chromosome }).ToArray();

            var expected = new DeploymentChromosome(featureModel, new[]
            {
                new DeploymentGene(new FeatureIdentifier("a"), new MicroserviceIdentifier("a")),
                new DeploymentGene(new FeatureIdentifier("b"), new MicroserviceIdentifier("a")),
                new DeploymentGene(new FeatureIdentifier("c"), new MicroserviceIdentifier("c")),
            });

            CollectionAssert.AreEqual(new[] { expected, expected }, result);
        }
예제 #4
0
        public void Reinsert_WithLargeEnoughOffspring_Returns_NewPopulationWithOffspring()
        {
            var deployment    = new DeploymentChromosome(A.Fake <FeatureModel>(), Enumerable.Empty <IDeploymentGene>());
            var deployments   = Enumerable.Repeat(deployment, 20);
            var oldPopulation = new Population(Enumerable.Empty <IDeploymentChromosome>(), 20, 40);
            var offspring     = deployments;
            var sot           = new EliteReinsertion();
            var result        = sot.Reinsert(offspring, oldPopulation);

            Assert.AreEqual(deployments, result.Deployments);
        }
예제 #5
0
        public void ToString_Returns_NonEmptyString()
        {
            var featureModel = A.Fake <FeatureModel>();
            var genes        = new[]
            {
                new DeploymentGene(new FeatureIdentifier("a"), new MicroserviceIdentifier("a")),
                new DeploymentGene(new FeatureIdentifier("b"), new MicroserviceIdentifier("b"))
            };
            var sot = new DeploymentChromosome(featureModel, genes);

            Assert.False(string.IsNullOrEmpty(sot.ToString()));
        }
예제 #6
0
        public void GetGene_Returns_CorrectGene()
        {
            var featureModel = A.Fake <FeatureModel>();
            var genes        = new[]
            {
                new DeploymentGene(new FeatureIdentifier("a"), new MicroserviceIdentifier("a")),
                new DeploymentGene(new FeatureIdentifier("b"), new MicroserviceIdentifier("b"))
            };
            var sot = new DeploymentChromosome(featureModel, genes);

            Assert.AreEqual(genes[0], sot.GetGene(new FeatureIdentifier("a")));
        }
예제 #7
0
        public void UpdateGene_ToSameMicroservice_Returns_SameDeployment()
        {
            var featureModel = A.Fake <FeatureModel>();
            var genes        = new[]
            {
                new DeploymentGene(new FeatureIdentifier("a"), new MicroserviceIdentifier("a")),
                new DeploymentGene(new FeatureIdentifier("b"), new MicroserviceIdentifier("b"))
            };
            var sot = new DeploymentChromosome(featureModel, genes);

            sot = (DeploymentChromosome)sot.UpdateGene(genes[0]);
            Assert.AreEqual(genes[0], sot.GetGene(new FeatureIdentifier("a")));
        }
예제 #8
0
        public void Constructor_Sets_Fields_Correctly()
        {
            var featureModel = A.Fake <FeatureModel>();
            var genes        = new[]
            {
                new DeploymentGene(new FeatureIdentifier("a"), new MicroserviceIdentifier("a")),
                new DeploymentGene(new FeatureIdentifier("b"), new MicroserviceIdentifier("b"))
            };
            var sot = new DeploymentChromosome(featureModel, genes);

            Assert.AreEqual(featureModel, sot.FeatureModel);
            Assert.AreEqual(genes, sot.Genes);
            Assert.AreEqual(null, sot.Fitness);
        }
예제 #9
0
        public void Fitness_Is_Settable()
        {
            var featureModel = A.Fake <FeatureModel>();
            var genes        = new[]
            {
                new DeploymentGene(new FeatureIdentifier("a"), new MicroserviceIdentifier("a")),
                new DeploymentGene(new FeatureIdentifier("b"), new MicroserviceIdentifier("b"))
            };
            var sot = new DeploymentChromosome(featureModel, genes)
            {
                Fitness = 1
            };

            Assert.AreEqual(1, sot.Fitness);
        }
예제 #10
0
        public void GetHashCode_Returns_Same_ForIdenticalDeployment()
        {
            var featureModel = A.Fake <FeatureModel>();
            var genes        = new[]
            {
                new DeploymentGene(new FeatureIdentifier("a"), new MicroserviceIdentifier("a")),
                new DeploymentGene(new FeatureIdentifier("b"), new MicroserviceIdentifier("b"))
            };
            var sot = new DeploymentChromosome(featureModel, genes);

            var sameFeatureModel = A.Fake <FeatureModel>();
            var samegenes        = new[]
            {
                new DeploymentGene(new FeatureIdentifier("a"), new MicroserviceIdentifier("a")),
                new DeploymentGene(new FeatureIdentifier("b"), new MicroserviceIdentifier("b"))
            };
            var same = new DeploymentChromosome(featureModel, genes);

            Assert.AreEqual(sot.GetHashCode(), same.GetHashCode());
        }
        public void Cross_WithSingleGene_Returns_SameChromosome()
        {
            var featureModel = new FeatureModel(new[]
            {
                new Feature(
                    new FeatureIdentifier("a"),
                    "a",
                    new[] { new Property(new PropertyIdentifier("p1"), "p1") }
                    )
            }, Enumerable.Empty <PropertyRelation>());
            var deploymentGenes = featureModel.Features.Select(f => new DeploymentGene(f.Id, new MicroserviceIdentifier(f.Id.Id))).ToArray();
            var chromosome      = new DeploymentChromosome(featureModel, deploymentGenes);

            var randomProvider = A.Fake <IRandomProvider>();

            A.CallTo(() => randomProvider.GetRandom()).Returns(0);
            var sot    = new MergeMicroserviceCrossover(randomProvider);
            var result = sot.Cross(new[] { chromosome, chromosome }).ToArray();

            CollectionAssert.AreEqual(new[] { chromosome, chromosome }, result);
        }
예제 #12
0
            public IEnumerator <TestCaseData> GetEnumerator()
            {
                var featureModel = new FeatureModel(new[]
                {
                    new Feature(new FeatureIdentifier("a"), "a", new[]
                    {
                        new Property(new PropertyIdentifier("p1"), "p1")
                    })
                }, Enumerable.Empty <PropertyRelation>());
                var gene1 = new DeploymentGene(new FeatureIdentifier("a"), new MicroserviceIdentifier("b"));
                var gene2 = new DeploymentGene(new FeatureIdentifier("b"), new MicroserviceIdentifier("b"));

                var chromosome = new DeploymentChromosome(featureModel, new[] { gene1, gene2 });

                var same = new DeploymentChromosome(featureModel, new[] { gene1, gene2 });

                yield return(new TestCaseData(chromosome, chromosome).Returns(true));

                yield return(new TestCaseData(chromosome, same).Returns(true));

                yield return(new TestCaseData(chromosome, null).Returns(false));

                yield return(new TestCaseData(chromosome, 3).Returns(false));
            }
예제 #13
0
        public void Mutate_Operates_Correctly()
        {
            var featureModel = new FeatureModel(Enumerable.Empty <Feature>(), Enumerable.Empty <PropertyRelation>());
            var chromosome   = new DeploymentChromosome(featureModel, new[]
            {
                new DeploymentGene(new FeatureIdentifier("a"), new MicroserviceIdentifier("a")),
                new DeploymentGene(new FeatureIdentifier("b"), new MicroserviceIdentifier("a")),
                new DeploymentGene(new FeatureIdentifier("c"), new MicroserviceIdentifier("a")),
            });

            var randomProvider = A.Fake <IRandomProvider>();

            A.CallTo(() => randomProvider.GetRandom(0, 0)).WithAnyArguments().ReturnsNextFromSequence(1, 0, 0);
            var sot      = new ScatterMicroserviceMutation(randomProvider);
            var result   = sot.Mutate(chromosome);
            var expected = new DeploymentChromosome(featureModel, new[]
            {
                new DeploymentGene(new FeatureIdentifier("a"), new MicroserviceIdentifier("a")),
                new DeploymentGene(new FeatureIdentifier("b"), new MicroserviceIdentifier("b")),
                new DeploymentGene(new FeatureIdentifier("c"), new MicroserviceIdentifier("b")),
            });

            Assert.AreEqual(expected, result);
        }
예제 #14
0
 public bool Equals_Returns_Correctly(DeploymentChromosome chromosome, object other)
 {
     return(chromosome.Equals(other));
 }