CreateRandomDirectory() 공개 정적인 메소드

Creates a new random directory in the current working directory. This should be used to ensure that each test runs in its own directory.
public static CreateRandomDirectory ( ) : string
리턴 string
예제 #1
0
        public void Setup()
        {
            this.directory = SetupHelper.CreateRandomDirectory();
            this.database  = Path.Combine(this.directory, "database.edb");
            this.table     = "table";
            this.instance  = SetupHelper.CreateNewInstance(this.directory);

            Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, JET_param.PageTempDBMin, SystemParameters.PageTempDBSmallest, null);
            Api.JetInit(ref this.instance);
            Api.JetBeginSession(this.instance, out this.sesid, String.Empty, String.Empty);
            Api.JetCreateDatabase(this.sesid, this.database, String.Empty, out this.dbid, CreateDatabaseGrbit.None);
            Api.JetBeginTransaction(this.sesid);
            Api.JetCreateTable(this.sesid, this.dbid, this.table, 0, 100, out this.tableid);

            var columndef = new JET_COLUMNDEF()
            {
                cp     = JET_CP.Unicode,
                coltyp = JET_coltyp.LongText,
            };

            Api.JetAddColumn(this.sesid, this.tableid, "TestColumn", columndef, null, 0, out this.columnidLongText);

            Api.JetCloseTable(this.sesid, this.tableid);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);
            Api.JetOpenTable(this.sesid, this.dbid, this.table, null, 0, OpenTableGrbit.None, out this.tableid);
        }
예제 #2
0
        public void JetSetDatabaseSizeThrowsExceptionWhenDesiredPagesIsNegative()
        {
            string       dir      = SetupHelper.CreateRandomDirectory();
            JET_INSTANCE instance = SetupHelper.CreateNewInstance(dir);

            Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.MaxTemporaryTables, 0, null);
            Api.JetInit(ref instance);
            string database = Path.Combine(dir, "test.db");

            JET_SESID sesid;
            JET_DBID  dbid;

            Api.JetBeginSession(instance, out sesid, string.Empty, string.Empty);

            try
            {
                Api.JetCreateDatabase(sesid, database, string.Empty, out dbid, CreateDatabaseGrbit.None);

                int actualPages;

                Api.JetSetDatabaseSize(sesid, database, -1, out actualPages);
            }
            finally
            {
                Api.JetTerm(instance);
                Cleanup.DeleteDirectoryWithRetry(dir);
            }
        }
예제 #3
0
        public void CreateDatabaseAndOpenReadOnly()
        {
            string       dir      = SetupHelper.CreateRandomDirectory();
            JET_INSTANCE instance = SetupHelper.CreateNewInstance(dir);

            Api.JetInit(ref instance);
            try
            {
                string database = Path.Combine(dir, "test.db");

                JET_SESID sesid;
                JET_DBID  dbid;
                Api.JetBeginSession(instance, out sesid, String.Empty, String.Empty);
                Api.JetCreateDatabase(sesid, database, String.Empty, out dbid, CreateDatabaseGrbit.None);
                Api.JetCloseDatabase(sesid, dbid, CloseDatabaseGrbit.None);
                Api.JetDetachDatabase(sesid, database);

                Api.JetAttachDatabase(sesid, database, AttachDatabaseGrbit.ReadOnly);
                Api.JetOpenDatabase(sesid, database, String.Empty, out dbid, OpenDatabaseGrbit.ReadOnly);
                Api.JetCloseDatabase(sesid, dbid, CloseDatabaseGrbit.None);
                Api.JetDetachDatabase(sesid, database);
            }
            finally
            {
                Api.JetTerm(instance);
                Directory.Delete(dir, true);
            }
        }
예제 #4
0
        public void TestSetup()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            this.directory = SetupHelper.CreateRandomDirectory();
            this.database  = Path.Combine(this.directory, "database.edb");
            this.instance  = SetupHelper.CreateNewInstance(this.directory);

////            Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, UnpublishedParam.EnablePeriodicShrinkDatabase, 0, null);
            this.callback = new DurableCommitCallback(this.instance, this.TestCallback);

            Api.JetInit(ref this.instance);
            Api.JetBeginSession(this.instance, out this.sesid, string.Empty, string.Empty);

            Api.JetCreateDatabase(this.sesid, this.database, string.Empty, out this.dbid, CreateDatabaseGrbit.None);
            Api.JetCloseDatabase(this.sesid, this.dbid, CloseDatabaseGrbit.None);

            Api.JetOpenDatabase(this.sesid, this.database, null, out this.dbid, OpenDatabaseGrbit.None);
            Api.JetBeginTransaction(this.sesid);
            JET_TABLECREATE tc = this.CreateTable(this.tableName);

            Api.JetCloseTable(this.sesid, tc.tableid);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.None);
            Api.JetOpenTable(this.sesid, this.dbid, this.tableName, null, 0, OpenTableGrbit.None, out this.tableid);
        }
