    @Test
    public void testWeightedDistribution() {

        final int nodeSize = 5;
        final int keySize = 10000;
        final List<String> nodes = generateRandomStrings(nodeSize);
        final List<String> weightedNodes = new ArrayList<String>(nodes);
        weightedNodes.add(nodes.get(3)); // 20%
        for (int ix = 0; ix < 4; ix++) { weightedNodes.add(nodes.get(4)); } // 50%
        final long start1 = System.currentTimeMillis();
        final KetamaNodeLocator locator = new KetamaNodeLocator(weightedNodes);

        // Make sure the initialization doesn't take too long.
        assertTrue((System.currentTimeMillis() - start1) < 100);

        final int[] counts = new int[nodeSize];
        for (int ix = 0; ix < nodeSize; ix++) { counts[ix] = 0; }

        final List<String> keys = generateRandomStrings(keySize);

        for (final String key : keys) {
            final String primary = locator.getPrimary(key);
            counts[nodes.indexOf(primary)] += 1;
        }

        // Give about a 30% leeway each way...
        final int min = (keySize * 7) / (nodeSize * 2 * 10);
        final int max = (keySize * 13) / (nodeSize * 2 * 10);
        int total = 0;
        boolean error = false;
        final StringBuilder sb = new StringBuilder("Key distribution error - \n");

        for (int ix = 0; ix < nodeSize; ix++) {
            int expectedMin = min;
            int expectedMax = max;
            if (ix == 3) { expectedMin = 2*min; expectedMax=2*max; }
            if (ix == 4) { expectedMin = 5*min; expectedMax=5*max; }
            if (counts[ix] < expectedMin || counts[ix] > expectedMax) {
                error = true;
                sb.append("  !!  ");
            } else {
                sb.append("      ");
            }
            sb.append(StringUtils.rightPad(nodes.get(ix), 12)).append(": ").append(counts[ix]).append("\n");
            total += counts[ix];
        }
        // Make sure we didn't miss any keys returning values.
        assertEquals(keySize, total);

//        System.out.println(sb.toString());
        if (error) {
            fail(sb.toString());
        }
    }