public void shouldAddChildNodesToNode()
        {
            ExecutionNode node = ExecutionNode.CreateLevelOneNode(1);

            node.AddChild(100);
            Assert.AreEqual(1, node.Children.Count(), "Number of children");

            node.AddChild(1);
            node.AddChild(1);
            Assert.AreEqual(3, node.Children.Count(), "Number of children");
            foreach (var item in node.Children)
            {
                Assert.That(item.Level, Is.GreaterThan(1));
                Console.WriteLine(item.Level);

                for (int i = 0; i < 3; i++)
                {
                    item.AddChild(1);
                }

                foreach (var child in item.Children)
                {
                    Assert.That(item.Level, Is.LessThan(child.Level));
                }
            }
        }
        public void shouldProduceUniqueIdentitiesForEachNodeAdded()
        {
            ExecutionNode node  = ExecutionNode.CreateLevelOneNode(1);
            var           node2 = node.AddChild(1);
            var           node3 = node2.AddChild(1);
            var           node4 = node2.AddChild(1);
            var           node5 = node.AddChild(1);

            Assert.That(node, Is.Not.EqualTo(node2));
            Assert.That(node3, Is.Not.EqualTo(node2));
            Assert.That(node4, Is.Not.EqualTo(node2));
            Assert.That(node5, Is.Not.EqualTo(node));

            Assert.That(node, Is.EqualTo(node));
            Assert.That(node2, Is.EqualTo(node2));
        }
        public void ShouldAddParentNodeToNode()
        {
            ExecutionNode root     = ExecutionNode.CreateLevelOneNode(1, "Root");
            var           customer = root.AddChild(1, "Customer");
            var           order    = customer.AddChild(10, "Order");

            string expected =
                @"-Customer
--Order";

            Assert.That(customer.getDebugString(), Is.EqualTo(expected));

            order.AddParent(1, "CustomerGroup");
            expected =
                @"Root
-Customer
--CustomerGroup
---Order";
            Assert.That(root.getDebugString(), Is.EqualTo(expected));
            customer.AddParent(1, "Country");
            expected =
                @"Root
-Country
--Customer
---CustomerGroup
----Order";
            Assert.That(root.getDebugString(), Is.EqualTo(expected));
        }
