Search in sources :

Example 41 with GridTestNode

use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.

the class GridRoundRobinLoadBalancingSpiTopologyChangeSelfTest method testTopologyChange.

/**
     * @throws Exception If failed.
     */
public void testTopologyChange() throws Exception {
    ComputeTaskSession ses = new GridTestTaskSession(IgniteUuid.randomUuid());
    // Warm up.
    List<ClusterNode> allNodes = (List<ClusterNode>) getSpiContext().nodes();
    List<UUID> orderedNodes = getSpi().getNodeIds(ses);
    checkCyclicBalancing(getSpi(), allNodes, orderedNodes, ses);
    // Remove node.
    UUID doomed = orderedNodes.get(0);
    if (getSpiContext().localNode().id().equals(doomed))
        doomed = orderedNodes.get(1);
    getSpiContext().removeNode(doomed);
    assertTrue(allNodes.remove(new GridTestNode(doomed)));
    orderedNodes = getSpi().getNodeIds(ses);
    assertFalse("Balancer uses removed node", orderedNodes.contains(doomed));
    checkCyclicBalancing(getSpi(), allNodes, orderedNodes, ses);
    // Add node.
    ClusterNode newNode = new GridTestNode(UUID.randomUUID());
    getSpiContext().addNode(newNode);
    assertTrue(allNodes.add(newNode));
    // Check that new node was added to balancing.
    boolean foundNewNode = false;
    for (int i = 0; i < allNodes.size(); i++) {
        ClusterNode node = getSpi().getBalancedNode(ses, allNodes, new GridTestJob());
        if (newNode.id().equals(node.id())) {
            foundNewNode = true;
            break;
        }
    }
    assertTrue("Balancer doesn't use added node", foundNewNode);
    orderedNodes = getSpi().getNodeIds(ses);
    checkCyclicBalancing(getSpi(), allNodes, orderedNodes, ses);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestTaskSession(org.apache.ignite.GridTestTaskSession) List(java.util.List) UUID(java.util.UUID) GridTestJob(org.apache.ignite.GridTestJob) ComputeTaskSession(org.apache.ignite.compute.ComputeTaskSession) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 42 with GridTestNode

use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.

the class GridTopologyHeapSizeSelfTest method testTopologyHeapSizeForNodesWithDifferentPids.

/** */
public void testTopologyHeapSizeForNodesWithDifferentPids() {
    GridTestNode node1 = getNode("123456789ABC", 1000);
    GridTestNode node2 = getNode("123456789ABC", 1001);
    double size1 = U.heapSize(node1, 10);
    double size2 = U.heapSize(node2, 10);
    double allSize = U.heapSize(F.asList((ClusterNode) node1, node2), 10);
    assertEquals(size1 + size2, allSize, 1E-5);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 43 with GridTestNode

use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.

the class AbstractAffinityFunctionSelfTest method checkNodeRemoved.

/**
     * @throws Exception If failed.
     */
protected void checkNodeRemoved(int backups, int neighborsPerHost, int neighborsPeriod) throws Exception {
    AffinityFunction aff = affinityFunction();
    int nodesCnt = 50;
    List<ClusterNode> nodes = new ArrayList<>(nodesCnt);
    List<List<ClusterNode>> prev = null;
    for (int i = 0; i < nodesCnt; i++) {
        info("======================================");
        info("Assigning partitions: " + i);
        info("======================================");
        ClusterNode node = new GridTestNode(UUID.randomUUID());
        if (neighborsPerHost > 0)
            node.attribute(MAC_PREF + ((i / neighborsPeriod) % (nodesCnt / neighborsPerHost)));
        nodes.add(node);
        DiscoveryEvent discoEvt = new DiscoveryEvent(node, "", EventType.EVT_NODE_JOINED, node);
        GridAffinityFunctionContextImpl ctx = new GridAffinityFunctionContextImpl(nodes, prev, discoEvt, new AffinityTopologyVersion(i), backups);
        List<List<ClusterNode>> assignment = aff.assignPartitions(ctx);
        info("Assigned.");
        verifyAssignment(assignment, backups, aff.partitions(), nodes.size());
        prev = assignment;
    }
    info("======================================");
    info("Will remove nodes.");
    info("======================================");
    for (int i = 0; i < nodesCnt - 1; i++) {
        info("======================================");
        info("Assigning partitions: " + i);
        info("======================================");
        ClusterNode rmv = nodes.remove(nodes.size() - 1);
        DiscoveryEvent discoEvt = new DiscoveryEvent(rmv, "", EventType.EVT_NODE_LEFT, rmv);
        List<List<ClusterNode>> assignment = aff.assignPartitions(new GridAffinityFunctionContextImpl(nodes, prev, discoEvt, new AffinityTopologyVersion(i), backups));
        info("Assigned.");
        verifyAssignment(assignment, backups, aff.partitions(), nodes.size());
        prev = assignment;
    }
}
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) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) ArrayList(java.util.ArrayList) List(java.util.List) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Aggregations

GridTestNode (org.apache.ignite.testframework.GridTestNode)43 ClusterNode (org.apache.ignite.cluster.ClusterNode)27 GridSpiTestContext (org.apache.ignite.testframework.GridSpiTestContext)17 GridTestTaskSession (org.apache.ignite.GridTestTaskSession)14 ArrayList (java.util.ArrayList)11 GridTestJob (org.apache.ignite.GridTestJob)9 HashMap (java.util.HashMap)7 IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)7 Map (java.util.Map)5 GridTestJobResult (org.apache.ignite.GridTestJobResult)5 GridFailoverTestContext (org.apache.ignite.spi.failover.GridFailoverTestContext)5 Serializable (java.io.Serializable)4 List (java.util.List)4 ComputeTaskSession (org.apache.ignite.compute.ComputeTaskSession)4 ClusterMetricsSnapshot (org.apache.ignite.internal.ClusterMetricsSnapshot)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)3 GridAffinityFunctionContextImpl (org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl)3 Message (org.apache.ignite.plugin.extensions.communication.Message)3 CollisionJobContext (org.apache.ignite.spi.collision.CollisionJobContext)3