예제 #5
0
        public void CreateBasicTableColumnIndex3OnXp()
        {
            var tablecreate = new JET_TABLECREATE {
                szTableName = "table"
            };

            string directory = SetupHelper.CreateRandomDirectory();
            string database  = Path.Combine(directory, "test.db");

            using (var instance = new Instance("XpCreateBasicTableColumnIndex3"))
            {
                instance.Parameters.Recovery           = false;
                instance.Parameters.NoInformationEvent = true;
                instance.Parameters.MaxTemporaryTables = 0;
                instance.Init();
                using (var session = new Session(instance))
                {
                    JET_DBID dbid;
                    Api.JetCreateDatabase(session, database, String.Empty, out dbid, CreateDatabaseGrbit.None);
                    using (var transaction = new Transaction(session))
                    {
                        Api.JetCreateTableColumnIndex3(session, dbid, tablecreate);
                        Assert.AreNotEqual(JET_TABLEID.Nil, tablecreate.tableid);
                        Assert.AreEqual(tablecreate.cCreated, 1);
                        Api.JetCloseTable(session, tablecreate.tableid);
                        transaction.Commit(CommitTransactionGrbit.LazyFlush);
                    }
                }
            }
        }
        public void GetDatabaseFileInfoOnVista()
        {
            if (!EsentVersion.SupportsVistaFeatures)
            {
                return;
            }

            string directory = SetupHelper.CreateRandomDirectory();
            string database  = Path.Combine(directory, "test.db");

            using (var instance = new Instance("VistaJetGetDatabaseFileInfo"))
            {
                SetupHelper.SetLightweightConfiguration(instance);
                instance.Init();
                using (var session = new Session(instance))
                {
                    JET_DBID dbid;
                    Api.JetCreateDatabase(session, database, string.Empty, out dbid, CreateDatabaseGrbit.None);
                }
            }

            JET_DBINFOMISC dbinfomisc;

            Api.JetGetDatabaseFileInfo(database, out dbinfomisc, JET_DbInfo.Misc);
            Assert.AreEqual(SystemParameters.DatabasePageSize, dbinfomisc.cbPageSize);

            Cleanup.DeleteDirectoryWithRetry(directory);
        }
예제 #7
0
        public void Setup()
        {
            this.directory = SetupHelper.CreateRandomDirectory();
            this.database  = Path.Combine(this.directory, "database.edb");
            this.table     = "table";
            this.instance  = SetupHelper.CreateNewInstance(this.directory);

            Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, JET_param.Recovery, 0, "off");
            Api.JetInit(ref this.instance);
            Api.JetBeginSession(this.instance, out this.sesid, string.Empty, string.Empty);
            Api.JetCreateDatabase(this.sesid, this.database, string.Empty, out this.dbid, CreateDatabaseGrbit.None);
            Api.JetBeginTransaction(this.sesid);
            Api.JetCreateTable(this.sesid, this.dbid, this.table, 0, 100, out this.tableid);

            JET_COLUMNID ignored;
            var          columndef = new JET_COLUMNDEF {
                coltyp = JET_coltyp.Text, cp = JET_CP.Unicode
            };

            Api.JetAddColumn(this.sesid, this.tableid, "C1", columndef, null, 0, out ignored);
            Api.JetAddColumn(this.sesid, this.tableid, "C2", columndef, null, 0, out ignored);
            Api.JetAddColumn(this.sesid, this.tableid, "C3", columndef, null, 0, out ignored);

            Api.JetCreateIndex(this.sesid, this.tableid, "Primary", CreateIndexGrbit.IndexPrimary, "+C1\0\0", 5, 100);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);

            JET_INDEXCREATE[] indexcreates = new[]
            {
                new JET_INDEXCREATE {
                    szIndexName = "Index2", cbKey = 5, szKey = "+C2\0\0"
                },
                new JET_INDEXCREATE {
                    szIndexName = "Index3", cbKey = 5, szKey = "+C3\0\0", cbVarSegMac = 100
                },
            };
            Api.JetCreateIndex2(this.sesid, this.tableid, indexcreates, indexcreates.Length);

            if (EsentVersion.SupportsWindows8Features)
            {
                var unicode = new JET_UNICODEINDEX()
                {
                    szLocaleName = "pt-br",
                    dwMapFlags   = Conversions.LCMapFlagsFromCompareOptions(CompareOptions.None),
                };

                var indexcreate = new JET_INDEXCREATE
                {
                    szIndexName = "win8BrazilIndex",
                    szKey       = "+C2\0\0",
                    cbKey       = 5,
                    pidxUnicode = unicode,
                    grbit       = CreateIndexGrbit.IndexIgnoreAnyNull,
                    ulDensity   = 100,
                };
                Windows8Api.JetCreateIndex4(this.sesid, this.tableid, new[] { indexcreate }, 1);
            }

            Api.JetCloseTable(this.sesid, this.tableid);
            Api.JetOpenTable(this.sesid, this.dbid, this.table, null, 0, OpenTableGrbit.None, out this.tableid);
        }
 public void Setup()
 {
     this.directory = SetupHelper.CreateRandomDirectory();
     this.instance  = SetupHelper.CreateNewInstance(this.directory);
     Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, JET_param.MaxTemporaryTables, 0, null);
     Api.JetInit(ref this.instance);
 }
