*/
private void verify(Hashtable expectedData, boolean doDelete)
throws DatabaseException {
Iterator iter = expectedData.entrySet().iterator();
StringDbt testKey = new StringDbt();
StringDbt testData = new StringDbt();
// Iterate over the expected values.
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
testKey.setString((String) entry.getKey());
// search for the expected values using SET.
OperationStatus status = cursor2.getSearchKey(testKey, testData,
LockMode.DEFAULT);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals((String) entry.getValue(), testData.getString());
assertEquals((String) entry.getKey(), testKey.getString());
// check that getCurrent returns the same thing.
status = cursor2.getCurrent(testKey, testData, LockMode.DEFAULT);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals((String) entry.getValue(), testData.getString());
assertEquals((String) entry.getKey(), testKey.getString());
if (doDelete) {
// Delete the entry and make sure that getSearchKey doesn't
// return it again.
status = cursor2.delete();
assertEquals(OperationStatus.SUCCESS, status);
// search for the expected values using SET.
status =
cursor2.getSearchKey(testKey, testData, LockMode.DEFAULT);
assertEquals(OperationStatus.NOTFOUND, status);
// search for the expected values using SET_BOTH.
status =
cursor2.getSearchBoth(testKey, testData, LockMode.DEFAULT);
assertEquals(OperationStatus.NOTFOUND, status);
// search for the expected values using SET_RANGE - should
// give 0 except if this is the last key in the tree, in which
// case DB_NOTFOUND. It should never be DB_KEYEMPTY.
// XXX: It would be nice to be definite about the expected
// status, but to do that we have to know whether this is the
// highest key in the set, which we don't currently track.
status = cursor2.getSearchKeyRange
(testKey, testData, LockMode.DEFAULT);
assertTrue(status == OperationStatus.SUCCESS ||
status == OperationStatus.NOTFOUND);
} else {
// search for the expected values using SET_BOTH.
status =
cursor2.getSearchBoth(testKey, testData, LockMode.DEFAULT);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals((String) entry.getValue(), testData.getString());
assertEquals((String) entry.getKey(), testKey.getString());
// check that getCurrent returns the same thing.
status =
cursor2.getCurrent(testKey, testData, LockMode.DEFAULT);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals((String) entry.getValue(), testData.getString());
assertEquals((String) entry.getKey(), testKey.getString());
// check that SET_RANGE works as expected for exact keys
status = cursor2.getSearchKeyRange
(testKey, testData, LockMode.DEFAULT);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals((String) entry.getValue(), testData.getString());
assertEquals((String) entry.getKey(), testKey.getString());
// search for the expected values using SET_RANGE.
byte[] keyBytes = testKey.getData();
keyBytes[keyBytes.length - 1]--;
status = cursor2.getSearchKeyRange
(testKey, testData, LockMode.DEFAULT);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals((String) entry.getValue(), testData.getString());
assertEquals((String) entry.getKey(), testKey.getString());
// check that getCurrent returns the same thing.
status =
cursor2.getCurrent(testKey, testData, LockMode.DEFAULT);
assertEquals(OperationStatus.SUCCESS, status);
assertEquals((String) entry.getValue(), testData.getString());
assertEquals((String) entry.getKey(), testKey.getString());
}
}
}