public void testSerialization() throws IOException, ClassNotFoundException
{
final byte[] bytes;
final int endOfTrueRange;
{
RowKeySetImpl set = _createKeySet(false);
endOfTrueRange = _initModel(set);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
// no need to worry about testing to make sure the model isn't
// serialized, because the Entry class isn't Serializable.
out.writeObject(set);
out.close();
bytes = bos.toByteArray();
// test to make sure that the serialized size is reasonable:
assertTrue(bytes.length <= 200);
assertTrue(bytes.length >= 80);
}
ObjectInputStream in =
new ObjectInputStream(new ByteArrayInputStream(bytes));
RowKeySetImpl set = (RowKeySetImpl)in.readObject();
assertNull("transient model", set.getCollectionModel());
set.setCollectionModel(_MODEL);
in.close();
_testAll(set, true, 0, endOfTrueRange);
_testAll(set, false, endOfTrueRange, _TEST_SIZE);
}