Пример #1
0
        public void CursorAppendAndGetSampleTest()
        {
            //arrange
            myCoreService = CoreService.GetInstance();
            myCoreService.Init("mongodb://127.0.0.1:27017", "JDBC-test", "Experiment");
            myCoreService.ClearDb();
            var exp1  = new Experiment("exp1");
            var sig11 = new Signal("sig1-1");

            myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp1).Wait();
            myCoreService.AddJdbcEntityToAsync(exp1.Id, sig11).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(sig11.Id, new List <long> {
                        i, j
                    }, oneDim).Wait();
                }
            }

            //get samples
            //expected data:
            //[213,214,215
            //223,224,225]
            //-----------
            //[313,314,315
            //323,324,325]
            //flatted!!
            var cursor = mongoEngine.GetCursorAsync <double>(sig11.Id, new List <long> {
                2, 1, 3
            },
                                                             new List <long> {
                2, 2, 3
            }).Result;

            //Assert  get
            //make a flatter array for assert
            var expectedSample = new double[2, 2, 3]
            {
                { { 213, 214, 215 }, { 223, 224, 225 } },
                { { 313, 314, 315 }, { 323, 324, 325 } }
            };
            var sample = cursor.Read(15).Result.ToList();
            var flat   = expectedSample.Cast <double>().ToList();

            CollectionAssert.AreEqual(flat, sample);
        }
Пример #2
0
        internal void Setup()
        {
            var node = myCoreService.GetChildByNameAsync(Guid.Empty, "exp1").Result;

            Debug.Write("");
            if (node == null)
            {
                var exp1 = new Experiment("exp1");
                myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp1).Wait();
                for (int i = 0; i < 2; i++)               //signalnum
                {
                    var sig11 = new Signal(i.ToString()); //"sig1-1"
                    myCoreService.AddJdbcEntityToAsync(exp1.Id, sig11).Wait();
                }
            }
        }
Пример #3
0
        public void AppendData1DTest()
        {
            var exp1  = new Experiment("exp1");
            var sig11 = new Signal("sig1-1");

            myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp1).Wait();
            myCoreService.AddJdbcEntityToAsync(exp1.Id, sig11).Wait();
            int number = 10;

            var writer = storageEngine.GetWriter <double>(sig11);

            for (int i = 0; i < number; i++)
            {
                var oneDim = new List <double>(number);
                for (double k = 0; k < number; k++)
                {
                    oneDim.Add(i * number + k);
                }
                //todo optimize, use array as input
                writer.AppendSampleAsync(new List <long>(), oneDim).Wait();
            }
            writer.DisposeAsync();
            var cursor = storageEngine.GetCursorAsync <double>(sig11.Id, new List <long> {
                15
            }, new List <long> {
                10
            }).Result;
            var samples        = cursor.Read(30).Result.ToList();
            var expectedSample = new double[] { 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 };
            var flat           = expectedSample.Cast <double>().ToList();

            CollectionAssert.AreEqual(samples, expectedSample);
        }
Пример #4
0
        //Use Cursor.Read()
        public void JDBCCursorSingleDimReadTest()
        {
            var exp1  = new Experiment("exp1");
            var sig11 = new Signal("sig1-1");

            myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp1).Wait();
            myCoreService.AddJdbcEntityToAsync(exp1.Id, sig11).Wait();
            var data = generateDummyData();
            //  var oneDim = new List<double>(8);
            int n = 0, m = 0;

            //append signal
            for (int i = 0; i < 20; i++)
            {
                m = n + 5;
                var oneDim = new List <double>(5);
                for (; n < m; n++)
                {
                    oneDim.Add(n);
                }
                mongoEngine.AppendSampleAsync(sig11.Id, new List <long> {
                }, oneDim).Wait();
            }
            var cursor = mongoEngine.GetCursorAsync <double>(sig11.Id, new List <long> {
                46
            }, new List <long> {
                60
            }).Result;

            List <double> result1 = cursor.Read(10).Result.ToList();

            //   double[] assertresult1 = { 4, 5, 6,7,8 };
            double[] assertresult1 = new double[10];
            for (int i = 46, j = 0; j < 10;)
            {
                assertresult1[j++] = i++;
            }
            CollectionAssert.AreEqual(assertresult1, result1);
            result1 = cursor.Read(10).Result.ToList();
            for (int i = 56, j = 0; j < 10;)
            {
                assertresult1[j++] = i++;
            }
            CollectionAssert.AreEqual(assertresult1, result1);
            result1 = cursor.Read(30).Result.ToList();
            //  result1 = cursor.Read(10).Result.ToList();
            List <double> result2 = cursor.Read(10).Result.ToList();

            double[] assertresult2 = { 96, 97, 98, 99, 0, 0, 0, 0, 0, 0 };
            //double[] assertresult2 = {9, 10, 11, 12,13, 14, 15, 16, 17, 18 };
            CollectionAssert.AreEqual(assertresult2, result2);
        }
