Esempio n. 1
0
        public void CreateAndOpenDatabaseWithMaxSize()
        {
            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.JetAttachDatabase2(sesid, database, 512, AttachDatabaseGrbit.None);
            }
            finally
            {
                Api.JetTerm(instance);
                Cleanup.DeleteDirectoryWithRetry(dir);
            }
        }
Esempio n. 2
0
        public void TestDeleteDirectoryWithRetryWhenDirectoryDoesNotExist()
        {
            string directory = EseInteropTestHelper.PathGetRandomFileName();

            Assert.IsFalse(EseInteropTestHelper.DirectoryExists(directory));
            Cleanup.DeleteDirectoryWithRetry(directory);
        }
Esempio n. 3
0
        public void TestDeleteFileWithRetryWhenFileDoesNotExist()
        {
            string file = EseInteropTestHelper.PathGetRandomFileName();

            Assert.IsFalse(EseInteropTestHelper.FileExists(file));
            Cleanup.DeleteFileWithRetry(file);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public void GetDatabaseFileInfoOnWindows7()
        {
            if (!EsentVersion.SupportsWindows7Features)
            {
                return;
            }

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

            using (var instance = new Instance("Windows7JetGetDatabaseFileInfo"))
            {
                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);
        }
Esempio n. 6
0
        public void Teardown()
        {
            this.testInstance.Term();
            Cleanup.DeleteDirectoryWithRetry(TestDirectory);

            SetupHelper.CheckProcessForInstanceLeaks();
        }
Esempio n. 7
0
 public void Teardown()
 {
     this.session.End();
     this.instance.Term();
     Api.JetSetSystemParameter(JET_INSTANCE.Nil, JET_SESID.Nil, JET_param.CacheSizeMin, this.cacheSizeMinSaved, null);
     Cleanup.DeleteDirectoryWithRetry(this.directory);
 }
Esempio n. 8
0
 public void Teardown()
 {
     Api.JetCloseTable(this.sesid, this.tableid);
     Api.JetEndSession(this.sesid, EndSessionGrbit.None);
     Api.JetTerm(this.instance);
     Cleanup.DeleteDirectoryWithRetry(this.directory);
 }
Esempio n. 9
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);
            }
        }
        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);
            }
        }
Esempio n. 11
0
 public void Setup()
 {
     this.engineSupportsUnicode = Api.Impl.Capabilities.SupportsUnicodePaths;
     Api.Impl.Capabilities.SupportsUnicodePaths = false;
     this.directory = "ascii_directory";
     Cleanup.DeleteDirectoryWithRetry(this.directory);
     this.database = Path.Combine(this.directory, "ascii.edb");
 }
Esempio n. 12
0
 public void Setup()
 {
     this.directory = "ascii_directory";
     Cleanup.DeleteDirectoryWithRetry(this.directory);
     this.database  = Path.Combine(this.directory, "ascii.edb");
     this.savedImpl = Api.Impl;
     Api.Impl       = new JetApi(Constants.XpVersion);
 }
Esempio n. 13
0
 public void Teardown()
 {
     Api.JetCloseTable(this.sesid, this.tableid);
     Api.JetEndSession(this.sesid, EndSessionGrbit.None);
     Api.JetTerm(this.instance);
     Cleanup.DeleteDirectoryWithRetry(this.directory);
     SetupHelper.CheckProcessForInstanceLeaks();
 }
        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);
        }
Esempio n. 15
0
 public void Teardown()
 {
     Api.JetCloseTable(this.sesid, this.tableidParent);
     Api.JetCloseTable(this.sesid, this.tableidChild);
     Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);
     Api.JetEndSession(this.sesid, EndSessionGrbit.None);
     Api.JetTerm(this.instance);
     Cleanup.DeleteDirectoryWithRetry(this.directory);
 }