예제 #9
0
        public void Setup()
        {
            this.directory = SetupHelper.CreateRandomDirectory();
            this.database  = Path.Combine(this.directory, "database.edb");
            this.table     = "table";
            this.instance  = SetupHelper.CreateNewInstance(this.directory);

            Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, JET_param.MaxTemporaryTables, 0, null);
            Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, JET_param.Recovery, 0, "off");
            Api.JetInit(ref this.instance);
            Api.JetBeginSession(this.instance, out this.sesid, String.Empty, String.Empty);
            Api.JetCreateDatabase(this.sesid, this.database, String.Empty, out this.dbid, CreateDatabaseGrbit.None);
            Api.JetBeginTransaction(this.sesid);
            Api.JetCreateTable(this.sesid, this.dbid, this.table, 0, 100, out this.tableid);

            var columndef = new JET_COLUMNDEF()
            {
                coltyp = JET_coltyp.Long,
                grbit  = ColumndefGrbit.ColumnEscrowUpdate,
            };

            Api.JetAddColumn(this.sesid, this.tableid, "EscrowColumn", columndef, BitConverter.GetBytes(0), 4, out this.columnid);

            Api.JetCloseTable(this.sesid, this.tableid);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);
            Api.JetOpenTable(this.sesid, this.dbid, this.table, null, 0, OpenTableGrbit.None, out this.tableid);
            Api.JetBeginTransaction(this.sesid);
            Api.JetPrepareUpdate(this.sesid, this.tableid, JET_prep.Insert);
            Api.JetUpdate(this.sesid, this.tableid);
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);
            Api.JetMove(this.sesid, this.tableid, JET_Move.First, MoveGrbit.None);
        }
예제 #10
0
        public void Setup()
        {
            var random = new Random();

            this.numRecords = random.Next(5, 20);

            this.directory = SetupHelper.CreateRandomDirectory();
            this.instance  = SetupHelper.CreateNewInstance(this.directory);

            // turn off logging so initialization is faster
            Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, JET_param.Recovery, 0, "off");
            Api.JetInit(ref this.instance);
            Api.JetBeginSession(this.instance, out this.sesid, String.Empty, String.Empty);

            var columns = new[] { new JET_COLUMNDEF {
                                      coltyp = JET_coltyp.Long, grbit = ColumndefGrbit.TTKey
                                  } };
            var columnids = new JET_COLUMNID[columns.Length];

            // BUG: use TempTableGrbit.Indexed once in-memory TT bugs are fixed
            Api.JetOpenTempTable(this.sesid, columns, columns.Length, TempTableGrbit.ForceMaterialization, out this.tableid, columnids);
            this.columnidLong = columnids[0];

            for (int i = 0; i < this.numRecords; ++i)
            {
                Api.JetPrepareUpdate(this.sesid, this.tableid, JET_prep.Insert);
                Api.JetSetColumn(this.sesid, this.tableid, this.columnidLong, BitConverter.GetBytes(i), 4, SetColumnGrbit.None, null);
                int ignored;
                Api.JetUpdate(this.sesid, this.tableid, null, 0, out ignored);
            }
        }
예제 #11
0
        public void CreateUsingDatabaseFilenameAndConfigSet()
        {
            string directory = SetupHelper.CreateRandomDirectory();
            string db        = Path.Combine(directory, DatabaseObjectTests.DbName);
            string log       = Path.Combine(directory, this.edbLogFileName);

            var engineConfig = new DatabaseConfig()
            {
                DatabasePageSize = 32 * 1024,
                CircularLog      = true,
                LogFileSize      = 1024,
                DisplayName      = "DatabaseTest",
            };

            using (this.database = new Database(db, engineConfig))
            {
                Assert.AreNotEqual(this.database.InstanceHandle, JET_INSTANCE.Nil);

                int    intParamVal = 0;
                string strParamVal;

                Api.JetGetSystemParameter(this.database.InstanceHandle, JET_SESID.Nil, JET_param.DatabasePageSize, ref intParamVal, out strParamVal, 256);
                Assert.AreEqual(engineConfig.DatabasePageSize, intParamVal);

                Api.JetGetSystemParameter(this.database.InstanceHandle, JET_SESID.Nil, JET_param.CircularLog, ref intParamVal, out strParamVal, 256);
                Assert.IsTrue(engineConfig.CircularLog == (intParamVal == 1));
            }

#if !MANAGEDESENT_ON_WSA
            Assert.AreEqual(engineConfig.LogFileSize * 1024, new FileInfo(log).Length);
            Assert.IsTrue(File.Exists(db));
            Assert.IsTrue(File.Exists(log));
#endif
        }
