Package org.xtreemfs.babudb.index.overlay

Examples of org.xtreemfs.babudb.index.overlay.MultiOverlayBufferTree


        this.maxEntriesPerBlock = maxEntriesPerBlock;
        this.maxBlockFileSize = maxBlockFileSize;
        this.useMMap = useMMap;
        this.mmapLimitBytes = mmapLimit * 1024 * 1024;
       
        overlay = new MultiOverlayBufferTree(NULL_ELEMENT, comp);
        totalOnDiskSize += indexFile == null ? 0 : getTotalDirSize(new File(indexFile));
        index = indexFile == null ? null : new DiskIndex(indexFile, comp, compressed, useMmap());
        lock = new Object();
    }
View Full Code Here


        assertFalse(itExpected.hasNext());
    }
   
    public void testOverlayBufferTree() {
       
        MultiOverlayBufferTree tree = new MultiOverlayBufferTree(new byte[0], DefaultByteRangeComparator
                .getInstance());
       
        // randomly insert 200 elements in a map
        final int numElements = 200;
       
        final SortedMap<String, byte[]> map1 = new TreeMap<String, byte[]>();
        for (int i = 0; i < numElements; i++) {
           
            String keyString = Integer.toHexString(i);
            String valString = Integer.toHexString((int) (Math.random() * Integer.MAX_VALUE));
            byte[] key = keyString.getBytes();
            byte[] val = valString.getBytes();
           
            map1.put(keyString, val);
            tree.insert(key, val);
        }
       
        // look up each key
        for (int i = 0; i < numElements; i++) {
           
            String keyString = Integer.toHexString(i);
            byte[] key = keyString.getBytes();
           
            assertEquals(tree.lookup(key), map1.get(keyString));
        }
       
        // create a new overlay
        int snap1 = tree.newOverlay();
        final SortedMap<String, byte[]> map2 = new TreeMap<String, byte[]>(map1);
       
        // remove every second element
        for (int i = 0; i < numElements; i += 2) {
           
            String keyString = Integer.toHexString(i);
            byte[] key = keyString.getBytes();
           
            tree.insert(key, null);
            map2.remove(keyString);
        }
       
        // look up all elements
        for (int i = 0; i < numElements; i++) {
           
            String keyString = Integer.toHexString(i);
            byte[] key = keyString.getBytes();
           
            byte[] mapVal = map2.get(keyString);
            byte[] val = tree.lookup(key);
            if (mapVal != null)
                assertEquals(mapVal, val);
            else
                assertTrue(val == null || val.length == 0);
        }
       
        // create a new overlay
        int snap2 = tree.newOverlay();
        final SortedMap<String, byte[]> map3 = new TreeMap<String, byte[]>(map2);
       
        // overwrite every 5th element
        for (int i = 0; i < numElements; i += 5) {
           
            String keyString = Integer.toHexString(i);
            byte[] key = keyString.getBytes();
            byte[] val = Integer.toHexString((int) (Math.random() * Integer.MAX_VALUE)).getBytes();
           
            tree.insert(key, val);
            map3.put(keyString, val);
        }
       
        // look up all elements
        for (int i = 0; i < numElements; i++) {
           
            String keyString = Integer.toHexString(i);
            byte[] key = keyString.getBytes();
           
            byte[] mapVal = map3.get(keyString);
            byte[] val = tree.lookup(key);
            if (mapVal != null)
                assertEquals(mapVal, val);
            else
                assertTrue(val == null || val.length == 0);
        }
       
        Iterator<Entry<byte[], byte[]>> it = tree.prefixLookup(null, false, true);
        Iterator<byte[]> itExpected = map3.values().iterator();
        while (it.hasNext())
            assertEquals(itExpected.next(), it.next().getValue());
        assertFalse(itExpected.hasNext());
       
        it = tree.prefixLookup(null, snap1, false, true);
        itExpected = map1.values().iterator();
        while (it.hasNext())
            assertEquals(itExpected.next(), it.next().getValue());
        assertFalse(itExpected.hasNext());
       
        it = tree.prefixLookup(null, snap2, false, true);
        itExpected = map2.values().iterator();
        while (it.hasNext())
            assertEquals(itExpected.next(), it.next().getValue());
        assertFalse(itExpected.hasNext());
       
        it = tree.prefixLookup("3".getBytes(), false, true);
        itExpected = map3.subMap("3", "4").values().iterator();
        while (it.hasNext())
            assertEquals(itExpected.next(), it.next().getValue());
        assertFalse(itExpected.hasNext());
    }
View Full Code Here

TOP

Related Classes of org.xtreemfs.babudb.index.overlay.MultiOverlayBufferTree

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.