Search in sources :

Example 1 with GridTestCollisionJobContext

use of org.apache.ignite.spi.collision.GridTestCollisionJobContext in project ignite by apache.

the class GridJobStealingCollisionSpiCustomTopologySelfTest method testThiefNodeNotInTopology.

/**
     * @throws Exception If test failed.
     */
public void testThiefNodeNotInTopology() throws Exception {
    List<CollisionJobContext> waitCtxs = new ArrayList<>(2);
    final ClusterNode node = getSpiContext().nodes().iterator().next();
    Collections.addAll(waitCtxs, new GridTestCollisionJobContext(createTaskSession(node), IgniteUuid.randomUuid()), new GridTestCollisionJobContext(createTaskSession(node), IgniteUuid.randomUuid()), new GridTestCollisionJobContext(createTaskSession(node), IgniteUuid.randomUuid()));
    Collection<CollisionJobContext> activeCtxs = new ArrayList<>(1);
    // Add active.
    Collections.addAll(activeCtxs, new GridTestCollisionJobContext(createTaskSession(node), IgniteUuid.randomUuid()));
    // Emulate message to steal 2 jobs.
    getSpiContext().triggerMessage(rmtNode2, new JobStealingRequest(2));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Check no action.
    checkNoAction((GridTestCollisionJobContext) waitCtxs.get(0));
    checkNoAction((GridTestCollisionJobContext) waitCtxs.get(1));
    checkNoAction((GridTestCollisionJobContext) waitCtxs.get(2));
    // Make sure that no message was sent.
    Serializable msg1 = getSpiContext().removeSentMessage(getSpiContext().localNode());
    assert msg1 == null;
    Serializable mgs2 = getSpiContext().removeSentMessage(rmtNode1);
    assert mgs2 == null;
    Serializable msg3 = getSpiContext().removeSentMessage(rmtNode2);
    assert msg3 == null;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) GridCollisionTestContext(org.apache.ignite.spi.collision.GridCollisionTestContext) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext)

Example 2 with GridTestCollisionJobContext

use of org.apache.ignite.spi.collision.GridTestCollisionJobContext in project ignite by apache.

the class GridJobStealingCollisionSpiSelfTest method testOnePassiveOneActiveJobs.

/**
     * @throws Exception If test failed.
     */
public void testOnePassiveOneActiveJobs() throws Exception {
    List<CollisionJobContext> waitCtxs = new ArrayList<>(1);
    // Add passive.
    Collections.addAll(waitCtxs, new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid()));
    List<CollisionJobContext> activeCtxs = new ArrayList<>(1);
    // Add active.
    Collections.addAll(activeCtxs, new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid()));
    ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Active job.
    checkNoAction((GridTestCollisionJobContext) activeCtxs.get(0));
    // Rejected.
    checkRejected((GridTestCollisionJobContext) waitCtxs.get(0), rmtNode);
    // Make sure that no message was sent.
    Serializable msg = getSpiContext().removeSentMessage(rmtNode);
    assert msg == null;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext) GridCollisionTestContext(org.apache.ignite.spi.collision.GridCollisionTestContext) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext)

Example 3 with GridTestCollisionJobContext

use of org.apache.ignite.spi.collision.GridTestCollisionJobContext in project ignite by apache.

the class GridJobStealingCollisionSpiSelfTest method testMultiplePassiveOneActive.

/**
     * @throws Exception If test failed.
     */
public void testMultiplePassiveOneActive() throws Exception {
    List<CollisionJobContext> waitCtxs = new ArrayList<>(2);
    Collections.addAll(waitCtxs, new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid()), new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid()), new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid()));
    Collection<CollisionJobContext> activeCtxs = new ArrayList<>(1);
    // Add active.
    Collections.addAll(activeCtxs, new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid()));
    ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
    // Emulate message to steal 2 jobs.
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(2));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Rejected.
    checkRejected((GridTestCollisionJobContext) waitCtxs.get(0), rmtNode);
    checkRejected((GridTestCollisionJobContext) waitCtxs.get(1), rmtNode);
    // Check no action.
    checkNoAction((GridTestCollisionJobContext) waitCtxs.get(2));
    // Make sure that no message was sent.
    Serializable msg = getSpiContext().removeSentMessage(rmtNode);
    assert msg == null;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext) GridCollisionTestContext(org.apache.ignite.spi.collision.GridCollisionTestContext) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext)