예제 #12
0
        public void CreateAndGrowDatabase()
        {
            string dir = SetupHelper.CreateRandomDirectory();
            JET_INSTANCE instance = SetupHelper.CreateNewInstance(dir);
            Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.MaxTemporaryTables, 0, null);
            Api.JetInit(ref instance);
            try
            {
                string database = Path.Combine(dir, "test.db");

                JET_SESID sesid;
                JET_DBID dbid;
                Api.JetBeginSession(instance, out sesid, String.Empty, String.Empty);
                Api.JetCreateDatabase(sesid, database, String.Empty, out dbid, CreateDatabaseGrbit.None);

                // BUG: ESENT requires that JetGrowDatabase be in a transaction (Win7 and below)
                Api.JetBeginTransaction(sesid);
                int actualPages;
                Api.JetGrowDatabase(sesid, dbid, 512, out actualPages);
                Api.JetCommitTransaction(sesid, CommitTransactionGrbit.None);
                Assert.IsTrue(actualPages >= 512, "Database didn't grow");
            }
            finally
            {
                Api.JetTerm(instance);
                Cleanup.DeleteDirectoryWithRetry(dir);
            }
        }
예제 #13
0
        public void CreateAndOpenDatabase()
        {
            string dir = SetupHelper.CreateRandomDirectory();
            JET_INSTANCE instance = SetupHelper.CreateNewInstance(dir);
            Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.MaxTemporaryTables, 0, null);
            Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.Recovery, 0, "off");
            Api.JetInit(ref instance);
            try
            {
                string database = Path.Combine(dir, "test.db");

                JET_SESID sesid;
                JET_DBID dbid;
                Api.JetBeginSession(instance, out sesid, String.Empty, String.Empty);
                Api.JetCreateDatabase(sesid, database, String.Empty, out dbid, CreateDatabaseGrbit.None);
                Api.JetCloseDatabase(sesid, dbid, CloseDatabaseGrbit.None);
                Api.JetDetachDatabase(sesid, database);

                Api.JetAttachDatabase(sesid, database, AttachDatabaseGrbit.None);
                Api.JetOpenDatabase(sesid, database, String.Empty, out dbid, OpenDatabaseGrbit.None);
                Api.JetCloseDatabase(sesid, dbid, CloseDatabaseGrbit.None);
                Api.JetDetachDatabase(sesid, database);
            }
            finally
            {
                Api.JetTerm(instance);
                Cleanup.DeleteDirectoryWithRetry(dir);
            }
        }
