Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.mapdb;
  
  import org.junit.Test;
  
  import java.io.File;
  import java.io.IOError;
  import java.util.Map;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 public class Issue254Test {
 
     @Test
     public void test(){
         File f = UtilsTest.tempDbFile();
         DB db = DBMaker.newFileDB(f)
                 .transactionDisable()
                 .make();
 
         db.getAtomicLong("long").set(1L);
         db.close();
 
         db = DBMaker.newFileDB(f)
                 .transactionDisable()
                 .readOnly()
                 .closeOnJvmShutdown()
                 .make();
 
         assertEquals(0L, db.getAtomicLong("non-existing long").get());
 
         db.close();
     }
 
 
     DB ro;
 
     {
         File f = UtilsTest.tempDbFile();
          = DBMaker.newFileDB(f).transactionDisable().transactionDisable().make();
          = DBMaker.newFileDB(f).transactionDisable().transactionDisable().readOnly().make();
     }
 
     @Test
     public void atomic_long(){
         Atomic.Long l = .getAtomicLong("non-existing");
         assertEquals(0L, l.get());
         try{
             l.set(1);
             fail();
         }catch(UnsupportedOperationException e){
             assertEquals("Read-only",e.getMessage());
         }
     }
 
     @Test
     public void atomic_int(){
         Atomic.Integer l = .getAtomicInteger("non-existing");
         assertEquals(0, l.get());
         try{
             l.set(1);
             fail();
         }catch(UnsupportedOperationException e){
             assertEquals("Read-only",e.getMessage());
         }
     }
 
     @Test
     public void atomic_boolean(){
         Atomic.Boolean l = .getAtomicBoolean("non-existing");
         assertEquals(falsel.get());
         try{
             l.set(true);
             fail();
         }catch(UnsupportedOperationException e){
             assertEquals("Read-only",e.getMessage());
         }
     }
 
     @Test
     public void atomic_string(){
         Atomic.String l = .getAtomicString("non-existing");
         assertEquals(""l.get());
         try{
             l.set("a");
             fail();
         }catch(UnsupportedOperationException e){
             assertEquals("Read-only",e.getMessage());
         }
     }
 
     @Test
     public void atomic_var(){
         Atomic.Var l = .getAtomicVar("non-existing");
         assertEquals(nulll.get());
         try{
            l.set("a");
            fail();
        }catch(UnsupportedOperationException e){
            assertEquals("Read-only",e.getMessage());
        }
    }
    @Test
    public void atomic_queue(){
        Collection l = .getQueue("non-existing");
        assertTrue(l.isEmpty());
        try{
            l.add("a");
            fail();
        }catch(UnsupportedOperationException e){
            assertEquals("Read-only",e.getMessage());
        }
    }
    @Test
    public void atomic_stack(){
        Collection l = .getStack("non-existing");
        assertTrue(l.isEmpty());
        try{
            l.add("a");
            fail();
        }catch(UnsupportedOperationException e){
            assertEquals("Read-only",e.getMessage());
        }
    }
    @Test
    public void atomic_circular_queue(){
        Collection l = .getCircularQueue("non-existing");
        assertTrue(l.isEmpty());
        try{
            l.add("a");
            fail();
        }catch(UnsupportedOperationException e){
            assertEquals("Read-only",e.getMessage());
        }
    }
    @Test
    public void atomic_tree_set(){
        Collection l = .getTreeSet("non-existing");
        assertTrue(l.isEmpty());
        try{
            l.add("a");
            fail();
        }catch(UnsupportedOperationException e){
            assertEquals("Read-only",e.getMessage());
        }
    }
    @Test
    public void atomic_hash_set(){
        Collection l = .getHashSet("non-existing");
        assertTrue(l.isEmpty());
        try{
            l.add("a");
            fail();
        }catch(UnsupportedOperationException e){
            assertEquals("Read-only",e.getMessage());
        }
    }
    @Test
    public void atomic_tree_map(){
        Map l = .getTreeMap("non-existing");
        assertTrue(l.isEmpty());
        try{
            l.put("a""a");
            fail();
        }catch(UnsupportedOperationException e){
            assertEquals("Read-only",e.getMessage());
        }
    }
    @Test
    public void atomic_hash_map(){
        Map l = .getHashMap("non-existing");
        assertTrue(l.isEmpty());
        try{
            l.put("a","a");
            fail();
        }catch(UnsupportedOperationException e){
            assertEquals("Read-only",e.getMessage());
        }
    }
New to GrepCode? Check out our FAQ X