Example 4 with GridTestCollisionJobContext

use of org.apache.ignite.spi.collision.GridTestCollisionJobContext in project ignite by apache.

the class GridPriorityQueueCollisionSpiSelfTest method testCollision4.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings({ "TooBroadScope" })
public void testCollision4() throws Exception {
    List<CollisionJobContext> activeJobs = makeContextList(null, false);
    List<CollisionJobContext> passiveJobs = makeContextList(null, false);
    int incVal = 2;
    getSpi().setParallelJobsNumber(12);
    getSpi().setStarvationIncrement(incVal);
    getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
    String jobAttrKey = DFLT_JOB_PRIORITY_ATTRIBUTE_KEY;
    for (CollisionJobContext ctx : passiveJobs) {
        int taskP = ((GridTestCollisionTaskSession) ctx.getTaskSession()).getPriority();
        if (taskP >= 8) {
            assert ((GridTestCollisionJobContext) ctx).isActivated();
            assert !((GridTestCollisionJobContext) ctx).isCanceled();
        } else {
            assert !((GridTestCollisionJobContext) ctx).isActivated();
            assert !((GridTestCollisionJobContext) ctx).isCanceled();
        }
        if (taskP < 5) {
            Integer p = ctx.getJobContext().getAttribute(jobAttrKey);
            assert p != null;
            assert p == incVal + taskP;
        }
    }
    for (CollisionJobContext ctx : activeJobs) {
        assert !((GridTestCollisionJobContext) ctx).isActivated();
        assert !((GridTestCollisionJobContext) ctx).isCanceled();
    }
    getSpi().setStarvationIncrement(DFLT_STARVATION_INCREMENT);
}
Also used : GridTestCollisionTaskSession(org.apache.ignite.spi.collision.GridTestCollisionTaskSession) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) GridCollisionTestContext(org.apache.ignite.spi.collision.GridCollisionTestContext) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext)

Example 5 with GridTestCollisionJobContext

use of org.apache.ignite.spi.collision.GridTestCollisionJobContext in project ignite by apache.

the class GridPriorityQueueCollisionSpiSelfTest method testCollision5.

/**
     * @throws Exception If failed.
     */
public void testCollision5() throws Exception {
    List<CollisionJobContext> activeJobs = makeContextList(null, false);
    List<CollisionJobContext> passiveJobs = makeContextList(null, false);
    getSpi().setParallelJobsNumber(12);
    getSpi().setStarvationPreventionEnabled(false);
    getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
    String jobAttrKey = DFLT_JOB_PRIORITY_ATTRIBUTE_KEY;
    for (CollisionJobContext ctx : passiveJobs) {
        int taskP = ((GridTestCollisionTaskSession) ctx.getTaskSession()).getPriority();
        if (taskP >= 8) {
            assert ((GridTestCollisionJobContext) ctx).isActivated();
            assert !((GridTestCollisionJobContext) ctx).isCanceled();
        } else {
            assert !((GridTestCollisionJobContext) ctx).isActivated();
            assert !((GridTestCollisionJobContext) ctx).isCanceled();
        }
        assert ctx.getJobContext().<String, Integer>getAttribute(jobAttrKey) == null;
    }
    for (CollisionJobContext ctx : activeJobs) {
        assert !((GridTestCollisionJobContext) ctx).isActivated();
        assert !((GridTestCollisionJobContext) ctx).isCanceled();
    }
}
Also used : GridTestCollisionTaskSession(org.apache.ignite.spi.collision.GridTestCollisionTaskSession) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) GridCollisionTestContext(org.apache.ignite.spi.collision.GridCollisionTestContext) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext)

Aggregations

CollisionJobContext (org.apache.ignite.spi.collision.CollisionJobContext)23 GridCollisionTestContext (org.apache.ignite.spi.collision.GridCollisionTestContext)23 GridTestCollisionJobContext (org.apache.ignite.spi.collision.GridTestCollisionJobContext)23 Serializable (java.io.Serializable)8 ArrayList (java.util.ArrayList)8 ClusterNode (org.apache.ignite.cluster.ClusterNode)8 GridTestCollisionTaskSession (org.apache.ignite.spi.collision.GridTestCollisionTaskSession)5 GridTestJobContext (org.apache.ignite.GridTestJobContext)2 CI1 (org.apache.ignite.internal.util.typedef.CI1)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1