001: /*
002: This source file is part of Smyle, a database library.
003: For up-to-date information, see http://www.drjava.de/smyle
004: Copyright (C) 2001 Stefan Reich (doc@drjava.de)
005:
006: This library is free software; you can redistribute it and/or
007: modify it under the terms of the GNU Lesser General Public
008: License as published by the Free Software Foundation; either
009: version 2.1 of the License, or (at your option) any later version.
010:
011: This library is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public
017: License along with this library; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019:
020: For full license text, see doc/license/lgpl.txt in this distribution
021: */
022:
023: package drjava.smyle.tests;
024:
025: import java.io.*;
026: import java.util.*;
027: import java.lang.reflect.*;
028: import junit.framework.*;
029: import drjava.smyle.*;
030: import drjava.smyle.testtypes.*;
031: import drjava.smyle.core.*;
032: import org.artsProject.mcop.*;
033: import drjava.util.*;
034:
035: public class DiskStoreTestBase extends XTestCase {
036: public DiskStoreTestBase(String name) {
037: super (name);
038: }
039:
040: Person john = new Person("John", 23),
041: anne = new Person("Anne", 21),
042: jane = new Person("Jane", 23), maria = new Person("Maria",
043: 45);
044:
045: MemoryDisk disk;
046: DiskStore store;
047: Snapshot snapshot;
048: Table<Person> table;
049: long bytes1, bytes2;
050:
051: public void setUp() throws Exception {
052: disk = new MemoryDisk();
053: createStore();
054: }
055:
056: public void tearDown() throws Exception {
057: if (store != null)
058: store.kill();
059: }
060:
061: void getNewSnapshot() throws Exception {
062: snapshot = store.mutableSnapshot();
063: table = snapshot.getTable("person", Person.getTypeInfo());
064: }
065:
066: void getImmutableSnapshot() throws Exception {
067: snapshot = store.snapshot();
068: table = snapshot.getTable("person", Person.getTypeInfo());
069: }
070:
071: void commitAndGetNewSnapshot() throws Exception {
072: snapshot.commit();
073: getNewSnapshot();
074: }
075:
076: void createStore() throws Exception {
077: if (store != null)
078: store.kill();
079: store = new DiskStore(disk);
080: store.setTimeout(5000);
081: getNewSnapshot();
082: }
083:
084: void rotate() throws Exception {
085: if (store != null)
086: store.close();
087: createStore();
088: }
089:
090: void addPersons(Table table) throws Exception {
091: for (int i = 1; i <= 5; i++)
092: table.add(new Person("someone", i));
093: }
094:
095: void addMorePersons(Table table) throws Exception {
096: for (int i = 6; i <= 10; i++)
097: table.add(new Person("someone", i));
098: }
099:
100: void removePersons(Table table) throws Exception {
101: for (int i = 1; i <= 5; i++)
102: table.remove(new Person("someone", i));
103: }
104:
105: void removeMorePersons(Table table) throws Exception {
106: for (int i = 6; i <= 10; i++)
107: table.remove(new Person("someone", i));
108: }
109:
110: void assertPersons(Table table) throws Exception {
111: assertEquals(5, table.size());
112: for (int i = 1; i <= 5; i++)
113: assertEquals(table.get(i - 1), new Person("someone", i));
114: }
115: }
|