Search in sources :

Example 11 with CollisionJobContext

use of org.apache.ignite.spi.collision.CollisionJobContext 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 12 with CollisionJobContext

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollisionEmpty.

/**
     * @throws Exception If failed.
     */
public void testCollisionEmpty() throws Exception {
    Collection<CollisionJobContext> activeJobs = new ArrayList<>();
    Collection<CollisionJobContext> passiveJobs = new ArrayList<>();
    getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
    assert activeJobs.isEmpty();
    assert passiveJobs.isEmpty();
}
Also used : 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)

Example 13 with CollisionJobContext

use of org.apache.ignite.spi.collision.CollisionJobContext 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)

Example 14 with CollisionJobContext

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

the class GridJobStealingCollisionSpiSelfTest method testMultiplePassiveZeroActive.

/**
     * @throws Exception If test failed.
     */
public void testMultiplePassiveZeroActive() throws Exception {
    final List<CollisionJobContext> waitCtxs = new ArrayList<>(2);
    final List<CollisionJobContext> activeCtxs = new ArrayList<>(2);
    CI1<GridTestCollisionJobContext> lsnr = new CI1<GridTestCollisionJobContext>() {

        @Override
        public void apply(GridTestCollisionJobContext c) {
            if (waitCtxs.remove(c))
                activeCtxs.add(c);
        }
    };
    Collections.addAll(waitCtxs, new GridTestCollisionJobContext(createTaskSession(), 1, lsnr), new GridTestCollisionJobContext(createTaskSession(), 2, lsnr), new GridTestCollisionJobContext(createTaskSession(), 3, lsnr));
    ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
    // Emulate message to steal 2 jobs.
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(2));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Make sure that one job got activated.
    checkActivated((GridTestCollisionJobContext) activeCtxs.get(0));
    // Rejected.
    checkRejected((GridTestCollisionJobContext) waitCtxs.get(0), rmtNode);
    checkRejected((GridTestCollisionJobContext) waitCtxs.get(1), 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) CI1(org.apache.ignite.internal.util.typedef.CI1) 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 15 with CollisionJobContext

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

the class GridJobStealingCollisionSpiSelfTest method testZeroPassiveZeroActive.

/**
     * @throws Exception If test failed.
     */
public void testZeroPassiveZeroActive() throws Exception {
    Collection<CollisionJobContext> empty = Collections.emptyList();
    getSpi().onCollision(new GridCollisionTestContext(empty, empty));
    ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
    JobStealingRequest sentMsg = (JobStealingRequest) getSpiContext().getSentMessage(rmtNode);
    assert sentMsg != null;
    assert sentMsg.delta() == 1 : "Invalid sent message: " + sentMsg;
    Serializable msg = getSpiContext().removeSentMessage(rmtNode);
    assert msg != null;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Serializable(java.io.Serializable) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext) GridCollisionTestContext(org.apache.ignite.spi.collision.GridCollisionTestContext)

Aggregations

CollisionJobContext (org.apache.ignite.spi.collision.CollisionJobContext)35 GridCollisionTestContext (org.apache.ignite.spi.collision.GridCollisionTestContext)32 GridTestCollisionJobContext (org.apache.ignite.spi.collision.GridTestCollisionJobContext)25 Serializable (java.io.Serializable)16 ClusterNode (org.apache.ignite.cluster.ClusterNode)13 ArrayList (java.util.ArrayList)10 GridTestCollisionTaskSession (org.apache.ignite.spi.collision.GridTestCollisionTaskSession)5 GridTestNode (org.apache.ignite.testframework.GridTestNode)3 GridTestJobContext (org.apache.ignite.GridTestJobContext)2 CI1 (org.apache.ignite.internal.util.typedef.CI1)2 Iterator (java.util.Iterator)1 Entry (java.util.Map.Entry)1 UUID (java.util.UUID)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteSpiContext (org.apache.ignite.spi.IgniteSpiContext)1