Search in sources :

Example 6 with WorkSession

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));
}
Also used : LeanJtxWorker(jodd.jtx.worker.LeanJtxWorker) WorkSession(jodd.jtx.data.WorkSession) Test(org.junit.Test)

Aggregations

WorkSession (jodd.jtx.data.WorkSession)6 Test (org.junit.Test)6 UncheckedException (jodd.exception.UncheckedException)1 LeanJtxWorker (jodd.jtx.worker.LeanJtxWorker)1