Package org.helidb.impl.txn.sc

Source Code of org.helidb.impl.txn.sc.ScTxnDbOnConstantRecordSizeHeapBackendTest

/* 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.impl.txn.sc;

import java.util.HashMap;
import java.util.Map;

import org.entityfs.Directory;
import org.entityfs.EFile;
import org.entityfs.Entity;
import org.entityfs.support.log.LogAdapterHolder;
import org.entityfs.support.log.StdOutLogAdapter;
import org.entityfs.util.Directories;
import org.helidb.CRSInsertionOrderBackendDBTester;
import org.helidb.Database;
import org.helidb.backend.heapcrs.ConstantRecordSizeHeapBackendFactory;
import org.helidb.lang.serializer.CharacterSerializer;
import org.helidb.lang.serializer.IntegerSerializer;
import org.helidb.lang.serializer.LongSerializer;
import org.helidb.txn.TransactionalDatabase;
import org.junit.Test;

public class ScTxnDbOnConstantRecordSizeHeapBackendTest extends AbstractScTxnDbOnConstantRecordSizeBackendTest<Long>
{
  private final Map<Database<?, ?>, Entity[]> m_dbFiles = new HashMap<Database<?, ?>, Entity[]>();

  private ShadowCopyTransactionalDatabase<Integer, Long, Long> createDatabaseUsingFile(Directory dir, EFile f)
  {
    LogAdapterHolder lah = new LogAdapterHolder(new StdOutLogAdapter());
    ShadowCopyTransactionalDatabase<Integer, Long, Long> res = new ShadowCopyTransactionalDatabase<Integer, Long, Long>(new SingleFileManager(f, dir), new ConstantRecordSizeHeapBackendFactory<Integer, Long>(IntegerSerializer.INSTANCE, LongSerializer.INSTANCE, 0, 8192, lah), false, lah);
    m_dbFiles.put(res, new Entity[] { dir, f });
    return res;
  }

  @Override
  public ShadowCopyTransactionalDatabase<Integer, Long, Long> createDatabaseWoTxnInDirectory(Directory dir)
  {
    EFile f = Directories.newFile(dir, "db");
    return createDatabaseUsingFile(dir, f);
  }

  @Override
  public ShadowCopyTransactionalDatabase<Integer, Long, Long> createNewDatabaseUsingSameFiles(TransactionalDatabase<Integer, Long> otherDb)
  {
    Entity[] ents = m_dbFiles.get(otherDb);
    return createDatabaseUsingFile((Directory) ents[0], (EFile) ents[1]);
  }

  private ShadowCopyTransactionalDatabase<Character, Character, Long> createCharacterDatabaseUsingFile(Directory dir, EFile f)
  {
    LogAdapterHolder lah = new LogAdapterHolder(new StdOutLogAdapter());
    ShadowCopyTransactionalDatabase<Character, Character, Long> res = new ShadowCopyTransactionalDatabase<Character, Character, Long>(new SingleFileManager(f, dir), new ConstantRecordSizeHeapBackendFactory<Character, Character>(CharacterSerializer.INSTANCE, CharacterSerializer.INSTANCE, 0, 8192, lah), false, lah);
    m_dbFiles.put(res, new Entity[] { dir, f });
    return res;
  }

  @Override
  protected TransactionalDatabase<Character, Character> createCharacterDatabaseWoTxnInDirectory(Directory dir)
  {
    EFile f = Directories.newFile(dir, "db");
    return createCharacterDatabaseUsingFile(dir, f);
  }

  @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.impl.txn.sc.ScTxnDbOnConstantRecordSizeHeapBackendTest

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.