Esempio n. 4
0
        public void ShouldReturnTablesInCorrectOrder()
        {
            // Scenario: Make 2 customers, for each customer make two accounts and do one deposit and one withdraw for each account
            string[] requestedOrder = { "Customer", "Account", "Deposit", "Withdraw", "Account", "Deposit", "Withdraw",
                                        "Customer", "Account", "Deposit", "Withdraw", "Account", "Deposit", "Withdraw", };

            // 2 Customers
            ExecutionNode customer = ExecutionNode.CreateLevelOneNode(2, "Customer");

            customer.AddTable(new TableEntity("dbo", "Customer"));

            // Make 2 accounts
            var accounts = customer.AddChild(2, "Accounts");

            accounts.AddTable(new TableEntity("dbo", "Account"));

            // make one one Deposit and one WithDraw
            var accountTransactions = accounts.AddChild(1, "AccountTransactions");

            accountTransactions.AddTable(new TableEntity("dbo", "Deposit"));
            accountTransactions.AddTable(new TableEntity("dbo", "Withdraw"));


            NodeIterator it = new NodeIterator(customer);

            var actual =
                new List <TableEntity>(it.GetTablesRecursive().Select(x => x.Table));

            for (int i = 0; i < requestedOrder.Length; i++)
            {
                Console.WriteLine(actual[i].TableName);
                Assert.That(requestedOrder[i], Is.EqualTo(actual[i].TableName));
            }
        }
        public void shouldIncreaseTheLevelOfEachChild()
        {
            ExecutionNode node  = ExecutionNode.CreateLevelOneNode(1);
            var           node2 = node.AddChild(100);
            var           node3 = node2.AddChild(24);

            var node4 = node.AddChild(1);

            Assert.That(node2.Level, Is.GreaterThan(node.Level));
            Assert.That(node2.Level, Is.EqualTo(node.Level + 1));

            Assert.That(node3.Level, Is.GreaterThan(node2.Level));
            Assert.That(node3.Level, Is.EqualTo(node2.Level + 1));

            Assert.That(node4.Level, Is.GreaterThan(node.Level));
            Assert.That(node4.Level, Is.EqualTo(node.Level + 1));
        }
 public void AddChildNode(ExecutionNode nodeToManipulate)
 {
     if (nodeToManipulate != null)
     {
         var newNode = nodeToManipulate.AddChild(1);
         _projectViewModel.SelectedExecutionNode = newNode;
     }
 }
        public void ShouldNotBeAbleToRemoveRootNode()
        {
            ExecutionNode root     = ExecutionNode.CreateLevelOneNode(1, "Root");
            var           customer = root.AddChild(1, "Customer");

            var someNode = root.RemoveNode();

            Assert.That(someNode, Is.EqualTo(root));
        }
 private static ExecutionNode BuildReleaseNode(RunContext context, ReleaseConfig release)
 {
     var node = new ExecutionNode(string.Format("Begin release {0}", release.Name), string.Format("End release {0}", release.Name));
     foreach (var feature in release.Features)
     {
         node.AddChild(BuildFeatureNode(context, feature));
     }
     return node;
 }
        public void ShouldNotBeAbleToMergeRootNodeWithParent()
        {
            ExecutionNode root     = ExecutionNode.CreateLevelOneNode(1, "Root");
            var           customer = root.AddChild(1, "Customer").AddTable(new TableEntity("dbo", "Customer"));

            var merged = root.MergeWithParent();

            Assert.That(merged, Is.EqualTo(root));
            Assert.That(merged.Tables, Is.Empty);
        }
        public void ShouldHaveParentIfItIsChild()
        {
            ExecutionNode root = ExecutionNode.CreateLevelOneNode(1);

            Assert.That(root.HasChildren, Is.False);

            var child = root.AddChild(1);

            Assert.That(root.HasChildren, Is.True);
            Assert.That(child.Parent, Is.EqualTo(root));
        }
        public void ShouldRemoveNode()
        {
            ExecutionNode root     = ExecutionNode.CreateLevelOneNode(1, "Root");
            var           customer = root.AddChild(1, "Customer");
            var           order    = customer.AddChild(10, "Order");
            var           recall   = order.AddChild(1, "Recall");

            var someNode = order.RemoveNode();

            Assert.That(someNode, Is.EqualTo(customer), "When removing a node, the parent node should be returned");
            Assert.That(customer.Children.Contains(order), Is.Not.True);
        }
        public void ShouldNotBeAbleToAddParentToRoot()
        {
            ExecutionNode root     = ExecutionNode.CreateLevelOneNode(1, "Root");
            var           customer = root.AddChild(1, "Customer");
            var           order    = customer.AddChild(10, "Order");

            string beforeAddingParent = root.getDebugString();

            var returnNode = root.AddParent(1, "Nono");

            Assert.That(returnNode, Is.EqualTo(root));
            Assert.That(root.getDebugString(), Is.EqualTo(beforeAddingParent));
        }
        public void ShouldCreateDebugString()
        {
            ExecutionNode root     = ExecutionNode.CreateLevelOneNode(1, "Root");
            var           customer = root.AddChild(1, "Customer");
            var           order    = customer.AddChild(10, "Order");

            root.AddChild(1, "Invoice");

            string expected =
                @"Root
-Customer
--Order
-Invoice";
            string actual = root.getDebugString();

            Console.WriteLine("{" + actual + "}");
            Console.WriteLine("{" + expected + "}");

            Assert.That(actual, Is.EqualTo(expected));
            Assert.That(order.getDebugString(), Is.EqualTo("--Order"));

            Assert.That(customer.getDebugString(), Is.EqualTo("-Customer" + Environment.NewLine + "--Order"));
        }
        private static ExecutionNode BuildFeatureNode(string featureName, DeployContext context)
        {
            FeatureConfig feature;
            if (!context.FeaturesConfig.TryGet(featureName, out feature))
                throw new SoftFailureException(string.Format("Cannot find feature {0}", featureName));

            var node = new ExecutionNode(string.Format("Begin feature {0}", featureName), string.Format("End feature {0}", featureName));
            foreach (var taskConfig in feature.Recipe)
            {
                var task = context.TaskManager.CreateTask(taskConfig);
                var replacer = new VariableReplacer(context.ApplicationContext, feature, taskConfig);
                node.AddChild(new ExecutionNode(task, new TaskExecutionContext(context.RunContext, feature, taskConfig, replacer)));
            }

            return node;
        }
