Skip to content
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

Expose subscriptions more directly #6231

Merged
merged 23 commits into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2a7a93c
WIP
cmelchior Sep 13, 2018
730a750
Add Javadoc. Remove problematic getSubscription on RealmResults.
cmelchior Oct 12, 2018
0e1a41c
WIP
cmelchior Oct 12, 2018
02b1b67
Merge branch 'master' into cm/better-subscriptions
cmelchior Oct 12, 2018
87413b8
Add subscription capabilities on RealmQuery
cmelchior Oct 12, 2018
be99baa
Add Subscription to query based module
cmelchior Oct 12, 2018
9d9eeae
Add Realm tests. Fix a few bugs plus and docs.
cmelchior Oct 13, 2018
76066ab
Add RealmQuery tests
cmelchior Oct 13, 2018
a3c1e94
Use ObjectStore implementation as much as possible.
cmelchior Oct 13, 2018
43767a9
Added changelog
cmelchior Oct 13, 2018
99a24f4
Refactor Realm initialization to support loading subscriptions. Other…
cmelchior Oct 14, 2018
16cf0ab
Use correct version of Object Store
cmelchior Oct 15, 2018
41b50bc
Work-around for adding __ResultSets twice
cmelchior Oct 15, 2018
381d989
Fix Findbugs warnings
cmelchior Oct 15, 2018
0c41625
Update Object Store. Revert RealmCache changes so opening Realm insta…
cmelchior Oct 15, 2018
fe37952
Use OS master
cmelchior Oct 17, 2018
025e3a2
Add missing field from schema
cmelchior Oct 17, 2018
322e1b4
PR feedback
cmelchior Oct 22, 2018
5a1a4b5
Merge branch 'master' into cm/better-subscriptions
cmelchior Oct 23, 2018
5f0b95e
PR feedback
cmelchior Oct 23, 2018
e4fa7d2
Attempt to fix flaky test
cmelchior Oct 23, 2018
b2ad370
Merge branch 'cm/better-subscriptions' of https://github.com/realm/re…
cmelchior Oct 23, 2018
dc1ff5b
Fix unstable tests by moving reset into tearing down tests instead of…
cmelchior Oct 23, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 5.?.? (2018-mm-dd)
## 5.?.? (2018-MM-DD)

### Enhancements
* None
Expand All @@ -15,6 +15,26 @@
* None


## 5.8.0 (YYYY-MM-DD)

