public void VerifyJetCommitIdEquality()
        {
            var sigX = new NATIVE_SIGNATURE()
            {
                ulRandom       = 1,
                logtimeCreate  = Any.Logtime,
                szComputerName = "Komputer",
            };
            var sigY = new NATIVE_SIGNATURE()
            {
                ulRandom       = 1,
                logtimeCreate  = sigX.logtimeCreate,
                szComputerName = "Komputer",
            };

            var x = new JET_COMMIT_ID(new NATIVE_COMMIT_ID()
            {
                signLog  = sigX,
                commitId = 123,
            });
            var y = new JET_COMMIT_ID(new NATIVE_COMMIT_ID()
            {
                signLog  = sigY,
                commitId = 123,
            });

            TestEquals(x, y);
            Assert.IsTrue(x == y);
            Assert.IsFalse(x != y);
        }
        public void VerifyJetCommitIdEqualityToNullIsFalse()
        {
            var sigX = new NATIVE_SIGNATURE()
            {
                ulRandom       = 1,
                logtimeCreate  = Any.Logtime,
                szComputerName = "Komputer",
            };

            var x = new JET_COMMIT_ID(new NATIVE_COMMIT_ID()
            {
                signLog  = sigX,
                commitId = 123,
            });

            Assert.IsFalse(x == null);

            Assert.AreEqual(1, x.CompareTo(null));

            var commitZero = new JET_COMMIT_ID(new NATIVE_COMMIT_ID()
            {
                signLog  = sigX,
                commitId = 0,
            });

            Assert.AreEqual(0, commitZero.CompareTo(null));
        }
        public void VerifyJetCommitIdThrowsExceptionWithInequalSignatures()
        {
            var sigX = new NATIVE_SIGNATURE()
            {
                ulRandom       = 1,
                logtimeCreate  = Any.Logtime,
                szComputerName = "Komputer",
            };
            var sigDifferent = new NATIVE_SIGNATURE()
            {
                ulRandom       = 7777,
                logtimeCreate  = Any.Logtime,
                szComputerName = "Different!",
            };

            var x = new JET_COMMIT_ID(new NATIVE_COMMIT_ID()
            {
                signLog  = sigX,
                commitId = 789,
            });
            var y = new JET_COMMIT_ID(new NATIVE_COMMIT_ID()
            {
                signLog  = sigDifferent,
                commitId = 789,
            });

            Assert.AreNotEqual(0, x.CompareTo(y));
        }
 /// <summary>
 /// Test callback method
 /// </summary>
 /// <param name="instance">Current instance.</param>
 /// <param name="commitId">Commit id seen.</param>
 /// <param name="grbit">Grbit - reserved.</param>
 /// <returns>Success or error.</returns>
 private JET_err TestFlushCallback(
     JET_INSTANCE instance,
     JET_COMMIT_ID commitId,
     DurableCommitCallbackGrbit grbit)
 {
     return(JET_err.Success);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Commits the changes made to the state of the database during the current save point
 /// and migrates them to the previous save point. If the outermost save point is committed
 /// then the changes made during that save point will be committed to the state of the
 /// database and the session will exit the transaction.
 /// </summary>
 /// <param name="sesid">The session to commit the transaction for.</param>
 /// <param name="grbit">Commit options.</param>
 /// <param name="durableCommit">Duration to commit lazy transaction.</param>
 /// <param name="commitId">Commit-id associated with this commit record.</param>
 public static void JetCommitTransaction2(
     JET_SESID sesid,
     CommitTransactionGrbit grbit,
     TimeSpan durableCommit,
     out JET_COMMIT_ID commitId)
 {
     Api.Check(Api.Impl.JetCommitTransaction2(sesid, grbit, durableCommit, out commitId));
 }
Exemplo n.º 6
0
        public void VerifyJetCommitIdIncomparable()
        {
            DateTime      d         = DateTime.Now;
            JET_COMMIT_ID commitId1 = DurableCommitTests.CreateJetCommitId(1, d, "computer", 3);
            JET_COMMIT_ID commitId2 = DurableCommitTests.CreateJetCommitId(2, d, "computer", 3);

            Assert.IsTrue(commitId1.GetHashCode() != commitId2.GetHashCode());
            Assert.IsFalse(commitId1 == commitId2);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Test callback method
 /// </summary>
 /// <param name="instance">Current instance.</param>
 /// <param name="commitId">Commit id seen.</param>
 /// <param name="grbit">Grbit - reserved.</param>
 /// <returns>Success or error.</returns>
 private JET_err TestCallback(
     JET_INSTANCE instance,
     JET_COMMIT_ID commitId,
     DurableCommitCallbackGrbit grbit)
 {
     this.lastCommitIdFlushed = commitId;
     this.lastCallbackTime    = DateTime.Now;
     return(JET_err.Success);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Commit a transaction. This object should be in a transaction.
        /// </summary>
        /// <param name="grbit">JetCommitTransaction options.</param>
        /// <param name="durableCommit">Duration for committing lazy transactions.</param>
        /// <param name="commitId">Commit-id for this commit record.</param>
        public void Commit(CommitTransactionGrbit grbit, TimeSpan durableCommit, out JET_COMMIT_ID commitId)
        {
            this.CheckObjectIsNotDisposed();
            if (!this.IsInTransaction)
            {
                throw new InvalidOperationException("Not in a transaction");
            }

            Windows8.Windows8Api.JetCommitTransaction2(this.sesid, grbit, durableCommit, out commitId);
            this.ResourceWasReleased();
            Debug.Assert(!this.IsInTransaction, "Commit finished, but object is still in a transaction");
        }
        public void JetCommitIdToString()
        {
            DateTime      d         = DateTime.Now;
            JET_COMMIT_ID commitId  = DurableCommitTests.CreateJetCommitId(1, d, "computer", 2);
            var           signature = new JET_SIGNATURE(1, d, "computer");

            string sigString = signature.ToString();
            string expected  = string.Format(
                CultureInfo.InvariantCulture,
                string.Format("JET_COMMIT_ID({0}:2", sigString));

            Assert.AreEqual(expected, commitId.ToString());
        }
Exemplo n.º 10
0
        public void VerifyJetCommitIdEquality()
        {
            DateTime      d         = DateTime.Now;
            JET_COMMIT_ID commitId1 = DurableCommitTests.CreateJetCommitId(1, d, "computer", 2);
            JET_COMMIT_ID commitId2 = DurableCommitTests.CreateJetCommitId(1, d, "computer", 2);

            Assert.IsTrue(commitId1 == commitId2);
            Assert.IsTrue(commitId1.GetHashCode() == commitId2.GetHashCode());
            Assert.IsTrue(commitId1.Equals(commitId2));
            Assert.IsFalse(commitId1 != commitId2);
            Assert.IsTrue(commitId1 <= commitId2);
            Assert.IsFalse(commitId1 < commitId2);
            Assert.IsTrue(commitId1 >= commitId2);
            Assert.IsFalse(commitId1 > commitId2);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Commits the changes made to the state of the database during the current save point
        /// and migrates them to the previous save point. If the outermost save point is committed
        /// then the changes made during that save point will be committed to the state of the
        /// database and the session will exit the transaction.
        /// </summary>
        /// <param name="sesid">The session to commit the transaction for.</param>
        /// <param name="grbit">Commit options.</param>
        /// <param name="durableCommit">Duration to commit lazy transaction.</param>
        /// <param name="commitId">Commit-id associated with this commit record.</param>
        /// <returns>An error if the call fails.</returns>
        public int JetCommitTransaction2(JET_SESID sesid, CommitTransactionGrbit grbit, TimeSpan durableCommit, out JET_COMMIT_ID commitId)
        {
            TraceFunctionCall("JetCommitTransaction2");
            this.CheckSupportsWindows8Features("JetCommitTransaction2");
            int err;
            uint cmsecDurableCommit = (uint)durableCommit.TotalMilliseconds;

            NATIVE_COMMIT_ID nativeCommitId = new NATIVE_COMMIT_ID();
            unsafe
            {
                err = Err(NativeMethods.JetCommitTransaction2(sesid.Value, unchecked((uint)grbit), cmsecDurableCommit, ref nativeCommitId));
            }

            commitId = new JET_COMMIT_ID(nativeCommitId);

            return err;
        }
        public void VerifyJetCommitIdEqualityToWrongTypeIsFalse()
        {
            var sigX = new NATIVE_SIGNATURE()
            {
                ulRandom       = 1,
                logtimeCreate  = Any.Logtime,
                szComputerName = "Komputer",
            };

            var x = new JET_COMMIT_ID(new NATIVE_COMMIT_ID()
            {
                signLog  = sigX,
                commitId = 123,
            });

            Assert.IsFalse(x.Equals(sigX));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Commits the changes made to the state of the database during the current save point
        /// and migrates them to the previous save point. If the outermost save point is committed
        /// then the changes made during that save point will be committed to the state of the
        /// database and the session will exit the transaction.
        /// </summary>
        /// <param name="sesid">The session to commit the transaction for.</param>
        /// <param name="grbit">Commit options.</param>
        /// <param name="durableCommit">Duration to commit lazy transaction.</param>
        /// <param name="commitId">Commit-id associated with this commit record.</param>
        /// <returns>An error if the call fails.</returns>
        public int JetCommitTransaction2(JET_SESID sesid, CommitTransactionGrbit grbit, TimeSpan durableCommit, out JET_COMMIT_ID commitId)
        {
            TraceFunctionCall();
            this.CheckSupportsWindows8Features("JetCommitTransaction2");
            int  err;
            uint cmsecDurableCommit = (uint)durableCommit.TotalMilliseconds;

            NATIVE_COMMIT_ID nativeCommitId = new NATIVE_COMMIT_ID();

            unsafe
            {
                err = Err(NativeMethods.JetCommitTransaction2(sesid.Value, unchecked ((uint)grbit), cmsecDurableCommit, ref nativeCommitId));
            }

            commitId = new JET_COMMIT_ID(nativeCommitId);

            return(err);
        }
        public void Setup()
        {
            var sigX = new NATIVE_SIGNATURE()
            {
                ulRandom       = 1,
                logtimeCreate  = Any.Logtime,
                szComputerName = "Komputer",
            };

            this.managedOriginal = new JET_COMMIT_ID(new NATIVE_COMMIT_ID()
            {
                signLog  = sigX,
                commitId = 123,
            });

            this.native  = this.managedOriginal.GetNativeCommitId();
            this.managed = new JET_COMMIT_ID(this.native);
        }
        /// <summary>
        /// The proxy callback function to call the user-defined managed delegate.
        /// </summary>
        /// <param name="instance">
        /// The instance.
        /// </param>
        /// <param name="commitIdSeen">
        /// The commit-id flushed.
        /// </param>
        /// <param name="grbit">
        /// Reserved currently.
        /// </param>
        /// <returns>
        /// An error code.
        /// </returns>
        private JET_err NativeDurableCommitCallback(
            IntPtr instance,
            ref NATIVE_COMMIT_ID commitIdSeen,
            uint grbit)
        {
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                JET_INSTANCE jetInstance = new JET_INSTANCE()
                {
                    Value = instance
                };

                if (this.instance != jetInstance)
                {
                    // We assume it's only called on one instance at a time. The only thing
                    // we really care about is serialization of the byte array.
                    //
                    // It would be nice to throw an error, but we're going back to real
                    // code, which doesn't deal with managed exceptions well.
                    return JET_err.CallbackFailed;
                }

                JET_COMMIT_ID commitId = new JET_COMMIT_ID(commitIdSeen);

                return this.wrappedCallback(jetInstance, commitId, (DurableCommitCallbackGrbit)grbit);
            }
            catch (Exception ex)
            {
                Trace.WriteLineIf(
                    TraceSwitch.TraceWarning, string.Format(CultureInfo.InvariantCulture, "Caught Exception {0}", ex));

                JetApi.ReportUnhandledException(ex, "Unhandled exception during NativeDurableCommitCallback");

                // This should never be executed, but the compiler doesn't know it.
                return JET_err.CallbackFailed;
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Commit a transaction. This object should be in a transaction.
        /// </summary>
        /// <param name="grbit">JetCommitTransaction options.</param>
        /// <param name="durableCommit">Duration for committing lazy transactions.</param>
        /// <param name="commitId">Commit-id for this commit record.</param>
        public void Commit(CommitTransactionGrbit grbit, TimeSpan durableCommit, out JET_COMMIT_ID commitId)
        {
            this.CheckObjectIsNotDisposed();
            if (!this.IsInTransaction)
            {
                throw new InvalidOperationException("Not in a transaction");
            }

            Windows8.Windows8Api.JetCommitTransaction2(this.sesid, grbit, durableCommit, out commitId);
            this.ResourceWasReleased();
            Debug.Assert(!this.IsInTransaction, "Commit finished, but object is still in a transaction");
        }