Search in sources :

Example 16 with GridAffinityFunctionContextImpl

use of org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl in project ignite by apache.

the class GridCacheAffinityApiSelfTest method testMapPartitionsToNodeCollection.

/**
 * JUnit.
 *
 * @throws Exception If failed.
 */
public void testMapPartitionsToNodeCollection() throws Exception {
    Collection<Integer> parts = new LinkedList<>();
    for (int p = 0; p < affinity().partitions(); p++) parts.add(p);
    Map<Integer, ClusterNode> map = grid(0).affinity(DEFAULT_CACHE_NAME).mapPartitionsToNodes(parts);
    AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(new ArrayList<>(grid(0).cluster().nodes()), null, null, new AffinityTopologyVersion(1), 1);
    AffinityFunction aff = affinity();
    List<List<ClusterNode>> assignment = aff.assignPartitions(ctx);
    for (Map.Entry<Integer, ClusterNode> e : map.entrySet()) assert F.eqNodes(F.first(nodes(assignment, aff, e.getKey())), e.getValue());
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) AffinityFunctionContext(org.apache.ignite.cache.affinity.AffinityFunctionContext) LinkedList(java.util.LinkedList) GridAffinityFunctionContextImpl(org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) Map(java.util.Map)

Example 17 with GridAffinityFunctionContextImpl

use of org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl in project ignite by apache.

the class GridCacheAffinityApiSelfTest method testPrimaryPartitions.

/**
 * JUnit.
 *
 * @throws Exception If failed.
 */
public void testPrimaryPartitions() throws Exception {
    // Pick 2 nodes and create a projection over them.
    ClusterNode n0 = grid(0).localNode();
    int[] parts = grid(0).affinity(DEFAULT_CACHE_NAME).primaryPartitions(n0);
    info("Primary partitions count: " + parts.length);
    assert parts.length > 1 : "Invalid partitions: " + Arrays.toString(parts);
    for (int part : parts) assert part >= 0;
    assert !F.isEmpty(parts);
    AffinityFunctionContext ctx = new GridAffinityFunctionContextImpl(new ArrayList<>(grid(0).cluster().nodes()), null, null, new AffinityTopologyVersion(1), 1);
    List<List<ClusterNode>> assignment = affinity().assignPartitions(ctx);
    for (int p : parts) {
        Collection<ClusterNode> owners = nodes(assignment, p);
        assert !F.isEmpty(owners);
        ClusterNode primary = F.first(owners);
        assert F.eqNodes(n0, primary);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridAffinityFunctionContextImpl(org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) AffinityFunctionContext(org.apache.ignite.cache.affinity.AffinityFunctionContext)

Aggregations

GridAffinityFunctionContextImpl (org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl)17 ArrayList (java.util.ArrayList)15 List (java.util.List)15 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)15 ClusterNode (org.apache.ignite.cluster.ClusterNode)13 AffinityFunctionContext (org.apache.ignite.cache.affinity.AffinityFunctionContext)11 LinkedList (java.util.LinkedList)8 AffinityFunction (org.apache.ignite.cache.affinity.AffinityFunction)8 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)7 Map (java.util.Map)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 GridTestNode (org.apache.ignite.testframework.GridTestNode)3 Ignite (org.apache.ignite.Ignite)2 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)2 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 UUID (java.util.UUID)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)1