void snapshotConsensusModuleState(
        final long nextSessionId,
        final long nextServiceSessionId,
        final long logServiceSessionId,
        final int pendingMessageCapacity)
    {
        final int length = MessageHeaderEncoder.ENCODED_LENGTH + ConsensusModuleEncoder.BLOCK_LENGTH;

        idleStrategy.reset();
        while (true)
        {
            final long result = publication.tryClaim(length, bufferClaim);
            if (result > 0)
            {
                consensusModuleEncoder
                    .wrapAndApplyHeader(bufferClaim.buffer(), bufferClaim.offset(), messageHeaderEncoder)
                    .nextSessionId(nextSessionId)
                    .nextServiceSessionId(nextServiceSessionId)
                    .logServiceSessionId(logServiceSessionId)
                    .pendingMessageCapacity(pendingMessageCapacity);

                bufferClaim.commit();
                break;
            }

            checkResultAndIdle(result);
        }
    }
@Test
    void snapshotConsensusModuleState()
    {
        final int offset = 32;
        final int length = MessageHeaderEncoder.ENCODED_LENGTH + ConsensusModuleEncoder.BLOCK_LENGTH;
        final long nextSessionId = 42;
        final long nextServiceSessionId = -4_000_000_001L;
        final long logServiceSessionId = -4_000_000_000L;
        final int pendingMessageCapacity = 4096;
        when(publication.tryClaim(eq(length), any()))
            .thenReturn(BACK_PRESSURED, ADMIN_ACTION)
            .thenAnswer(mockTryClaim(offset));

        snapshotTaker.snapshotConsensusModuleState(
            nextSessionId, nextServiceSessionId, logServiceSessionId, pendingMessageCapacity);

        final InOrder inOrder = inOrder(idleStrategy, publication);
        inOrder.verify(idleStrategy).reset();
        inOrder.verify(publication).tryClaim(anyInt(), any());
        inOrder.verify(idleStrategy).idle();
        inOrder.verify(publication).tryClaim(anyInt(), any());
        inOrder.verify(idleStrategy).idle();
        inOrder.verify(publication).tryClaim(anyInt(), any());
        inOrder.verifyNoMoreInteractions();

        consensusModuleDecoder.wrapAndApplyHeader(buffer, offset + HEADER_LENGTH, messageHeaderDecoder);
        assertEquals(nextSessionId, consensusModuleDecoder.nextSessionId());
        assertEquals(nextServiceSessionId, consensusModuleDecoder.nextServiceSessionId());
        assertEquals(logServiceSessionId, consensusModuleDecoder.logServiceSessionId());
        assertEquals(pendingMessageCapacity, consensusModuleDecoder.pendingMessageCapacity());
    }