Esempio n. 15
0
        public void ShouldRestartNodeCounterWhenNodeIsRestarted()
        {
            // 2 Customers
            ExecutionNode customer = ExecutionNode.CreateLevelOneNode(2, "Customer");

            customer.AddTable(new TableEntity("dbo", "Customer"));

            // Make 2 accounts
            var accounts = customer.AddChild(2, "Accounts");

            accounts.AddTable(new TableEntity("dbo", "Account"));

            // make one one Deposit and one WithDraw
            var accountTransactions = accounts.AddChild(1, "AccountTransactions");

            accountTransactions.AddTable(new TableEntity("dbo", "Deposit"));
            accountTransactions.AddTable(new TableEntity("dbo", "Withdraw"));


            NodeIterator it = new NodeIterator(customer);

            var et         = it.GetTablesRecursive().ToList();
            int rowCounter = 0;

            et[rowCounter++].AssertNAndTable(1, "Customer");
            et[rowCounter++].AssertNAndTable(1, "Account");
            et[rowCounter++].AssertNAndTable(1, "Deposit");
            et[rowCounter++].AssertNAndTable(1, "Withdraw");
            // first customer, second account
            et[rowCounter++].AssertNAndTable(2, "Account");
            et[rowCounter++].AssertNAndTable(1, "Deposit");
            et[rowCounter++].AssertNAndTable(1, "Withdraw");

            // second customer
            et[rowCounter++].AssertNAndTable(2, "Customer");
            et[rowCounter++].AssertNAndTable(1, "Account");
            et[rowCounter++].AssertNAndTable(1, "Deposit");
            et[rowCounter++].AssertNAndTable(1, "Withdraw");
            et[rowCounter++].AssertNAndTable(2, "Account");
            et[rowCounter++].AssertNAndTable(1, "Deposit");
            et[rowCounter++].AssertNAndTable(1, "Withdraw");
        }
        public void ShouldMergeNodeWithParent()
        {
            ExecutionNode root     = ExecutionNode.CreateLevelOneNode(1, "Root");
            var           customer = root.AddChild(1, "Customer");
            var           order    = customer.AddChild(10, "Order");
            var           recall   = order.AddChild(1, "Recall");

            customer.AddTable(new TableEntity("dbo", "Customer")).AddTable(new TableEntity("dbo", "Account"));
            order.AddTable(new TableEntity("dbo", "Order")).AddTable(new TableEntity("dbo", "OrderLine")).AddTable(new TableEntity("dbo", "Invoice"));

            var tablesBeforeMerge = new List <TableEntity>(customer.Tables);
            var tablesToBeMerged  = new List <TableEntity>(order.Tables);

            var mergedInto = order.MergeWithParent();

            Assert.That(mergedInto, Is.EqualTo(customer));
            CollectionAssert.IsSubsetOf(tablesBeforeMerge, customer.Tables);
            CollectionAssert.IsSubsetOf(tablesToBeMerged, customer.Tables);
            Assert.That(customer.Tables.Count(), Is.EqualTo(tablesBeforeMerge.Count + tablesToBeMerged.Count));
            Assert.That(customer.Children.Contains(recall));
        }
Esempio n. 17
0
        public void ShouldBeAbleToRemoveOneTableFromExecutionNode()
        {
            // 2 Customers
            ExecutionNode customer = ExecutionNode.CreateLevelOneNode(2, "Customer");

            customer.AddTable(_CustomerTable);

            // Make 2 accounts per customer
            ExecutionNode accounts = customer.AddChild(2, "Accounts");

            accounts.AddTable(_AccountTable);

            NodeIterator it = new NodeIterator(customer);

            Assert.That(it.GetExpectedInsertCount(), Is.EqualTo(6));
            AssertOrder(it.GetTablesRecursive().Select(x => x.Table), "Customer", "Accounts", "Accounts", "Customer", "Accounts", "Accounts");

            accounts.RemoveTable(_AccountTable);

            Assert.That(it.GetExpectedInsertCount(), Is.EqualTo(2));
            AssertOrder(it.GetTablesRecursive().Select(x => x.Table), "Customer", "Customer");
        }
Esempio n. 18
0
        public void ShouldGetAllExecutionItems()
        {
            ExecutionNode node = ExecutionNode.CreateLevelOneNode(1);

            node.AddTable(new TableEntity("", ""));
            node.AddTable(new TableEntity("", ""));

            var child = node.AddChild(1);

            node.AddTable(new TableEntity("", ""));
            node.AddTable(new TableEntity("", ""));
            node.AddTable(new TableEntity("", ""));

            NodeIterator it      = new NodeIterator(node);
            int          counter = 0;

            foreach (var ei in it.GetTablesRecursive())
            {
                Console.WriteLine(ei);
                counter++;
            }

            Assert.That(counter, Is.EqualTo(5));
        }