예제 #14
0
        public void VerifyInstanceGetSetPropertiesWork()
        {
            string dir = SetupHelper.CreateRandomDirectory();

#if !MANAGEDESENT_ON_WSA
            string dirFull = Path.GetFullPath(dir);
#endif
            using (var instance = new Instance("createnoinit"))
            {
                Assert.AreNotEqual(JET_INSTANCE.Nil, instance.JetInstance);
                Assert.IsNotNull(instance.Parameters);

                instance.Parameters.LogFileDirectory = dir;
                instance.Parameters.SystemDirectory  = dir;
                instance.Parameters.TempDirectory    = dir;
                instance.TermGrbit = TermGrbit.Complete;

#if MANAGEDESENT_ON_WSA
                // We can't get the full path in Windows Store Apps, so we'll just confirm that
                // everything was set to the same value.
                string dirFull = instance.Parameters.LogFileDirectory;
                Assert.AreNotEqual(".\\", dirFull);
#else
                Assert.AreEqual(dirFull, instance.Parameters.LogFileDirectory);
#endif
                Assert.AreEqual(dirFull, instance.Parameters.SystemDirectory);
                Assert.AreEqual(dirFull, instance.Parameters.TempDirectory);
                Assert.AreEqual(TermGrbit.Complete, instance.TermGrbit);
            }

            Cleanup.DeleteDirectoryWithRetry(dir);
        }
        public void CreateResizeAndTrimDatabase()
        {
            if (!EsentVersion.SupportsWindows81Features)
            {
                return;
            }

            string       dir      = SetupHelper.CreateRandomDirectory();
            JET_INSTANCE instance = SetupHelper.CreateNewInstance(dir);

            Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.MaxTemporaryTables, 0, null);

            InstanceParameters instanceParameters = new InstanceParameters(instance);

            instanceParameters.EnableShrinkDatabase = ShrinkDatabaseGrbit.On;
            Api.JetInit(ref instance);
            try
            {
                string database = Path.Combine(dir, "CreateAndResizeDatabase.db");

                JET_SESID sesid;
                JET_DBID  dbid;
                Api.JetBeginSession(instance, out sesid, string.Empty, string.Empty);

                Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.DbExtensionSize, 256, null);
                Api.JetCreateDatabase(sesid, database, string.Empty, out dbid, CreateDatabaseGrbit.None);

                Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.DbExtensionSize, 1, null);

                int databaseSpaceOwned;
                Api.JetGetDatabaseInfo(sesid, dbid, out databaseSpaceOwned, JET_DbInfo.SpaceOwned);

                // We have to take into account the reserved pages in the database as per the API to get the actual
                // space.
                databaseSpaceOwned += ReservedPages;

                int actualPages;
                Windows8Api.JetResizeDatabase(sesid, dbid, databaseSpaceOwned + 100, out actualPages, ResizeDatabaseGrbit.None);
                EseInteropTestHelper.ConsoleWriteLine("actualPages is {0}.", actualPages);

                Assert.IsTrue(actualPages >= databaseSpaceOwned + 100, "Database didn't grow enough!");

                int actualPagesAfterTrim = 0;
                Windows8Api.JetResizeDatabase(sesid, dbid, 0, out actualPagesAfterTrim, ResizeDatabaseGrbit.None);
                EseInteropTestHelper.ConsoleWriteLine("actualPagesAfterTrim is {0}.", actualPagesAfterTrim);

                Assert.IsTrue(actualPagesAfterTrim < actualPages, "Database didn't shrink!");

                int databaseSizeOnDiskInPages;
                Api.JetGetDatabaseInfo(sesid, dbid, out databaseSizeOnDiskInPages, Windows81DbInfo.FilesizeOnDisk);
                EseInteropTestHelper.ConsoleWriteLine("databaseSizeOnDiskInPages is {0}.", databaseSizeOnDiskInPages);
                Assert.AreEqual(actualPagesAfterTrim, databaseSizeOnDiskInPages);
            }
            finally
            {
                Api.JetTerm(instance);
                Cleanup.DeleteDirectoryWithRetry(dir);
            }
        }
        public void CreateIndexesOnVista()
        {
            if (!EsentVersion.SupportsVistaFeatures)
            {
                return;
            }

            string directory = SetupHelper.CreateRandomDirectory();
            string database  = Path.Combine(directory, "test.db");

            using (var instance = new Instance("VistaCreateindexes"))
            {
                instance.Parameters.Recovery           = false;
                instance.Parameters.NoInformationEvent = true;
                instance.Parameters.MaxTemporaryTables = 0;
                instance.Parameters.TempDirectory      = directory;
                instance.Init();
                using (var session = new Session(instance))
                {
                    JET_DBID dbid;
                    Api.JetCreateDatabase(session, database, string.Empty, out dbid, CreateDatabaseGrbit.None);
                    using (var transaction = new Transaction(session))
                    {
                        JET_TABLEID tableid;
                        Api.JetCreateTable(session, dbid, "table", 0, 100, out tableid);
                        JET_COLUMNID columnid;
                        Api.JetAddColumn(
                            session,
                            tableid,
                            "column1",
                            new JET_COLUMNDEF {
                            coltyp = JET_coltyp.Long
                        },
                            null,
                            0,
                            out columnid);

                        var indexcreates = new[]
                        {
                            new JET_INDEXCREATE
                            {
                                szKey       = "+column1\0",
                                cbKey       = 10,
                                szIndexName = "index1",
                                pidxUnicode = new JET_UNICODEINDEX {
                                    lcid = 1033
                                },
                            },
                        };

                        Api.JetCreateIndex2(session, tableid, indexcreates, indexcreates.Length);
                        transaction.Commit(CommitTransactionGrbit.LazyFlush);
                    }
                }
            }

            Cleanup.DeleteDirectoryWithRetry(directory);
        }
