use of jodd.jtx.data.WorkSession in project jodd by oblac.
the class JtxManagerTest method testPropagationRequiredWithWorker.
@Test
public void testPropagationRequiredWithWorker() {
LeanJtxWorker worker = createWorker();
JtxTransaction jtx1 = worker.maybeRequestTransaction(new JtxTransactionMode().propagationRequired().readOnly(false), null);
WorkSession work1 = jtx1.requestResource(WorkSession.class);
assertEquals(1, worker.getTransactionManager().totalTransactions());
work1.writeValue("one");
assertEquals("[1] one", work1.readValue());
JtxTransaction jtx2 = worker.maybeRequestTransaction(new JtxTransactionMode().propagationRequired().readOnly(false), null);
assertEquals(1, worker.getTransactionManager().totalTransactions());
assertNull(jtx2);
WorkSession work2 = jtx1.requestResource(WorkSession.class);
assertSame(work2, work1);
work2.writeValue("two");
assertEquals("[1] two", work2.readValue());
assertFalse(worker.maybeCommitTransaction(jtx2));
work1.writeValue("three");
assertEquals("[1] three", work1.readValue());
assertTrue(worker.maybeCommitTransaction(jtx1));
}
Aggregations