Ejemplo n.º 1
0
        public void VerifyJetSetSessionContextAllowsThreadMigration()
        {
            using (var instance = new Instance("JetSetSessionContext"))
            {
                SetupHelper.SetLightweightConfiguration(instance);
                instance.Init();
                using (var session = new Session(instance))
                {
                    // Without the calls to JetSetSessionContext/JetResetSessionContext
                    // this will generate a session sharing violation.
                    var context = new IntPtr(Any.Int32);

                    var thread = new Thread(() =>
                    {
                        EseInteropTestHelper.ThreadBeginThreadAffinity();
                        Api.JetSetSessionContext(session, context);
                        Api.JetBeginTransaction(session);
                        Api.JetResetSessionContext(session);
                        EseInteropTestHelper.ThreadEndThreadAffinity();
                    });
                    thread.Start();
                    thread.Join();

                    Api.JetSetSessionContext(session, context);
                    Api.JetCommitTransaction(session, CommitTransactionGrbit.None);
                    Api.JetResetSessionContext(session);
                }
            }
        }
Ejemplo n.º 2
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>
            /// Initializes a new instance of the <see cref="PerfTestWorker"/> class.
            /// </summary>
            public PerfTestWorker()
            {
                EseInteropTestHelper.ThreadBeginThreadAffinity();

                this.data            = new byte[DictionaryOpenCloseTest.DataSize];
                this.persistentBlob  = new PersistentBlob(this.data);
                this.RandomGenerator = new Random();
            }
Ejemplo n.º 4
0
            /// <summary>
            /// Initializes a new instance of the <see cref="PerfTestWorker"/> class.
            /// </summary>
            /// <param name="instance">
            /// The instance to use.
            /// </param>
            /// <param name="database">
            /// Path to the database. The database should already be created.
            /// </param>
            public PerfTestWorker(JET_INSTANCE instance, string database)
            {
                EseInteropTestHelper.ThreadBeginThreadAffinity();
                this.instance = instance;
                this.database = database;
                this.session  = new Session(this.instance);
                Api.JetOpenDatabase(this.session, this.database, string.Empty, out this.dbid, OpenDatabaseGrbit.None);
                this.table        = new Table(this.session, this.dbid, SimplePerfTest.TableName, OpenTableGrbit.None);
                this.columnidKey  = Api.GetTableColumnid(this.session, this.table, SimplePerfTest.KeyColumnName);
                this.columnidData = Api.GetTableColumnid(this.session, this.table, SimplePerfTest.DataColumnName);

                this.data    = new byte[SimplePerfTest.DataSize];
                this.dataBuf = new byte[SimplePerfTest.DataSize];
            }
Ejemplo n.º 5
0
            /// <summary>
            /// Initializes a new instance of the <see cref="PerfTestWorker"/> class.
            /// </summary>
            /// <param name="longDictionary">
            /// The dictionary to use for integer lookups.
            /// </param>
            /// <param name="longDatabase">
            /// Path to the integer-lookup database. The database should already be created.
            /// </param>
            /// <param name="stringDictionary">
            /// The dictionary to use for string lookups.
            /// </param>
            /// <param name="stringDatabase">
            /// Path to the string-lookup database. The database should already be created.
            /// </param>
            public PerfTestWorker(
                PersistentDictionary <long, PersistentBlob> longDictionary,
                string longDatabase,
                PersistentDictionary <string, PersistentBlob> stringDictionary,
                string stringDatabase)
            {
                EseInteropTestHelper.ThreadBeginThreadAffinity();
                this.longDictionary   = longDictionary;
                this.longDatabase     = longDatabase;
                this.stringDictionary = stringDictionary;
                this.stringDatabase   = stringDatabase;

                this.data           = new byte[SimpleDictionaryPerfTest.DataSize];
                this.persistentBlob = new PersistentBlob(this.data);
            }
Ejemplo n.º 6
0
        public void VerifyJetSetSessionContextAllowsThreadMigration()
        {
            // Without the calls to JetSetSessionContext/JetResetSessionContext
            // this will generate a session sharing violation.
            var context = new IntPtr(Any.Int32);

            var thread = new Thread(() =>
            {
                EseInteropTestHelper.ThreadBeginThreadAffinity();
                Api.JetSetSessionContext(this.sesid, context);
                Api.JetBeginTransaction(this.sesid);
                Api.JetResetSessionContext(this.sesid);
                EseInteropTestHelper.ThreadEndThreadAffinity();
            });

            thread.Start();
            thread.Join();

            Api.JetSetSessionContext(this.sesid, context);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.None);
            Api.JetResetSessionContext(this.sesid);
        }