Package org.xtreemfs.babudb.api.database

Examples of org.xtreemfs.babudb.api.database.Database


    public void testLargeIndexWithConcurrentCheckpoint() throws Exception {
       
        database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 0, 1000, 0,
            SyncMode.ASYNC, 0, 0, compression, maxNumRecs, maxBlockFileSize, true, 1000, 7));
       
        Database db = database.getDatabaseManager().createDatabase("test", 1);
       
        final long entryCount = 50000;
       
        Thread cpThread = new Thread() {
            public void run() {
                try {
                    for (int i = 0; i < 2; i++) {
                        database.getCheckpointer().checkpoint();
                        sleep(1000);
                    }
                } catch (BabuDBException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
       
        for (long i = 0; i < entryCount; i++) {
           
            ByteBuffer keyBuf = ByteBuffer.wrap(new byte[8]);
            keyBuf.putLong(0, i);
           
            ByteBuffer valBuf = ByteBuffer.wrap(new byte[32]);
            valBuf.putLong(0, i);
            valBuf.putLong(24, i);
           
            if (i == 10) {
                cpThread.start();
                Thread.sleep(2);
            }
           
            db.singleInsert(0, keyBuf.array(), valBuf.array(), null).get();
        }
       
        ByteBuffer keyBuf = ByteBuffer.wrap(new byte[8]);
        ByteBuffer valBuf = ByteBuffer.wrap(new byte[32]);
        for (long i = 0; i < entryCount; i++) {
           
            keyBuf.putLong(0, i);
            valBuf.putLong(0, i);
            valBuf.putLong(24, i);
           
            byte[] val = db.lookup(0, keyBuf.array(), null).get();
            assertEquals(valBuf.array(), val);
        }
       
        Iterator<Entry<byte[], byte[]>> it = db.prefixLookup(0, new byte[0], null).get();
        for (long i = 0; i < entryCount; i++) {
           
            Entry<byte[], byte[]> next = it.next();
           
            byte[] key = next.getKey();
View Full Code Here


   
    @Test
    public void testReplayAfterCrash() throws Exception {
        database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 1, 0, 0,
            SyncMode.SYNC_WRITE, 0, 0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, LOG_LEVEL));
        Database db = database.getDatabaseManager().createDatabase("test", 2);
        db.singleInsert(0, "Yagga".getBytes(), "Brabbel".getBytes(), null).get();
        database.getCheckpointer().checkpoint();
        byte[] result = db.lookup(0, "Yagga".getBytes(), null).get();
        String value = new String(result);
        assertEquals(value, "Brabbel");
       
        db.singleInsert(0, "Brabbel".getBytes(), "Blupp".getBytes(), null).get();
        result = db.lookup(0, "Brabbel".getBytes(), null).get();
        value = new String(result);
        assertEquals(value, "Blupp");
       
        db.singleInsert(0, "Blupp".getBytes(), "Blahh".getBytes(), null).get();
        result = db.lookup(0, "Blupp".getBytes(), null).get();
        value = new String(result);
        assertEquals(value, "Blahh");
       
        ((BabuDBImpl) database).__test_killDB_dangerous();
        Thread.sleep(500);
       
        database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 2, 0, 0,
            SyncMode.SYNC_WRITE, 0, 0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, LOG_LEVEL));
        db = database.getDatabaseManager().getDatabase("test");
        result = db.lookup(0, "Yagga".getBytes(), null).get();
        assertNotNull(result);
        value = new String(result);
        assertEquals(value, "Brabbel");
       
        result = db.lookup(0, "Brabbel".getBytes(), null).get();
        assertNotNull(result);
        value = new String(result);
        assertEquals(value, "Blupp");
       
        result = db.lookup(0, "Blupp".getBytes(), null).get();
        assertNotNull(result);
        value = new String(result);
        assertEquals(value, "Blahh");
       
        System.out.println("shutting down database...");
View Full Code Here

   
    @Test
    public void testShutdownAfterCheckpoint() throws Exception {
        database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 1, 0, 0,
            SyncMode.SYNC_WRITE, 0, 0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, LOG_LEVEL));
        Database db = database.getDatabaseManager().createDatabase("test", 2);
        db.singleInsert(0, "Yagga".getBytes(), "Brabbel".getBytes(), null).get();
       
        byte[] result = db.lookup(0, "Yagga".getBytes(), null).get();
        String value = new String(result);
        assertEquals(value, "Brabbel");
       
        db.singleInsert(0, "Brabbel".getBytes(), "Blupp".getBytes(), null).get();
        result = db.lookup(0, "Brabbel".getBytes(), null).get();
        value = new String(result);
        assertEquals(value, "Blupp");
       
        db.singleInsert(0, "Blupp".getBytes(), "Blahh".getBytes(), null).get();
        result = db.lookup(0, "Blupp".getBytes(), null).get();
        value = new String(result);
        assertEquals(value, "Blahh");
       
        database.getCheckpointer().checkpoint();
        database.shutdown();
       
        database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 2, 0, 0,
            SyncMode.SYNC_WRITE, 0, 0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, LOG_LEVEL));
        db = database.getDatabaseManager().getDatabase("test");
        result = db.lookup(0, "Yagga".getBytes(), null).get();
        assertNotNull(result);
        value = new String(result);
        assertEquals(value, "Brabbel");
       
        result = db.lookup(0, "Brabbel".getBytes(), null).get();
        assertNotNull(result);
        value = new String(result);
        assertEquals(value, "Blupp");
       
        result = db.lookup(0, "Blupp".getBytes(), null).get();
        assertNotNull(result);
        value = new String(result);
        assertEquals(value, "Blahh");
       
        System.out.println("shutting down database...");