예제 #17
0
        public void Setup()
        {
            Thread.CurrentThread.Priority = ThreadPriority.Highest;

            this.directory = SetupHelper.CreateRandomDirectory();

            this.random  = new Random();
            this.data    = Any.BytesOfLength(DataSize);
            this.dataBuf = new byte[DataSize];

            JET_DBID dbid;

            string ignored;

            Api.JetGetSystemParameter(
                JET_INSTANCE.Nil, JET_SESID.Nil, JET_param.CacheSizeMin, ref this.cacheSizeMinSaved, out ignored, 0);
            Api.JetSetSystemParameter(JET_INSTANCE.Nil, JET_SESID.Nil, JET_param.CacheSizeMin, 16384, null);

            this.instance = new Instance("SimplePerfTest");
            this.instance.Parameters.LogFileDirectory = this.directory;
            this.instance.Parameters.SystemDirectory  = this.directory;
            this.instance.Parameters.MaxVerPages      = 1024;
            this.instance.Parameters.Recovery         = false;

            // Create the instance, database and table
            this.instance.Init();
            this.session = new Session(this.instance);
            Api.JetCreateDatabase(this.session, Path.Combine(this.directory, "esentperftest.db"), string.Empty, out dbid, CreateDatabaseGrbit.None);

            // Create a dummy table to force the database to grow
            using (var trx = new Transaction(this.session))
            {
                JET_TABLEID tableid;
                Api.JetCreateTable(this.session, dbid, "dummy_table", 64 * 1024 * 1024 / SystemParameters.DatabasePageSize, 100, out tableid);
                Api.JetCloseTable(this.session, tableid);
                Api.JetDeleteTable(this.session, dbid, "dummy_table");
                trx.Commit(CommitTransactionGrbit.LazyFlush);
            }

            // Create the table
            using (var trx = new Transaction(this.session))
            {
                JET_TABLEID tableid;
                var         columndef = new JET_COLUMNDEF();

                Api.JetCreateTable(this.session, dbid, "table", 0, 100, out tableid);
                columndef.coltyp = JET_coltyp.Currency;
                Api.JetAddColumn(this.session, tableid, "Key", columndef, null, 0, out this.columnidKey);
                columndef.coltyp = JET_coltyp.Binary;
                Api.JetAddColumn(this.session, tableid, "Data", columndef, null, 0, out this.columnidData);
                Api.JetCreateIndex(this.session, tableid, "primary", CreateIndexGrbit.IndexPrimary, "+key\0\0", 6, 100);
                Api.JetCloseTable(this.session, tableid);
                trx.Commit(CommitTransactionGrbit.None);
            }

            this.table = new Table(this.session, dbid, "table", OpenTableGrbit.None);
        }
예제 #18
0
        public void Setup()
        {
            this.directory = SetupHelper.CreateRandomDirectory();

            this.random = new Random();

            JET_DBID dbid;

            string ignored;

            Api.JetGetSystemParameter(
                JET_INSTANCE.Nil, JET_SESID.Nil, JET_param.CacheSizeMin, ref this.cacheSizeMinSaved, out ignored, 0);
            Api.JetSetSystemParameter(JET_INSTANCE.Nil, JET_SESID.Nil, JET_param.CacheSizeMin, 16384, null);

            this.instance = new Instance(Guid.NewGuid().ToString(), "SimplePerfTest");
            this.instance.Parameters.LogFileDirectory = this.directory;
            this.instance.Parameters.SystemDirectory  = this.directory;
            this.instance.Parameters.MaxVerPages      = 1024;
            this.instance.Parameters.Recovery         = false;

            // Create the instance, database and table
            this.instance.Init();
            this.session  = new Session(this.instance);
            this.database = Path.Combine(this.directory, "esentperftest.db");
            Api.JetCreateDatabase(this.session, this.database, string.Empty, out dbid, CreateDatabaseGrbit.None);

            // Create a dummy table to force the database to grow
            using (var trx = new Transaction(this.session))
            {
                JET_TABLEID tableid;
                Api.JetCreateTable(this.session, dbid, "dummy_table", 64 * 1024 * 1024 / SystemParameters.DatabasePageSize, 100, out tableid);
                Api.JetCloseTable(this.session, tableid);
                Api.JetDeleteTable(this.session, dbid, "dummy_table");
                trx.Commit(CommitTransactionGrbit.LazyFlush);
            }

            // Create the table
            using (var trx = new Transaction(this.session))
            {
                JET_COLUMNID columnid;
                JET_TABLEID  tableid;
                var          columndef = new JET_COLUMNDEF();

                Api.JetCreateTable(this.session, dbid, TableName, 0, 100, out tableid);
                columndef.coltyp = JET_coltyp.Currency;
                Api.JetAddColumn(this.session, tableid, KeyColumnName, columndef, null, 0, out columnid);
                columndef.coltyp = JET_coltyp.Binary;
                Api.JetAddColumn(this.session, tableid, DataColumnName, columndef, null, 0, out columnid);
                Api.JetCreateIndex(this.session, tableid, IndexName, CreateIndexGrbit.IndexPrimary, "+key\0\0", 6, 100);
                Api.JetCloseTable(this.session, tableid);
                trx.Commit(CommitTransactionGrbit.None);
            }

            // Reset the key for the worker thread
            PerfTestWorker.NextKey = 0;
        }
예제 #19
0
        public void Setup()
        {
            this.directory = SetupHelper.CreateRandomDirectory();
            this.instance  = SetupHelper.CreateNewInstance(this.directory);

            // turn off logging so initialization is faster
            Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, JET_param.Recovery, 0, "off");
            Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, JET_param.MaxTemporaryTables, 0, null);
            Api.JetInit(ref this.instance);
        }
