public static Counter allocate(
        final Aeron aeron,
        final MutableDirectBuffer tempBuffer,
        final int typeId,
        final String name,
        final long archiveId)
    {
        int index = 0;
        tempBuffer.putLong(index, archiveId);
        index += SIZE_OF_LONG;
        final int keyLength = index;

        index += tempBuffer.putStringWithoutLengthAscii(index, name);
        index += appendArchiveIdLabel(tempBuffer, index, archiveId);

        return aeron.addCounter(typeId, tempBuffer, 0, keyLength, tempBuffer, keyLength, index - keyLength);
    }
@Test
    void allocateCounterUsingAeronClientIdAsArchiveIdentifier()
    {
        final int typeId = 999;
        final String name = "<test counter>";
        final long archiveId = -1832178932131546L;
        final String expectedLabel = name + " - archiveId=" + archiveId;
        final Aeron aeron = mock(Aeron.class);
        final MutableDirectBuffer tempBuffer = new UnsafeBuffer(new byte[200]);
        final Counter counter = mock(Counter.class);
        when(aeron.clientId()).thenReturn(archiveId);
        when(aeron.addCounter(typeId, tempBuffer, 0, SIZE_OF_LONG, tempBuffer, SIZE_OF_LONG, expectedLabel.length()))
            .thenReturn(counter);

        final Counter result = ArchiveCounters.allocate(aeron, tempBuffer, typeId, name, aeron.clientId());

        assertSame(counter, result);
        final InOrder inOrder = inOrder(aeron);
        inOrder.verify(aeron).clientId();
        inOrder.verify(aeron).addCounter(anyInt(), any(), anyInt(), anyInt(), any(), anyInt(), anyInt());
        inOrder.verifyNoMoreInteractions();
        assertEquals(archiveId, tempBuffer.getLong(0));
        assertEquals(expectedLabel, tempBuffer.getStringWithoutLengthAscii(SIZE_OF_LONG, expectedLabel.length()));
    }