Пример #5
0
        public void ReadData2DTest()
        {
            var exp1  = new Experiment("exp1");
            var sig11 = new Signal("sig1-1");

            myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp1).Wait();
            myCoreService.AddJdbcEntityToAsync(exp1.Id, sig11).Wait();
            var data = generateDummyData();
            int n = 0, m = 0;

            //append signal
            for (int i = 0; i < 20; i++)
            {
                m = n + 5;
                var oneDim = new List <double>(5);
                for (; n < m; n++)
                {
                    oneDim.Add(n);
                }
                storageEngine.AppendSampleAsync(sig11.Id, new List <long> {
                    0
                }, oneDim).Wait();
            }
            n = m = 0;
            for (int i = 0; i < 20; i++)
            {
                m = n + 5;
                var oneDim = new List <double>(5);
                for (; n < m; n++)
                {
                    oneDim.Add(n);
                }
                storageEngine.AppendSampleAsync(sig11.Id, new List <long> {
                    1
                }, oneDim).Wait();
            }

            double[] assertresult1  = new double[50];
            double[] assertresult21 = new double[60];
            double[] assertresult22 = new double[40];
            for (int i = 46, j = 0; j < 50;)
            {
                assertresult1[j]    = i;
                assertresult21[j++] = i++;
            }
            for (int i = 46, j = 50; j < 60;)
            {
                assertresult21[j++] = i++;
            }
            for (int i = 56, j = 0; j < 40;)
            {
                assertresult22[j++] = i++;
            }
            // 1  读取测试
            var cursor1             = storageEngine.GetCursorAsync <double>(sig11.Id, new List <long> {
                0, 46
            }, new List <long> {
                2, 60
            }).Result;
            List <double> result1 = cursor1.Read(50).Result.ToList();

            CollectionAssert.AreEqual(assertresult1, result1);

            // 2  跨维度测试
            var cursor2 = storageEngine.GetCursorAsync <double>(sig11.Id, new List <long> {
                0, 46
            }, new List <long> {
                2, 50
            }).Result;
            List <double> result21 = cursor2.Read(60).Result.ToList();

            CollectionAssert.AreEqual(assertresult21, result21);

            List <double> result122 = cursor2.Read(50).Result.ToList();

            CollectionAssert.AreEqual(assertresult22, result122);

            // 3  边界测试
            double[] assertresult31 = new double[60];
            for (int i = 40, j = 0; j < 60;)
            {
                assertresult31[j++] = i++;
            }
            var cursor3 = storageEngine.GetCursorAsync <double>(sig11.Id, new List <long> {
                0, 40
            }, new List <long> {
                2, 60
            }).Result;
            List <double> result31 = cursor3.Read(60).Result.ToList();

            CollectionAssert.AreEqual(assertresult31, result31);

            List <double> result32 = cursor3.Read(60).Result.ToList();

            CollectionAssert.AreEqual(assertresult31, result32);

            // 4  读取测试,带factor
            double[] assertresult41 = new double[5] {
                5, 10, 15, 20, 25
            };
            var cursor4 = storageEngine.GetCursorAsync <double>(sig11.Id, new List <long> {
                0, 5
            }, new List <long> {
                2, 10
            }, new List <long> {
                1, 5
            }).Result;
            List <double> result41 = cursor4.Read(5).Result.ToList();

            CollectionAssert.AreEqual(assertresult41, result41);
        }
Пример #6
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);
        }
Пример #7
0
        //Use Cursor.Read()
        public void JDBCCursorTest()
        {
            var exp1  = new Experiment("exp1");
            var sig11 = new Signal("sig1-1");

            myCoreService.AddJdbcEntityToAsync(Guid.Empty, exp1).Wait();
            myCoreService.AddJdbcEntityToAsync(exp1.Id, sig11).Wait();
            var data = generateDummyData();
            //  var oneDim = new List<double>(8);
            int n = 0, m = 0;

            //append signal
            for (int i = 0; i < 20; i++)
            {
                m = n + 5;
                var oneDim = new List <double>(5);
                for (; n < m; n++)
                {
                    oneDim.Add(n);
                }
                storageEngine.AppendSampleAsync(sig11.Id, new List <long> {
                    0
                }, oneDim).Wait();
            }
            n = m = 0;
            for (int i = 0; i < 20; i++)
            {
                m = n + 5;
                var oneDim = new List <double>(5);
                for (; n < m; n++)
                {
                    oneDim.Add(n);
                }
                storageEngine.AppendSampleAsync(sig11.Id, new List <long> {
                    1
                }, oneDim).Wait();
            }

            double[] assertresult1 = new double[50];
            for (int i = 46, j = 0; j < 50;)
            {
                assertresult1[j++] = i++;
            }

            var cursor             = storageEngine.GetCursorAsync <double>(sig11.Id, new List <long> {
                0, 46
            }, new List <long> {
                2, 60
            }).Result;
            List <double> result1 = cursor.Read(50).Result.ToList();

            CollectionAssert.AreEqual(assertresult1, result1);
            //var errorGetData = "";
            //try
            //{
            //    List<double> result1 = cursor.Read(5).Result.ToList();
            //}
            //catch (Exception e)
            //{
            //    errorGetData = e.InnerException.Message;
            //}
            //Assert.AreEqual(ErrorMessages.OutOfRangeError,errorGetData);

            var cursor1 = storageEngine.GetCursorAsync <double>(sig11.Id, new List <long> {
                0, 46
            }, new List <long> {
                2, 50
            }).Result;
            List <double> result2 = cursor1.Read(50).Result.ToList();

            CollectionAssert.AreEqual(assertresult1, result2);

            List <double> result3 = cursor1.Read(50).Result.ToList();

            CollectionAssert.AreEqual(assertresult1, result3);
        }