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());
}
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);
}
}
Aggregations