TestUtils.DEBUGOUT("Put: " + (char)outbuf[0] + ": " + new String(outbuf, 0, i));
db.putNoOverwrite(null, key, data);
// Acquire a cursor for the table.
Cursor dbcp = db.openCursor(null, CursorConfig.DEFAULT);
// Walk through the table, checking
DatabaseEntry readkey = new DatabaseEntry();
DatabaseEntry readdata = new DatabaseEntry();
DatabaseEntry whoknows = new DatabaseEntry();
/*
* NOTE: Maybe want to change from user-buffer to DB buffer
* depending on the flag options.user_buffer (setReuseBuffer)
* The old version set MALLOC/REALLOC here - not sure if it is the same.
*/
TestUtils.DEBUGOUT("Dbc.get");
while (dbcp.getNext(readkey, readdata, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
String key_string =
new String(readkey.getData(), 0, readkey.getSize());
String data_string =
new String(readdata.getData(), 0, readkey.getSize());
TestUtils.DEBUGOUT("Got: " + key_string + ": " + data_string);
int len = key_string.length();
if (len <= 0 || key_string.charAt(len-1) != 'x') {
TestUtils.ERR("reread terminator is bad");
}
len--;
long bit = (1 << len);
if (len > count) {
TestUtils.ERR("reread length is bad: expect " + count + " got "+ len + " (" + key_string + ")" );
}
else if (!data_string.equals(key_string)) {
TestUtils.ERR("key/data don't match");
}
else if ((bitmap & bit) != 0) {
TestUtils.ERR("key already seen");
}
else if ((expected & bit) == 0) {
TestUtils.ERR("key was not expected");
}
else {
bitmap |= bit;
expected &= ~(bit);
for (i=0; i<len; i++) {
if (key_string.charAt(i) != ('0' + i)) {
System.out.print(" got " + key_string
+ " (" + (int)key_string.charAt(i)
+ "), wanted " + i
+ " (" + (int)('0' + i)
+ ") at position " + i + "\n");
TestUtils.ERR("key is corrupt");
}
}
}
}
if (expected != 0) {
System.out.print(" expected more keys, bitmap is: " + expected + "\n");
TestUtils.ERR("missing keys in database");
}
dbcp.close();
TestUtils.DEBUGOUT("options.save_db " + options.save_db + " options.database " + options.database);
if(options.save_db == false)
db.close(false);
else if (options.database == null)
options.database = db;