Example #1
0
        public void LazyCommitWithSmallerDuration()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            Api.JetBeginTransaction(this.sesid);
            this.InsertRecord(this.tableid, 2);
            this.InsertRecord(this.tableid, 1);
            this.InsertRecord(this.tableid, 3);
            JET_COMMIT_ID commitId1;

            Windows8Api.JetCommitTransaction2(this.sesid, CommitTransactionGrbit.LazyFlush, new TimeSpan(0, 0, 5), out commitId1);
            Api.JetBeginTransaction(this.sesid);
            this.InsertRecord(this.tableid, 4);
            this.InsertRecord(this.tableid, 5);
            JET_COMMIT_ID commitId2;

            Windows8Api.JetCommitTransaction2(this.sesid, CommitTransactionGrbit.LazyFlush, new TimeSpan(0, 0, 2), out commitId2);
            DateTime commitTime = DateTime.Now;

            Assert.IsTrue(commitId2 > commitId1);
            EseInteropTestHelper.ThreadSleep(2500);
            TimeSpan timeToFlush = this.lastCallbackTime - commitTime;

            Assert.IsTrue(commitId2 < this.lastCommitIdFlushed);
            Assert.IsTrue(timeToFlush.TotalMilliseconds < 2500);
        }
Example #2
0
        /// <summary>
        /// Perform an action and retry on I/O failure, with a 1 second
        /// sleep between retries.
        /// </summary>
        /// <param name="action">The action to perform.</param>
        private static void PerformActionWithRetry(Action action)
        {
            for (int attempt = 1; attempt <= MaxAttempts; ++attempt)
            {
                try
                {
                    action();
                    return;
                }
                catch (UnauthorizedAccessException)
                {
                    if (MaxAttempts == attempt)
                    {
                        throw;
                    }
                }
                catch (IOException)
                {
                    if (MaxAttempts == attempt)
                    {
                        throw;
                    }
                }

                EseInteropTestHelper.ThreadSleep(TimeSpan.FromSeconds(1));
            }
        }
Example #3
0
            /// <summary>
            /// Process the records sequentially. This method tries
            /// to lock a record and moves to the next record if
            /// it fails to get the lock.
            /// </summary>
            public void DoWork()
            {
                EseInteropTestHelper.ThreadBeginThreadAffinity();

                // We must be in a transaction for locking to work.
                using (var transaction = new Transaction(this.sesid))
                {
                    if (Api.TryMoveFirst(this.sesid, this.tableid))
                    {
                        do
                        {
                            // Getting a lock in ESENT is instantaneous -- if
                            // another thread has the record locked or has
                            // updated this record, this call will fail. There
                            // is no way to wait for the lock to be released.
                            // (because ESENT uses Snapshot Isolation the other
                            // session's lock will always be visible until this
                            // transaction commits).
                            if (Api.TryGetLock(this.sesid, this.tableid, GetLockGrbit.Write))
                            {
                                // [Do something]
                                EseInteropTestHelper.ThreadSleep(1);
                                Api.JetDelete(this.sesid, this.tableid);
                                this.RecordsProcessed++;
                            }
                        }while (Api.TryMoveNext(this.sesid, this.tableid));
                    }

                    transaction.Commit(CommitTransactionGrbit.LazyFlush);
                }

                EseInteropTestHelper.ThreadEndThreadAffinity();
            }
        /// <summary>
        /// Thread function for MemoryCache stress. This allocates, uses and frees buffers.
        /// </summary>
        /// <param name="id">The id of the thread.</param>
        /// <param name="endTime">The time this test should stop running.</param>
        private void MemoryCacheStressThread(int id, DateTime endTime)
        {
            byte marker = checked ((byte)id);

            while (DateTime.Now < endTime)
            {
                for (int i = 0; i < 128; ++i)
                {
                    byte[] buffer = this.memoryCache.Allocate();
                    Assert.IsNotNull(buffer);
                    buffer[0] = marker;
                    EseInteropTestHelper.ThreadSleep(0);
                    Assert.AreEqual(marker, buffer[0]);
                    this.memoryCache.Free(ref buffer);
                }
            }
        }