Package org.helidb.simple

Source Code of org.helidb.simple.SimpleDatabaseOnConstantRecordSizeHeapBackendTest

/* 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 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.AbstractDatabaseOnConstantRecordSizeBackendTest;
import org.helidb.CRSInsertionOrderBackendDBTester;
import org.helidb.Database;
import org.helidb.backend.DatabaseBackend;
import org.helidb.backend.heapcrs.ConstantRecordSizeHeapBackend;
import org.helidb.impl.simple.SimpleDatabase;
import org.helidb.lang.serializer.CharacterSerializer;
import org.helidb.lang.serializer.IntegerSerializer;
import org.helidb.lang.serializer.LongSerializer;
import org.helidb.test.support.FileSupport;
import org.junit.Test;

public class SimpleDatabaseOnConstantRecordSizeHeapBackendTest extends AbstractDatabaseOnConstantRecordSizeBackendTest
{
  private Map<Integer, File> m_dbFiles = new HashMap<Integer, File>();

  @Override
  protected SimpleDatabase<Integer, Long, Long> createDatabase()
  {
    File f = FileSupport.createTempFile();
    LogAdapterHolder lah = new LogAdapterHolder(new StdOutLogAdapter());
    DatabaseBackend<Integer, Long, Long> b = new ConstantRecordSizeHeapBackend<Integer, Long>(new ReadWritableFileAdapter(f), false, IntegerSerializer.INSTANCE, LongSerializer.INSTANCE, 0L, 8192, lah);
    SimpleDatabase<Integer, Long, Long> res = new SimpleDatabase<Integer, Long, Long>(b, lah);
    m_dbFiles.put(System.identityHashCode(res), f);
    return res;
  }

  @Override
  protected SimpleDatabase<Character, Character, Long> createCharacterDatabase()
  {
    File f = FileSupport.createTempFile();
    LogAdapterHolder lah = new LogAdapterHolder(new StdOutLogAdapter());
    DatabaseBackend<Character, Character, Long> b = new ConstantRecordSizeHeapBackend<Character, Character>(new ReadWritableFileAdapter(f), false, CharacterSerializer.INSTANCE, CharacterSerializer.INSTANCE, 0L, 8192, lah);
    SimpleDatabase<Character, Character, Long> res = new SimpleDatabase<Character, Character, Long>(b, lah);
    m_dbFiles.put(System.identityHashCode(res), f);
    return res;
  }

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

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

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

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

Related Classes of org.helidb.simple.SimpleDatabaseOnConstantRecordSizeHeapBackendTest

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.