Ejemplo n.º 1
0
        public void TimestampNotEqual()
        {
            var newId  = SequentialId.NewId();
            var newId2 = new SequentialId(DateTime.UtcNow.AddSeconds(1));

            Assert.AreNotEqual(newId.ToTimestamp(), newId2.ToTimestamp());
        }
Ejemplo n.º 2
0
        public void Equals()
        {
            var newId  = SequentialId.NewId();
            var newId2 = new SequentialId(newId.ToByteArray());

            Assert.AreEqual(newId, newId2);
        }
Ejemplo n.º 3
0
        public void NotEquals()
        {
            var newId  = SequentialId.NewId();
            var newId2 = SequentialId.NewId();

            Assert.AreNotEqual(newId, newId2);
        }
Ejemplo n.º 4
0
        public void TimestampEqual()
        {
            var newId  = SequentialId.NewId();
            var newId2 = new SequentialId(newId.ToByteArray());

            Assert.AreEqual(newId.ToTimestamp(), newId2.ToTimestamp());
        }
Ejemplo n.º 5
0
        private void TestCreateNewNode()
        {
            var command = CreateCommandForNewDb("Tester.rootcause");

            var problem = NodeFactory.CreateProblem("Problem", SequentialId.NewId());

            SqliteDb.GetInstance().InsertTopLevel(problem);

            var node = NodeFactory.CreateCause("Node 1", SequentialId.NewId());

            SqliteDb.GetInstance().AddNode(problem, node);

            string sql = $"SELECT * FROM nodes WHERE nodeid = '{node.NodeId}'";

            command.CommandText = sql;
            SQLiteDataReader reader = command.ExecuteReader();

            reader.Read();
            string newNodeText = reader["nodetext"].ToString();

            reader.Close();

            sql = $"SELECT count(*) AS result FROM hierarchy WHERE parentid = '{problem.NodeId}' AND childid = '{node.NodeId}';";
            command.CommandText = sql;
            reader = command.ExecuteReader();
            reader.Read();
            string hierarchies = reader["result"].ToString();

            reader.Close();
            CleanUpCommand(command);

            Assert.AreEqual("Node 1", newNodeText);
            Assert.AreEqual("1", hierarchies);
        }
Ejemplo n.º 6
0
        /*This is the model that is created by CreateComplexModelForText
         *
         *                  Problem
         *                     |
         *               -------------
         *               |           |
         *            Node 1.1    Node 1.2
         *               |           |
         *               |      -------------------------
         *               |      |           |           |
         *               |---Node 2.1    Node 2.2    Node 2.3
         *                      |           |           |
         *                      |      -------------    |
         *                      |      |           |    |
         *                      |---Node 3.1    Node 3.2-
         */
        private Dictionary <string, Node> CreateComplexModelForTest()
        {
            var  db      = SqliteDb.GetInstance();
            Node problem = NodeFactory.CreateProblem("Problem", SequentialId.NewId());

            db.InsertTopLevel(problem);

            Node node1_1 = new AddNodeCommand(db, problem, "Node 1.1", true).NewNode;
            Node node1_2 = new AddNodeCommand(db, problem, "Node 1.2", true).NewNode;
            Node node2_1 = new AddNodeCommand(db, node1_2, "Node 2.1", true).NewNode;
            Node node2_2 = new AddNodeCommand(db, node1_2, "Node 2.2", true).NewNode;
            Node node2_3 = new AddNodeCommand(db, node1_2, "Node 2.3", true).NewNode;
            Node node3_1 = new AddNodeCommand(db, node2_2, "Node 3.1", true).NewNode;
            Node node3_2 = new AddNodeCommand(db, node2_2, "Node 3.2", true).NewNode;

            new AddLinkCommand(db, node1_1, node2_1, true);
            new AddLinkCommand(db, node2_1, node3_1, true);
            new AddLinkCommand(db, node2_3, node3_2, true);

            return(new Dictionary <string, Node>()
            {
                { problem.Text, problem },
                { node1_1.Text, node1_1 },
                { node1_2.Text, node1_2 },
                { node2_1.Text, node2_1 },
                { node2_2.Text, node2_2 },
                { node2_3.Text, node2_3 },
                { node3_1.Text, node3_1 },
                { node3_2.Text, node3_2 }
            });
        }
Ejemplo n.º 7
0
        private void TestCreateProblemStatement()
        {
            var command = CreateCommandForNewDb("Tester.rootcause");
            var node    = NodeFactory.CreateProblem("This is my problem", SequentialId.NewId());

            SqliteDb.GetInstance().InsertTopLevel(node);
            string nodeId = node.NodeId.ToString();

            string sql = $"SELECT count(*) AS result FROM toplevel WHERE nodeid = '{nodeId}'";

            command.CommandText = sql;
            SQLiteDataReader reader = command.ExecuteReader();

            reader.Read();
            string toplevels = reader["result"].ToString();

            reader.Close();

            sql = $"SELECT * FROM nodes WHERE nodeid = '{nodeId}'";
            command.CommandText = sql;
            reader = command.ExecuteReader();
            reader.Read();
            string topLevelId   = reader["nodeid"].ToString();
            string topLevelText = reader["nodetext"].ToString();

            reader.Close();
            CleanUpCommand(command);

            Assert.AreEqual("1", toplevels);
            Assert.AreEqual(nodeId, topLevelId);
            Assert.AreEqual("This is my problem", topLevelText);
        }
