*/
public void testMixed() throws IOException {
System.out.println("testMixed");
Properties props = new Properties();
RecordManager recman = RecordManagerFactory.createRecordManager( TestRecordFile.testFileName, props );
HashDirectory dir = new HashDirectory((byte)0);
long recid = recman.insert(dir);
dir.setPersistenceContext(recman, recid);
Hashtable hash = new Hashtable(); // use to compare results
int max = 30; // must be even
// insert & check values
for (int i=0; i<max; i++) {
dir.put("key"+i, "value"+i);
hash.put("key"+i, "value"+i);
}
recman.commit();
for (int i=0; i<max; i++) {
String s = (String)dir.get("key"+i);
assertEquals("value"+i, s);
}
recman.commit();
// replace only even values
for (int i=0; i<max; i+=2) {
dir.put("key"+i, "value"+(i*2+1));
hash.put("key"+i, "value"+(i*2+1));
}
recman.commit();
for (int i=0; i<max; i++) {
if ((i%2) == 1) {
// odd
String s = (String)dir.get("key"+i);
assertEquals("value"+i, s);
} else {
// even
String s = (String)dir.get("key"+i);
assertEquals("value"+(i*2+1), s);
}
}
recman.commit();
// remove odd numbers
for (int i=1; i<max; i+=2) {
dir.remove("key"+i);
hash.remove("key"+i);
}
recman.commit();
for (int i=0; i<max; i++) {
if ((i%2) == 1) {
// odd
String s = (String)dir.get("key"+i);
assertEquals(null, s);
} else {
// even
String s = (String)dir.get("key"+i);
assertEquals("value"+(i*2+1), s);
}
}
recman.commit();
recman.close();
recman = null;
}