View Full Code Here

   
    @Test
    public void testMultipleIndices() throws Exception {
        database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 1, 0, 0,
            SyncMode.SYNC_WRITE, 0, 0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, LOG_LEVEL));
        Database db = database.getDatabaseManager().createDatabase("test", 3);
       
        DatabaseInsertGroup ir = db.createInsertGroup();
        ir.addInsert(0, "Key1".getBytes(), "Value1".getBytes());
        ir.addInsert(1, "Key2".getBytes(), "Value2".getBytes());
        ir.addInsert(2, "Key3".getBytes(), "Value3".getBytes());
        db.insert(ir, null).get();
       
        database.getCheckpointer().checkpoint();
        database.shutdown();
       
        database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 2, 0, 0,
            SyncMode.SYNC_WRITE, 0, 0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, LOG_LEVEL));
        db = database.getDatabaseManager().getDatabase("test");
       
        byte[] result = db.lookup(0, "Key1".getBytes(), null).get();
        assertNotNull(result);
        String value = new String(result);
        assertEquals(value, "Value1");
       
        result = db.lookup(1, "Key2".getBytes(), null).get();
        assertNotNull(result);
        value = new String(result);
        assertEquals(value, "Value2");
       
        result = db.lookup(2, "Key3".getBytes(), null).get();
        assertNotNull(result);
        value = new String(result);
        assertEquals(value, "Value3");
       
        System.out.println("shutting down database...");
View Full Code Here

   
    @Test
    public void testMultipleIndicesAndCheckpoint() throws Exception {
        database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 1, 0, 0,
            SyncMode.SYNC_WRITE, 0, 0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, LOG_LEVEL));
        Database db = database.getDatabaseManager().createDatabase("test", 4);
       
        DatabaseInsertGroup ir = db.createInsertGroup();
        ir.addInsert(0, "Key1".getBytes(), "Value1".getBytes());
        ir.addInsert(1, "Key2".getBytes(), "Value2".getBytes());
        ir.addInsert(2, "Key3".getBytes(), "Value3".getBytes());
        db.insert(ir, null).get();
       
        database.getCheckpointer().checkpoint();
       
        byte[] result = db.lookup(0, "Key1".getBytes(), null).get();
        assertNotNull(result);
        String value = new String(result);
        assertEquals(value, "Value1");
       
        result = db.lookup(1, "Key2".getBytes(), null).get();
        assertEquals("Value2", new String(result));
       
        result = db.lookup(2, "Key3".getBytes(), null).get();
        assertEquals("Value3", new String(result));
       
        Iterator<Entry<byte[], byte[]>> iter = db.prefixLookup(3, "Key3".getBytes(), null).get();
        assertFalse(iter.hasNext());
       
        ir = db.createInsertGroup();
        ir.addDelete(0, "Key1".getBytes());
        ir.addInsert(1, "Key2".getBytes(), "Value2.2".getBytes());
        ir.addInsert(2, "Key3".getBytes(), "Value2.3".getBytes());
        db.insert(ir, null).get();
        database.getCheckpointer().checkpoint();
       
        iter = db.prefixLookup(2, "Key3".getBytes(), null).get();
        assertTrue(iter.hasNext());
        Entry<byte[], byte[]> next = iter.next();
        assertEquals("Key3", new String(next.getKey()));
        assertEquals("Value2.3", new String(next.getValue()));
        assertTrue(!iter.hasNext());
View Full Code Here

    @Test
    public void testUserDefinedLookup() throws Exception {
       
        database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 1, 0, 0,
            SyncMode.SYNC_WRITE, 0, 0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, LOG_LEVEL));
        Database db = database.getDatabaseManager().createDatabase("test", 3);
       
        DatabaseInsertGroup ir = db.createInsertGroup();
        ir.addInsert(0, "Key1".getBytes(), "Value1".getBytes());
        ir.addInsert(1, "Key2".getBytes(), "Value2".getBytes());
        ir.addInsert(2, "Key3".getBytes(), "Value3".getBytes());
        db.insert(ir, null).get();
       
        UserDefinedLookup lookup = new UserDefinedLookup() {
           
            public Object execute(LSMLookupInterface database) throws BabuDBException {
                if ((database.lookup(0, "Key1".getBytes()) != null)
                    && (database.lookup(1, "Key2".getBytes()) != null)) {
                    return new Boolean(true);
                } else {
                    return new Boolean(false);
                }
            }
        };
       
        Boolean result = (Boolean) db.userDefinedLookup(lookup, null).get();
        assertTrue(result);
       
        System.out.println("shutting down database...");
       
        database.shutdown();
View Full Code Here

       
        Logging.logMessage(Logging.LEVEL_DEBUG, Category.test, this, BufferPool.getStatus());
       
        database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 0, 0, 0, SyncMode.ASYNC, 0,
            50, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, LOG_LEVEL));
        Database db = database.getDatabaseManager().createDatabase("test", 2);
       
        for (int i = 0; i < 100000; i++) {
            DatabaseInsertGroup ir = db.createInsertGroup();
            ir.addInsert(0, (i + "").getBytes(), "bla".getBytes());
            ir.addInsert(1, (i + "").getBytes(), "bla".getBytes());
            db.insert(ir, null).get();
        }
       
        Logging.logMessage(Logging.LEVEL_DEBUG, Category.test, this, BufferPool.getStatus());
       
        database.getCheckpointer().checkpoint();
       
        for (int i = 0; i < 100000; i++) {
           
            byte[] v0 = db.lookup(0, (i + "").getBytes(), null).get();
            byte[] v1 = db.lookup(1, (i + "").getBytes(), null).get();
           
            assertEquals("bla", new String(v0));
            assertEquals("bla", new String(v1));
        }
       
View Full Code Here

    @Test
    public void testInsDelGet() throws Exception {
       
        database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 0, 0, 0, SyncMode.ASYNC, 0,
            0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, LOG_LEVEL));
        Database db = database.getDatabaseManager().createDatabase("test", 3);
       
        for (int i = 0; i < 1000; i++) {
            DatabaseInsertGroup ir = db.createInsertGroup();
            ir.addInsert(0, (i + "").getBytes(), "bla".getBytes());
            ir.addInsert(1, (i + "").getBytes(), "bla".getBytes());
            ir.addInsert(2, (i + "").getBytes(), "bla".getBytes());
            db.insert(ir, null).get();
        }
       
        byte[] data = new byte[2048];
        for (int i = 0; i < 1000; i++) {
            DatabaseInsertGroup ir = db.createInsertGroup();
            ir.addInsert(0, (i + "").getBytes(), data);
            ir.addInsert(1, (i + "").getBytes(), data);
            ir.addInsert(2, (i + "").getBytes(), data);
            db.insert(ir, null).get();
        }
       
        database.getCheckpointer().checkpoint();
       
        for (int i = 0; i < 1000; i++) {
           
            byte[] v0 = db.lookup(0, (i + "").getBytes(), null).get();
            byte[] v1 = db.lookup(1, (i + "").getBytes(), null).get();
            byte[] v2 = db.lookup(2, (i + "").getBytes(), null).get();
           
            assertNotNull(v0);
            assertNotNull(v1);
            assertNotNull(v2);
        }
       
        for (int i = 0; i < 1000; i++) {
            DatabaseInsertGroup ir = db.createInsertGroup();
            ir.addDelete(0, (i + "").getBytes());
            ir.addDelete(1, (i + "").getBytes());
            ir.addDelete(2, (i + "").getBytes());
            db.insert(ir, null).get();
        }
       
        for (int i = 0; i < 1000; i++) {
           
            byte[] v0 = db.lookup(0, (i + "").getBytes(), null).get();
            byte[] v1 = db.lookup(1, (i + "").getBytes(), null).get();
            byte[] v2 = db.lookup(2, (i + "").getBytes(), null).get();
           
            assertNull(v0);
            assertNull(v1);
            assertNull(v2);
        }
