Example #1
0
        public static void RestartTest()
        {
            string TestDbDir      = "testdb_" + DateTime.Now.ToString("MMMdd_HHmm");
            string TestDbFullPath = Path.Combine(Directory.GetCurrentDirectory(), TestDbDir);

            {
                var TestDb = DatabaseInfo.CreateOrOpen(TestDbFullPath);
                DatabaseInfo.Close(TestDb);
            }

            /*
             * Guid gridGuid;
             * {
             *  var xNodes = GenericBlas.Linspace(-1.0/3.0, 10.0/3.0, 11*3 + 1);
             *  var yNodes = GenericBlas.Linspace(-1, 1, 6 * 2 + 1);
             *  var grd = Grid2D.Cartesian2DGrid(xNodes, yNodes);
             *
             *  Guid GridGuid = TestDb.Controller.DBDriver.SaveGrid(grd, TestDb);
             * };
             */

            var ctrl1 = RestartTest_FirstControl(TestDbFullPath, out var ExpectedTs1stRun);

            using (var FirstRun = new XDGTestMain()) {
                FirstRun.Init(ctrl1);
                FirstRun.RunSolverMode();
            }


            Guid RestartSession;
            {
                var TestDb2 = DatabaseInfo.CreateOrOpen(TestDbFullPath);
                Assert.IsTrue(TestDb2.Grids.Count() == 1, "Number of grids seems to be wrong.");
                Assert.IsTrue(TestDb2.Sessions.Count() == 1, "Number of sessions seems to be wrong.");


                var   si         = TestDb2.Sessions.Single();
                int[] tsiNumbers = si.Timesteps.Select(tsi => tsi.TimeStepNumber.MajorNumber).ToArray();
                Assert.IsTrue(ExpectedTs1stRun.ListEquals(tsiNumbers), "mismatch between saved time-steps in test database and expected saves.");

                //var tend = si.Timesteps.Last();
                RestartSession = si.ID;

                DatabaseInfo.Close(TestDb2);
            }


            var ctrl2 = RestartTest_SecondControl(TestDbFullPath, RestartSession, out var ExpectedTs2ndRun);

            using (var SecondRun = new XDGTestMain()) {
                SecondRun.Init(ctrl2);
                SecondRun.RunSolverMode();
            }


            {
                var TestDb3 = DatabaseInfo.CreateOrOpen(TestDbFullPath);
                Assert.IsTrue(TestDb3.Grids.Count() == 1, "Number of grids seems to be wrong.");
                Assert.IsTrue(TestDb3.Sessions.Count() == 2, "Number of sessions seems to be wrong.");


                var   si         = TestDb3.Sessions.First();
                int[] tsiNumbers = si.Timesteps.Select(tsi => tsi.TimeStepNumber.MajorNumber).ToArray();
                Assert.IsTrue(ExpectedTs2ndRun.ListEquals(tsiNumbers), "mismatch between saved time-steps in test database and expected saves.");


                DatabaseInfo.Close(TestDb3);
            }

            csMPI.Raw.Comm_Rank(csMPI.Raw._COMM.WORLD, out int rank);
            if (rank == 0)
            {
                Console.WriteLine($"Deleting test database at {TestDbFullPath} ...");
                Directory.Delete(TestDbFullPath, true);
                Console.WriteLine("done.");
            }
            csMPI.Raw.Barrier(csMPI.Raw._COMM.WORLD);
        }
Example #2
0
 private void RemoveTestDatabase(IDatabaseInfo database)
 {
     DatabaseInfo.Close(database);
     Directory.Delete(database.Path, true);
 }