Exemplo n.º 1
0
        public void DuplicateDataTest()
        {
            //arrange
            var exp1   = new Experiment("exp1");
            var exp2   = new Experiment("exp2");
            var exp11  = new Experiment("exp1-1");
            var exp111 = new TestExp("exp1-1-1");
            var exp12  = new Experiment("exp1-2");
            var sig121 = new Signal("sig1-2-1");
            var sig111 = new TestSignal("sig1-1-1");

            exp111.TestString = "test";
            exp111.TestList   = new List <string> {
                "1", "1", "1"
            };
            sig111.TestString = "test";
            sig111.TestList   = new List <string> {
                "1", "1", "1"
            };

            //add 2 root
            myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp1).Wait();
            myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp2).Wait();

            //add child
            myCoreService.AddJdbcEntityToAsync(exp1.Id, exp11).Wait();
            myCoreService.AddJdbcEntityToAsync(exp1.Id, exp12).Wait();
            myCoreService.AddJdbcEntityToAsync(exp12.Id, sig121).Wait();
            myCoreService.AddJdbcEntityToAsync(exp11.Id, sig111).Wait();
            myCoreService.AddJdbcEntityToAsync(exp11.Id, exp111).Wait();

            var data = generateDummyData();

            //append signal
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    var oneDim = new List <double>(8);
                    for (int k = 0; k < 8; k++)
                    {
                        oneDim.Add(data[i, j, k]);
                    }
                    //notice that this has only 2 interations for 3 dimention arry
                    storageEngine.AppendSampleAsync(sig111.Id, new List <long> {
                        i, j
                    }, oneDim).Wait();
                }
            }
            // 1 新的节点不能和原来的子节点同名
            var errorSameName = "";

            try
            {
                myCoreService.DuplicateAsync(exp11.Id, exp1.Id, exp11.Name).Wait();
            }
            catch (Exception e)
            {
                errorSameName = e.InnerException.Message;
            }
            Assert.AreEqual(ErrorMessages.NameDuplicateError, errorSameName);
            //old tree                              new tree

            /*
             * /exp1/exp11/sig111/payload64       /exp1/exp11/sig111/payload64
             *          /exp111                            /exp111
             *    /exp12/sig121                      /exp11c/sig111
             * /exp2                                          /exp111
             *                                       /exp12/sig121
             *                                  /exp2/exp12
             */

            //2 get for assert /exp1/exp11c,递归拷贝节点测试.
            myCoreService.DuplicateAsync(exp11.Id, exp1.Id, "exp1-1-c", true).Wait();
            myCoreService.DuplicateAsync(exp12.Id, exp2.Id, exp12.Name).Wait();

            var childrenNameOfExp1 = myCoreService.GetAllChildrenAsync(exp1.Id).Result.Select(e => e.Name);

            CollectionAssert.AreEquivalent(new List <string> {
                "exp1-1-c", "exp1-1", "exp1-2"
            }, childrenNameOfExp1.ToList());

            var exp11c  = myCoreService.GetChildByNameAsync(exp1.Id, "exp1-1-c").Result;
            var exp111c = myCoreService.GetChildByNameAsync(exp11c.Id, "exp1-1-1").Result as TestExp;

            Assert.AreEqual(exp111.TestString, exp111c.TestString);
            Assert.AreNotEqual(exp111.Id, exp111c.Id);               //   exp1/exp11/exp111   exp1/exp11c/exp111
            Assert.AreNotEqual(exp111.ParentId, exp111c.ParentId);   //  /exp1/exp11/
            CollectionAssert.AreEqual(exp111.TestList, exp111c.TestList);


            var sig111c = myCoreService.GetChildByNameAsync(exp11c.Id, "sig1-1-1").Result as TestSignal;

            Assert.AreEqual(sig111.TestString, sig111c.TestString);
            CollectionAssert.AreEqual(sig111.TestList, sig111c.TestList);

            var childOfExp2 = myCoreService.GetAllChildrenAsync(exp2.Id).Result.Single();

            Assert.AreEqual("/exp2/exp1-2", childOfExp2.Path);

            /*
             * /exp1/exp11/sig111/payload64       /exp1/exp11/sig111/payload64
             *         /exp111                            /exp111
             *   /exp12/sig121                      /exp11c/sig111
             * /exp2                                          /exp111
             *                                      /exp12/sig121
             *                                 /exp2/exp12
             *                                      /exp11/sig111/payload64
             *                                            /exp111
             */
            //3 get for assert /exp2/exp11,递归拷贝节点和数据测试.
            myCoreService.DuplicateAsync(exp11.Id, exp2.Id, exp11.Name, true, true).Wait();
            var childrenOfExp2 = myCoreService.GetAllChildrenAsync(exp2.Id).Result;

            Assert.AreEqual(2, childrenOfExp2.Count());

            var sig111New = myCoreService.GetOneByPathAsync("/exp2/exp1-1/sig1-1-1").Result;
            var cursor    = storageEngine.GetCursorAsync <double>(sig111New.Id, new List <long> {
                2, 1, 3
            }, new List <long> {
                2, 2, 3
            }).Result;
            List <double> result = cursor.Read(3).Result.ToList();

            double[] assertresult = { 213, 214, 215 };
            CollectionAssert.AreEqual(assertresult, result);
        }
Exemplo n.º 2
0
        public void DeleteTest()
        {
            //arrange
            //arrange
            var exp1   = new Experiment("exp1");
            var exp2   = new Experiment("exp2");
            var exp11  = new Experiment("exp1-1");
            var exp111 = new Experiment("exp1-1-1");
            var exp12  = new Experiment("exp1-2");
            var sig121 = new Signal("sig1-2-1");
            var sig111 = new Signal("sig1-1-1");

            //add 2 root
            myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp1).Wait();
            myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp2).Wait();

            //add child
            myCoreService.AddJdbcEntityToAsync(exp1.Id, exp11).Wait();
            myCoreService.AddJdbcEntityToAsync(exp1.Id, exp12).Wait();
            myCoreService.AddJdbcEntityToAsync(exp12.Id, sig121).Wait();
            myCoreService.AddJdbcEntityToAsync(exp11.Id, sig111).Wait();
            myCoreService.AddJdbcEntityToAsync(exp11.Id, exp111).Wait();
            var data = generateDummyData();

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    var oneDim = new List <double>(8);
                    for (int k = 0; k < 8; k++)
                    {
                        oneDim.Add(data[i, j, k]);
                    }
                    //notice that this has only 2 interations for 3 dimention arry
                    mongoEngine.AppendSampleAsync(sig111.Id, new List <long> {
                        i, j
                    }, oneDim).Wait();
                }
            }
            //old tree

            /*
             * /exp1/exp11/sig111/payload1-1-1-1
             *          /exp111
             *    /exp12/sig121
             * /exp2
             *
             */

            //act
            //try delet exp12 error expetced
            var errorDelete = "";

            try
            {
                myCoreService.DeleteAsync(exp12.Id).Wait();
            }
            catch (Exception e)
            {
                errorDelete = e.InnerException.Message;
            }
            myCoreService.DeleteAsync(exp12.Id, true).Wait();
            myCoreService.DeleteAsync(exp2.Id).Wait();
            //the deleted entity is  non exist, error expected
            string errorDeleteNonExist = "";

            try
            {
                myCoreService.DeleteAsync(exp2.Id).Wait();
            }
            catch (Exception e)
            {
                //this is async call so exception is wrapped
                errorDeleteNonExist = e.InnerException.Message;
            }

            //get for assert
            var root    = myCoreService.GetAllChildrenAsync().Result;
            var nSig121 = myCoreService.GetOneByIdAsync(sig121.Id).Result;
            var nExp12  = myCoreService.GetChildIdByNameAsync(exp1.Id, exp12.Name).Result;

            //assert
            Assert.AreEqual(ErrorMessages.DeleteEntityWithChildError, errorDelete);
            Assert.AreEqual(ErrorMessages.EntityNotFoundError, errorDeleteNonExist);
            CollectionAssert.AreEquivalent(new List <Guid> {
                exp1.Id
            }, root.Select(r => r.Id).ToList());
            Assert.IsNull(nSig121);
            Assert.AreEqual(Guid.Empty, nExp12);

            var payloads = mongoEngine.GetPayloadIdsByParentIdAsync(sig111.Id).Result;

            Assert.AreEqual(64, payloads.Count());
            myCoreService.DeleteAsync(sig111.Id, true).Wait();
            var payloadZero = mongoEngine.GetPayloadIdsByParentIdAsync(sig111.Id).Result;

            Assert.AreEqual(0, payloadZero.Count());
        }
