Search in sources :

Example 66 with Person

use of io.requery.test.model.Person in project requery by requery.

the class RxTest method testRunInTransaction.

@Test
public void testRunInTransaction() {
    final Person person = randomPerson();
    data.runInTransaction(data.insert(person), data.update(person), data.delete(person)).toBlocking().forEach(new Action1<Object>() {

        @Override
        public void call(Object o) {
        }
    });
    assertEquals(0, data.count(Person.class).get().value().intValue());
    final Person person2 = randomPerson();
    data.runInTransaction(data.insert(person2)).toBlocking().forEach(new Action1<Person>() {

        @Override
        public void call(Person person) {
        }
    });
    assertEquals(1, data.count(Person.class).get().value().intValue());
}
Also used : Person(io.requery.test.model.Person) Test(org.junit.Test)

Example 67 with Person

use of io.requery.test.model.Person in project requery by requery.

the class RxTest method testQueryObservable.

@Test
public void testQueryObservable() throws Exception {
    for (int i = 0; i < 30; i++) {
        Person person = randomPerson();
        data.insert(person).toBlocking().value();
    }
    final List<Person> people = new ArrayList<>();
    data.select(Person.class).limit(50).get().toObservable().subscribe(new Action1<Person>() {

        @Override
        public void call(Person person) {
            people.add(person);
        }
    });
    assertEquals(30, people.size());
}
Also used : ArrayList(java.util.ArrayList) Person(io.requery.test.model.Person) Test(org.junit.Test)

Example 68 with Person

use of io.requery.test.model.Person in project requery by requery.

the class ReactiveTest method testSelfObservableDeleteQuery.

@Test
public void testSelfObservableDeleteQuery() throws Exception {
    final AtomicInteger count = new AtomicInteger();
    Disposable disposable = data.select(Person.class).get().observableResult().subscribe(new Consumer<Result<Person>>() {

        @Override
        public void accept(Result<Person> persons) {
            count.incrementAndGet();
        }
    });
    Person person = randomPerson();
    data.insert(person).blockingGet();
    assertEquals(2, count.get());
    int rows = data.delete(Person.class).get().value();
    assertEquals(3, count.get());
    disposable.dispose();
    assertEquals(rows, 1);
}
Also used : Disposable(io.reactivex.disposables.Disposable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Person(io.requery.test.model.Person) ReactiveResult(io.requery.reactivex.ReactiveResult) Result(io.requery.query.Result) Test(org.junit.Test)

Example 69 with Person

use of io.requery.test.model.Person in project requery by requery.

the class ReactiveTest method testRunInTransaction.

@Test
public void testRunInTransaction() {
    final Person person = randomPerson();
    data.runInTransaction(data.insert(person), data.update(person)).subscribe(new Consumer<Object>() {

        @Override
        public void accept(Object o) {
        }
    });
    assertEquals(1, data.count(Person.class).get().value().intValue());
}
Also used : Person(io.requery.test.model.Person) Test(org.junit.Test)

Example 70 with Person

use of io.requery.test.model.Person in project requery by requery.

the class ReactiveTest method testQueryEmpty.

@Test
public void testQueryEmpty() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    data.select(Person.class).get().observable().subscribe(new Consumer<Person>() {

        @Override
        public void accept(Person person) throws Exception {
            Assert.fail();
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable throwable) throws Exception {
            Assert.fail();
        }
    }, new Action() {

        @Override
        public void run() throws Exception {
            latch.countDown();
        }
    });
    if (!latch.await(1, TimeUnit.SECONDS)) {
        Assert.fail();
    }
}
Also used : Action(io.reactivex.functions.Action) CountDownLatch(java.util.concurrent.CountDownLatch) Person(io.requery.test.model.Person) SQLException(java.sql.SQLException) Test(org.junit.Test)

Aggregations

Person (io.requery.test.model.Person)120 Test (org.junit.Test)117 Group_Person (io.requery.test.model.Group_Person)75 Phone (io.requery.test.model.Phone)22 ArrayList (java.util.ArrayList)18 Tuple (io.requery.query.Tuple)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 Result (io.requery.query.Result)8 Address (io.requery.test.model.Address)8 Group (io.requery.test.model.Group)8 HashSet (java.util.HashSet)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 ReactiveResult (io.requery.reactivex.ReactiveResult)5 RxResult (io.requery.rx.RxResult)5 SQLException (java.sql.SQLException)5 Disposable (io.reactivex.disposables.Disposable)4 Calendar (java.util.Calendar)4 Subscription (rx.Subscription)4 Function (io.reactivex.functions.Function)3 PersistenceException (io.requery.PersistenceException)3