Esempio n. 19
0
        public void ShouldCountTheTotalExpectedInsertedRowsInOrderToPredictProgress()
        {
            // 2 Customers
            ExecutionNode customer = ExecutionNode.CreateLevelOneNode(2, "Customer");

            customer.AddTable(new TableEntity("dbo", "Customer"));

            // Make 2 accounts
            var accounts = customer.AddChild(2, "Accounts");

            accounts.AddTable(new TableEntity("dbo", "Account"));

            // make one one Deposit and one WithDraw
            var accountTransactions = accounts.AddChild(1, "AccountTransactions");

            accountTransactions.AddTable(new TableEntity("dbo", "Deposit"));
            accountTransactions.AddTable(new TableEntity("dbo", "Withdraw"));


            NodeIterator it = new NodeIterator(customer);
            long         actualExpectedCount = it.GetExpectedInsertCount();

            Assert.That(actualExpectedCount, Is.EqualTo(14));
        }
 private static ExecutionNode BuildRestoreDatabasesNode(DatabaseBackupInfo[] databases, DeployContext context)
 {
     var node = new ExecutionNode("Restoring databases...", "All databases restored!");
     node.AddChild(new ExecutionNode(new RestoreDatabasesTransform(context.ApplicationContext.UserConfig.Databases.Connection, databases)));
     return node;
 }
            public Tuple<ExecutionNode, StateHash, bool, StateHash> Calculate(DeployContext context, StateHash hash, StateHash startingHash, ICacheManager cacheManager)
            {
                if (mTransform != null)
                {
                    hash = mTransform.CalculateTransform(hash);
                    if (hash == startingHash)
                        return Tuple.Create((ExecutionNode)null, hash, true, (StateHash)null);

                    var backups = GetCachedBackups(cacheManager, hash, context.ApplicationContext.ProjectConfig.Databases);
                    if (backups != null)
                    {
                        var node = new ExecutionNode("Restoring state from cache...", "Cache restored");
                        node.AddChild(new ExecutionNode(new RestoreDatabasesTransform(context.ApplicationContext.UserConfig.Databases.Connection, backups, hash)));

                        return Tuple.Create(node, hash, true, hash);
                    }
                }
                else if (mChildren.Count > 0)
                {
                    var result = new ExecutionNode(mLogPre, mLogPost);
                    var changed = false;
                    StateHash cacheHash = null;

                    foreach (var child in mChildren)
                    {
                        var calc = child.Calculate(context, hash, startingHash, cacheManager);
                        if (calc.Item3)
                        {
                            changed = true;
                            result.mChildren.Clear();
                        }

                        if (calc.Item1 != null)
                            result.mChildren.Add(calc.Item1);

                        hash = calc.Item2;
                        if (calc.Item4 != null)
                            cacheHash = calc.Item4;
                    }

                    if (result.mChildren.Count == 0)
                        result = null;

                    return Tuple.Create(result, hash, changed, cacheHash);
                }

                return Tuple.Create(this, hash, false, (StateHash)null);
            }
        private static void RunCore(DeployContext context)
        {
            Beep(context, "start");

            var plan = ActionPlan.Build(context.RunContext);

            var root = new ExecutionNode("Begin deploy", "Deploy completed");
            root.AddChild(BuildRestoreDatabasesNode(plan.Databases, context));

            foreach (var release in plan.Releases)
            {
                var releaseNode = BuildReleaseNode(release, context);
                root.AddChild(releaseNode);
            }

            var hash = StateHash.Empty;
            try
            {
                StateHash startingHash = null;
                if (context.Resume)
                {
                    startingHash = LoadResumeHash(context);
                }

                var improved = root.Calculate(context, hash, startingHash, context.CacheManager);
                if (improved.Item3)
                {
                    root = improved.Item1;
                    if (improved.Item4 != null)
                    {
                        context.CacheManager.UpdateHits(context.ApplicationContext.ProjectConfig.Databases.Select(x => Tuple.Create(x, improved.Item4)));
                    }
                }

                var sink = new CheckingRequirementSink(context.ApplicationContext.Log);
                root.GetRequirements(sink);
                if (sink.Finish())
                    throw new SoftFailureException("Command aborted due to unmet requirements.");

                root.Run(context, startingHash ?? hash, context.CacheManager);

                if (!context.DryRun)
                    CleanResumeHash(context);
            }
            catch (SoftFailureException ex)
            {
                Beep(context, "error");
                throw new SoftFailureException("Blocking error detected", ex);
            }

            Beep(context, "success");
        }
Esempio n. 23
0
        private static void RunCore(RunContext context)
        {
            var plan = ActionPlan.Build(context);

            var root = new ExecutionNode(string.Format("Running '{0}' action", context.Action), "Success!");
            foreach (var release in plan.Releases)
            {
                root.AddChild(BuildReleaseNode(context, release));
            }

            var sink = new CheckingRequirementSink(context.ApplicationContext.Log);
            root.GetRequirements(sink);
            if (sink.Finish())
                throw new SoftFailureException("Command aborted due to unmet requirements.");

            root.Run(context);
        }