Skip to content

Commit

Permalink
Flexible Sync: Additive Changes 1/2 (#7805)
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaafanador3 authored May 30, 2022
1 parent 8b4cf79 commit 812fafa
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 128 deletions.
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
x.y.z Release notes (yyyy-MM-dd)
=============================================================
### Enhancements
* None.
* Allow adding a subscription querying for all documents of a type in swift for flexible sync.
```
try await subscriptions.update {
subscriptions.append(QuerySubscription<SwiftPerson>(name: "all_people"))
}
```
* Add Combine API support for flexible sync beta.

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-swift/issues/????), since v?.?.?)
* None.

<!-- ### Breaking Changes - ONLY INCLUDE FOR NEW MAJOR version -->
### Breaking Changes

* Rename `SyncSubscriptionSet.write` to `SyncSubscriptionSet.update` to avoid confusion with `Realm.write`.
* Rename `SyncSubscription.update` to `SyncSubscription.updateQuery` to avoid confusion with `SyncSubscriptionSet.update`.
* Rename `RLMSyncSubscriptionSet.write` to `RLMSyncSubscriptionSet.update` to align it with swift API.

### Compatibility
* Realm Studio: 11.0.0 or later.
Expand Down
66 changes: 33 additions & 33 deletions Realm/ObjectServerTests/RLMFlexibleSyncServerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ - (void)testCheckVersionAfterAddSubscription {
XCTAssertEqual(subs.version, 0UL);
XCTAssertEqual(subs.count, 0UL);

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
where:@"age > 15"];
}];
Expand All @@ -103,7 +103,7 @@ - (void)testEmptyWriteSubscriptions {
XCTAssertEqual(subs.version, 0UL);
XCTAssertEqual(subs.count, 0UL);

[subs write:^{
[subs update:^{
}];

XCTAssertEqual(subs.version, 1UL);
Expand All @@ -114,7 +114,7 @@ - (void)testAddAndFindSubscriptionByQuery {
RLMRealm *realm = [self openFlexibleSyncRealm:_cmd];
RLMSyncSubscriptionSet *subs = realm.subscriptions;

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
where:@"age > 15"];
}];
Expand All @@ -133,7 +133,7 @@ - (void)testAddAndFindSubscriptionWithCompoundQuery {
XCTAssertEqual(subs.version, 0UL);
XCTAssertEqual(subs.count, 0UL);

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
where:@"firstName == %@ and lastName == %@", @"John", @"Doe"];
}];
Expand All @@ -155,7 +155,7 @@ - (void)testAddAndFindSubscriptionWithPredicate {
XCTAssertEqual(subs.version, 0UL);
XCTAssertEqual(subs.count, 0UL);

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
predicate:[NSPredicate predicateWithFormat:@"age == %d", 20]];
}];
Expand Down Expand Up @@ -184,7 +184,7 @@ - (void)testAddAndFindSubscriptionByName {
XCTAssertEqual(realm.subscriptions.version, 0UL);
XCTAssertEqual(realm.subscriptions.count, 0UL);

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
subscriptionName:@"person_older_15"
where:@"age > 15"];
Expand All @@ -200,7 +200,7 @@ - (void)testAddDuplicateSubscription {
RLMRealm *realm = [self openFlexibleSyncRealm:_cmd];
RLMSyncSubscriptionSet *subs = realm.subscriptions;

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
where:@"age > 15"];
[subs addSubscriptionWithClassName:Person.className
Expand All @@ -215,7 +215,7 @@ - (void)testAddDuplicateNamedSubscriptionWillThrow {
RLMRealm *realm = [self openFlexibleSyncRealm:_cmd];
RLMSyncSubscriptionSet *subs = realm.subscriptions;

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
subscriptionName:@"person_age"
where:@"age > 15"];
Expand All @@ -240,7 +240,7 @@ - (void)testAddDuplicateSubscriptionWithPredicate {
RLMRealm *realm = [self openFlexibleSyncRealm:_cmd];
RLMSyncSubscriptionSet *subs = realm.subscriptions;

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
where:@"age > 15"];
[subs addSubscriptionWithClassName:Person.className
Expand All @@ -255,7 +255,7 @@ - (void)testAddDuplicateSubscriptionWithDifferentName {
RLMRealm *realm = [self openFlexibleSyncRealm:_cmd];
RLMSyncSubscriptionSet *subs = realm.subscriptions;

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
subscriptionName:@"person_age_1"
where:@"age > 15"];
Expand All @@ -282,7 +282,7 @@ - (void)testOverrideNamedWithUnnamedSubscription {
RLMRealm *realm = [self openFlexibleSyncRealm:_cmd];
RLMSyncSubscriptionSet *subs = realm.subscriptions;

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
subscriptionName:@"person_age_1"
where:@"age > 15"];
Expand All @@ -298,7 +298,7 @@ - (void)testOverrideUnnamedWithNamedSubscription {
RLMRealm *realm = [self openFlexibleSyncRealm:_cmd];
RLMSyncSubscriptionSet *subs = realm.subscriptions;

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
predicate:[NSPredicate predicateWithFormat:@"age > %d", 15]];
[subs addSubscriptionWithClassName:Person.className
Expand All @@ -314,13 +314,13 @@ - (void)testAddSubscriptionInDifferentWriteBlocks {
RLMRealm *realm = [self openFlexibleSyncRealm:_cmd];
RLMSyncSubscriptionSet *subs = realm.subscriptions;

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
subscriptionName:@"person_age_1"
where:@"age > 15"];
}];

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
subscriptionName:@"person_age_2"
predicate:[NSPredicate predicateWithFormat:@"age > %d", 20]];
Expand All @@ -340,7 +340,7 @@ - (void)testRemoveSubscriptionByName {
RLMRealm *realm = [self openFlexibleSyncRealm:_cmd];
RLMSyncSubscriptionSet *subs = realm.subscriptions;

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
subscriptionName:@"person_age_1"
where:@"age > 15"];
Expand All @@ -352,7 +352,7 @@ - (void)testRemoveSubscriptionByName {
XCTAssertEqual(subs.version, 1UL);
XCTAssertEqual(subs.count, 2UL);

[subs write:^{
[subs update:^{
[subs removeSubscriptionWithName:@"person_age_1"];
}];

Expand All @@ -370,7 +370,7 @@ - (void)testRemoveSubscriptionWithoutWriteThrow {
RLMRealm *realm = [self openFlexibleSyncRealm:_cmd];
RLMSyncSubscriptionSet *subs = realm.subscriptions;

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
subscriptionName:@"person_age_1"
where:@"age > 15"];
Expand All @@ -385,7 +385,7 @@ - (void)testRemoveSubscriptionByQuery {
RLMRealm *realm = [self openFlexibleSyncRealm:_cmd];
RLMSyncSubscriptionSet *subs = realm.subscriptions;

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
subscriptionName:@"person_age"
where:@"age > 15"];
Expand All @@ -400,7 +400,7 @@ - (void)testRemoveSubscriptionByQuery {
XCTAssertEqual(subs.version, 1UL);
XCTAssertEqual(subs.count, 3UL);

[subs write:^{
[subs update:^{
[subs removeSubscriptionWithClassName:Person.className where:@"firstName == %@", @"John"];
[subs removeSubscriptionWithClassName:Person.className predicate:[NSPredicate predicateWithFormat:@"lastName == %@", @"Doe"]];
}];
Expand All @@ -422,7 +422,7 @@ - (void)testRemoveSubscription {
RLMRealm *realm = [self openFlexibleSyncRealm:_cmd];
RLMSyncSubscriptionSet *subs = realm.subscriptions;

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
subscriptionName:@"person_age"
where:@"age > 15"];
Expand All @@ -440,7 +440,7 @@ - (void)testRemoveSubscription {
RLMSyncSubscription *foundSubscription = [subs subscriptionWithName:@"person_age"];
XCTAssertNotNil(foundSubscription);

[subs write:^{
[subs update:^{
[subs removeSubscription:foundSubscription];
}];

Expand All @@ -450,7 +450,7 @@ - (void)testRemoveSubscription {
RLMSyncSubscription *foundSubscription2 = [subs subscriptionWithName:@"person_firstname"];
XCTAssertNotNil(foundSubscription2);

[subs write:^{
[subs update:^{
[subs removeSubscription:foundSubscription2];
}];

Expand All @@ -462,7 +462,7 @@ - (void)testRemoveAllSubscription {
RLMRealm *realm = [self openFlexibleSyncRealm:_cmd];
RLMSyncSubscriptionSet *subs = realm.subscriptions;

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
subscriptionName:@"person_age"
where:@"age > 15"];
Expand All @@ -477,7 +477,7 @@ - (void)testRemoveAllSubscription {
XCTAssertEqual(subs.version, 1UL);
XCTAssertEqual(subs.count, 3UL);

[subs write:^{
[subs update:^{
[subs removeAllSubscriptions];
}];

Expand All @@ -492,7 +492,7 @@ - (void)testRemoveAllSubscriptionForType {
RLMRealm *realm = [self openFlexibleSyncRealm:_cmd];
RLMSyncSubscriptionSet *subs = realm.subscriptions;

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
subscriptionName:@"person_age"
where:@"age > 15"];
Expand All @@ -507,7 +507,7 @@ - (void)testRemoveAllSubscriptionForType {
XCTAssertEqual(subs.version, 1UL);
XCTAssertEqual(subs.count, 3UL);

[subs write:^{
[subs update:^{
[subs removeAllSubscriptionsWithClassName:Person.className];
}];

Expand All @@ -517,7 +517,7 @@ - (void)testRemoveAllSubscriptionForType {
RLMSyncSubscription *foundSubscription = [subs subscriptionWithName:@"dog_name"];
XCTAssertNotNil(foundSubscription);

[subs write:^{
[subs update:^{
[subs removeAllSubscriptionsWithClassName:Dog.className];
}];

Expand All @@ -529,7 +529,7 @@ - (void)testUpdateSubscriptionQuery {
RLMRealm *realm = [self openFlexibleSyncRealm:_cmd];
RLMSyncSubscriptionSet *subs = realm.subscriptions;

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
subscriptionName:@"person_age"
where:@"age > 15"];
Expand All @@ -541,7 +541,7 @@ - (void)testUpdateSubscriptionQuery {
RLMSyncSubscription *foundSubscription = [subs subscriptionWithName:@"person_age"];
XCTAssertNotNil(foundSubscription);

[subs write:^{
[subs update:^{
[foundSubscription updateSubscriptionWhere:@"age > 20"];
}];

Expand All @@ -558,7 +558,7 @@ - (void)testUpdateSubscriptionQueryWithoutWriteThrow {
RLMRealm *realm = [self openFlexibleSyncRealm:_cmd];
RLMSyncSubscriptionSet *subs = realm.subscriptions;

[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
subscriptionName:@"subscription_1"
where:@"age > 15"];
Expand All @@ -578,7 +578,7 @@ - (void)testSubscriptionSetIterate {
RLMSyncSubscriptionSet *subs = realm.subscriptions;

double numberOfSubs = 100;
[subs write:^{
[subs update:^{
for (int i = 0; i < numberOfSubs; ++i) {
[subs addSubscriptionWithClassName:Person.className
subscriptionName:[NSString stringWithFormat:@"person_age_%d", i]
Expand Down Expand Up @@ -609,7 +609,7 @@ - (void)testSubscriptionSetFirstAndLast {
XCTAssertNil(subs.lastObject);

int numberOfSubs = 20;
[subs write:^{
[subs update:^{
for (int i = 1; i <= numberOfSubs; ++i) {
[subs addSubscriptionWithClassName:Person.className
subscriptionName:[NSString stringWithFormat:@"person_age_%d", i]
Expand All @@ -636,7 +636,7 @@ - (void)testSubscriptionSetSubscript {
XCTAssertEqual(subs.count, 0UL);

int numberOfSubs = 20;
[subs write:^{
[subs update:^{
for (int i = 1; i <= numberOfSubs; ++i) {
[subs addSubscriptionWithClassName:Person.className
subscriptionName:[NSString stringWithFormat:@"person_age_%d", i]
Expand Down
4 changes: 2 additions & 2 deletions Realm/ObjectServerTests/RLMSyncTestCase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ - (bool)writeToFlxRealm:(void (^)(RLMRealm *))block {
XCTAssertNotNil(subs);

XCTestExpectation *ex = [self expectationWithDescription:@"state change complete"];
[subs write:^{
[subs update:^{
[subs addSubscriptionWithClassName:Person.className
subscriptionName:@"person_all"
where:@"TRUEPREDICATE"];
Expand All @@ -732,7 +732,7 @@ - (void)writeQueryAndCompleteForRealm:(RLMRealm *)realm block:(void (^)(RLMSyncS
XCTAssertNotNil(subs);

XCTestExpectation *ex = [self expectationWithDescription:@"state changes"];
[subs write:^{
[subs update:^{
block(subs);
} onComplete:^(NSError* error) {
if (error == nil) {
Expand Down
1 change: 1 addition & 0 deletions Realm/ObjectServerTests/RealmServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ private extension ObjectSchema {
"bsonType": "\(partitionKeyType)"
]
]

var relationships: [String: Any] = [:]
for property in properties {
// First pass we only add the properties to the schema as we can't add
Expand Down
Loading

0 comments on commit 812fafa

Please sign in to comment.