replicationServer, dbEnv, 10);
handler.setCounterWindowSize(counterWindow);
// Populate the db with 'max' msg
int mySeqnum = 1;
ChangeNumber cnarray[] = new ChangeNumber[2*(max+1)];
long now = System.currentTimeMillis();
for (int i=1; i<=max; i++)
{
cnarray[i] = new ChangeNumber(now+i, mySeqnum, 1);
mySeqnum+=2;
DeleteMsg update1 = new DeleteMsg(TEST_ROOT_DN_STRING, cnarray[i], "uid");
handler.add(update1);
}
handler.flush();
// Test first and last
ChangeNumber cn1 = handler.getFirstChange();
assertEquals(cn1, cnarray[1], "First change");
ChangeNumber cnlast = handler.getLastChange();
assertEquals(cnlast, cnarray[max], "Last change");
// Test count in different subcases trying to handle all special cases
// regarding the 'counter' record and 'count' algorithm
testcase="FROM change1 TO change1 ";
actualCnt = handler.getCount(cnarray[1], cnarray[1]);
debugInfo(tn,testcase + " actualCnt=" + actualCnt);
assertEquals(actualCnt, 1, testcase);
testcase="FROM change1 TO change2 ";
actualCnt = handler.getCount(cnarray[1], cnarray[2]);
debugInfo(tn,testcase + " actualCnt=" + actualCnt);
assertEquals(actualCnt, 2, testcase);
testcase="FROM change1 TO counterWindow="+(counterWindow);
actualCnt = handler.getCount(cnarray[1], cnarray[counterWindow]);
debugInfo(tn,testcase + " actualCnt=" + actualCnt);
assertEquals(actualCnt, counterWindow, testcase);
testcase="FROM change1 TO counterWindow+1="+(counterWindow+1);
actualCnt = handler.getCount(cnarray[1], cnarray[counterWindow+1]);
debugInfo(tn,testcase + " actualCnt=" + actualCnt);
assertEquals(actualCnt, counterWindow+1, testcase);
testcase="FROM change1 TO 2*counterWindow="+(2*counterWindow);
actualCnt = handler.getCount(cnarray[1], cnarray[2*counterWindow]);
debugInfo(tn,testcase + " actualCnt=" + actualCnt);
assertEquals(actualCnt, 2*counterWindow, testcase);
testcase="FROM change1 TO 2*counterWindow+1="+((2*counterWindow)+1);
actualCnt = handler.getCount(cnarray[1], cnarray[(2*counterWindow)+1]);
debugInfo(tn,testcase + " actualCnt=" + actualCnt);
assertEquals(actualCnt, (2*counterWindow)+1, testcase);
testcase="FROM change2 TO change5 ";
actualCnt = handler.getCount(cnarray[2], cnarray[5]);
debugInfo(tn,testcase + " actualCnt=" + actualCnt);
assertEquals(actualCnt, 4, testcase);
testcase="FROM counterWindow+2 TO counterWindow+5 ";
actualCnt = handler.getCount(cnarray[(counterWindow+2)], cnarray[(counterWindow+5)]);
debugInfo(tn,testcase + " actualCnt=" + actualCnt);
assertEquals(actualCnt, 4, testcase);
testcase="FROM change2 TO counterWindow+5 ";
actualCnt = handler.getCount(cnarray[2], cnarray[(counterWindow+5)]);
debugInfo(tn,testcase + " actualCnt=" + actualCnt);
assertEquals(actualCnt, counterWindow+4, testcase);
testcase="FROM counterWindow+4 TO counterWindow+4 ";
actualCnt = handler.getCount(cnarray[(counterWindow+4)], cnarray[(counterWindow+4)]);
debugInfo(tn,testcase + " actualCnt=" + actualCnt);
assertEquals(actualCnt, 1, testcase);
// Now test with changes older than first or newer than last
ChangeNumber olderThanFirst = null;
ChangeNumber newerThanLast =
new ChangeNumber(System.currentTimeMillis() + (2*(max+1)), 100, 1);
// Now we want to test with start and stop outside of the db
testcase="FROM our first generated change TO now (> newest change in the db)";
actualCnt = handler.getCount(cnarray[1], newerThanLast);
debugInfo(tn,testcase + " actualCnt=" + actualCnt);
assertEquals(actualCnt, max, testcase);
testcase="FROM null (start of time) TO now (> newest change in the db)";
actualCnt = handler.getCount(olderThanFirst, newerThanLast);
debugInfo(tn,testcase + " actualCnt=" + actualCnt);
assertEquals(actualCnt, max, testcase);
// Now we want to test that after closing and reopening the db, the
// counting algo is well reinitialized and when new messages are added
// the new counter are correctly generated.
debugInfo(tn,"SHUTDOWN handler and recreate");
handler.shutdown();
handler =
new DbHandler( 1, TEST_ROOT_DN_STRING,
replicationServer, dbEnv, 10);
handler.setCounterWindowSize(counterWindow);
// Test first and last
cn1 = handler.getFirstChange();
assertEquals(cn1, cnarray[1], "First change");
cnlast = handler.getLastChange();
assertEquals(cnlast, cnarray[max], "Last change");
testcase="FROM our first generated change TO now (> newest change in the db)";
actualCnt = handler.getCount(cnarray[1], newerThanLast);
debugInfo(tn,testcase + " actualCnt=" + actualCnt);
assertEquals(actualCnt, max, testcase);
// Populate the db with 'max' msg
for (int i=max+1; i<=(2*max); i++)
{
cnarray[i] = new ChangeNumber(now+i, mySeqnum, 1);
mySeqnum+=2;
DeleteMsg update1 = new DeleteMsg(TEST_ROOT_DN_STRING, cnarray[i], "uid");
handler.add(update1);
}
handler.flush();