Skip to content

Commit

Permalink
remove macOS restriction and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
velicuvlad committed Oct 16, 2024
1 parent 1d97907 commit 4a65654
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 48 deletions.
4 changes: 1 addition & 3 deletions Objective-C/CBLDatabaseConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 1 addition & 11 deletions Objective-C/CBLDatabaseConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
23 changes: 13 additions & 10 deletions Objective-C/Tests/DatabaseTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -2916,7 +2912,7 @@ - (void) testDefaultMMapConfig {
Assert(config.mmapEnabled);

config.mmapEnabled = false;
Assert(!config.mmapEnabled);
AssertFalse(config.mmapEnabled);

config.mmapEnabled = true;
Assert(config.mmapEnabled);
Expand All @@ -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.
Expand All @@ -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
12 changes: 2 additions & 10 deletions Swift/DatabaseConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
}
}
23 changes: 9 additions & 14 deletions Swift/Tests/DatabaseTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

}

0 comments on commit 4a65654

Please sign in to comment.