Search in sources :

Example 71 with TestEntity

use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.

the class TestEntityIdentityScopeTest method testDetach.

public void testDetach() {
    TestEntity entity = createEntity(null);
    dao.insert(entity);
    dao.detach(entity);
    TestEntity entity2 = dao.load(entity.getId());
    dao.detach(entity2);
    TestEntity entity3 = dao.load(entity.getId());
    assertNotSame(entity, entity2);
    assertNotSame(entity2, entity3);
    assertNotSame(entity, entity3);
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity)

Example 72 with TestEntity

use of org.greenrobot.greendao.daotest.TestEntity in project greenDAO by greenrobot.

the class DeadlockPreventionTest method _testLoadAll.

// Runs pretty long, only run manually
public void _testLoadAll() throws InterruptedException {
    dao = daoSession.getTestEntityDao();
    List<TestEntity> entities = new ArrayList<>();
    for (int i = 0; i < 10000; i++) {
        TestEntity entity = new TestEntity();
        entity.setSimpleStringNotNull("Text" + i);
        entities.add(entity);
    }
    dao.insertInTx(entities);
    System.out.println("Entities inserted");
    LoadThread loadThread = new LoadThread();
    InsertThread insertThread = new InsertThread();
    InsertBatchThread insertBatchThread = new InsertBatchThread();
    loadThread.start();
    insertThread.start();
    insertBatchThread.start();
    int lastCounterInsert = insertThread.counter;
    int lastCounterInsertBatch = insertBatchThread.counter;
    int noProgressCount = 0;
    while (!done.await(10, TimeUnit.SECONDS)) {
        if (lastCounterInsert == insertThread.counter && lastCounterInsertBatch == insertBatchThread.counter) {
            noProgressCount++;
            System.err.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            System.err.println("No progress #" + noProgressCount + ", dumping threads");
            System.err.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            dumpStacktrace("LOAD", loadThread);
            dumpStacktrace("INSERT", insertThread);
            dumpStacktrace("INSERT BATCH", insertBatchThread);
            if (noProgressCount >= 3) {
                // Test seems to be stuck, kill everything!
                System.exit(1);
            }
        } else {
            lastCounterInsert = insertThread.counter;
            lastCounterInsertBatch = insertBatchThread.counter;
            noProgressCount = 0;
        }
    }
    loadThread.join();
    insertThread.join();
    insertBatchThread.join();
}
Also used : TestEntity(org.greenrobot.greendao.daotest.TestEntity) ArrayList(java.util.ArrayList)

Aggregations

TestEntity (org.greenrobot.greendao.daotest.TestEntity)72 ArrayList (java.util.ArrayList)16 RelationEntity (org.greenrobot.greendao.daotest.RelationEntity)4 List (java.util.List)3 DaoException (org.greenrobot.greendao.DaoException)2 TestSubscriber (rx.observers.TestSubscriber)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Date (java.util.Date)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 WhereCondition (org.greenrobot.greendao.query.WhereCondition)1 Subscription (rx.Subscription)1