/* 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.AbstractDatabaseOnVariableRecordSizeBackendTest;
import org.helidb.Database;
import org.helidb.InsertionOrderBackendDBTester;
import org.helidb.backend.DatabaseBackend;
import org.helidb.backend.heap.HeapBackend;
import org.helidb.impl.simple.SimpleDatabase;
import org.helidb.lang.serializer.StringSerializer;
import org.helidb.test.support.FileSupport;
import org.junit.Test;
public class SimpleDatabaseOnHeapBackendTest extends AbstractDatabaseOnVariableRecordSizeBackendTest
{
private Map<Integer, File> m_dbFiles = new HashMap<Integer, File>();
@Override
protected SimpleDatabase<String, String, Long> createDatabase()
{
File f = FileSupport.createTempFile();
LogAdapterHolder lah = new LogAdapterHolder(new StdOutLogAdapter());
DatabaseBackend<String, String, Long> b = new HeapBackend<String, String>(new ReadWritableFileAdapter(f), false, StringSerializer.INSTANCE, StringSerializer.INSTANCE, lah);
SimpleDatabase<String, String, Long> res = new SimpleDatabase<String, String, 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<String, String> db = createDatabase();
try
{
InsertionOrderBackendDBTester.testCursor(db);
}
finally
{
tearDownDatabase(db);
}
}
@Test
public void testCursorIterator()
{
Database<String, String> db = createDatabase();
try
{
InsertionOrderBackendDBTester.testCursorIterator(db);
}
finally
{
tearDownDatabase(db);
}
}
@Test
public void testCursorBackwardsIterator()
{
Database<String, String> db = createDatabase();
try
{
InsertionOrderBackendDBTester.testCursorBackwardsIterator(db);
}
finally
{
tearDownDatabase(db);
}
}
}