Package org.helidb.impl.txn.log

Source Code of org.helidb.impl.txn.log.LoggingTxnDbOnMapBackendTest

/* 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.log;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;

import org.entityfs.Directory;
import org.entityfs.EFile;
import org.entityfs.support.log.LogAdapterHolder;
import org.entityfs.support.log.StdOutLogAdapter;
import org.entityfs.util.Directories;
import org.helidb.Database;
import org.helidb.UnknownOrderBackendDBTester;
import org.helidb.backend.impl.map.MapBackend;
import org.helidb.lang.serializer.StringNullSerializer;
import org.helidb.lang.serializer.StringSerializer;
import org.helidb.txn.TransactionalDatabase;
import org.junit.Test;

public class LoggingTxnDbOnMapBackendTest extends AbstractLoggingTxnDbTest<String>
{
  private final Map<Database<?, ?>, Object[]> m_dbFiles = new HashMap<Database<?, ?>, Object[]>();

  private LoggingTransactionalDatabase<String, String, String> createDbUsingFiles(Map<String, String> m, EFile logf)
  {
    LogAdapterHolder lah = new LogAdapterHolder(new StdOutLogAdapter());
    lah.setLevel(Level.SEVERE);
    MapBackend<String, String> backend = new MapBackend<String, String>(m, StringNullSerializer.INSTANCE, StringSerializer.INSTANCE, lah);
    LoggingTransactionalDatabase<String, String, String> res = new LoggingTransactionalDatabase<String, String, String>(backend, logf, StringNullSerializer.INSTANCE, StringSerializer.INSTANCE, lah);
    m_dbFiles.put(res, new Object[] { m, logf });
    return res;
  }

  @Override
  protected LoggingTransactionalDatabase<String, String, String> createDatabaseWoTxnInDirectory(Directory dir)
  {
    EFile logf = Directories.newFile(dir, "log");
    return createDbUsingFiles(new HashMap<String, String>(), logf);
  }

  @Override
  @SuppressWarnings("unchecked")
  protected LoggingTransactionalDatabase<String, String, String> createNewDatabaseUsingSameFiles(TransactionalDatabase<String, String> otherDb)
  {
    Object[] objs = m_dbFiles.get(otherDb);
    return createDbUsingFiles(new HashMap<String, String>((Map<String, String>) objs[0]), (EFile) objs[1]);
  }

  @Override
  @SuppressWarnings("unchecked")
  protected LoggingTransactionalDatabase<String, String, String> createNewDatabaseUsingSameFilesButTruncateRollbackLog(TransactionalDatabase<String, String> otherDb, int howMuchToTruncate)
  {
    Object[] objs = m_dbFiles.get(otherDb);
    return createDbUsingFiles(new HashMap<String, String>((Map<String, String>) objs[0]), truncate((EFile) objs[1], howMuchToTruncate));
  }

  @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.impl.txn.log.LoggingTxnDbOnMapBackendTest

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.