Search in sources :

Example 51 with AllJavaTypes

use of io.realm.entities.AllJavaTypes in project realm-java by realm.

the class OrderedRealmCollectionIteratorTests method useCase_simpleIterator_modifyQueryResult_innerTransaction.

@Test
public void useCase_simpleIterator_modifyQueryResult_innerTransaction() {
    if (skipTest(CollectionClass.MANAGED_REALMLIST, CollectionClass.UNMANAGED_REALMLIST, CollectionClass.REALMRESULTS)) {
        return;
    }
    assertEquals(TEST_SIZE, collection.size());
    for (int i = 0; i < collection.size(); i++) {
        realm.beginTransaction();
        AllJavaTypes obj = collection.get(i);
        obj.setFieldLong(obj.getFieldLong() + TEST_SIZE);
        realm.commitTransaction();
    }
    // Verifies that all elements were modified.
    assertEquals(0, realm.where(AllJavaTypes.class).lessThan(AllJavaTypes.FIELD_LONG, TEST_SIZE).count());
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 52 with AllJavaTypes

use of io.realm.entities.AllJavaTypes in project realm-java by realm.

the class OrderedRealmCollectionIteratorTests method useCase_simpleIterator_modifyQueryResult_outerTransaction_looperThread.

@Test
@UiThreadTest
public void useCase_simpleIterator_modifyQueryResult_outerTransaction_looperThread() {
    if (skipTest(CollectionClass.MANAGED_REALMLIST, CollectionClass.UNMANAGED_REALMLIST, CollectionClass.REALMRESULTS)) {
        return;
    }
    assertEquals(TEST_SIZE, collection.size());
    realm.beginTransaction();
    for (int i = 0; i < collection.size(); i++) {
        AllJavaTypes obj = collection.get(i);
        obj.setFieldLong(obj.getFieldLong() + TEST_SIZE);
    }
    realm.commitTransaction();
    // Verifies that all elements were modified.
    assertEquals(0, realm.where(AllJavaTypes.class).lessThan(AllJavaTypes.FIELD_LONG, TEST_SIZE).count());
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 53 with AllJavaTypes

use of io.realm.entities.AllJavaTypes in project realm-java by realm.

the class OrderedRealmCollectionIteratorTests method listIterator_unsupportedMethods.

@Test
public void listIterator_unsupportedMethods() {
    ListIterator<AllJavaTypes> it = collection.listIterator();
    try {
        it.remove();
        fail();
    } catch (UnsupportedOperationException e) {
        assertResultsOrSnapshot();
    } catch (IllegalStateException e) {
        assertRealmList();
    }
    try {
        it.add(null);
        fail();
    } catch (UnsupportedOperationException e) {
        assertResultsOrSnapshot();
    } catch (IllegalArgumentException e) {
        assertRealmList();
    }
    try {
        it.set(new AllJavaTypes());
        fail();
    } catch (UnsupportedOperationException e) {
        assertResultsOrSnapshot();
    } catch (IllegalStateException e) {
        assertRealmList();
    }
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 54 with AllJavaTypes

use of io.realm.entities.AllJavaTypes in project realm-java by realm.

the class OrderedRealmCollectionIteratorTests method listIterator_transactionBeforeNextItem.

@Test
public void listIterator_transactionBeforeNextItem() {
    Iterator<AllJavaTypes> it = collection.listIterator();
    int i = 0;
    while (it.hasNext()) {
        AllJavaTypes item = it.next();
        assertEquals("Failed at index: " + i, i, item.getFieldLong());
        i++;
        // Committing transactions while iterating should not effect the current iterator if on a looper thread.
        createNewObject();
    }
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 55 with AllJavaTypes

use of io.realm.entities.AllJavaTypes in project realm-java by realm.

the class OrderedRealmCollectionIteratorTests method iterator_unrelatedTransactionBeforeNextItem.

@Test
public void iterator_unrelatedTransactionBeforeNextItem() {
    Iterator<AllJavaTypes> it = collection.iterator();
    int i = 0;
    while (it.hasNext()) {
        AllJavaTypes item = it.next();
        assertEquals("Failed at index: " + i, i, item.getFieldLong());
        i++;
        // Committing unrelated transactions while iterating should not effect the current iterator.
        createNewObject();
    }
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Aggregations

AllJavaTypes (io.realm.entities.AllJavaTypes)90 Test (org.junit.Test)78 UiThreadTest (android.support.test.annotation.UiThreadTest)24 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Date (java.util.Date)5 RealmException (io.realm.exceptions.RealmException)4 Ignore (org.junit.Ignore)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutorService (java.util.concurrent.ExecutorService)2 ExpectedException (org.junit.rules.ExpectedException)2 Pair (android.util.Pair)1 CyclicType (io.realm.entities.CyclicType)1 Dog (io.realm.entities.Dog)1 NonLatinFieldNames (io.realm.entities.NonLatinFieldNames)1 PrimaryKeyAsString (io.realm.entities.PrimaryKeyAsString)1 RealmPrimaryKeyConstraintException (io.realm.exceptions.RealmPrimaryKeyConstraintException)1 RunInLooperThread (io.realm.rule.RunInLooperThread)1 Field (java.lang.reflect.Field)1