-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RNET-1154, RNET-1151, RNET-1139: Compact-related fixes #3618
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,50 +321,6 @@ public void RealmObjectClassesOnlyAllowRealmObjects() | |
Assert.That(ex.Message, Does.Contain("must descend directly from either RealmObject, EmbeddedObject, or AsymmetricObject")); | ||
} | ||
|
||
[TestCase(true)] | ||
[TestCase(false)] | ||
public void ShouldCompact_IsInvokedAfterOpening(bool shouldCompact) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is moved to |
||
{ | ||
var config = (RealmConfiguration)RealmConfiguration.DefaultConfiguration; | ||
|
||
using (var realm = GetRealm(config)) | ||
{ | ||
AddDummyData(realm); | ||
} | ||
|
||
var oldSize = new FileInfo(config.DatabasePath).Length; | ||
long projectedNewSize = 0; | ||
var hasPrompted = false; | ||
config.ShouldCompactOnLaunch = (totalBytes, bytesUsed) => | ||
{ | ||
Assert.That(totalBytes, Is.EqualTo(oldSize)); | ||
hasPrompted = true; | ||
projectedNewSize = (long)bytesUsed; | ||
return shouldCompact; | ||
}; | ||
|
||
using (var realm = GetRealm(config)) | ||
{ | ||
Assert.That(hasPrompted, Is.True); | ||
var newSize = new FileInfo(config.DatabasePath).Length; | ||
if (shouldCompact) | ||
{ | ||
// Less than or equal because of the new online compaction mechanism - it's possible | ||
// that the Realm was already at the optimal size. | ||
Assert.That(newSize, Is.LessThanOrEqualTo(oldSize)); | ||
|
||
// Less than 20% error in projections | ||
Assert.That((newSize - projectedNewSize) / newSize, Is.LessThan(0.2)); | ||
} | ||
else | ||
{ | ||
Assert.That(newSize, Is.EqualTo(oldSize)); | ||
} | ||
|
||
Assert.That(realm.All<IntPrimaryKeyWithValueObject>().Count(), Is.EqualTo(DummyDataSize / 2)); | ||
} | ||
} | ||
|
||
[TestCase(false, true)] | ||
[TestCase(false, false)] | ||
[TestCase(true, true)] | ||
|
@@ -454,7 +410,7 @@ public void Compact_WhenResultsAreOpen_ShouldReturnFalse() | |
{ | ||
using var realm = GetRealm(); | ||
|
||
var token = realm.All<Person>().SubscribeForNotifications((sender, changes) => | ||
var token = realm.All<Person>().SubscribeForNotifications((_, changes) => | ||
{ | ||
Console.WriteLine(changes?.InsertedIndices); | ||
}); | ||
|
@@ -463,6 +419,32 @@ public void Compact_WhenResultsAreOpen_ShouldReturnFalse() | |
token.Dispose(); | ||
} | ||
|
||
[Test] | ||
public void Compact_WhenShouldDeleteIfMigrationNeeded_PreservesObjects() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{ | ||
var config = (RealmConfiguration)RealmConfiguration.DefaultConfiguration; | ||
config.ShouldDeleteIfMigrationNeeded = true; | ||
|
||
using (var realm = GetRealm(config)) | ||
{ | ||
realm.Write(() => | ||
{ | ||
realm.Add(new Person | ||
{ | ||
FirstName = "Peter" | ||
}); | ||
}); | ||
} | ||
|
||
Assert.That(Realm.Compact(config), Is.True); | ||
|
||
using (var realm = GetRealm(config)) | ||
{ | ||
Assert.That(realm.All<Person>().Count(), Is.EqualTo(1)); | ||
Assert.That(realm.All<Person>().Single().FirstName, Is.EqualTo("Peter")); | ||
} | ||
} | ||
|
||
[Test] | ||
public void RealmChangedShouldFireForEveryInstance() | ||
{ | ||
|
@@ -472,13 +454,13 @@ public void RealmChangedShouldFireForEveryInstance() | |
using var realm2 = GetRealm(); | ||
|
||
var changed1 = 0; | ||
realm1.RealmChanged += (sender, e) => | ||
realm1.RealmChanged += (_, _) => | ||
{ | ||
changed1++; | ||
}; | ||
|
||
var changed2 = 0; | ||
realm2.RealmChanged += (sender, e) => | ||
realm2.RealmChanged += (_, _) => | ||
{ | ||
changed2++; | ||
}; | ||
|
@@ -628,7 +610,7 @@ public void GetInstanceAsync_ExecutesMigrationsInBackground() | |
var threadId = Environment.CurrentManagedThreadId; | ||
var hasCompletedMigration = false; | ||
config.SchemaVersion = 2; | ||
config.MigrationCallback = (migration, oldSchemaVersion) => | ||
config.MigrationCallback = (migration, _) => | ||
{ | ||
Assert.That(Environment.CurrentManagedThreadId, Is.Not.EqualTo(threadId)); | ||
Task.Delay(300).Wait(); | ||
|
@@ -914,8 +896,7 @@ public void FrozenRealm_CannotSubscribeForNotifications() | |
using var realm = GetRealm(); | ||
using var frozenRealm = realm.Freeze(); | ||
|
||
Assert.Throws<RealmFrozenException>(() => frozenRealm.RealmChanged += (_, __) => { }); | ||
Assert.Throws<RealmFrozenException>(() => frozenRealm.RealmChanged -= (_, __) => { }); | ||
Assert.Throws<RealmFrozenException>(() => frozenRealm.RealmChanged += (_, _) => { }); | ||
} | ||
|
||
[Test] | ||
|
@@ -1046,7 +1027,7 @@ await TestHelpers.EnsureObjectsAreCollected(() => | |
using var realm = Realm.GetInstance(); | ||
var state = stateAccessor.GetValue(realm)!; | ||
|
||
return new object[] { state }; | ||
return new[] { state }; | ||
}); | ||
}); | ||
} | ||
|
@@ -1093,7 +1074,7 @@ public void GetInstance_WithManualSchema_CanReadAndWrite() | |
{ | ||
Schema = new RealmSchema.Builder | ||
{ | ||
new ObjectSchema.Builder("MyType", ObjectSchema.ObjectType.RealmObject) | ||
new ObjectSchema.Builder("MyType") | ||
{ | ||
Property.Primitive("IntValue", RealmValueType.Int), | ||
Property.PrimitiveList("ListValue", RealmValueType.Date), | ||
|
@@ -1104,7 +1085,7 @@ public void GetInstance_WithManualSchema_CanReadAndWrite() | |
Property.ObjectSet("ObjectSetValue", "OtherObject"), | ||
Property.ObjectDictionary("ObjectDictionaryValue", "OtherObject"), | ||
}, | ||
new ObjectSchema.Builder("OtherObject", ObjectSchema.ObjectType.RealmObject) | ||
new ObjectSchema.Builder("OtherObject") | ||
{ | ||
Property.Primitive("Id", RealmValueType.String, isPrimaryKey: true), | ||
Property.Backlinks("MyTypes", "MyType", "ObjectValue") | ||
|
@@ -1230,13 +1211,10 @@ public void GetInstance_WithTypedSchemaWithMissingProperties_ThrowsException() | |
|
||
using var realm = GetRealm(config); | ||
|
||
var person = realm.Write(() => | ||
var person = realm.Write(() => realm.Add(new Person | ||
{ | ||
return realm.Add(new Person | ||
{ | ||
LastName = "Smith" | ||
}); | ||
}); | ||
LastName = "Smith" | ||
})); | ||
|
||
var exGet = Assert.Throws<MissingMemberException>(() => _ = person.FirstName)!; | ||
Assert.That(exGet.Message, Does.Contain(nameof(Person))); | ||
|
@@ -1255,13 +1233,10 @@ public void RealmWithFrozenObjects_WhenDeleted_DoesNotThrow() | |
{ | ||
var config = new RealmConfiguration(Guid.NewGuid().ToString()); | ||
var realm = GetRealm(config); | ||
var frozenObj = realm.Write(() => | ||
var frozenObj = realm.Write(() => realm.Add(new IntPropertyObject | ||
{ | ||
return realm.Add(new IntPropertyObject | ||
{ | ||
Int = 1 | ||
}).Freeze(); | ||
}); | ||
Int = 1 | ||
}).Freeze()); | ||
|
||
frozenObj.Realm!.Dispose(); | ||
realm.Dispose(); | ||
|
@@ -1275,7 +1250,7 @@ public void RealmWithFrozenObjects_WhenDeleted_DoesNotThrow() | |
public void BeginWrite_CalledMultipleTimes_Throws() | ||
{ | ||
using var realm = GetRealm(); | ||
var ts = realm.BeginWrite(); | ||
using var ts = realm.BeginWrite(); | ||
|
||
Assert.That(() => realm.BeginWrite(), Throws.TypeOf<RealmInvalidTransactionException>()); | ||
} | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are moved to RealmConfigurationBase so they become available to sync configs.