Skip to content

Commit

Permalink
Fix typo and exception thrown in testcase's thread
Browse files Browse the repository at this point in the history
  • Loading branch information
beeender committed Jun 29, 2015
1 parent cba96db commit c4c6096
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
0.81.2
* Closing realm on another thread different from which it was created on throws an exception.
* Closing realm on another thread different from where it was created now throws an exception.

0.81.1
* Fixed memory leak causing Realm to never release Realm objects.
Expand Down
20 changes: 13 additions & 7 deletions realm/src/androidTest/java/io/realm/RealmTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import android.os.SystemClock;
import android.test.AndroidTestCase;

import junit.framework.AssertionFailedError;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -36,12 +38,12 @@
import java.util.Random;
import java.util.Scanner;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import io.realm.entities.AllTypes;
import io.realm.entities.AllTypesPrimaryKey;
Expand Down Expand Up @@ -1723,23 +1725,27 @@ public void testFinalizerThread() throws NoSuchFieldException, IllegalAccessExce

// Test close Realm in another thread different from where it is created.
public void testCloseRealmInDifferentThread() throws InterruptedException {
final AtomicBoolean threadReady = new AtomicBoolean(false);
final CountDownLatch latch = new CountDownLatch(1);
final AssertionFailedError threadAssertionError[] = new AssertionFailedError[1];

final Thread thatThread = new Thread(new Runnable() {
@Override
public void run() {
try {
testRealm.close();
fail("Close realm in a different thread should throw IllegalStateException.");
} catch (IllegalStateException ignored){
threadAssertionError[0] = new AssertionFailedError(
"Close realm in a different thread should throw IllegalStateException.");
} catch (IllegalStateException ignored) {
}
threadReady.set(true);
latch.countDown();
}
});
thatThread.start();

while (!threadReady.get()) {
Thread.sleep(5);
// Timeout should never happen
latch.await();
if (threadAssertionError[0] != null) {
throw threadAssertionError[0];
}
// After exception thrown in another thread, nothing should be changed to the realm in this thread.
testRealm.checkIfValid();
Expand Down

0 comments on commit c4c6096

Please sign in to comment.