Exemplo n.º 3
0
        public void AddNodeTest()
        {
            //arrange
            var exp1    = new Experiment("exp1");
            var exp2    = new Experiment("exp2");
            var exp2c   = new Experiment("exp2");
            var exp11   = new Experiment("exp1-1");
            var exp12   = new Experiment("exp1-2");
            var sig121  = new Signal("sig1-2-1");
            var sig121c = new Signal("sig1-2-1");

            //act
            //add 2 root
            //    /exp1
            //    /exp2
            myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp1).Wait();
            myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp2).Wait();

            //1.1 add entity with same name to root.
            string errorSameNameOnRoot = "";

            try
            {
                myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp2c).Wait();
            }
            catch (Exception e)
            {
                //this is async call so exception is wrapped
                errorSameNameOnRoot = e.InnerException.Message;
            }
            Assert.AreEqual(ErrorMessages.NameDuplicateError, errorSameNameOnRoot);

            //1.2 add signal to root, expecting error, signal's parent can only be experiment.
            string errorSigOnRoot = "";

            try
            {
                myCoreService.AddJdbcEntityToAsync(Guid.Empty, sig121).Wait();
            }
            catch (Exception e)
            {
                //this is async call so exception is wrapped
                errorSigOnRoot = e.InnerException.Message;
            }
            Assert.AreEqual(ErrorMessages.NotValidParentError, errorSigOnRoot);

            //add child
            //    /exp1/exp1-1/
            //    /exp1/exp1-2/sig1-2-1
            myCoreService.AddJdbcEntityToAsync(exp1.Id, exp11).Wait();
            myCoreService.AddJdbcEntityToAsync(exp1.Id, exp12).Wait();
            myCoreService.AddJdbcEntityToAsync(exp12.Id, sig121).Wait();

            //1.3 add signal to another signal, expecting error, signal's parent can only be experiment.
            string errorAddToSignal = "";

            try
            {
                myCoreService.AddJdbcEntityToAsync(sig121.Id, sig121c).Wait();
            }
            catch (Exception e)
            {
                //this is async call so exception is wrapped
                errorAddToSignal = e.InnerException.Message;
            }
            Assert.AreEqual(ErrorMessages.NotValidParentError, errorAddToSignal);

            //1.4 add the sig with the same name to the parent errexpected
            string errorSameName = "";

            try
            {
                myCoreService.AddJdbcEntityToAsync(exp12.Id, sig121c).Wait();
            }
            catch (Exception e)
            {
                errorSameName = e.InnerException.Message;
            }
            Assert.AreEqual(ErrorMessages.NameDuplicateError, errorSameName);

            //1.5 the parent is  non exist, error expected
            string errorParentNonExistWhenAdd = "";

            try
            {
                myCoreService.AddJdbcEntityToAsync(Guid.NewGuid(), sig121c).Wait();
            }
            catch (Exception e)
            {
                //this is async call so exception is wrapped
                errorParentNonExistWhenAdd = e.InnerException.Message;
            }
            Assert.AreEqual(ErrorMessages.ParentNotExistError, errorParentNonExistWhenAdd);

            //1.6 the parent is  non exist, error expected
            string errorParentNonExist2 = "";

            try
            {
                var tNothing = myCoreService.GetAllChildrenIdAsync(Guid.NewGuid()).Result;
            }
            catch (Exception e)
            {
                //this is async call so exception is wrapped
                errorParentNonExist2 = e.InnerException.Message;
            }
            Assert.AreEqual(ErrorMessages.ParentNotExistError, errorParentNonExist2);

            //1.7 assert id and entity.
            //    /exp1/exp1-1/
            //    /exp1/exp1-2/sig1-2-1
            var roots = myCoreService.GetAllChildrenAsync().Result;

            CollectionAssert.AreEqual(new List <Guid> {
                exp1.Id, exp2.Id
            }, roots.Select(r => r.Id).ToList());

            var rootsById = myCoreService.GetAllChildrenAsync(Guid.Empty).Result;

            CollectionAssert.AreEqual(new List <Guid> {
                exp1.Id, exp2.Id
            }, rootsById.Select(r => r.Id).ToList());

            var rootIdsById = myCoreService.GetAllChildrenIdAsync(Guid.Empty).Result;

            CollectionAssert.AreEqual(new List <Guid> {
                exp1.Id, exp2.Id
            }, rootIdsById.ToList());

            var secLevId = myCoreService.GetAllChildrenIdAsync(exp1).Result;

            CollectionAssert.AreEquivalent(new List <Guid> {
                exp11.Id, exp12.Id
            }, secLevId.ToList());

            var secLevIdById = myCoreService.GetAllChildrenIdAsync(exp1.Id).Result;

            CollectionAssert.AreEquivalent(new List <Guid> {
                exp11.Id, exp12.Id
            }, secLevIdById.ToList());

            var trdLevIdById = myCoreService.GetAllChildrenIdAsync(exp12.Id).Result;

            CollectionAssert.AreEquivalent(new List <Guid> {
                sig121.Id
            }, trdLevIdById.ToList());

            var shouldBeEmpty = myCoreService.GetAllChildrenAsync(exp11).Result;

            Assert.AreEqual(shouldBeEmpty.Count(), 0);

            var sig121ParentId = myCoreService.GetParentIdAsync(sig121.Id).Result;

            Assert.AreEqual(exp12.Id, sig121ParentId);

            var errorParentNullId = myCoreService.GetParentIdAsync(Guid.NewGuid()).Result;

            Assert.AreEqual(Guid.Empty, errorParentNullId);

            Assert.AreEqual(exp11.EntityType, JDBCEntityType.Experiment);
            Assert.AreEqual(sig121.EntityType, JDBCEntityType.Signal);
        }