public static Status unblock(
        final UnsafeBuffer logMetaDataBuffer,
        final UnsafeBuffer termBuffer,
        final int blockedOffset,
        final int tailOffset,
        final int termId)
    {
        Status status = NO_ACTION;
        int frameLength = frameLengthVolatile(termBuffer, blockedOffset);

        if (frameLength < 0)
        {
            resetHeader(logMetaDataBuffer, termBuffer, blockedOffset, termId, -frameLength);
            status = UNBLOCKED;
        }
        else if (0 == frameLength)
        {
            int currentOffset = blockedOffset + FRAME_ALIGNMENT;

            while (currentOffset < tailOffset)
            {
                frameLength = frameLengthVolatile(termBuffer, currentOffset);

                if (frameLength != 0)
                {
                    if (scanBackToConfirmZeroed(termBuffer, currentOffset, blockedOffset))
                    {
                        final int length = currentOffset - blockedOffset;
                        resetHeader(logMetaDataBuffer, termBuffer, blockedOffset, termId, length);
                        status = UNBLOCKED;
                    }

                    break;
                }

                currentOffset += FRAME_ALIGNMENT;
            }

            if (currentOffset == termBuffer.capacity())
            {
                if (0 == frameLengthVolatile(termBuffer, blockedOffset))
                {
                    final int length = currentOffset - blockedOffset;
                    resetHeader(logMetaDataBuffer, termBuffer, blockedOffset, termId, length);
                    status = UNBLOCKED_TO_END;
                }
            }
        }

        return status;
    }
@Test
    void shouldPatchToEndOfPartition()
    {
        final int messageLength = HEADER_LENGTH * 4;
        final int termOffset = TERM_BUFFER_CAPACITY - messageLength;
        final int tailOffset = TERM_BUFFER_CAPACITY;

        when(mockTermBuffer.getIntVolatile(termOffset)).thenReturn(0);

        assertEquals(
            UNBLOCKED_TO_END,
            TermUnblocker.unblock(mockLogMetaDataBuffer, mockTermBuffer, termOffset, tailOffset, TERM_ID));

        final InOrder inOrder = inOrder(mockTermBuffer);
        inOrder.verify(mockTermBuffer).putShort(typeOffset(termOffset), (short)HDR_TYPE_PAD, LITTLE_ENDIAN);
        inOrder.verify(mockTermBuffer).putInt(termOffsetOffset(termOffset), termOffset, LITTLE_ENDIAN);
        inOrder.verify(mockTermBuffer).putIntOrdered(termOffset, messageLength);
    }