Created
January 20, 2015 13:55
-
-
Save kneth/7cbad830461e57ffbe0d to your computer and use it in GitHub Desktop.
Scheduled queries
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
private void runSingleThread(ScheduledExecutorService scheduler, final AllTypes allTypes) { | |
testRealm.beginTransaction(); | |
allTypes.setColumnLong(1); | |
testRealm.commitTransaction(); | |
Log.d("REALM", "runSingleThread"); | |
scheduler.schedule(new Runnable() { | |
@Override | |
public void run() { | |
Log.d("REALM", "run"); | |
Realm realm = Realm.getInstance(getContext()); | |
RealmResults<AllTypes> allTypeses = realm.where(AllTypes.class).equalTo(FIELD_LONG, 1).findAll(); | |
Log.d("REALM", "size " + allTypeses.size()); | |
realm.close(); | |
} | |
}, 5, TimeUnit.SECONDS); | |
} | |
public void testSingleThread() { | |
ScheduledExecutorService scheduler; | |
scheduler = newSingleThreadScheduledExecutor(); | |
testRealm.beginTransaction(); | |
testRealm.clear(AllTypes.class); | |
testRealm.commitTransaction(); | |
testRealm.beginTransaction(); | |
AllTypes allTypes1 = testRealm.createObject(AllTypes.class); | |
AllTypes allTypes2 = testRealm.createObject(AllTypes.class); | |
AllTypes allTypes3 = testRealm.createObject(AllTypes.class); | |
testRealm.commitTransaction(); | |
runSingleThread(scheduler, allTypes1); | |
try { | |
Thread.sleep(10000); | |
} catch (InterruptedException e) { | |
fail(); | |
} | |
runSingleThread(scheduler, allTypes2); | |
runSingleThread(scheduler, allTypes3); | |
try { | |
Thread.sleep(10000); | |
} catch (InterruptedException e) { | |
fail(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment