Package org.helidb.simple

Source Code of org.helidb.simple.SimpleDatabaseOnHeapBackendWithBPlusTreeIndexTest

/* HeliDB -- A simple database for Java, http://www.helidb.org
* Copyright (C) 2008, 2009 Karl Gustafsson
*
* This file is a part of HeliDB.
*
* HeliDB is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeliDB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package org.helidb.simple;

import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.entityfs.support.log.LogAdapterHolder;
import org.entityfs.support.log.StdOutLogAdapter;
import org.entityfs.util.io.ReadWritableFileAdapter;
import org.helidb.AbstractDatabaseOnVariableRecordSizeBackendTest;
import org.helidb.Database;
import org.helidb.UnknownOrderBackendDBTester;
import org.helidb.backend.DatabaseBackend;
import org.helidb.backend.heap.HeapBackend;
import org.helidb.backend.index.bplus.BPlusTreeIndexBackend;
import org.helidb.impl.simple.SimpleDatabase;
import org.helidb.lang.hasher.StringToLongHasher;
import org.helidb.lang.serializer.LongNullSerializer;
import org.helidb.lang.serializer.LongSerializer;
import org.helidb.lang.serializer.StringSerializer;
import org.helidb.test.support.FileSupport;
import org.helidb.util.bplus.BPlusTree;
import org.helidb.util.bplus.FileBackedNodeRepository;
import org.helidb.util.bplus.LruCacheNodeRepository;
import org.helidb.util.bplus.NumberOfRecordsNodeSizeStrategy;
import org.junit.Test;

public class SimpleDatabaseOnHeapBackendWithBPlusTreeIndexTest extends AbstractDatabaseOnVariableRecordSizeBackendTest
{
  private Map<Integer, File[]> m_dbFiles = new HashMap<Integer, File[]>();

  @Override
  protected SimpleDatabase<String, String, Long> createDatabase()
  {
    File f = FileSupport.createTempFile();
    File indf = FileSupport.createTempFile();
    LogAdapterHolder lah = new LogAdapterHolder(new StdOutLogAdapter());
    BPlusTree<Long, Long> btr = new BPlusTree<Long, Long>(new LruCacheNodeRepository<Long, Long>(new FileBackedNodeRepository<Long, Long>(new ReadWritableFileAdapter(indf), false, 0, new NumberOfRecordsNodeSizeStrategy(3), true, LongNullSerializer.INSTANCE, LongSerializer.INSTANCE, 4, 8192, null, lah), 10), lah);
    DatabaseBackend<String, String, Long> b = new BPlusTreeIndexBackend<String, String, Long, Long>(new HeapBackend<String, String>(new ReadWritableFileAdapter(f), false, StringSerializer.INSTANCE, StringSerializer.INSTANCE, lah), false, btr, new StringToLongHasher(), lah);
    SimpleDatabase<String, String, Long> res = new SimpleDatabase<String, String, Long>(b, lah);
    m_dbFiles.put(System.identityHashCode(res), new File[] { f, indf });
    return res;
  }

  @Override
  protected void tearDownDatabase(Database<?, ?> db)
  {
    db.close();
    for (File f : m_dbFiles.get(System.identityHashCode(db)))
    {
      assertTrue(f.delete());
    }
  }

  @Test
  public void testCursor()
  {
    Database<String, String> db = createDatabase();
    try
    {
      UnknownOrderBackendDBTester.testCursor(db);
    }
    finally
    {
      tearDownDatabase(db);
    }
  }

  @Test
  public void testCursorIterator()
  {
    Database<String, String> db = createDatabase();
    try
    {
      UnknownOrderBackendDBTester.testCursorIterator(db);
    }
    finally
    {
      tearDownDatabase(db);
    }
  }

  @Test
  public void testCursorBackwardsIterator()
  {
    Database<String, String> db = createDatabase();
    try
    {
      UnknownOrderBackendDBTester.testCursorBackwardsIterator(db);
    }
    finally
    {
      tearDownDatabase(db);
    }
  }
}
TOP

Related Classes of org.helidb.simple.SimpleDatabaseOnHeapBackendWithBPlusTreeIndexTest

TOP
Copyright © 2018 www.massapi.com. 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.