public boolean ensureSame(final int waitTimes) throws InterruptedException {
        this.lock.lock();
        List<MockStateMachine> fsmList = new ArrayList<>(this.fsms.values());
        if (fsmList.size() <= 1) {
            this.lock.unlock();
            return true;
        }
        System.out.println("Start ensureSame, waitTimes=" + waitTimes);
        try {
            int nround = 0;
            final MockStateMachine first = fsmList.get(0);
            CHECK: while (true) {
                first.lock();
                if (first.getLogs().isEmpty()) {
                    first.unlock();
                    Thread.sleep(10);
                    nround++;
                    if (waitTimes > 0 && nround > waitTimes) {
                        return false;
                    }
                    continue CHECK;
                }

                for (int i = 1; i < fsmList.size(); i++) {
                    final MockStateMachine fsm = fsmList.get(i);
                    fsm.lock();
                    if (fsm.getLogs().size() != first.getLogs().size()) {
                        fsm.unlock();
                        first.unlock();
                        Thread.sleep(10);
                        nround++;
                        if (waitTimes > 0 && nround > waitTimes) {
                            return false;
                        }
                        continue CHECK;
                    }

                    for (int j = 0; j < first.getLogs().size(); j++) {
                        final ByteBuffer firstData = first.getLogs().get(j);
                        final ByteBuffer fsmData = fsm.getLogs().get(j);
                        if (!firstData.equals(fsmData)) {
                            fsm.unlock();
                            first.unlock();
                            Thread.sleep(10);
                            nround++;
                            if (waitTimes > 0 && nround > waitTimes) {
                                return false;
                            }
                            continue CHECK;
                        }
                    }
                    fsm.unlock();
                }
                first.unlock();
                break;
            }
            return true;
        } finally {
            this.lock.unlock();
            System.out.println("End ensureSame, waitTimes=" + waitTimes);
        }
    }
Ensure all logs is the same in all nodes.
@param waitTimes
@return
@throws InterruptedException
jraft-extension/java-log-storage-impl/src/test/java/com/alipay/sofa/jraft/core/TestCluster.java