Search in sources :

Example 16 with GridTestCollisionJobContext

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

the class GridJobStealingCollisionSpiSelfTest method testTwoPassiveJobs.

/**
 * @throws Exception If test failed.
 */
public void testTwoPassiveJobs() throws Exception {
    final List<CollisionJobContext> waitCtxs = new ArrayList<>(2);
    final List<CollisionJobContext> activeCtxs = new ArrayList<>(1);
    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));
    ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Activated.
    checkActivated((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) 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 17 with GridTestCollisionJobContext

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

the class GridJobStealingCollisionSpiSelfTest method testZeroPassiveOneActive.

/**
 * @throws Exception If test failed.
 */
public void testZeroPassiveOneActive() throws Exception {
    Collection<CollisionJobContext> empty = Collections.emptyList();
    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, empty));
    // Active job.
    checkNoAction((GridTestCollisionJobContext) activeCtxs.get(0));
    // 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 18 with GridTestCollisionJobContext

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

the class GridJobStealingCollisionSpiSelfTest method testMaxHopsExceeded.

/**
 * @throws Exception If test failed.
 */
public void testMaxHopsExceeded() throws Exception {
    Collection<CollisionJobContext> waitCtxs = new ArrayList<>(2);
    GridTestCollisionJobContext excluded = new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid());
    GridTestCollisionJobContext ctx1 = new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid());
    GridTestCollisionJobContext ctx2 = new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid());
    Collections.addAll(waitCtxs, ctx1, excluded, ctx2);
    Collection<CollisionJobContext> activeCtxs = new ArrayList<>(1);
    // Add active.
    Collections.addAll(activeCtxs, new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid()));
    ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
    // Exceed hops.
    excluded.getJobContext().setAttribute(STEALING_ATTEMPT_COUNT_ATTR, 1);
    // Emulate message to steal 2 jobs.
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(2));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Make sure that none happened to 1st job.
    checkNoAction(excluded);
    // Rejected.
    checkRejected(ctx1, rmtNode);
    checkRejected(ctx2, 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 19 with GridTestCollisionJobContext

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollisionWithWrongPriorityAttribute.

/**
 * @throws Exception If failed.
 */
public void testCollisionWithWrongPriorityAttribute() throws Exception {
    List<CollisionJobContext> activeJobs = makeContextList(null);
    List<CollisionJobContext> passiveJobs = makeContextList(null);
    for (CollisionJobContext ctx : passiveJobs) {
        if (((GridTestCollisionTaskSession) ctx.getTaskSession()).getPriority() >= 8) {
            ((GridTestCollisionJobContext) ctx).setTaskSession(new GridTestCollisionTaskSession(100, DFLT_PRIORITY_ATTRIBUTE_KEY) {

                @SuppressWarnings("unchecked")
                @Override
                public <K, V> V getAttribute(K key) {
                    if (getPriorityAttributeKey() != null && getPriorityAttributeKey().equals(key))
                        return (V) "wrong-attr";
                    return null;
                }
            });
            ((GridTestCollisionJobContext) ctx).setJobContext(new GridTestJobContext() {

                @SuppressWarnings({ "unchecked", "RedundantTypeArguments" })
                @Override
                public <K, V> V getAttribute(K key) {
                    if (DFLT_JOB_PRIORITY_ATTRIBUTE_KEY.equals(key))
                        return (V) "wrong-attr";
                    return super.<K, V>getAttribute(key);
                }
            });
        }
    }
    getSpi().setParallelJobsNumber(12);
    getSpi().setDefaultPriority(100);
    getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
    for (CollisionJobContext ctx : passiveJobs) {
        if (((GridTestCollisionTaskSession) ctx.getTaskSession()).getPriority() >= 8) {
            assert ((GridTestCollisionJobContext) ctx).isActivated();
            assert !((GridTestCollisionJobContext) ctx).isCanceled();
        } else {
            assert !((GridTestCollisionJobContext) ctx).isActivated();
            assert !((GridTestCollisionJobContext) ctx).isCanceled();
        }
    }
    for (CollisionJobContext ctx : activeJobs) {
        assert !((GridTestCollisionJobContext) ctx).isActivated();
        assert !((GridTestCollisionJobContext) ctx).isCanceled();
    }
}
Also used : GridTestCollisionTaskSession(org.apache.ignite.spi.collision.GridTestCollisionTaskSession) GridTestJobContext(org.apache.ignite.GridTestJobContext) 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 20 with GridTestCollisionJobContext

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollision2.

/**
 * @throws Exception If failed.
 */
public void testCollision2() throws Exception {
    List<CollisionJobContext> activeJobs = makeContextList(null);
    List<CollisionJobContext> passiveJobs = makeContextList(null);
    getSpi().setParallelJobsNumber(10);
    getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
    for (CollisionJobContext ctx : passiveJobs) {
        assert !((GridTestCollisionJobContext) ctx).isActivated();
        assert !((GridTestCollisionJobContext) ctx).isCanceled();
    }
    for (CollisionJobContext ctx : activeJobs) {
        assert !((GridTestCollisionJobContext) ctx).isActivated();
        assert !((GridTestCollisionJobContext) ctx).isCanceled();
    }
}
Also used : GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) GridCollisionTestContext(org.apache.ignite.spi.collision.GridCollisionTestContext)

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