### Enhancements
* [ObjectServer] Added Subscription class available to Query-based Realms. This exposes a Subscription more directly. This class is in beta. [#6231](https://github.com/realm/realm-java/pull/6231).
* [ObjectServer] Added `Realm.getSubscriptions()`, `Realm.getSubscriptions(String pattern)` and `Realm.getSubscription` to make it easier to find existing subscriptions. These API's are in beta. [#6231](https://github.com/realm/realm-java/pull/6231).
cmelchior marked this conversation as resolved.
Show resolved Hide resolved
* [ObjectServer] Added `RealmQuery.subscribe()` and `RealmQuery.subscribe(String name)` to subscribe immediately inside a transaction. These API's are in beta. [#6231](https://github.com/realm/realm-java/pull/6231).
cmelchior marked this conversation as resolved.
Show resolved Hide resolved
* [ObjectServer] Added support for subscribing directly inside `SyncConfiguration.initialData()`. This can be coupled with `SyncConfiguration.waitForInitialRemoteData()` in order to block a Realm from opening until the initial subscriptions are ready and have downloaded data. This API are in beta. [#6231](https://github.com/realm/realm-java/pull/6231).
cmelchior marked this conversation as resolved.
Show resolved Hide resolved

### Fixed
* ?? (Issue [#??](https://github.com/realm/realm-java/issues/??), since ??).

### Compatibility
* Realm Object Server: 3.11.0 or later.
* File format: Generates Realms with format v9 (Reads and upgrades all previous formats)
* APIs are backwards compatible with all previous release of realm-java in the 5.x.y series.

### Internal
* None


## 5.7.1 (2018-10-22)

### Enhancements
Expand All @@ -29,7 +49,7 @@
* APIs are backwards compatible with all previous release of realm-java in the 5.x.y series.

### Internal
* None
* Updated to Object Store commit: 362b886628b3aefc5b7a0bc32293d794dc1d4ad5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that solve any issues in Java?



## 5.7.0 (2018-09-24)
Expand Down
3 changes: 3 additions & 0 deletions realm/config/findbugs/findbugs-filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@
<Match>
<Class name="io.realm.io_realm_sync_permissions_PermissionUserRealmProxy"/>
</Match>
<Match>
<Class name="io.realm.io_realm_sync_SubscriptionRealmProxy"/>
</Match>

</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -695,19 +695,27 @@ public void onSuccess(DynamicRealm realm) {
@Test
@RunTestInLooperThread
public void getInstanceAsync_nullConfigShouldThrow() {
thrown.expect(IllegalArgumentException.class);
DynamicRealm.getInstanceAsync(null, new DynamicRealm.Callback() {
@Override
public void onSuccess(DynamicRealm realm) {
fail();
}
});
try {
//noinspection ConstantConditions
DynamicRealm.getInstanceAsync(null, new DynamicRealm.Callback() {
@Override
public void onSuccess(DynamicRealm realm) {
fail();
}
});
} catch (IllegalArgumentException ignored) {
}
looperThread.testComplete();
}

@Test
@RunTestInLooperThread
public void getInstanceAsync_nullCallbackShouldThrow() {
thrown.expect(IllegalArgumentException.class);
DynamicRealm.getInstanceAsync(defaultConfig, null);
try {
//noinspection ConstantConditions
DynamicRealm.getInstanceAsync(defaultConfig, null);
} catch (IllegalArgumentException ignored) {
}
looperThread.testComplete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -475,17 +475,18 @@ public void execute(Realm realm) {
});

final DynamicRealm dynamicRealm = DynamicRealm.getInstance(looperThread.getConfiguration());
try {
final DynamicRealmObject targetAsync = dynamicRealm.where(BacklinksTarget.CLASS_NAME)
.equalTo(BacklinksTarget.FIELD_ID, 1L).findFirstAsync();
// precondition
assertFalse(targetAsync.isLoaded());
looperThread.closeAfterTest(dynamicRealm);
final DynamicRealmObject targetAsync = dynamicRealm.where(BacklinksTarget.CLASS_NAME)
.equalTo(BacklinksTarget.FIELD_ID, 1L).findFirstAsync();
// precondition
assertFalse(targetAsync.isLoaded());

thrown.expect(IllegalStateException.class);
try {
targetAsync.linkingObjects(BacklinksSource.CLASS_NAME, BacklinksSource.FIELD_CHILD);
} finally {
dynamicRealm.close();
fail();
} catch (IllegalStateException ignored) {
}
looperThread.testComplete();
}

@Test
Expand All @@ -505,25 +506,26 @@ public void execute(Realm realm) {
});

final DynamicRealm dynamicRealm = DynamicRealm.getInstance(looperThread.getConfiguration());
try {
final DynamicRealmObject target = dynamicRealm.where(BacklinksTarget.CLASS_NAME)
.equalTo(BacklinksTarget.FIELD_ID, 1L).findFirst();
looperThread.closeAfterTest(dynamicRealm);
final DynamicRealmObject target = dynamicRealm.where(BacklinksTarget.CLASS_NAME)
.equalTo(BacklinksTarget.FIELD_ID, 1L).findFirst();

dynamicRealm.executeTransaction(new DynamicRealm.Transaction() {
@Override
public void execute(DynamicRealm realm) {
target.deleteFromRealm();
}
});
dynamicRealm.executeTransaction(new DynamicRealm.Transaction() {
@Override
public void execute(DynamicRealm realm) {
target.deleteFromRealm();
}
});

// precondition
assertFalse(target.isValid());
// precondition
assertFalse(target.isValid());

thrown.expect(IllegalStateException.class);
try {
target.linkingObjects(BacklinksSource.CLASS_NAME, BacklinksSource.FIELD_CHILD);
} finally {
dynamicRealm.close();
fail();
} catch (IllegalStateException ignored) {
}
looperThread.testComplete();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,13 @@ public void execute(Realm realm) {
// precondition
assertFalse(targetAsync.isLoaded());

thrown.expect(IllegalStateException.class);
//noinspection ResultOfMethodCallIgnored
targetAsync.getParents();
fail();
try {
//noinspection ResultOfMethodCallIgnored
targetAsync.getParents();
fail();
} catch (IllegalStateException ignore) {
}
looperThread.testComplete();
}

@Test
Expand Down Expand Up @@ -471,10 +474,13 @@ public void execute(Realm realm) {
// precondition
assertFalse(target.isValid());

thrown.expect(IllegalStateException.class);
//noinspection ResultOfMethodCallIgnored
target.getParents();
fail();
try {
//noinspection ResultOfMethodCallIgnored
target.getParents();
fail();
} catch (IllegalStateException ignore) {
}
looperThread.testComplete();
}

@Test
Expand Down Expand Up @@ -509,10 +515,13 @@ public void execute(Realm realm) {
// precondition
assertFalse(target.isValid());

thrown.expect(IllegalStateException.class);
//noinspection ResultOfMethodCallIgnored
target.getParents();
fail();
try {
//noinspection ResultOfMethodCallIgnored
target.getParents();
fail();
} catch (IllegalStateException ignore) {
}
looperThread.testComplete();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,6 @@ public void onSuccess() {
public void run() {
// Manually call refresh, so the did_change will be triggered.
foregroundRealm.sharedRealm.refresh();
foregroundRealm.setAutoRefresh(true);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4322,13 +4322,15 @@ public void onSuccess(Realm realm) {
fail();
}
});
looperThread.testComplete();
}

@Test
@RunTestInLooperThread
public void getInstanceAsync_nullCallbackShouldThrow() {
thrown.expect(IllegalArgumentException.class);
Realm.getInstanceAsync(realmConfig, null);
looperThread.testComplete();
}

// Verify that the logic for waiting for the users file dir to be come available isn't totally broken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
* - @Before()
* - @RunTestInLooperThread/@Test
* - @After : This is called when exiting the test method. Warning: Looper test is still running.
* - looperThread.runAfterTest(Runnable) : This is called when the LooperTest either succeed or fails.
* - looperThread.runAfterTest(Runnable) : This is called when `testComplete()` is called. This can
* be both before and after `@After` has run.
*/

@RunWith(AndroidJUnit4.class)
Expand Down
48 changes: 17 additions & 31 deletions realm/realm-library/src/androidTest/java/io/realm/RxJavaTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,10 @@ public class RxJavaTests {

@Rule
public final UiThreadTestRule uiThreadTestRule = new UiThreadTestRule();

@Rule
public final RunInLooperThread looperThread = new RunInLooperThread() {
@Override
public void looperTearDown() {
if (subscription != null && !subscription.isDisposed()) {
subscription.dispose();
}
}
};
public final RunInLooperThread looperThread = new RunInLooperThread();

@Rule
public final TestRealmConfigurationFactory configFactory = new TestRealmConfigurationFactory();

Expand All @@ -76,6 +71,11 @@ public void looperTearDown() {
public void setUp() throws Exception {
// For non-LooperThread tests.
realm = Realm.getInstance(configFactory.createConfiguration());
looperThread.runAfterTest(() -> {
if (subscription != null && !subscription.isDisposed()) {
subscription.dispose();
}
});
}

@After
Expand Down Expand Up @@ -936,30 +936,16 @@ public void realmResults_gcStressTest() {
realm.commitTransaction();

for (int i = 0; i < TEST_SIZE; i++) {
// Doesn't keep a reference to the Observable.
realm.where(AllTypes.class).equalTo(AllTypes.FIELD_LONG, i).findAllAsync().asFlowable()
.filter(new Predicate<RealmResults<AllTypes>>() {
@Override
public boolean test(RealmResults<AllTypes> results) throws Exception {
return results.isLoaded();
}
})
.filter(results -> results.isLoaded())
.take(1) // Unsubscribes from Realm.
.subscribe(new Consumer<RealmResults<AllTypes>>() {
@Override
public void accept(RealmResults<AllTypes> allTypes) throws Exception {
// Not guaranteed, but can result in the GC of other RealmResults waiting for a result.
Runtime.getRuntime().gc();
if (innerCounter.incrementAndGet() == TEST_SIZE) {
looperThread.testComplete();
}
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
fail(throwable.toString());
.subscribe(allTypes -> {
// Not guaranteed, but can result in the GC of other RealmResults waiting for a result.
Runtime.getRuntime().gc();
if (innerCounter.incrementAndGet() == TEST_SIZE) {
looperThread.testComplete();
}
});
}, throwable -> fail(throwable.toString()));
}
}

Expand All @@ -972,6 +958,7 @@ public void dynamicRealmResults_gcStressTest() {
final int TEST_SIZE = 50;
final AtomicLong innerCounter = new AtomicLong();
final DynamicRealm realm = DynamicRealm.getInstance(looperThread.getConfiguration());
looperThread.closeAfterTest(realm);

realm.beginTransaction();
for (int i = 0; i < TEST_SIZE; i++) {
Expand All @@ -995,7 +982,6 @@ public void accept(RealmResults<DynamicRealmObject> dynamicRealmObjects) throws
// Not guaranteed, but can result in the GC of other RealmResults waiting for a result.
Runtime.getRuntime().gc();
if (innerCounter.incrementAndGet() == TEST_SIZE) {
realm.close();
looperThread.testComplete();
}
}
Expand Down Expand Up @@ -1061,6 +1047,7 @@ public void dynamicRealmObject_gcStressTest() {
final int TEST_SIZE = 50;
final AtomicLong innerCounter = new AtomicLong();
final DynamicRealm realm = DynamicRealm.getInstance(looperThread.getConfiguration());
looperThread.closeAfterTest(realm);

realm.beginTransaction();
for (int i = 0; i < TEST_SIZE; i++) {
Expand All @@ -1084,7 +1071,6 @@ public void accept(DynamicRealmObject dynamicRealmObject) throws Exception {
// Not guaranteed, but can result in the GC of other RealmResults waiting for a result.
Runtime.getRuntime().gc();
if (innerCounter.incrementAndGet() == TEST_SIZE) {
realm.close();
looperThread.testComplete();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public void addChangeListener_byLocalChanges() {
public void onChange(OsSharedRealm sharedRealm) {
// Transaction has been committed in core, but commitTransaction hasn't returned in java.
assertFalse(commitReturns.get());
looperThread.testComplete();
sharedRealm.close();
looperThread.testComplete();
}
});
sharedRealm.beginTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public void tearDown() {
userStore.remove(syncUser.getIdentity(), syncUser.getAuthenticationUrl().toString());
}
SyncManager.reset();
BaseRealm.applicationContext = null; // Required for Realm.init() to work
Realm.init(InstrumentationRegistry.getTargetContext());
}

@Test
Expand Down
Loading