예제 #20
0
        public void ApiThrowsArgumentExceptionOnUnmappableChar()
        {
            string directory = SetupHelper.CreateRandomDirectory();
            string database  = Path.Combine(directory, "test.db");

            using (var instance = new Instance("Windows7Createindexes"))
            {
                instance.Parameters.Recovery           = false;
                instance.Parameters.NoInformationEvent = true;
                instance.Parameters.MaxTemporaryTables = 0;
                instance.Parameters.TempDirectory      = directory;
                instance.Init();
                using (var session = new Session(instance))
                {
                    JET_DBID dbid;
                    Api.JetCreateDatabase(session, database, string.Empty, out dbid, CreateDatabaseGrbit.None);
                    using (var transaction = new Transaction(session))
                    {
                        JET_TABLEID tableid;
                        Api.JetCreateTable(session, dbid, "table", 0, 100, out tableid);
                        JET_COLUMNID columnid;

                        try
                        {
                            Api.JetAddColumn(
                                session,
                                tableid,
                                "한글",
                                new JET_COLUMNDEF {
                                coltyp = JET_coltyp.Long
                            },
                                null,
                                0,
                                out columnid);
                            Assert.Fail("An exception should have been thrown!");
                        }
#if MANAGEDESENT_SUPPORTS_ANSI
                        // The ArgumentException is thrown by the marshalling layer.
                        catch (ArgumentException)
                        {
                        }
#else
                        // What's the more precise error code to catch?
                        catch (Microsoft.Isam.Esent.EsentException)
                        {
                        }
#endif

                        transaction.Commit(CommitTransactionGrbit.LazyFlush);
                    }
                }
            }

            Cleanup.DeleteDirectoryWithRetry(directory);
        }
예제 #21
0
        public void Setup()
        {
            this.directory = SetupHelper.CreateRandomDirectory();
            this.instance  = SetupHelper.CreateNewInstance(this.directory);

            // turn off logging so initialization is faster
            Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, JET_param.Recovery, 0, "off");
            Api.JetInit(ref this.instance);
            Api.JetBeginSession(this.instance, out this.sesid, String.Empty, String.Empty);
            this.tableid = JET_TABLEID.Nil;
        }
예제 #22
0
        public void Setup()
        {
            this.directory = SetupHelper.CreateRandomDirectory();
            this.database  = Path.Combine(this.directory, "database.edb");
            this.instance  = SetupHelper.CreateNewInstance(this.directory);

            Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, JET_param.MaxTemporaryTables, 0, null);
            Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, JET_param.Recovery, 0, "off");
            Api.JetInit(ref this.instance);
            Api.JetBeginSession(this.instance, out this.sesid, String.Empty, String.Empty);
            Api.JetCreateDatabase(this.sesid, this.database, String.Empty, out this.dbid, CreateDatabaseGrbit.None);
        }
예제 #23
0
        public void CreateIndexesOnXp()
        {
            string directory = SetupHelper.CreateRandomDirectory();
            string database  = Path.Combine(directory, "test.db");

            using (var instance = new Instance("XpCompatability"))
            {
                instance.Parameters.Recovery           = false;
                instance.Parameters.NoInformationEvent = true;
                instance.Parameters.PageTempDBMin      = SystemParameters.PageTempDBSmallest;
                instance.Parameters.TempDirectory      = directory;
                instance.Init();
                using (var session = new Session(instance))
                {
                    JET_DBID dbid;
                    Api.JetCreateDatabase(session, database, String.Empty, out dbid, CreateDatabaseGrbit.None);
                    using (var transaction = new Transaction(session))
                    {
                        JET_TABLEID tableid;
                        Api.JetCreateTable(session, dbid, "table", 0, 100, out tableid);
                        JET_COLUMNID columnid;
                        Api.JetAddColumn(
                            session,
                            tableid,
                            "column1",
                            new JET_COLUMNDEF {
                            coltyp = JET_coltyp.Long
                        },
                            null,
                            0,
                            out columnid);

                        var indexcreates = new[]
                        {
                            new JET_INDEXCREATE
                            {
                                szKey       = "+column1\0",
                                cbKey       = 10,
                                szIndexName = "index1",
                                pidxUnicode = new JET_UNICODEINDEX {
                                    lcid = 1033
                                },
                            },
                        };

                        Api.JetCreateIndex2(session, tableid, indexcreates, indexcreates.Length);
                        transaction.Commit(CommitTransactionGrbit.LazyFlush);
                    }
                }
            }

            Directory.Delete(directory, true);
        }
예제 #24
0
        public void Setup()
        {
            this.directory = SetupHelper.CreateRandomDirectory();
            this.instance  = SetupHelper.CreateNewInstance(this.directory);

            // turn off logging so initialization is faster
            Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, JET_param.Recovery, 0, "off");
            Api.JetSetSystemParameter(this.instance, JET_SESID.Nil, JET_param.PageTempDBMin, SystemParameters.PageTempDBSmallest, null);
            Api.JetInit(ref this.instance);
            Api.JetBeginSession(this.instance, out this.sesid, string.Empty, string.Empty);

            this.columnidDict = SetupHelper.CreateTempTableWithAllColumns(this.sesid, TempTableGrbit.None, out this.tableid);
        }
