static SegmentStatus getSegmentStatus(Path path) {
        try (RecordIOReader ioReader = new RecordIOReader(path)) {
            boolean moreEvents = true;
            SegmentStatus segmentStatus = SegmentStatus.EMPTY;
            while (moreEvents) {
                // If all events in the segment can be read, then assume that this is a valid segment
                moreEvents = (ioReader.readEvent() != null);
                if (moreEvents) segmentStatus = SegmentStatus.VALID;
            }
            return segmentStatus;
        } catch (IOException | IllegalStateException e) {
            logger.warn("Error reading segment file {}", path, e);
            return SegmentStatus.INVALID;
        }
    }
@Test
    public void testPartiallyWrittenSegment() throws Exception {
        try(RecordIOWriter writer = new RecordIOWriter(file)) {
            writer.writeRecordHeader(
                    new RecordHeader(RecordType.COMPLETE, 100, OptionalInt.empty(), 0));
        }
        assertThat(RecordIOReader.getSegmentStatus(file), is(RecordIOReader.SegmentStatus.INVALID));
    }