diff --git a/Objective-C/CBLDatabaseConfiguration.h b/Objective-C/CBLDatabaseConfiguration.h index bd16ec1c8..c86ac5ea8 100644 --- a/Objective-C/CBLDatabaseConfiguration.h +++ b/Objective-C/CBLDatabaseConfiguration.h @@ -43,16 +43,14 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic) BOOL fullSync; -#if !TARGET_OS_OSX /** Enables or disables memory-mapped I/O. By default, memory-mapped I/O is enabled. Disabling it may affect database performance. Typically, there is no need to modify this setting. @note: Memory-mapped I/O is always disabled to prevent database corruption on macOS. - As a result, this configuration is not supported on the macOS platform. + As a result, setting this configuration has no effect on the macOS platform. */ @property (nonatomic) BOOL mmapEnabled; -#endif /** Initializes the CBLDatabaseConfiguration object. diff --git a/Objective-C/CBLDatabaseConfiguration.m b/Objective-C/CBLDatabaseConfiguration.m index 944605162..9c31f7df4 100644 --- a/Objective-C/CBLDatabaseConfiguration.m +++ b/Objective-C/CBLDatabaseConfiguration.m @@ -25,12 +25,7 @@ @implementation CBLDatabaseConfiguration { BOOL _readonly; } -@synthesize directory=_directory, fullSync=_fullSync; - -#if !TARGET_OS_OSX -@synthesize mmapEnabled=_mmapEnabled; -#endif - +@synthesize directory=_directory, fullSync=_fullSync, mmapEnabled=_mmapEnabled; #ifdef COUCHBASE_ENTERPRISE @synthesize encryptionKey=_encryptionKey; @@ -54,19 +49,14 @@ - (instancetype) initWithConfig: (nullable CBLDatabaseConfiguration*)config if (config) { _directory = config.directory; _fullSync = config.fullSync; -#if !TARGET_OS_OSX _mmapEnabled = config.mmapEnabled; -#endif - #ifdef COUCHBASE_ENTERPRISE _encryptionKey = config.encryptionKey; #endif } else { _directory = [CBLDatabaseConfiguration defaultDirectory]; _fullSync = kCBLDefaultDatabaseFullSync; -#if !TARGET_OS_OSX _mmapEnabled = kCBLDefaultDatabaseMmapEnabled; -#endif } } return self; diff --git a/Objective-C/Tests/DatabaseTest.m b/Objective-C/Tests/DatabaseTest.m index b171ba4be..c8759750d 100644 --- a/Objective-C/Tests/DatabaseTest.m +++ b/Objective-C/Tests/DatabaseTest.m @@ -2892,18 +2892,14 @@ - (void) testDBWithFullSync { } #pragma mark - MMap -/** Test Spec v1.0.0: +/** Test Spec v1.0.1: https://github.com/couchbaselabs/couchbase-lite-api/blob/master/spec/tests/T0006-MMap-Config.md */ -#if !TARGET_OS_OSX - /** 1. TestDefaultMMapConfig Description Test that the mmapEnabled default value is as expected and that it's setter and getter work. - For macOS, an unsupported arugment or equivalent exception should be thrown - when accessing the mmapEnabled property. Steps 1. Create a DatabaseConfiguration object. 2. Get and check that the value of the mmapEnabled property is true. @@ -2916,7 +2912,7 @@ - (void) testDefaultMMapConfig { Assert(config.mmapEnabled); config.mmapEnabled = false; - Assert(!config.mmapEnabled); + AssertFalse(config.mmapEnabled); config.mmapEnabled = true; Assert(config.mmapEnabled); @@ -2925,7 +2921,7 @@ - (void) testDefaultMMapConfig { /** 2. TestDatabaseWithConfiguredMMap Description - Test that a Database respects the mmapEnabled property. This test is not applicable for macOS. + Test that a Database respects the mmapEnabled property. Steps 1. Create a DatabaseConfiguration object and set mmapEnabled to false. 2. Create a database with the config. @@ -2940,21 +2936,28 @@ - (void) testDefaultMMapConfig { - (void) testDatabaseWithConfiguredMMap { NSError* err; CBLDatabaseConfiguration* config = [[CBLDatabaseConfiguration alloc] init]; - config.mmapEnabled = false; + + config.mmapEnabled = false; CBLDatabase* db1 = [[CBLDatabase alloc] initWithName: @"mmap1" config: config error:&err]; + CBLDatabaseConfiguration* tempConfig = [db1 config]; + AssertFalse(tempConfig.mmapEnabled); +#if TARGET_OS_OSX + AssertFalse(([db1 getC4DBConfig]->flags & kC4DB_MmapDisabled) == kC4DB_MmapDisabled); +#else Assert(([db1 getC4DBConfig]->flags & kC4DB_MmapDisabled) == kC4DB_MmapDisabled); +#endif config.mmapEnabled = true; CBLDatabase* db2 = [[CBLDatabase alloc] initWithName: @"mmap2" config: config error:&err]; + tempConfig = [db2 config]; + Assert(tempConfig.mmapEnabled); AssertFalse(([db2 getC4DBConfig]->flags & kC4DB_MmapDisabled) == kC4DB_MmapDisabled); db1 = nil; db2 = nil; } -#endif - #pragma clang diagnostic pop @end diff --git a/Swift/DatabaseConfiguration.swift b/Swift/DatabaseConfiguration.swift index c173544e6..9af90dcfa 100644 --- a/Swift/DatabaseConfiguration.swift +++ b/Swift/DatabaseConfiguration.swift @@ -38,14 +38,11 @@ public struct DatabaseConfiguration { /// is very safe but it is also dramatically slower. public var fullSync: Bool = defaultFullSync - - #if !os(macOS) /// Enables or disables memory-mapped I/O. By default, memory-mapped I/O is enabled. /// Disabling it may affect database performance. Typically, there is no need to modify this setting. /// - Note: Memory-mapped I/O is always disabled to prevent database corruption on macOS. - /// As a result, this configuration is not supported on the macOS platform. + /// As a result, setting this configuration has no effect on the macOS platform. public var mmapEnabled: Bool = defaultMmapEnabled; - #endif #if COUCHBASE_ENTERPRISE /// The key to encrypt the database with. @@ -62,10 +59,7 @@ public struct DatabaseConfiguration { if let c = config { self.directory = c.directory self.fullSync = c.fullSync - - #if !os(macOS) self.mmapEnabled = c.mmapEnabled - #endif #if COUCHBASE_ENTERPRISE self.encryptionKey = c.encryptionKey @@ -79,14 +73,12 @@ public struct DatabaseConfiguration { let config = CBLDatabaseConfiguration() config.directory = self.directory config.fullSync = self.fullSync - - #if !os(macOS) config.mmapEnabled = self.mmapEnabled - #endif #if COUCHBASE_ENTERPRISE config.encryptionKey = self.encryptionKey?.impl #endif + return config } } diff --git a/Swift/Tests/DatabaseTest.swift b/Swift/Tests/DatabaseTest.swift index fd6ed1513..ff158eb57 100644 --- a/Swift/Tests/DatabaseTest.swift +++ b/Swift/Tests/DatabaseTest.swift @@ -1575,24 +1575,21 @@ class DatabaseTest: CBLTestCase { var config = DatabaseConfiguration() config.directory = self.directory db = try Database(name: dbName, config: config) - XCTAssertFalse(DatabaseConfiguration(config: config).fullSync) + XCTAssertFalse(db.config.fullSync) db = nil config.fullSync = true db = try Database(name: dbName, config: config) - XCTAssert(DatabaseConfiguration(config: config).fullSync) + XCTAssert(db.config.fullSync) } // MARK: MMap - /// Test Spec v1.0.0: + /// Test Spec v1.0.1: /// https://github.com/couchbaselabs/couchbase-lite-api/blob/master/spec/tests/T0006-MMap-Config.md -#if !TARGET_OS_OSX /// 1. TestDefaultMMapConfig /// Description /// Test that the mmapEnabled default value is as expected and that it's setter and getter work. - /// For macOS, an unsupported arugment or equivalent exception should be thrown - /// when accessing the mmapEnabled property. /// Steps /// 1. Create a DatabaseConfiguration object. /// 2. Get and check that the value of the mmapEnabled property is true. @@ -1612,28 +1609,26 @@ class DatabaseTest: CBLTestCase { /// 2. TestDatabaseWithConfiguredMMap /// Description - /// Test that a Database respects the mmapEnabled property. This test is not applicable for macOS. + /// Test that a Database respects the mmapEnabled property. /// Steps /// 1. Create a DatabaseConfiguration object and set mmapEnabled to false. /// 2. Create a database with the config. /// 3. Get the configuration object from the database and check that the mmapEnabled is false. - /// 4. Use c4db_config2 to confirm that its config contains the kC4DB_MmapDisabled flag + /// 4. Use c4db_config2 to confirm that its config contains the kC4DB_MmapDisabled flag - done in Obj-C /// 5. Set the config's mmapEnabled property true /// 6. Create a database with the config. /// 7. Get the configuration object from the database and verify that mmapEnabled is true - /// 8. Use c4db_config2 to confirm that its config doesn't contains the kC4DB_MmapDisabled flag + /// 8. Use c4db_config2 to confirm that its config doesn't contains the kC4DB_MmapDisabled flag - done in Obj-C func testDatabaseWithConfiguredMMap() throws { var config = DatabaseConfiguration() config.mmapEnabled = false; let db1 = try Database(name: "mmap1", config: config) - XCTAssertFalse(DatabaseConfiguration(config: config).mmapEnabled) - + XCTAssertFalse(db1.config.mmapEnabled) + config.mmapEnabled = true; let db2 = try Database(name: "mmap2", config: config) - XCTAssert(DatabaseConfiguration(config: config).mmapEnabled) + XCTAssert(db2.config.mmapEnabled) } - #endif - }