Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.mapdb;
 
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
 public class TxMakerTest{
 
    TxMaker tx = DBMaker.newMemoryDB().makeTxMaker();
    @Test public void simple_commit(){
        DB db =.makeTx();
        db.getHashMap("test").put("aa""bb");
        db.commit();
        assertEquals("bb".makeTx().getHashMap("test").get("aa"));
    }
    @Test public void simple_rollback(){
        DB db =.makeTx();
        db.getHashMap("test").put("aa""bb");
        db.rollback();
        assertEquals(null.makeTx().getHashMap("test").get("aa"));
    }
    @Test public void commit_conflict(){
        DB db0 = .makeTx();
        long recid = db0.getEngine().put(111, .);
        db0.commit();
        DB db1 = .makeTx();
        db1.getEngine().update(recid, 222, .);
        try{
            .makeTx().getEngine().update(recid, 333, .);
            fail("should throw exception");
        }catch(TxRollbackException e){
            //expected
        }
        //original transaction should complete well
        db1.commit();
        assertEquals(Integer.valueOf(222), .makeTx().getEngine().get(recid.));
    }
New to GrepCode? Check out our FAQ X