Esempio n. 16
0
 public void Setup()
 {
     Cleanup.DeleteDirectoryWithRetry(TestDirectory);
     Directory.CreateDirectory(TestDirectory);
     this.testInstance = new Instance("HowDoI");
     SetupHelper.SetLightweightConfiguration(this.testInstance);
     this.testInstance.Init();
     this.testSession = new Session(this.testInstance);
     Api.JetCreateDatabase(this.testSession, TestDatabase, null, out this.testDbid, CreateDatabaseGrbit.OverwriteExisting);
 }
        public void TestTeardown()
        {
            Api.JetCloseDatabase(this.sesId, this.databaseId, CloseDatabaseGrbit.None);

            Api.JetEndSession(this.sesId, EndSessionGrbit.None);
            Api.JetTerm(this.instance);
            SystemParameters.CacheSizeMin = this.savedCacheSizeMin;
            SystemParameters.CacheSizeMax = this.savedCacheSizeMax;
            Cleanup.DeleteDirectoryWithRetry(this.directory);
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
 /// <summary>
 /// Create a database and call JetGetDatabaseFileInfo.
 /// </summary>
 public void TestGetDatabaseFileInfo()
 {
     try
     {
         this.CreateDatabase();
         this.TestJetGetDatabaseFileInfo();
     }
     finally
     {
         Cleanup.DeleteDirectoryWithRetry(this.databaseDirectory);
     }
 }
Esempio n. 20
0
 /// <summary>
 /// Create a database and do a streaming backup.
 /// </summary>
 public void TestStreamingBackup2()
 {
     try
     {
         this.CreateDatabase();
         this.StreamingBackup2();
         this.CheckDatabase();
     }
     finally
     {
         Cleanup.DeleteDirectoryWithRetry(this.databaseDirectory);
     }
 }
Esempio n. 21
0
 /// <summary>
 /// Create a database and then set the size of the database.
 /// </summary>
 public void TestSetDatabaseSize()
 {
     try
     {
         this.CreateDatabase();
         this.SetDatabaseSize();
         this.CheckDatabase();
     }
     finally
     {
         Cleanup.DeleteDirectoryWithRetry(this.databaseDirectory);
     }
 }
Esempio n. 22
0
 /// <summary>
 /// Create a database and then have the status callback throw an
 /// exception during compaction.
 /// </summary>
 /// <param name="ex">The exception to throw.</param>
 public void TestCompactDatabaseCallbackExceptionHandling(Exception ex)
 {
     try
     {
         this.CreateDatabase();
         this.CompactDatabaseWithCallbackException(ex);
         this.CheckDatabase();
     }
     finally
     {
         Cleanup.DeleteDirectoryWithRetry(this.databaseDirectory);
     }
 }
Esempio n. 23
0
 /// <summary>
 /// Backup a database and have the status callback throw
 /// an exception during backup.
 /// </summary>
 /// <param name="ex">
 /// The exception to throw from the callback.
 /// </param>
 public void TestBackupCallbackExceptionHandling(Exception ex)
 {
     try
     {
         this.CreateDatabase();
         this.BackupDatabaseWithCallbackException(ex);
     }
     finally
     {
         Cleanup.DeleteDirectoryWithRetry(this.databaseDirectory);
         Cleanup.DeleteDirectoryWithRetry(this.backupDirectory);
     }
 }
Esempio n. 24
0
        public void VerifyDeleteFileWithRetryRemovesFile()
        {
            // Create a random file
            string file = Path.GetRandomFileName();

            File.WriteAllText(file, "hello");
            Assert.IsTrue(File.Exists(file));

            // Delete the file
            Cleanup.DeleteFileWithRetry(file);

            // The file should no longer exist
            Assert.IsFalse(File.Exists(file));
        }
Esempio n. 25
0
        public void VerifyDeleteFileWithRetryRemovesFile()
        {
            // Create a random file
            string file = EseInteropTestHelper.PathGetRandomFileName();

            EseInteropTestHelper.FileWriteAllText(file, "hello");
            Assert.IsTrue(EseInteropTestHelper.FileExists(file));

            // Delete the file
            Cleanup.DeleteFileWithRetry(file);

            // The file should no longer exist
            Assert.IsFalse(EseInteropTestHelper.FileExists(file));
        }
Esempio n. 26
0
        public void VerifyDeleteDirectoryWithRetryRemovesDirectory()
        {
            // Create a random directory with a file in it
            string directory = Path.GetRandomFileName();

            Directory.CreateDirectory(directory);
            File.WriteAllText(Path.Combine(directory, "foo.txt"), "hello");
            Assert.IsTrue(Directory.Exists(directory));

            // Delete the directory
            Cleanup.DeleteDirectoryWithRetry(directory);

            // The directory should no longer exist
            Assert.IsFalse(Directory.Exists(directory));
        }
Esempio n. 27
0
        public void TestTeardown()
        {
            if (!EsentVersion.SupportsWindows8Features)
            {
                return;
            }

            Api.JetCloseTable(this.sesid, this.tableid);
            Api.JetCloseDatabase(this.sesid, this.dbid, CloseDatabaseGrbit.None);
            Api.JetEndSession(this.sesid, EndSessionGrbit.None);
            Api.JetTerm(this.instance);
            this.callback.End();
            this.callback = null;
            Cleanup.DeleteDirectoryWithRetry(this.directory);
        }
Esempio n. 28
0
 /// <summary>
 /// Create a database, back it up to the backup directory and
 /// then restore it.
 /// </summary>
 public void TestBackupRestore()
 {
     try
     {
         this.CreateDatabase();
         this.BackupDatabase();
         this.DeleteDatabaseFiles();
         this.RestoreDatabase();
         this.CheckDatabase();
     }
     finally
     {
         Cleanup.DeleteDirectoryWithRetry(this.databaseDirectory);
         Cleanup.DeleteDirectoryWithRetry(this.backupDirectory);
     }
 }
Esempio n. 29
0
        public void CreateInstanceNoInit()
        {
            string dir = SetupHelper.CreateRandomDirectory();

            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;
            }

            Cleanup.DeleteDirectoryWithRetry(dir);
        }
Esempio n. 30
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
            }
        }