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.util.*;
026: import junit.framework.*;
027: import drjava.smyle.*;
028: import drjava.smyle.testtypes.*;
029: import drjava.smyle.core.*;
030:
031: public class Stresstest extends Assert {
032: // immutables currently force frequent flushing
033: static final boolean immutables = false;
034:
035: static class Worker extends Thread {
036: Store store;
037: String tableName;
038:
039: Worker(Store store, String tableName) {
040: this .store = store;
041: this .tableName = tableName;
042: }
043:
044: public void run() {
045: try {
046: while (true) {
047:
048: for (int i = 0; i < 300; i++) {
049: //System.out.println(i);
050:
051: if (immutables)
052: store.snapshot(); // just get and leave open
053:
054: Snapshot snapshot = store.mutableSnapshot();
055: Table<StressRecord> table = snapshot.getTable(
056: tableName, StressRecord.getTypeInfo());
057: if (i == 0)
058: table.clear();
059:
060: for (int key2 = 0; key2 < 100; key2++) {
061: StressRecord r = table
062: .get(new StressRecord_filter()
063: .key1Equals("").key2Equals(
064: key2));
065: if (key2 >= i)
066: assertNull(r);
067: else
068: assertTrue("key2=" + key2 + ", r=" + r,
069: r != null && r.key2 == key2
070: /*&& r.value == (i-1)/100*100+key2*/);
071: }
072:
073: //int key2 = (random.nextInt() & 0x7fffffff) % 100;
074: int key2 = i % 100;
075: StressRecord_filter filter = new StressRecord_filter()
076: .key1Equals("").key2Equals(key2);
077: int idx = table.indexOf(filter);
078: if (idx >= 0) {
079: //System.out.println("update "+key2+" to "+i);
080: table.set(idx, table.get(idx).value(i));
081: } else {
082: //System.out.println("add "+key2+"/"+i);
083: table.add(new StressRecord().key1("").key2(
084: key2).value(i));
085: }
086:
087: /*PersistentBTree index = ((TableImpl<StressRecord>) table).getIndex();
088: if (index != null)
089: BTreeTestBase.printTree(index);*/
090:
091: snapshot.commit();
092: }
093: System.out.println(tableName + ": cycle complete");
094: }
095: } catch (Throwable e) {
096: e.printStackTrace();
097: System.exit(1);
098: }
099: }
100: }
101:
102: public static void main(String[] args) throws Exception {
103: Store store = Smyle.createEmptyStore("temp/stress");
104: //((drjava.smyle.core.DiskStore) store).enableIndexing();
105: //store.setWriteLatency(200);
106: DiskStore.showGC = false;
107: DefaultChunkManager.verbose = false;
108:
109: Random random = new Random(0);
110:
111: for (int i = 1; i <= 5; i++) {
112: new Worker(store, "table" + i).start();
113: }
114:
115: //store.close();
116: }
117: }
|