*/
public void testBasics() throws Exception {
RecordManager recman;
recman = RecordManagerFactory.createRecordManager( TestRecordFile.testFileName );
// as this code is meant to test data structure calculcations
// and stuff like that, we may want to disable transactions
// that just slow us down.
// mgr.disableTransactions();
RecordData[] d = new RecordData[RECORDS];
int recordCount = 0, rootCount = 0;
int inserts = 0, updates = 0, deletes = 0, fetches = 0;
int rootgets = 0, rootsets = 0;
int slot = -1;
try {
for (int i = 0; i < ROUNDS; i++) {
if ((i % RPPROMILLE) == 0)
System.out.print("\rComplete: "
+ i/RPPROMILLE + "/1000th");
// close and re-open a couple of times during the
// test, in order to check flushing etcetera.
if ((i % (ROUNDS / 5)) == 0) {
System.out.print(" (reopened at round "
+ i/RPPROMILLE + ")");
recman.close();
recman = RecordManagerFactory.createRecordManager( TestRecordFile.testFileName );
// recman.disableTransactions();
}
// generate a random number and assign ranges to operations:
// 0-10 = insert, 20 = delete, 30-50 = update, 51 = set root,
// 52 = get root, rest = fetch.
int op = rnd.nextInt(100);
if (op <= 10) {
// INSERT RECORD
if (recordCount == RECORDS) {
i -= 1;
continue;
}
slot = 0;
while (d[slot] != null)
slot++;
d[slot] = new RecordData(0, rnd.nextInt(MAXSIZE),
(byte) rnd.nextInt());
d[slot].rowid =
recman.insert(TestUtil.makeRecord(d[slot].size,
d[slot].b));
recordCount++;
inserts++;
}
else if (op == 20) {
// DELETE RECORD
if (recordCount == 0) {
i -= 1;
continue;
}
slot = getRandomAllocatedSlot(d);
recman.delete(d[slot].rowid);
d[slot] = null;
recordCount--;
deletes++;
}
else if (op <= 50) {
// UPDATE RECORD
if (recordCount == 0) {
i -= 1;
continue;
}
slot = getRandomAllocatedSlot(d);
d[slot].size = rnd.nextInt(MAXSIZE);
d[slot].b = (byte) rnd.nextInt();
recman.update(d[slot].rowid,
TestUtil.makeRecord(d[slot].size,
d[slot].b));
updates++;
}
else if (op == 51) {
// SET ROOT
int root = rnd.nextInt(FileHeader.NROOTS);
roots[root] = rnd.nextLong();
recman.setRoot(root, roots[root]);
rootsets++;
}
else if (op == 52) {
// GET ROOT
if (rootCount == 0) {
i -= 1;
continue;
}
int root = getRandomAllocatedRoot();
assertEquals("root", roots[root], recman.getRoot(root));
rootgets++;
}
else {
// FETCH RECORD
if (recordCount == 0) {
i -= 1;
continue;
}
slot = getRandomAllocatedSlot(d);
byte[] data = (byte[]) recman.fetch(d[slot].rowid, ByteArraySerializer.INSTANCE );
assertTrue("fetch round=" + i + ", slot=" + slot
+ ", " + d[slot],
TestUtil.checkRecord(data, d[slot].size, d[slot].b));
fetches++;
}
}
recman.close();
} catch (Throwable e) {
e.printStackTrace();