}
@Test
public void testAppendSegmentDeleteSegment() throws Exception {
final SegmentList segmentList = new SegmentList();
assertEquals(0, segmentList.contents.get().length);
final File file = new File("testAppendSegmentDeleteSegment.test");
if (!file.exists()) {
file.createNewFile();
}
final Segment segment1 = new Segment(0, file);
final Segment segment2 = new Segment(1024, file);
final Segment segment3 = new Segment(2048, file);
try {
segmentList.append(segment1);
assertEquals(1, segmentList.contents.get().length);
assertSame(segment1, segmentList.first());
assertSame(segment1, segmentList.last());
segmentList.append(segment2);
assertEquals(2, segmentList.contents.get().length);
assertSame(segment1, segmentList.first());
assertSame(segment2, segmentList.last());
segmentList.append(segment3);
assertEquals(3, segmentList.contents.get().length);
assertSame(segment1, segmentList.first());
assertSame(segment3, segmentList.last());
segmentList.delete(segment1);
assertEquals(2, segmentList.contents.get().length);
assertSame(segment2, segmentList.first());
assertSame(segment3, segmentList.last());
segmentList.delete(segment3);
assertEquals(1, segmentList.contents.get().length);
assertSame(segment2, segmentList.first());
assertSame(segment2, segmentList.last());
// delete not existing
segmentList.delete(segment3);
assertEquals(1, segmentList.contents.get().length);
assertSame(segment2, segmentList.first());
assertSame(segment2, segmentList.last());
segmentList.delete(segment2);
assertEquals(0, segmentList.contents.get().length);
assertNull(segmentList.first());
assertNull(segmentList.last());
}
finally {
if (segment1 != null) {
segment1.fileMessageSet.close();
}