Search in sources :

Example 6 with GridTestNode

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

the class GridJobStealingCollisionSpiAttributesSelfTest method testDiffAttribute.

/**
    * @throws Exception If test failed.
    */
public void testDiffAttribute() throws Exception {
    List<CollisionJobContext> waitCtxs = Collections.emptyList();
    Collection<CollisionJobContext> activeCtxs = Collections.emptyList();
    GridTestNode rmtNode = (GridTestNode) F.first(getSpiContext().remoteNodes());
    rmtNode.setAttribute("useCollision1", true);
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
    // Set up the same attribute and value as for remote node.
    getSpi().setStealingAttributes(F.asMap("useCollision2", true));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Cleanup
    rmtNode.removeAttribute("useCollision1");
    // Set up the same attribute and value as for remote node.
    getSpi().setStealingAttributes(Collections.<String, Serializable>emptyMap());
    // Make sure that no message was sent.
    Serializable msg = getSpiContext().removeSentMessage(rmtNode);
    // attributes.
    assert msg == null;
}
Also used : Serializable(java.io.Serializable) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) GridCollisionTestContext(org.apache.ignite.spi.collision.GridCollisionTestContext) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 7 with GridTestNode

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

the class GridJobStealingCollisionSpiStartStopSelfTest method initSpiContext.

/** {@inheritDoc} */
@Override
protected GridSpiTestContext initSpiContext() throws Exception {
    GridSpiTestContext ctx = super.initSpiContext();
    GridTestNode locNode = new GridTestNode(UUID.randomUUID());
    addSpiDependency(locNode);
    ctx.setLocalNode(locNode);
    return ctx;
}
Also used : GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 8 with GridTestNode

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

the class AbstractAffinityFunctionSelfTest method checkRandomReassignment.

/**
     * @param backups Backups.
     */
protected void checkRandomReassignment(int backups) {
    AffinityFunction aff = affinityFunction();
    Random rnd = new Random();
    int maxNodes = 50;
    List<ClusterNode> nodes = new ArrayList<>(maxNodes);
    List<List<ClusterNode>> prev = null;
    int state = 0;
    int i = 0;
    while (true) {
        boolean add;
        if (nodes.size() < 2) {
            // Returned back to one node?
            if (state == 1)
                return;
            add = true;
        } else if (nodes.size() == maxNodes) {
            if (state == 0)
                state = 1;
            add = false;
        } else {
            // Nodes size in [2, maxNodes - 1].
            if (state == 0)
                // 66% to add, 33% to remove.
                add = rnd.nextInt(3) != 0;
            else
                // 33% to add, 66% to remove.
                add = rnd.nextInt(3) == 0;
        }
        DiscoveryEvent discoEvt;
        if (add) {
            ClusterNode addedNode = new GridTestNode(UUID.randomUUID());
            nodes.add(addedNode);
            discoEvt = new DiscoveryEvent(addedNode, "", EventType.EVT_NODE_JOINED, addedNode);
        } else {
            ClusterNode rmvNode = nodes.remove(rnd.nextInt(nodes.size()));
            discoEvt = new DiscoveryEvent(rmvNode, "", EventType.EVT_NODE_LEFT, rmvNode);
        }
        info("======================================");
        info("Assigning partitions [iter=" + i + ", discoEvt=" + discoEvt + ", nodesSize=" + nodes.size() + ']');
        info("======================================");
        List<List<ClusterNode>> assignment = aff.assignPartitions(new GridAffinityFunctionContextImpl(nodes, prev, discoEvt, new AffinityTopologyVersion(i), backups));
        verifyAssignment(assignment, backups, aff.partitions(), nodes.size());
        prev = assignment;
        i++;
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) ArrayList(java.util.ArrayList) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridTestNode(org.apache.ignite.testframework.GridTestNode) GridAffinityFunctionContextImpl(org.apache.ignite.internal.processors.affinity.GridAffinityFunctionContextImpl) Random(java.util.Random) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with GridTestNode

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

the class GridTopologyHeapSizeSelfTest method testTopologyHeapSizeForNodesWithDifferentMacs.

/** */
public void testTopologyHeapSizeForNodesWithDifferentMacs() {
    GridTestNode node1 = getNode("123456789ABC", 1000);
    GridTestNode node2 = getNode("CBA987654321", 1000);
    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 10 with GridTestNode

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

the class GridTopologyHeapSizeSelfTest method getNode.

/**
     * Creates test node with specified attributes.
     *
     * @param mac Node mac addresses.
     * @param pid Node PID.
     * @return Node.
     */
private GridTestNode getNode(String mac, int pid) {
    ClusterMetricsSnapshot metrics = new ClusterMetricsSnapshot();
    metrics.setHeapMemoryMaximum(1024 * 1024 * 1024);
    metrics.setHeapMemoryInitialized(1024 * 1024 * 1024);
    GridTestNode node = new GridTestNode(UUID.randomUUID(), metrics);
    node.addAttribute(ATTR_MACS, mac);
    node.addAttribute(ATTR_JVM_PID, pid);
    return node;
}
Also used : ClusterMetricsSnapshot(org.apache.ignite.internal.ClusterMetricsSnapshot) 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