예제 #25
0
        public void InitAndTermOneInstanceAbruptly()
        {
            string dir = SetupHelper.CreateRandomDirectory();

            try
            {
                JET_INSTANCE instance = SetupHelper.CreateNewInstance(dir);
                Api.JetInit(ref instance);
                Api.JetTerm2(instance, TermGrbit.Abrupt);
            }
            finally
            {
                Directory.Delete(dir, true);
            }
        }
예제 #26
0
        public void CreateInstanceInitTerm()
        {
            string dir = SetupHelper.CreateRandomDirectory();

            using (var instance = new Instance("theinstance"))
            {
                instance.Parameters.LogFileDirectory   = dir;
                instance.Parameters.SystemDirectory    = dir;
                instance.Parameters.TempDirectory      = dir;
                instance.Parameters.NoInformationEvent = true;
                instance.Init();
                instance.Term();
                Directory.Delete(dir, true);    // only works if the instance is terminated
            }
        }
예제 #27
0
        public void CreateUsingDatabaseFilename()
        {
            string directory = SetupHelper.CreateRandomDirectory();
            string db        = Path.Combine(directory, DatabaseObjectTests.DbName);

            using (this.database = new Database(db))
            {
                Assert.AreNotEqual(this.database.InstanceHandle, JET_INSTANCE.Nil);
            }

#if !MANAGEDESENT_ON_WSA
            Assert.IsTrue(File.Exists(db));
            Assert.IsTrue(File.Exists(Path.Combine(directory, this.edbLogFileName)));
#endif
        }
예제 #28
0
        public void CreateUsingInitializedInstance()
        {
            string directory = SetupHelper.CreateRandomDirectory();
            string db        = Path.Combine(directory, DatabaseObjectTests.DbName);

            JET_INSTANCE instance;
            JET_SESID    sesid;
            JET_DBID     dbid;

            instance = SetupHelper.CreateNewInstance(directory);
            Api.JetSetSystemParameter(instance, JET_SESID.Nil, JET_param.Recovery, 0, "off");
            Api.JetInit(ref instance);
            Api.JetBeginSession(instance, out sesid, string.Empty, string.Empty);
            Api.JetCreateDatabase(sesid, db, string.Empty, out dbid, CreateDatabaseGrbit.None);
            Api.JetCloseDatabase(sesid, dbid, CloseDatabaseGrbit.None);
            Api.JetEndSession(sesid, EndSessionGrbit.None);

            var engineConfig = new DatabaseConfig()
            {
                DatabaseFilename = db,
            };

            using (this.database = new Database(instance, false, engineConfig))
            {
                Assert.AreNotEqual(this.database.InstanceHandle, JET_INSTANCE.Nil);
                Assert.AreEqual(this.database.Config.Recovery, "off");
            }

            using (this.database = new Database(instance, true, engineConfig))
            {
                Assert.AreNotEqual(this.database.InstanceHandle, JET_INSTANCE.Nil);
                Assert.AreEqual(this.database.Config.Recovery, "off");
            }

            try
            {
                Api.JetTerm(instance);
                Assert.Fail("EsentInvalidInstanceException expected !");
            }

            // ISSUE-2014/10/28-UmairA - Debug build returns InvalidInstance, retail returns InvalidParameter. JetTerm() should be fixed.
            catch (EsentInvalidInstanceException)
            {
            }
            catch (EsentInvalidParameterException)
            {
            }
        }
예제 #29
0
        public void CreateInstanceInitTerm()
        {
            string dir = SetupHelper.CreateRandomDirectory();

            using (var instance = new Instance("initterm"))
            {
                instance.Parameters.LogFileDirectory   = dir;
                instance.Parameters.SystemDirectory    = dir;
                instance.Parameters.TempDirectory      = dir;
                instance.Parameters.LogFileSize        = 256; // 256Kb
                instance.Parameters.NoInformationEvent = true;
                instance.Init();
                instance.Term();
                Cleanup.DeleteDirectoryWithRetry(dir);    // only works if the instance is terminated
            }
        }
예제 #30
0
        public void CreateInstanceNoInit()
        {
            string dir = SetupHelper.CreateRandomDirectory();

            using (var instance = new Instance("theinstance"))
            {
                Assert.AreNotEqual(JET_INSTANCE.Nil, instance.JetInstance);
                Assert.IsNotNull(instance.Parameters);

                instance.Parameters.LogFileDirectory = dir;
                instance.Parameters.SystemDirectory  = dir;
                instance.Parameters.TempDirectory    = dir;
            }

            Directory.Delete(dir, true);
        }