{
int sender = 2;
int dest = 3;
// RS State
ServerState rsState = new ServerState();
ChangeNumber rscn1 = new ChangeNumber(1, 1, 1);
ChangeNumber rscn2 = new ChangeNumber(1, 1, 45678);
rsState.update(rscn1);
rsState.update(rscn2);
// LS1 state
ServerState s1 = new ServerState();
int sid1 = 111;
ChangeNumber cn1 = new ChangeNumber(1, 1, sid1);
s1.update(cn1);
// LS2 state
ServerState s2 = new ServerState();
int sid2 = 222;
Long now = ((Integer)10).longValue();
ChangeNumber cn2 = new ChangeNumber(now, 123, sid2);
s2.update(cn2);
// LS3 state
ServerState s3 = new ServerState();
int sid3 = 56789;
ChangeNumber cn3 = new ChangeNumber(now, 123, sid3);
s3.update(cn3);
MonitorMsg msg =
new MonitorMsg(sender, dest);
msg.setReplServerDbState(rsState);
msg.setServerState(sid1, s1, now+1, true);
msg.setServerState(sid2, s2, now+2, true);
msg.setServerState(sid3, s3, now+3, false);
byte[] b = msg.getBytes();
MonitorMsg newMsg = new MonitorMsg(b, ProtocolVersion.getCurrentVersion());
assertEquals(rsState, msg.getReplServerDbState());
assertEquals(newMsg.getReplServerDbState().toString(),
msg.getReplServerDbState().toString());
Iterator<Integer> it = newMsg.ldapIterator();
while (it.hasNext())
{
int sid = it.next();
ServerState s = newMsg.getLDAPServerState(sid);
if (sid == sid1)
{
assertEquals(s.toString(), s1.toString(), "");
assertEquals((Long)(now+1), newMsg.getLDAPApproxFirstMissingDate(sid), "");
}
else if (sid == sid2)
{
assertEquals(s.toString(), s2.toString());
assertEquals((Long)(now+2), newMsg.getLDAPApproxFirstMissingDate(sid), "");
}
else
{
fail("Bad sid" + sid);
}
}
Iterator<Integer> it2 = newMsg.rsIterator();
while (it2.hasNext())
{
int sid = it2.next();
ServerState s = newMsg.getRSServerState(sid);
if (sid == sid3)
{
assertEquals(s.toString(), s3.toString(), "");
assertEquals((Long)(now+3), newMsg.getRSApproxFirstMissingDate(sid), "");
}
else
{
fail("Bad sid " + sid);