(new File(dir,"Old_Version_Number")).delete();
} catch (Exception e) {
}
Recovery handler = new Recovery();
ReliableLog log;
if (size == 4 && deathpoint == 6) {
Runtime.getRuntime().traceMethodCalls(true);
}
log = new ReliableLog(dir, handler);
if (size == 4 && deathpoint == 6) {
Runtime.getRuntime().traceMethodCalls(false);
}
// Generate a number of updates (size - 1) until failing
int i;
StringBuffer writ = new StringBuffer();
char[] u = new char[1];
for (i = 1; i < size; i++) {
u[0] = (char)(64 + (i % 26));
String update = new String(u);
handler.basicUpdate(update);
log.update(update, true);
writ.append(update);
}
// Fail
String f = ("FALL" + deathpoint);
boolean failed_as_desired = false;
try {
ReliableLog.fallOverPoint = deathpoint;
handler.basicUpdate(f);
log.update(f, true);
log.snapshot(handler);
} catch (InternalError e) {
if (!e.getMessage().equals(f))
throw e; // oops, not ours
failed_as_desired = true;
} finally {
ReliableLog.fallOverPoint = 0;
try {
log.close();
} catch (IOException ign) {
}
}
// deathpoint == 0 means that there is no deathpoint and we are testing
// undisastered behaviour.
if (!failed_as_desired && deathpoint != 0) {
System.err.println ("sun.rmi.log.ReliableLog is not instrumented for" +
" this test; test skipped");
return;
}
// Now try to recover.
Recovery laz = new Recovery();
ReliableLog carbon = new ReliableLog(dir, laz);
Recovery thingy;
thingy = (Recovery)carbon.recover();
try {
carbon.close();
} catch (IOException ign) {
}
// Recovered thingy must be equal to writ or to writ + f, but nothing
// else (or in between).