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 testNextGtidResetsSequenceOnNewMillisecond() throws InterruptedException {
        long firstGtid = gtidGenerator.nextGtid();
        Thread.sleep(1); // Ensure the next GTID is in a new millisecond
        long nextGtid = gtidGenerator.nextGtid();

        Assertions.assertTrue((nextGtid & GtidGenerator.MAX_SEQUENCE) == 0, "Sequence should reset on a new millisecond");
    }