public void VerifyValidityCatchesInvalidCrstmap()
        {
            var x = new JET_RSTINFO {
                crstmap = 1
            };

            x.CheckMembersAreValid();
        }
        public void VerifyValidityCatchesTooLongCrstmap()
        {
            var x = new JET_RSTINFO {
                crstmap = 3, rgrstmap = new JET_RSTMAP[2]
            };

            x.CheckMembersAreValid();
        }
        public void VerifyValidityCatchesNegativeCrstmap()
        {
            var x = new JET_RSTINFO {
                crstmap = -1
            };

            x.CheckMembersAreValid();
        }
Example #4
0
        public void JetRstinfoToString()
        {
            var value = new JET_RSTINFO()
            {
                crstmap = 3,
            };

            Assert.AreEqual("JET_RSTINFO(crstmap=3)", value.ToString());
        }
Example #5
0
        public void VerifyRstinfoCanBeSerialized()
        {
            var expected = new JET_RSTINFO
            {
                crstmap     = 1,
                lgposStop   = Any.Lgpos,
                logtimeStop = Any.Logtime,
                rgrstmap    = new[] { new JET_RSTMAP {
                                          szDatabaseName = "foo", szNewDatabaseName = "bar"
                                      } },
            };

            SerializeAndCompareContent(expected);
        }
Example #6
0
        /// <summary>
        /// Recovery to an alternate path with JetInit3.
        /// </summary>
        private void RecoverAlternatePathWithJetInit3()
        {
            using (var instance = this.CreateInstance())
            {
                instance.Init();
                using (var session = new Session(instance))
                {
                    Api.JetAttachDatabase(session, this.database, AttachDatabaseGrbit.None);
                    JET_DBID dbid;
                    Api.JetOpenDatabase(session, this.database, string.Empty, out dbid, OpenDatabaseGrbit.None);
                }
            }

#if !MANAGEDESENT_ON_WSA // The File model in Windows Store Apps has changed.
            // Delete the database and checkpoint
            File.Delete(this.database);
            File.Delete(Path.Combine(this.databaseDirectory, "edb.chk"));
#endif

            // Recovery to a different database
            string newDatabaseName = this.database + ".moved";
            var    recoveryOptions = new JET_RSTINFO
            {
                crstmap   = 1,
                pfnStatus = this.StatusCallback,
                rgrstmap  = new[]
                {
                    new JET_RSTMAP {
                        szDatabaseName = this.database, szNewDatabaseName = newDatabaseName
                    },
                },
            };

            JET_INSTANCE recoveryInstance;
            Api.JetCreateInstance(out recoveryInstance, "JetInit3");
            Api.JetSetSystemParameter(recoveryInstance, JET_SESID.Nil, JET_param.LogFileSize, 128, null);
            Api.JetSetSystemParameter(recoveryInstance, JET_SESID.Nil, JET_param.LogFilePath, 0, this.databaseDirectory);
            Api.JetSetSystemParameter(recoveryInstance, JET_SESID.Nil, JET_param.TempPath, 0, this.databaseDirectory);
            Api.JetSetSystemParameter(recoveryInstance, JET_SESID.Nil, JET_param.SystemPath, 0, this.databaseDirectory);
            VistaApi.JetInit3(ref recoveryInstance, recoveryOptions, InitGrbit.None);
            Api.JetTerm(recoveryInstance);

#if !MANAGEDESENT_ON_WSA // The File model in Windows Store Apps has changed.
            Assert.IsTrue(EseInteropTestHelper.FileExists(newDatabaseName), "New database ({0}) doesn't exist", newDatabaseName);
            Assert.IsFalse(EseInteropTestHelper.FileExists(this.database), "Old database ({0}) still exists", this.database);
            File.Move(newDatabaseName, this.database);
#endif
        }
