Package org.gridgain.grid.cache.affinity.consistenthash

Examples of org.gridgain.grid.cache.affinity.consistenthash.GridCacheConsistentHashAffinityFunction


        for (int i = 5; i < NODES_CNT; i = i * 3 / 2) {
            for (int replicas = 128; replicas <= 4096; replicas*=2) {
                Collection<GridNode> nodes = createNodes(i, replicas);

                GridCacheConsistentHashAffinityFunction aff = new GridCacheConsistentHashAffinityFunction(false, 10000);

                checkDistribution(aff, nodes);
            }

            System.out.println();
View Full Code Here


    }

    /** Test predefined affinity - must be ported to all clients. */
    @SuppressWarnings("UnaryPlus")
    public void testPredefined() throws GridException {
        GridCacheConsistentHashAffinityFunction aff = new GridCacheConsistentHashAffinityFunction();

        getTestResources().inject(aff);

        aff.setHashIdResolver(new GridCacheAffinityNodeIdHashResolver());

        List<GridNode> nodes = new ArrayList<>();

        nodes.add(createNode("000ea4cd-f449-4dcb-869a-5317c63bd619", 50));
        nodes.add(createNode("010ea4cd-f449-4dcb-869a-5317c63bd62a", 60));
        nodes.add(createNode("0209ec54-ff53-4fdb-8239-5a3ac1fb31bd", 70));
        nodes.add(createNode("0309ec54-ff53-4fdb-8239-5a3ac1fb31ef", 80));
        nodes.add(createNode("040c9b94-02ae-45a6-9d5c-a066dbdf2636", 90));
        nodes.add(createNode("050c9b94-02ae-45a6-9d5c-a066dbdf2747", 100));
        nodes.add(createNode("0601f916-4357-4cfe-a7df-49d4721690bf", 110));
        nodes.add(createNode("0702f916-4357-4cfe-a7df-49d4721691c0", 120));

        Map<Object, Integer> data = new LinkedHashMap<>();

        data.put("", 4);
        data.put("asdf", 4);
        data.put("224ea4cd-f449-4dcb-869a-5317c63bd619", 5);
        data.put("fdc9ec54-ff53-4fdb-8239-5a3ac1fb31bd", 2);
        data.put("0f9c9b94-02ae-45a6-9d5c-a066dbdf2636", 2);
        data.put("d8f1f916-4357-4cfe-a7df-49d4721690bf", 7);
        data.put("c77ffeae-78a1-4ee6-a0fd-8d197a794412", 3);
        data.put("35de9f21-3c9b-4f4a-a7d5-3e2c6cb01564", 1);
        data.put("d67eb652-4e76-47fb-ad4e-cd902d9b868a", 7);

        data.put(0, 4);
        data.put(1, 7);
        data.put(12, 5);
        data.put(123, 6);
        data.put(1234, 4);
        data.put(12345, 6);
        data.put(123456, 6);
        data.put(1234567, 6);
        data.put(12345678, 0);
        data.put(123456789, 7);
        data.put(1234567890, 7);
        data.put(1234567890L, 7);
        data.put(12345678901L, 2);
        data.put(123456789012L, 1);
        data.put(1234567890123L, 0);
        data.put(12345678901234L, 1);
        data.put(123456789012345L, 6);
        data.put(1234567890123456L, 7);
        data.put(-23456789012345L, 4);
        data.put(-2345678901234L, 1);
        data.put(-234567890123L, 5);
        data.put(-23456789012L, 5);
        data.put(-2345678901L, 7);
        data.put(-234567890L, 4);
        data.put(-234567890, 7);
        data.put(-23456789, 7);
        data.put(-2345678, 0);
        data.put(-234567, 6);
        data.put(-23456, 6);
        data.put(-2345, 6);
        data.put(-234, 7);
        data.put(-23, 5);
        data.put(-2, 4);

        data.put(0x80000000, 4);
        data.put(0x7fffffff, 7);
        data.put(0x8000000000000000L, 4);
        data.put(0x7fffffffffffffffL, 4);

        data.put(+1.1, 3);
        data.put(-10.01, 4);
        data.put(+100.001, 4);
        data.put(-1000.0001, 4);
        data.put(+1.7976931348623157E+308, 6);
        data.put(-1.7976931348623157E+308, 6);
        data.put(+4.9E-324, 7);
        data.put(-4.9E-324, 7);

        boolean ok = true;

        for (Map.Entry<Object, Integer> entry : data.entrySet()) {
            int part = aff.partition(entry.getKey());
            Collection<GridNode> affNodes = aff.nodes(part, nodes, 1);
            UUID act = F.<GridNode>first(affNodes).id();
            UUID exp = nodes.get(entry.getValue()).id();

            if (!exp.equals(act)) {
                ok = false;
View Full Code Here

    /** Test predefined affinity - must be ported to other clients. */
    @SuppressWarnings("UnaryPlus")
    public void testPredefinedHashIdResolver() throws GridException {
        // Use Md5 hasher for this test.
        GridCacheConsistentHashAffinityFunction aff = new GridCacheConsistentHashAffinityFunction();

        getTestResources().inject(aff);

        aff.setHashIdResolver(new GridCacheAffinityNodeHashResolver() {
            @Override public Object resolve(GridNode node) {
                return node.attribute(DFLT_REPLICA_COUNT_ATTR_NAME);
            }
        });

        List<GridNode> nodes = new ArrayList<>();

        nodes.add(createNode("000ea4cd-f449-4dcb-869a-5317c63bd619", 50));
        nodes.add(createNode("010ea4cd-f449-4dcb-869a-5317c63bd62a", 60));
        nodes.add(createNode("0209ec54-ff53-4fdb-8239-5a3ac1fb31bd", 70));
        nodes.add(createNode("0309ec54-ff53-4fdb-8239-5a3ac1fb31ef", 80));
        nodes.add(createNode("040c9b94-02ae-45a6-9d5c-a066dbdf2636", 90));
        nodes.add(createNode("050c9b94-02ae-45a6-9d5c-a066dbdf2747", 100));
        nodes.add(createNode("0601f916-4357-4cfe-a7df-49d4721690bf", 110));
        nodes.add(createNode("0702f916-4357-4cfe-a7df-49d4721691c0", 120));

        Map<Object, Integer> data = new LinkedHashMap<>();

        data.put("", 4);
        data.put("asdf", 3);
        data.put("224ea4cd-f449-4dcb-869a-5317c63bd619", 5);
        data.put("fdc9ec54-ff53-4fdb-8239-5a3ac1fb31bd", 2);
        data.put("0f9c9b94-02ae-45a6-9d5c-a066dbdf2636", 2);
        data.put("d8f1f916-4357-4cfe-a7df-49d4721690bf", 4);
        data.put("c77ffeae-78a1-4ee6-a0fd-8d197a794412", 3);
        data.put("35de9f21-3c9b-4f4a-a7d5-3e2c6cb01564", 4);
        data.put("d67eb652-4e76-47fb-ad4e-cd902d9b868a", 2);

        data.put(0, 4);
        data.put(1, 1);
        data.put(12, 7);
        data.put(123, 1);
        data.put(1234, 6);
        data.put(12345, 2);
        data.put(123456, 5);
        data.put(1234567, 4);
        data.put(12345678, 6);
        data.put(123456789, 3);
        data.put(1234567890, 3);
        data.put(1234567890L, 3);
        data.put(12345678901L, 0);
        data.put(123456789012L, 1);
        data.put(1234567890123L, 3);
        data.put(12345678901234L, 5);
        data.put(123456789012345L, 5);
        data.put(1234567890123456L, 7);
        data.put(-23456789012345L, 6);
        data.put(-2345678901234L, 4);
        data.put(-234567890123L, 3);
        data.put(-23456789012L, 0);
        data.put(-2345678901L, 4);
        data.put(-234567890L, 5);
        data.put(-234567890, 3);
        data.put(-23456789, 3);
        data.put(-2345678, 6);
        data.put(-234567, 4);
        data.put(-23456, 5);
        data.put(-2345, 2);
        data.put(-234, 7);
        data.put(-23, 6);
        data.put(-2, 6);

        data.put(0x80000000, 7);
        data.put(0x7fffffff, 1);
        data.put(0x8000000000000000L, 7);
        data.put(0x7fffffffffffffffL, 7);

        data.put(+1.1, 2);
        data.put(-10.01, 0);
        data.put(+100.001, 2);
        data.put(-1000.0001, 0);
        data.put(+1.7976931348623157E+308, 6);
        data.put(-1.7976931348623157E+308, 1);
        data.put(+4.9E-324, 1);
        data.put(-4.9E-324, 1);

        boolean ok = true;

        for (Map.Entry<Object, Integer> entry : data.entrySet()) {
            int part = aff.partition(entry.getKey());

            UUID exp = nodes.get(entry.getValue()).id();
            UUID act = F.first(aff.nodes(part, nodes, 1)).id();

            if (!exp.equals(act)) {
                ok = false;

                info("Failed to validate affinity for key '" + entry.getKey() + "' [expected=" + exp +
View Full Code Here

        getTestResources().inject(aff);

        aff.setHashIdResolver(HASH_ID_RSLVR);

        GridCacheConsistentHashAffinityFunction srvAff = new GridCacheConsistentHashAffinityFunction();

        getTestResources().inject(srvAff);

        srvAff.setHashIdResolver(new GridCacheAffinityNodeIdHashResolver());

        // Define keys to test affinity for.
        Collection<String> keys = new ArrayList<>(
            Arrays.asList("", "1", "12", "asdf", "Hadoop\u3092\u6bba\u3059"));
View Full Code Here

TOP

Related Classes of org.gridgain.grid.cache.affinity.consistenthash.GridCacheConsistentHashAffinityFunction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.