public synchronized long nextGtid() {
        long timestamp = timeGen();

        if (timestamp < lastTimestamp) {
            timestamp = lastTimestamp;
        }

        if (lastTimestamp == timestamp) {
            sequence = (sequence + 1) & MAX_SEQUENCE;
            if (sequence == 0) {
                timestamp += 1;
            }
        } else {
            sequence = 0L;
        }

        if (timestamp - EPOCH >= (1L << 42)) {
            throw new IllegalStateException("Timestamp overflow");
        }

        lastTimestamp = timestamp;
        return ((timestamp - EPOCH) << TIMESTAMP_SHIFT) | (CLUSTER_ID << CLUSTER_ID_SHIFT) | sequence;
    }
@Test
    public void testGtidTimestampAdvancement() {
        long firstGtid = gtidGenerator.nextGtid();
        long secondGtid = gtidGenerator.nextGtid();
        long firstTimestamp = firstGtid >> GtidGenerator.TIMESTAMP_SHIFT;
        long secondTimestamp = secondGtid >> GtidGenerator.TIMESTAMP_SHIFT;

        Assertions.assertTrue(secondTimestamp >= firstTimestamp, "Timestamp should advance or stay the same on subsequent GTIDs");
    }