@Override public void run() { getTestEntityBox().put(new TestEntity()); } });
@Override public Long call() throws Exception { TestEntity entity = new TestEntity(); entity.setId(-1); getTestEntityBox().put(entity); return null; } };
@Test public void testCallInTxAsync_multiThreaded() throws InterruptedException { final Box<TestEntity> box = getTestEntityBox(); final Thread mainTestThread = Thread.currentThread(); final AtomicInteger number = new AtomicInteger();
@Test public void testRunInTx_PutAfterRemoveAll() { final Box<TestEntity> box = getTestEntityBox(); final long[] counts = {0}; box.put(new TestEntity()); store.runInTx(new Runnable() { @Override public void run() { putTestEntities(2); box.removeAll(); putTestEntity("hello", 3); counts[0] = box.count(); } }); assertEquals(1, counts[0]); }
@Test public void testRunInReadTxAndThenPut() { final Box<TestEntity> box = getTestEntityBox(); store.runInReadTx(new Runnable() { @Override public void run() { box.count(); } }); // Verify that box does not hang on to the read-only TX by doing a put box.put(new TestEntity()); assertEquals(1, box.count()); }
@Test public void testCallInReadTx() { final Box<TestEntity> box = getTestEntityBox(); box.put(new TestEntity()); long[] counts = store.callInReadTx(new Callable<long[]>() { @Override public long[] call() throws Exception { long count1 = store.callInReadTx(new Callable<Long>() { @Override public Long call() throws Exception { return box.count(); } }); return new long[]{box.count(), count1}; } }); assertEquals(1, counts[0]); assertEquals(1, counts[1]); }
@Test public void testRunInReadTx() { final Box<TestEntity> box = getTestEntityBox(); final long[] counts = {0, 0}; box.put(new TestEntity()); store.runInReadTx(new Runnable() { @Override public void run() { counts[0] = box.count(); store.runInReadTx(new Runnable() { @Override public void run() { counts[1] = box.count(); } }); } }); assertEquals(1, counts[0]); assertEquals(1, counts[1]); }
@Test public void testRunInTxRecursive() { final Box<TestEntity> box = getTestEntityBox(); final long[] counts = {0, 0, 0}; store.runInTx(new Runnable() {