Example #7
0
        public void VerifyJetRstinfoEquality()
        {
            DateTime      now    = DateTime.Now;
            JET_PFNSTATUS status = (sesid, snp, snt, data) => JET_err.Success;
            var           x      = new JET_RSTINFO
            {
                crstmap   = 1,
                lgposStop = new JET_LGPOS {
                    ib = 1, isec = 2, lGeneration = 3
                },
                logtimeStop = new JET_LOGTIME(now),
                pfnStatus   = status,
                rgrstmap    = new[] { new JET_RSTMAP {
                                          szDatabaseName = "foo", szNewDatabaseName = "bar"
                                      } },
            };
            var y = new JET_RSTINFO
            {
                crstmap   = 1,
                lgposStop = new JET_LGPOS {
                    ib = 1, isec = 2, lGeneration = 3
                },
                logtimeStop = new JET_LOGTIME(now),
                pfnStatus   = status,
                rgrstmap    = new[]
                {
                    new JET_RSTMAP {
                        szDatabaseName = "foo", szNewDatabaseName = "bar"
                    },
                    new JET_RSTMAP {
                        szDatabaseName = "foo", szNewDatabaseName = "bar"
                    }
                },
            };

            TestContentEquals(x, y);
        }
Example #8
0
        public void VerifyJetRstinfoInequality()
        {
            DateTime      now    = DateTime.Now;
            JET_PFNSTATUS status = (sesid, snp, snt, data) => JET_err.Success;

            var values = new JET_RSTINFO[7];

            for (int i = 0; i < values.Length; ++i)
            {
                values[i] = new JET_RSTINFO
                {
                    crstmap   = 1,
                    lgposStop = new JET_LGPOS {
                        ib = 1, isec = 2, lGeneration = 3
                    },
                    logtimeStop = new JET_LOGTIME(now),
                    pfnStatus   = status,
                    rgrstmap    = new[] { new JET_RSTMAP {
                                              szDatabaseName = "foo", szNewDatabaseName = "bar"
                                          } },
                };
            }

            int j = 1;

            values[j++].crstmap--;
            values[j++].lgposStop   = Any.Lgpos;
            values[j++].logtimeStop = Any.Logtime;
            values[j++].pfnStatus   = (sesid, snp, snt, data) => JET_err.OutOfMemory;
            values[j++].rgrstmap    = new[] { new JET_RSTMAP {
                                                  szDatabaseName = "foo", szNewDatabaseName = "baz"
                                              } };
            values[j++] = new JET_RSTINFO();
            Debug.Assert(j == values.Length, "Didn't fill in all entries of values", values.Length.ToString());
            VerifyAll(values);
        }
        /// <summary>
        /// Recovery to an alternate path with JetInit3.
        /// </summary>
        private void RecoverAlternatePathWithJetInit3()
        {
            using (var instance = this.CreateInstance())
            {
                instance.Init();
                using (var session = new Session(instance))
                {
                    Api.JetAttachDatabase(session, this.database, AttachDatabaseGrbit.None);
                    JET_DBID dbid;
                    Api.JetOpenDatabase(session, this.database, String.Empty, out dbid, OpenDatabaseGrbit.None);
                }
            }

            // Delete the database and checkpoint
            File.Delete(this.database);
            File.Delete(Path.Combine(this.databaseDirectory, "edb.chk"));

            // Recovery to a different database
            string newDatabaseName = this.database + ".moved";
            var recoveryOptions = new JET_RSTINFO
            {
                crstmap = 1,
                pfnStatus = this.StatusCallback,
                rgrstmap = new[]
                {
                    new JET_RSTMAP { szDatabaseName = this.database, szNewDatabaseName = newDatabaseName },
                },
            };

            JET_INSTANCE recoveryInstance;
            Api.JetCreateInstance(out recoveryInstance, "JetInit3");
            Api.JetSetSystemParameter(recoveryInstance, JET_SESID.Nil, JET_param.LogFileSize, 128, null);
            Api.JetSetSystemParameter(recoveryInstance, JET_SESID.Nil, JET_param.LogFilePath, 0, this.databaseDirectory);
            Api.JetSetSystemParameter(recoveryInstance, JET_SESID.Nil, JET_param.TempPath, 0, this.databaseDirectory);
            Api.JetSetSystemParameter(recoveryInstance, JET_SESID.Nil, JET_param.SystemPath, 0, this.databaseDirectory);
            VistaApi.JetInit3(ref recoveryInstance, recoveryOptions, InitGrbit.None);
            Api.JetTerm(recoveryInstance);

            Assert.IsTrue(File.Exists(newDatabaseName), "New database ({0}) doesn't exist", newDatabaseName);
            Assert.IsFalse(File.Exists(this.database), "Old database ({0}) still exists", this.database);
            File.Move(newDatabaseName, this.database);
        }
 public void VerifyValidityCatchesTooLongCrstmap()
 {
     var x = new JET_RSTINFO { crstmap = 3, rgrstmap = new JET_RSTMAP[2] };
     x.CheckMembersAreValid();
 }
 public void VerifyValidityCatchesInvalidCrstmap()
 {
     var x = new JET_RSTINFO { crstmap = 1 };
     x.CheckMembersAreValid();
 }
 public void VerifyValidityCatchesNegativeCrstmap()
 {
     var x = new JET_RSTINFO { crstmap = -1 };
     x.CheckMembersAreValid();
 }
