@Override
    public Map<Consumer, List<Range>> getConsumerKeyHashRanges() {
        Map<Consumer, List<Range>> result = new HashMap<>();
        Map.Entry<Integer, Consumer> prev = null;
        for (Map.Entry<Integer, Consumer> entry: rangeMap.entrySet()) {
            if (prev == null) {
                prev = entry;
            } else {
                if (prev.getValue().equals(entry.getValue())) {
                    result.computeIfAbsent(entry.getValue(), key -> new ArrayList<>())
                            .add(Range.of(prev.getKey(), entry.getKey()));
                }
                prev = null;
            }
        }
        return result;
    }
@Test
    public void testGetConsumerKeyHashRanges() throws ExecutionException, InterruptedException {
        HashRangeExclusiveStickyKeyConsumerSelector selector = new HashRangeExclusiveStickyKeyConsumerSelector(10);
        List<String> consumerName = Arrays.asList("consumer1", "consumer2", "consumer3", "consumer4");
        List<int[]> range = Arrays.asList(new int[] {0, 2}, new int[] {3, 7}, new int[] {9, 12}, new int[] {15, 20});
        List<Consumer> consumers = new ArrayList<>();
        for (int index = 0; index < consumerName.size(); index++) {
            Consumer consumer = mock(Consumer.class);
            KeySharedMeta keySharedMeta = new KeySharedMeta()
                    .setKeySharedMode(KeySharedMode.STICKY);
            keySharedMeta.addHashRange()
                    .setStart(range.get(index)[0])
                    .setEnd(range.get(index)[1]);
            when(consumer.getKeySharedMeta()).thenReturn(keySharedMeta);
            when(consumer.consumerName()).thenReturn(consumerName.get(index));
            Assert.assertEquals(consumer.getKeySharedMeta(), keySharedMeta);
            selector.addConsumer(consumer).get();
            consumers.add(consumer);
        }

        Map<Consumer, List<Range>> expectedResult = new HashMap<>();
        expectedResult.put(consumers.get(0), Collections.singletonList(Range.of(0, 2)));
        expectedResult.put(consumers.get(1), Collections.singletonList(Range.of(3, 7)));
        expectedResult.put(consumers.get(2), Collections.singletonList(Range.of(9, 12)));
        expectedResult.put(consumers.get(3), Collections.singletonList(Range.of(15, 20)));
        for (Map.Entry<Consumer, List<Range>> entry : selector.getConsumerKeyHashRanges().entrySet()) {
            Assert.assertEquals(entry.getValue(), expectedResult.get(entry.getKey()));
            expectedResult.remove(entry.getKey());
        }
        Assert.assertEquals(expectedResult.size(), 0);
    }