void updateOldestSegmentReference() throws IOException {
        final Optional<Path> previousOldestSegmentPath = oldestSegmentPath;
        oldestSegmentPath = listSegmentPathsSortedBySegmentId(this.queuePath)
                .filter(p -> p.toFile().length() > 1) // take the files that have content to process
                .findFirst();
        if (!oldestSegmentPath.isPresent()) {
            oldestSegmentTimestamp = Optional.empty();
            return;
        }

        boolean previousPathEqualsToCurrent = previousOldestSegmentPath.isPresent() && // contains a value
                previousOldestSegmentPath.get().equals(oldestSegmentPath.get()); // and the value is the same as the current
        if (!previousPathEqualsToCurrent) {
            // oldest segment path has changed
            logger.debug("Oldest segment is {}", oldestSegmentPath.get());
        }

        // extract the newest timestamp from the oldest segment
        Optional<Timestamp> foundTimestamp = readTimestampOfLastEventInSegment(oldestSegmentPath.get());
        if (!foundTimestamp.isPresent()) {
            // clean also the last segment, because doesn't contain a timestamp (corrupted maybe)
            // or is not present anymore
            oldestSegmentPath = Optional.empty();
        }
        oldestSegmentTimestamp = foundTimestamp;
    }
@Test
    public void testUpdateOldestSegmentReference() throws IOException {
        try (DeadLetterQueueWriter sut = DeadLetterQueueWriter
                .newBuilderWithoutFlusher(dir, 10 * MB, 20 * MB)
                .build()) {

            final byte[] eventBytes = new DLQEntry(new Event(), "", "", "").serialize();

            try(RecordIOWriter writer = new RecordIOWriter(dir.resolve("1.log"))){
                writer.writeEvent(eventBytes);
            }

            try(RecordIOWriter writer = new RecordIOWriter(dir.resolve("2.log"))){
                writer.writeEvent(eventBytes);
            }

            try(RecordIOWriter writer = new RecordIOWriter(dir.resolve("3.log"))){
                writer.writeEvent(eventBytes);
            }

            // Exercise
            sut.updateOldestSegmentReference();

            // Verify
            final Optional<Path> oldestSegmentPath = sut.getOldestSegmentPath();
            assertTrue(oldestSegmentPath.isPresent());
            assertEquals("1.log", oldestSegmentPath.get().getFileName().toString());
        }
    }