public final void testWriteAndReadFields() throws IOException {
DataOutputBuffer out = new DataOutputBuffer();
DataInputBuffer in = new DataInputBuffer();
ClusterStatus status1;
Map<String, String> grooms = new HashMap<String, String>();
for (int i = 0; i < 10; i++) {
int num = rnd.nextInt();
String groomName = "groom_" + num;
String peerName = "peerhost:" + num;
grooms.put(groomName, peerName);
}
int tasks = rnd.nextInt(100);
int maxTasks = rnd.nextInt(100);
BSPMaster.State state = BSPMaster.State.RUNNING;
status1 = new ClusterStatus(grooms, tasks, maxTasks, state);
status1.write(out);
in.reset(out.getData(), out.getLength());
ClusterStatus status2 = new ClusterStatus();
status2.readFields(in);
Map<String, String> grooms_s = new HashMap<String, String>(status1
.getActiveGroomNames());
Map<String, String> grooms_o = new HashMap<String, String>(status2
.getActiveGroomNames());
assertEquals(status1.getGroomServers(), status2.getGroomServers());
assertTrue(grooms_s.entrySet().containsAll(grooms_o.entrySet()));
assertTrue(grooms_o.entrySet().containsAll(grooms_s.entrySet()));
assertEquals(status1.getTasks(), status2.getTasks());
assertEquals(status1.getMaxTasks(), status2.getMaxTasks());
}