Search in sources :

Example 11 with AffinityFunctionContext

use of org.apache.ignite.cache.affinity.AffinityFunctionContext 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 12 with AffinityFunctionContext

use of org.apache.ignite.cache.affinity.AffinityFunctionContext 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)

Example 13 with AffinityFunctionContext

use of org.apache.ignite.cache.affinity.AffinityFunctionContext in project ignite by apache.

the class GridCacheAffinityApiSelfTest method testAllPartitions.

/**
     * JUnit.
     *
     * @throws Exception If failed.
     */
public void testAllPartitions() throws Exception {
    // Pick 2 nodes and create a projection over them.
    ClusterNode n0 = grid(0).localNode();
    int[] parts = grid(0).affinity(DEFAULT_CACHE_NAME).allPartitions(n0);
    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);
        assert owners.contains(n0);
    }
}
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

List (java.util.List)13 AffinityFunctionContext (org.apache.ignite.cache.affinity.AffinityFunctionContext)13 ArrayList (java.util.ArrayList)12 ClusterNode (org.apache.ignite.cluster.ClusterNode)11 GridAffinityFunctionContextImpl (org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl)11 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)9 LinkedList (java.util.LinkedList)8 AffinityFunction (org.apache.ignite.cache.affinity.AffinityFunction)8 Map (java.util.Map)3 UUID (java.util.UUID)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 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 IgniteException (org.apache.ignite.IgniteException)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)1 GridKernalContext (org.apache.ignite.internal.GridKernalContext)1 GridNodeOrderComparator (org.apache.ignite.internal.GridNodeOrderComparator)1