use of org.greenrobot.greendao.daotest.AnActiveEntity in project greenDAO by greenrobot.
the class AnActiveEntityTest method testActiveDelete.
public void testActiveDelete() {
AnActiveEntity entity = new AnActiveEntity(1l);
dao.insert(entity);
entity.delete();
assertNull(dao.load(1l));
}
use of org.greenrobot.greendao.daotest.AnActiveEntity in project greenDAO by greenrobot.
the class AnActiveEntityTest method testThrowWhenDetached.
public void testThrowWhenDetached() {
AnActiveEntity entity = new AnActiveEntity();
try {
entity.delete();
fail("Should fail for detached entity");
} catch (DaoException e) {
// OK, expected
}
try {
entity.refresh();
fail("Should fail for detached entity");
} catch (DaoException e) {
// OK, expected
}
try {
entity.update();
fail("Should fail for detached entity");
} catch (DaoException e) {
// OK, expected
}
}
use of org.greenrobot.greendao.daotest.AnActiveEntity in project greenDAO by greenrobot.
the class AnActiveEntityTest method testActiveUpdate.
public void testActiveUpdate() {
AnActiveEntity entity = new AnActiveEntity(1l);
long rowId = dao.insert(entity);
entity.setText("NEW");
entity.update();
daoSession.clear();
AnActiveEntity entity2 = dao.load(rowId);
assertNotSame(entity, entity2);
assertEquals("NEW", entity2.getText());
}
use of org.greenrobot.greendao.daotest.AnActiveEntity in project greenDAO by greenrobot.
the class AnActiveEntityMultithreadingTest method doTestAlwaysAttached.
private void doTestAlwaysAttached(Thread thread) throws Exception {
thread.start();
Field daoSessionField = AnActiveEntity.class.getDeclaredField("daoSession");
daoSessionField.setAccessible(true);
int countEntity = 0;
countDownAndAwaitLatch();
try {
assertTrue(latch.await(10, TimeUnit.SECONDS));
for (int i = 0; ; i++) {
AnActiveEntity entity = dao.load(1l);
if (entity != null) {
countEntity++;
assertNotNull(daoSessionField.get(entity));
}
if (i == 1000000 && countEntity == 0) {
fail("No entity available");
}
if (countEntity % 10000 == 0) {
DaoLog.d("Checked entities " + countEntity + " in " + i + " iterations");
}
if (countEntity == ENTITIES_TO_CHECK) {
break;
}
}
} finally {
running = false;
thread.join();
}
}
use of org.greenrobot.greendao.daotest.AnActiveEntity in project greenDAO by greenrobot.
the class AnActiveEntityTest method testActiveRefresh.
public void testActiveRefresh() {
AnActiveEntity entity = new AnActiveEntity(1l);
dao.insert(entity);
AnActiveEntity entity2 = new AnActiveEntity(1l);
entity2.setText("NEW");
dao.update(entity2);
entity.refresh();
assertEquals("NEW", entity.getText());
}
Aggregations