use of org.eclipse.scout.rt.platform.transaction.ITransaction in project scout.rt by eclipse.
the class AbstractTransactionalMapTest method testRollback.
@Test
public void testRollback() {
ITransaction tr1 = createNewTransaction();
ITransaction tr2 = createNewTransaction();
Map<Integer, String> initalMap = new HashMap<Integer, String>();
initalMap.put(1, "1");
initalMap.put(2, "2");
initalMap.put(3, "3");
Map<Integer, String> map = createTransactionalMap(TRANSACTION_MEMBER_ID, true, initalMap);
// shared
ITransaction.CURRENT.set(null);
assertMapStateSimple(map, 1, "1", 2, "2", 3, "3");
// tr1
ITransaction.CURRENT.set(tr1);
map.put(2, "2.2");
assertMapStateSimple(map, 1, "1", 2, "2.2", 3, "3");
// tr2
ITransaction.CURRENT.set(tr2);
map.remove(3);
assertMapStateSimple(map, 1, "1", 2, "2");
// shared
ITransaction.CURRENT.set(null);
assertMapStateSimple(map, 1, "1", 2, "2", 3, "3");
rollbackTransaction(tr1);
assertMapStateSimple(map, 1, "1", 2, "2", 3, "3");
rollbackTransaction(tr2);
assertMapStateSimple(map, 1, "1", 2, "2", 3, "3");
}
use of org.eclipse.scout.rt.platform.transaction.ITransaction in project scout.rt by eclipse.
the class AbstractTransactionalMapTest method testIteratorRemove.
@Test
public void testIteratorRemove() {
ITransaction tr1 = createNewTransaction();
Map<Integer, String> initalMap = new HashMap<Integer, String>();
initalMap.put(2, "2");
initalMap.put(3, "3");
Map<Integer, String> map = createTransactionalMap(TRANSACTION_MEMBER_ID, false, initalMap);
ITransaction.CURRENT.set(tr1);
map.put(1, "1");
map.put(2, "2.2");
map.put(4, "4");
// remove entries while iterating (no concurrent modification exception is thrown)
for (Iterator<Entry<Integer, String>> iterator = map.entrySet().iterator(); iterator.hasNext(); ) {
iterator.next();
iterator.remove();
}
assertTrue("Map must be empty", map.isEmpty());
}
use of org.eclipse.scout.rt.platform.transaction.ITransaction in project scout.rt by eclipse.
the class AbstractTransactionalMapTest method testPut.
@Test
public void testPut() {
ITransaction tr1 = createNewTransaction();
ITransaction tr2 = createNewTransaction();
Map<Integer, String> initalMap = new HashMap<Integer, String>();
initalMap.put(1, "1");
Map<Integer, String> map = createTransactionalMap(TRANSACTION_MEMBER_ID, false, initalMap);
// shared
ITransaction.CURRENT.set(null);
assertMapStateSimple(map, 1, "1");
// tr1
ITransaction.CURRENT.set(tr1);
assertMapStateSimple(map, 1, "1");
map.put(2, "2");
assertMapStateSimple(map, 1, "1", 2, "2");
// shared
ITransaction.CURRENT.set(null);
assertMapStateSimple(map, 1, "1");
// tr2
ITransaction.CURRENT.set(tr2);
assertMapStateSimple(map, 1, "1");
map.put(3, "3");
assertMapStateSimple(map, 1, "1", 3, "3");
// shared
ITransaction.CURRENT.set(null);
assertMapStateSimple(map, 1, "1");
commitTransaction(tr1);
assertMapStateSimple(map, 1, "1", 2, "2");
commitTransaction(tr2);
assertMapStateSimple(map, 1, "1", 2, "2", 3, "3");
}
use of org.eclipse.scout.rt.platform.transaction.ITransaction in project scout.rt by eclipse.
the class AbstractTransactionalMapTest method testFastForward.
@Test
public void testFastForward() {
ITransaction tr1 = createNewTransaction();
ITransaction tr2 = createNewTransaction();
Map<Integer, String> initalMap = new HashMap<Integer, String>();
initalMap.put(1, "1");
Map<Integer, String> map = createTransactionalMap(TRANSACTION_MEMBER_ID, true, initalMap);
// shared
ITransaction.CURRENT.set(null);
assertMapStateSimple(map, 1, "1");
// tr1
ITransaction.CURRENT.set(tr1);
assertMapStateSimple(map, 1, "1");
map.put(2, "2");
assertMapStateSimple(map, 1, "1", 2, "2");
// shared
ITransaction.CURRENT.set(null);
assertMapStateSimple(map, 1, "1", 2, "2");
// tr2
ITransaction.CURRENT.set(tr2);
assertMapStateSimple(map, 1, "1", 2, "2");
map.put(3, "3");
assertMapStateSimple(map, 1, "1", 2, "2", 3, "3");
map.put(2, "2.2");
assertMapStateSimple(map, 1, "1", 2, "2.2", 3, "3");
// shared
ITransaction.CURRENT.set(null);
assertMapStateSimple(map, 1, "1", 2, "2", 3, "3");
commitTransaction(tr1);
assertMapStateSimple(map, 1, "1", 2, "2", 3, "3");
commitTransaction(tr2);
assertMapStateSimple(map, 1, "1", 2, "2.2", 3, "3");
}
use of org.eclipse.scout.rt.platform.transaction.ITransaction in project scout.rt by eclipse.
the class ServerTestRunnerDifferentSessionTest method test3.
@Test
@RunWithServerSession(value = JUnitServerSession2.class)
public void test3() {
ISession serverSession = IServerSession.CURRENT.get();
assertTrue(serverSession instanceof JUnitServerSession2);
assertEquals("anna", serverSession.getUserId());
m_serverSessions.add(serverSession);
ITransaction transaction = ITransaction.CURRENT.get();
assertNotNull(transaction);
m_transactions.add(transaction);
}
Aggregations