Example #13
0
        public void Init(JET_RSTINFO recoveryOptions, InitGrbit grbit)
        {
            this.CheckObjectIsNotDisposed();
            JET_INSTANCE instance = this.JetInstance;

            // Use a constrained region so that the handle is
            // always set after JetInit3 is called.
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                // Remember that a failure in JetInit can zero the handle
                // and that JetTerm should not be called in that case.
                VistaApi.JetInit3(ref instance, recoveryOptions, grbit);
            }
            finally
            {
                this.SetHandle(instance.Value);
            }
        }
Example #14
0
 /// <summary>
 /// Initialize the ESENT database engine.
 /// </summary>
 /// <param name="instance">
 /// The instance to initialize. If an instance hasn't been
 /// allocated then a new one is created and the engine
 /// will operate in single-instance mode.
 /// </param>
 /// <param name="recoveryOptions">
 /// Additional recovery parameters for remapping databases during
 /// recovery, position where to stop recovery at, or recovery status.
 /// </param>
 /// <param name="grbit">
 /// Initialization options.
 /// </param>
 /// <returns>
 /// A warning code.
 /// </returns>
 public static JET_wrn JetInit3(ref JET_INSTANCE instance, JET_RSTINFO recoveryOptions, InitGrbit grbit)
 {
     return(Api.Check(Api.Impl.JetInit3(ref instance, recoveryOptions, grbit)));
 }
Example #15
0
 /// <summary>
 /// Initialize the ESENT database engine.
 /// </summary>
 /// <param name="instance">
 /// The instance to initialize. If an instance hasn't been
 /// allocated then a new one is created and the engine
 /// will operate in single-instance mode.
 /// </param>
 /// <param name="recoveryOptions">
 /// Additional recovery parameters for remapping databases during
 /// recovery, position where to stop recovery at, or recovery status.
 /// </param>
 /// <param name="grbit">
 /// Initialization options.
 /// </param>
 /// <returns>
 /// A warning code.
 /// </returns>
 public static JET_wrn JetInit3(ref JET_INSTANCE instance, JET_RSTINFO recoveryOptions, InitGrbit grbit)
 {
     return Api.Check(Api.Impl.JetInit3(ref instance, recoveryOptions, grbit));            
 }
Example #16
0
 public void JetRstinfoToString()
 {
     var value = new JET_RSTINFO()
     {
         crstmap = 3,
     };
     Assert.AreEqual("JET_RSTINFO(crstmap=3)", value.ToString());
 }