Package java.util.concurrent.atomic

Examples of java.util.concurrent.atomic.AtomicReference


            tt(DBMaker.newMemoryDB().transactionDisable().make().getTreeMap("test"));
        }


        void tt(Bind.MapWithModificationListener m){
            final AtomicReference key = new AtomicReference(null);
            final AtomicReference newVal = new AtomicReference(null);
            final AtomicReference oldVal = new AtomicReference(null);
            final AtomicInteger counter = new AtomicInteger(0);

            Bind.MapListener listener = new Bind.MapListener(){
                @Override public void update(Object key2, Object oldVal2, Object newVal2) {
                    counter.incrementAndGet();
                    key.set(key2);
                    oldVal.set(oldVal2);
                    newVal.set(newVal2);
                }
            };

            m.modificationListenerAdd(listener);

            //check CRUD
            m.put("aa","bb");
            assertTrue(key.get()=="aa" && newVal.get()=="bb" && oldVal.get()==null && counter.get()==1);

            m.put("aa","cc");
            assertTrue(key.get()=="aa" && newVal.get()=="cc" && oldVal.get()=="bb" && counter.get()==2);

            m.remove("aa");
            assertTrue(key.get()=="aa" && newVal.get()==null && oldVal.get()=="cc" && counter.get()==3);

            //check clear()
            m.put("aa","bb");
            assertTrue(key.get()=="aa" && newVal.get()=="bb" && oldVal.get()==null && counter.get()==4);
            m.clear();
            assertTrue(key.get()=="aa" && newVal.get()==null && oldVal.get()=="bb" && counter.get()==5);


            //check it was unregistered
            counter.set(0);
            m.modificationListenerRemove(listener);
View Full Code Here


    @Test
    public void interrupt_raf_file_exception() throws IOException, InterruptedException {
        // when IO thread is interrupted, channel gets closed and it throws  ClosedByInterruptException
        final Volume.FileChannelVol v = new Volume.FileChannelVol(File.createTempFile("mapdb", "mapdb"), false, 0, 0, 0);
        final AtomicReference ref = new AtomicReference();
        Thread t = new Thread() {
            @Override
            public void run() {
                try {
                    long pos = 0;
                    while (true) {
                        v.ensureAvailable(pos++);
                        v.putByte(pos - 1, (byte) 1);
                    }
                }catch(Throwable e){
                    ref.set(e);
                }
            }
        };
        t.start();
        Thread.sleep(100);
        t.interrupt();
        Thread.sleep(100);
        assertEquals(DBException.Code.VOLUME_CLOSED_BY_INTERRUPT, ((DBException)ref.get()).getCode());
        //now channel should be closed
        assertFalse(v.channel.isOpen());
        try {
            v.putLong(0, 1000);
            fail();
View Full Code Here

TOP

Related Classes of java.util.concurrent.atomic.AtomicReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.