Ejemplo n.º 8
0
        public void CollisionTest()
        {
            int count = 5000000;
            var set   = new HashSet <SequentialId>();

            for (int i = 0; i < count; i++)
            {
                set.Add(SequentialId.NewId());
            }

            Assert.AreEqual(count, set.Count);
        }
Ejemplo n.º 9
0
 public void TestSequentiality()
 {
     long[] ids = new long[100];
     for (int i = 0; i < 100; i++)
     {
         ids[i] = SequentialId.NewId();
         System.Diagnostics.Debug.WriteLine(ids[i]);
     }
     for (int i = 1; i < 100; i++)
     {
         Assert.AreEqual(1, ids[i].CompareTo(ids[i - 1]), $"Failed on {i}");
     }
 }
Ejemplo n.º 10
0
        private void TestChangeNodeText()
        {
            var command = CreateCommandForNewDb("Tester.rootcause");

            var problem = NodeFactory.CreateProblem("Problem", SequentialId.NewId());

            SqliteDb.GetInstance().InsertTopLevel(problem);
            SqliteDb.GetInstance().ChangeNodeText(problem, "This is my problem");

            string sql = $"SELECT * FROM nodes WHERE nodeid = '{problem.NodeId}';";

            command.CommandText = sql;
            SQLiteDataReader reader = command.ExecuteReader();

            reader.Read();
            string newText = reader["nodetext"].ToString();

            reader.Close();
            CleanUpCommand(command);

            Assert.AreEqual("This is my problem", newText);
        }
Ejemplo n.º 11
0
        public void GuidRace()
        {
            int count = 15000000;

            var st = new Stopwatch();

            st.Start();
            for (int i = 0; i < count; i++)
            {
                var newId = SequentialId.NewId();
                //Debug.WriteLine(newId);
            }
            st.Stop();

            Debug.WriteLine($"{count.ToString("N0")} SequentialIds created in {st.Elapsed}");


            st.Restart();
            for (int i = 0; i < count; i++)
            {
                var newId = Guid.NewGuid();
                //Debug.WriteLine(newId);
            }
            st.Stop();

            Debug.WriteLine($"{count.ToString("N0")} Guids created in {st.Elapsed}");


            st.Restart();
            for (int i = 0; i < count; i++)
            {
                var newId = UuidUtil.NewSequentialId();
                //Debug.WriteLine(newId);
            }
            st.Stop();

            Debug.WriteLine($"{count.ToString("N0")} WinSequentialIds created in {st.Elapsed}");
        }
Ejemplo n.º 12
0
        private void TestRemoveLink()
        {
            var command = CreateCommandForNewDb("Tester.rootcause");

            var problem = NodeFactory.CreateProblem("Problem", SequentialId.NewId());
            var node1   = NodeFactory.CreateCause("Node 1", SequentialId.NewId());
            var node2   = NodeFactory.CreateCause("Node 2", SequentialId.NewId());

            SqliteDb.GetInstance().InsertTopLevel(problem);
            SqliteDb.GetInstance().AddNode(problem, node1);
            SqliteDb.GetInstance().AddNode(node1, node2);
            SqliteDb.GetInstance().AddLink(problem, node2);
            SqliteDb.GetInstance().RemoveLink(problem, node2);

            var expectedLinks = new Node[2, 2]
            {
                { problem, node1 },
                { node1, node2 }
            };

            TestHierarchy(command, expectedLinks);
            CleanUpCommand(command);
        }
Ejemplo n.º 13
0
        /* This method builds a complex tree for some of the link and removal command testing.
         * The structure of the tree is as follows:
         * Problem
         *      -> Node 1
         *          -> Node 1.1
         *          -> Node 1.2
         *      -> Node 2
         *          -> Node 2.1
         *              -> Node 2.1.1
         *          -> Node 2.2
         */
        private Dictionary <string, Node> BuildTestTree()
        {
            Dictionary <string, Node> dict = new Dictionary <string, Node>();
            IRootCauseDb db = new NullDb();

            dict.Add("Problem", NodeFactory.CreateProblem("Problem", SequentialId.NewId()));
            dict.Add("Node 1", NodeFactory.CreateCause("Node 1", SequentialId.NewId()));
            dict.Add("Node 1.1", NodeFactory.CreateCause("Node 1.1", SequentialId.NewId()));
            dict.Add("Node 1.2", NodeFactory.CreateCause("Node 1.2", SequentialId.NewId()));
            dict.Add("Node 2", NodeFactory.CreateCause("Node 2", SequentialId.NewId()));
            dict.Add("Node 2.1", NodeFactory.CreateCause("Node 2.1", SequentialId.NewId()));
            dict.Add("Node 2.1.1", NodeFactory.CreateCause("Node 2.1.1", SequentialId.NewId()));
            dict.Add("Node 2.2", NodeFactory.CreateCause("Node 2.2", SequentialId.NewId()));

            new AddLinkCommand(db, dict["Problem"], dict["Node 1"], true);
            new AddLinkCommand(db, dict["Problem"], dict["Node 2"], true);
            new AddLinkCommand(db, dict["Node 1"], dict["Node 1.1"], true);
            new AddLinkCommand(db, dict["Node 1"], dict["Node 1.2"], true);
            new AddLinkCommand(db, dict["Node 2"], dict["Node 2.1"], true);
            new AddLinkCommand(db, dict["Node 2"], dict["Node 2.2"], true);
            new AddLinkCommand(db, dict["Node 2.1"], dict["Node 2.1.1"], true);

            return(dict);
        }