View Full Code Here

    @Test
    public void testInsPrefLookup() throws Exception {
       
        database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 0, 0, 0, SyncMode.ASYNC, 0,
            0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, LOG_LEVEL));
        Database db = database.getDatabaseManager().createDatabase("test", 3);
       
        for (int i = 1000; i < 2000; i++) {
            DatabaseInsertGroup ir = db.createInsertGroup();
            ir.addInsert(0, (i + "").getBytes(), (i + "").getBytes());
            ir.addInsert(1, (i + "").getBytes(), (i + "").getBytes());
            ir.addInsert(2, (i + "").getBytes(), (i + "").getBytes());
            db.insert(ir, null);
        }
       
        Iterator<Entry<byte[], byte[]>> it = db.prefixLookup(0, new byte[0], null).get();
        for (int i = 1000; i < 2000; i++)
            assertEquals(i + "", new String(it.next().getValue()));
        assertFalse(it.hasNext());
       
        it = db.prefixLookup(0, "15".getBytes(), null).get();
        for (int i = 1500; i < 1600; i++)
            assertEquals(i + "", new String(it.next().getValue()));
        assertFalse(it.hasNext());
       
        database.getCheckpointer().checkpoint();
       
        it = db.prefixLookup(0, "15".getBytes(), null).get();
        for (int i = 1500; i < 1600; i++)
            assertEquals(i + "", new String(it.next().getValue()));
        assertFalse(it.hasNext());
       
        database.shutdown();
View Full Code Here

    @Test
    public void testInsRangeLookup() throws Exception {
       
        database = BabuDBFactory.createBabuDB(new BabuDBConfig(baseDir, baseDir, 0, 0, 0, SyncMode.ASYNC, 0,
            0, COMPRESSION, maxNumRecs, maxBlockFileSize, !MMAP, -1, LOG_LEVEL));
        Database db = database.getDatabaseManager().createDatabase("test", 3);
       
        for (int i = 1000; i < 2000; i++) {
            DatabaseInsertGroup ir = db.createInsertGroup();
            ir.addInsert(0, (i + "").getBytes(), (i + "").getBytes());
            ir.addInsert(1, (i + "").getBytes(), (i + "").getBytes());
            ir.addInsert(2, (i + "").getBytes(), (i + "").getBytes());
            db.insert(ir, null);
        }
       
        Iterator<Entry<byte[], byte[]>> it = db.rangeLookup(0, new byte[0], new byte[0], null).get();
        for (int i = 1000; i < 2000; i++)
            assertEquals(i + "", new String(it.next().getValue()));
        assertFalse(it.hasNext());
       
        it = db.rangeLookup(0, "1500".getBytes(), "1600".getBytes(), null).get();
        for (int i = 1500; i < 1600; i++)
            assertEquals(i + "", new String(it.next().getValue()));
        assertFalse(it.hasNext());
       
        database.getCheckpointer().checkpoint();
       
        it = db.rangeLookup(0, "1500".getBytes(), "1600".getBytes(), null).get();
        for (int i = 1500; i < 1600; i++)
            assertEquals(i + "", new String(it.next().getValue()));
        assertFalse(it.hasNext());
       
        database.shutdown();
View Full Code Here

TOP

Related Classes of org.xtreemfs.babudb.api.database.Database

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.