int compareSegmentedKeys(final Bytes cacheKey, final Bytes storeKey) {
        final long storeSegmentId = segmentId(storeKey);
        final long cacheSegmentId = ByteBuffer.wrap(cacheKey.get()).getLong();

        final int segmentCompare = Long.compare(cacheSegmentId, storeSegmentId);
        if (segmentCompare == 0) {
            final byte[] cacheKeyBytes = cacheKey.get();
            final byte[] storeKeyBytes = storeKey.get();
            return Bytes.BYTES_LEXICO_COMPARATOR.compare(
                cacheKeyBytes, SEGMENT_ID_BYTES, cacheKeyBytes.length - SEGMENT_ID_BYTES,
                storeKeyBytes, 0, storeKeyBytes.length
            );
        } else {
            return segmentCompare;
        }
    }
@Test
    public void compareSegmentedKeys() {
        assertThat(
            "same key in same segment should be ranked the same",
            cacheFunction.compareSegmentedKeys(
                cacheFunction.cacheKey(THE_KEY),
                THE_KEY
            ) == 0
        );

        final Bytes sameKeyInPriorSegment = WindowKeySchema.toStoreKeyBinary(new byte[]{0xA, 0xB, 0xC}, 1234, 42);

        assertThat(
            "same keys in different segments should be ordered according to segment",
            cacheFunction.compareSegmentedKeys(
                cacheFunction.cacheKey(sameKeyInPriorSegment),
                THE_KEY
            ) < 0
        );

        assertThat(
            "same keys in different segments should be ordered according to segment",
            cacheFunction.compareSegmentedKeys(
                cacheFunction.cacheKey(THE_KEY),
                sameKeyInPriorSegment
            ) > 0
        );

        final Bytes lowerKeyInSameSegment = WindowKeySchema.toStoreKeyBinary(new byte[]{0xA, 0xB, 0xB}, TIMESTAMP - 1, 0);

        assertThat(
            "different keys in same segments should be ordered according to key",
            cacheFunction.compareSegmentedKeys(
                cacheFunction.cacheKey(THE_KEY),
                lowerKeyInSameSegment
            ) > 0
        );

        assertThat(
            "different keys in same segments should be ordered according to key",
            cacheFunction.compareSegmentedKeys(
                cacheFunction.cacheKey(lowerKeyInSameSegment),
                THE_KEY
            ) < 0
        );
    }