Example #1
0
        public void DeleteTest()
        {
            //arrange
            var exp1   = new Experiment("exp1");
            var exp11  = new Experiment("exp1-1");
            var exp12  = new Experiment("exp1-2");
            var sig121 = new Signal("sig1-2-1");
            var sig111 = new Signal("sig1-1-1");

            myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp1).Wait();

            myCoreService.AddJdbcEntityToAsync(exp1.Id, exp11).Wait();
            myCoreService.AddJdbcEntityToAsync(exp1.Id, exp12).Wait();
            myCoreService.AddJdbcEntityToAsync(exp12.Id, sig121).Wait();
            myCoreService.AddJdbcEntityToAsync(exp11.Id, sig111).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
                    storageEngine.AppendSampleAsync(sig111.Id, new List <long> {
                        i, j
                    }, oneDim).Wait();
                }
            }
            myCoreService.DuplicateAsync(exp11.Id, exp1.Id, "exp1-1-c", true, true).Wait();
            //old tree

            /*
             * /exp1/exp11/sig111/payload1-1-1-1
             *    /exp12/sig121
             *    /exp11c/sig111/payload-1-1-1
             */
            //act

            //var cursor = storageEngine.GetCursorAsync<double>(sig111.Id, new List<long> { 2, 1, 3 }, new List<long> { 2, 2, 2 }).Result;
            //List<double> result = cursor.Read(3).Result.ToList();
            //double[] assertresult = { 213, 214, 223 };
            //CollectionAssert.AreEqual(assertresult, result);

            myCoreService.DeleteAsync(exp11.Id, true).Wait();

            var exp11Result = myCoreService.GetChildByNameAsync(exp1.Id, "exp1-1").Result;

            Assert.AreEqual(null, exp11Result);

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

            double[] assertresult = { 213, 214, 223 };
            CollectionAssert.AreEqual(assertresult, result);

            storageEngine.DeleteDataAsync(sig111Duplicate.Id);
            try
            {
                var cursor1 = storageEngine.GetCursorAsync <double>(sig111Duplicate.Id, new List <long> {
                    2, 1, 3
                }, new List <long> {
                    2, 2, 3
                }).Result;
                List <double> result1 = cursor1.Read(3).Result.ToList();
            }
            catch (Exception e)
            {
                Assert.AreEqual(e.InnerException.Message, ErrorMessages.OutOfRangeError);
            }
        }
Example #2
0
        public void DuplicateTest()
        {
            //arrange
            //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
                    mongoEngine.AppendSampleAsync(sig111.Id, new List <long> {
                        i, j
                    }, oneDim).Wait();
                }
            }
            var errorSameName = "";

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

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


            myCoreService.DuplicateAsync(exp11.Id, exp1.Id, "exp1-1-c", true).Wait();
            myCoreService.DuplicateAsync(exp12.Id, exp2.Id, exp12.Name).Wait();


            //get for assert
            var childrenNameOfExp1 = myCoreService.GetAllChildrenAsync(exp1.Id).Result.Select(e => e.Name);
            var exp11c             = myCoreService.GetChildByNameAsync(exp1.Id, "exp1-1-c").Result;
            var exp111c            = myCoreService.GetChildByNameAsync(exp11c.Id, "exp1-1-1").Result as TestExp;
            var sig111c            = myCoreService.GetChildByNameAsync(exp11c.Id, "sig1-1-1").Result as TestSignal;
            var childOfExp2        = myCoreService.GetAllChildrenAsync(exp2.Id).Result.Single();

            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    = mongoEngine.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);
            //assert
            Assert.AreEqual(ErrorMessages.NameDuplicateError, errorSameName);

            CollectionAssert.AreEquivalent(new List <string> {
                "exp1-1-c", "exp1-1", "exp1-2"
            }, childrenNameOfExp1.ToList());
            Assert.AreEqual(exp111.TestString, exp111c.TestString);
            Assert.AreNotEqual(exp111.Id, exp111c.Id);
            Assert.AreNotEqual(exp111.ParentId, exp111c.ParentId);
            Assert.AreEqual(sig111.TestString, sig111c.TestString);
            CollectionAssert.AreEqual(exp111.TestList, exp111c.TestList);
            CollectionAssert.AreEqual(sig111.TestList, sig111c.TestList);
            //    Assert.AreEqual(0, childOfNewExp12.Count());
        }
Example #3
0
        public void DuplicateTest()
        {
            //arrange
            //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();

            //old tree                                       new tree

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

            // 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);

            myCoreService.DuplicateAsync(exp11.Id, exp1.Id, "exp1-1-c", true).Wait();
            myCoreService.DuplicateAsync(exp12.Id, exp2.Id, exp12.Name).Wait();

            //get for assert
            var childrenNameOfExp1 = myCoreService.GetAllChildrenAsync(exp1.Id).Result.Select(e => e.Name);
            var exp11c             = myCoreService.GetChildByNameAsync(exp1.Id, "exp1-1-c").Result;
            var exp111c            = myCoreService.GetChildByNameAsync(exp11c.Id, "exp1-1-1").Result as TestExp;
            var sig111c            = myCoreService.GetChildByNameAsync(exp11c.Id, "sig1-1-1").Result as TestSignal;
            var childrenOfExp2     = myCoreService.GetAllChildrenAsync(exp2.Id).Result.Single();
            var childOfNewExp12    = myCoreService.GetAllChildrenAsync(childrenOfExp2.Id).Result;

            //assert

            CollectionAssert.AreEquivalent(new List <string> {
                "exp1-1-c", "exp1-1", "exp1-2"
            }, childrenNameOfExp1.ToList());
            Assert.AreEqual(exp111.TestString, exp111c.TestString);
            Assert.AreNotEqual(exp111.Id, exp111c.Id);
            Assert.AreNotEqual(exp111.ParentId, exp111c.ParentId);
            Assert.AreEqual(sig111.TestString, sig111c.TestString);
            CollectionAssert.AreEqual(exp111.TestList, exp111c.TestList);
            CollectionAssert.AreEqual(sig111.TestList, sig111c.TestList);
            Assert.AreEqual(0, childOfNewExp12.Count());
        }