final memprofiler profiler = new memprofiler(1024, 320, 120, new File(tablename_test + ".profile.png"));
profiler.start();
// create the database access
final Row testRow = new Row("byte[] key-" + keylength + ", byte[] dummy-" + keylength + ", value-" + valuelength, Base64Order.enhancedCoder);
final Index table_test = selectTableType(dbe_test, tablename_test, testRow);
final Index table_reference = (dbe_reference == null) ? null : selectTableType(dbe_reference, tablename_reference, testRow);
final long afterinit = System.currentTimeMillis();
System.out.println("Test for db-engine " + dbe_test + " started to create file " + tablename_test + " with test " + command);
// execute command
if (command.equals("create")) {
// do nothing, since opening of the database access must handle this
System.out.println("Database created");
}
if (command.equals("fill")) {
// fill database with random entries;
// args: <number-of-entries> <random-startpoint>
// example: java -ea -Xmx200m fill kelondroEcoTable kelondroFlexTable filldbtest 50000 0
final long count = Long.parseLong(args[4]);
final long randomstart = Long.parseLong(args[5]);
final Random random = new Random(randomstart);
byte[] key;
for (int i = 0; i < count; i++) {
key = randomHash(random);
table_test.put(testRow.newEntry(new byte[][]{key, key, dummyvalue2}));
if (table_reference != null) table_reference.put(testRow.newEntry(new byte[][]{key, key, dummyvalue2}));
if (i % 1000 == 0) {
System.out.println(i + " entries. ");
}
}
}
if (command.equals("read")) {
// read the database and compare with random entries;
// args: <number-of-entries> <random-startpoint>
final long count = Long.parseLong(args[4]);
final long randomstart = Long.parseLong(args[5]);
final Random random = new Random(randomstart);
Row.Entry entry;
byte[] key;
for (int i = 0; i < count; i++) {
key = randomHash(random);
entry = table_test.get(key);
if (entry == null)
System.out.println("missing value for entry " + UTF8.String(key) + " in test table");
else
if (!ByteBuffer.equals(entry.getColBytes(1, false), key)) System.out.println("wrong value for entry " + UTF8.String(key) + ": " + UTF8.String(entry.getColBytes(1, false)) + " in test table");
if (table_reference != null) {
entry = table_reference.get(key);
if (entry == null)
System.out.println("missing value for entry " + UTF8.String(key) + " in reference table");
else
if (!ByteBuffer.equals(entry.getColBytes(1, false), key)) System.out.println("wrong value for entry " + UTF8.String(key) + ": " + UTF8.String(entry.getColBytes(1, false)) + " in reference table");
}
if (i % 1000 == 0) {
System.out.println(i + " entries processed so far.");
}
}
}
if (command.equals("ramtest")) {
// fill database with random entries and delete them again;
// this is repeated without termination; after each loop
// the current ram is printed out
// args: <number-of-entries> <random-startpoint>
final long count = Long.parseLong(args[4]);
final long randomstart = Long.parseLong(args[5]);
byte[] key;
Random random;
long start, write, remove;
int loop = 0;
while (true) {
// write
random = new Random(randomstart);
start = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
key = randomHash(random);
table_test.put(table_test.row().newEntry(new byte[][]{key, key, dummyvalue2}));
}
write = System.currentTimeMillis() - start;
// delete
random = new Random(randomstart);
start = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
key = randomHash(random);
table_test.delete(key);
}
remove = System.currentTimeMillis() - start;
System.out.println("Loop " + loop + ": Write = " + write + ", Remove = " + remove);
System.out.println(" bevore GC: " +
"free = " + MemoryControl.free() +
", max = " + MemoryControl.maxMemory +
", total = " + MemoryControl.total());
System.gc();
System.out.println(" after GC: " +
"free = " + MemoryControl.free() +
", max = " + MemoryControl.maxMemory +
", total = " + MemoryControl.total());
loop++;
}
}
if (command.equals("list")) {
CloneableIterator<Row.Entry> i = null;
if (table_test instanceof SQLTable) i = ((SQLTable) table_test).rows();
if(i != null) {
Row.Entry row;
while (i.hasNext()) {
row = i.next();
for (int j = 0; j < row.columns(); j++) System.out.print(row.getColString(j) + ",");
System.out.println();
}
}
}
final long aftercommand = System.currentTimeMillis();
checkEquivalence(table_test, table_reference);
final long afterequiv = System.currentTimeMillis();
// final report
System.out.println("Database size = " + table_test.size() + " unique entries.");
// finally close the database/table
table_test.close();
if (table_reference != null) table_reference.close();
final long afterclose = System.currentTimeMillis();
System.out.println("Execution time: open=" + (afterinit - startup) +
", command=" + (aftercommand - afterinit) +