Search in sources :

Example 21 with GridTestCollisionJobContext

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollisionWithoutPriorityAttribute.

/**
 * @throws Exception If failed.
 */
public void testCollisionWithoutPriorityAttribute() throws Exception {
    List<CollisionJobContext> activeJobs = makeContextList(null);
    List<CollisionJobContext> passiveJobs = makeContextList(null);
    for (CollisionJobContext ctx : passiveJobs) {
        if (((GridTestCollisionTaskSession) ctx.getTaskSession()).getPriority() >= 8) {
            ((GridTestCollisionTaskSession) ctx.getTaskSession()).setPriorityAttributeKey("bad-attr-name");
            ((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 null;
                    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 22 with GridTestCollisionJobContext

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollision0.

/**
 * @throws Exception If failed.
 */
public void testCollision0() throws Exception {
    List<CollisionJobContext> activeJobs = makeContextList(null);
    List<CollisionJobContext> passiveJobs = makeContextList(null);
    getSpi().setParallelJobsNumber(30);
    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) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext)

Example 23 with GridTestCollisionJobContext

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollision1.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings({ "RedundantTypeArguments" })
public void testCollision1() throws Exception {
    List<CollisionJobContext> activeJobs = makeContextList(null);
    List<CollisionJobContext> passiveJobs = makeContextList(null);
    getSpi().setParallelJobsNumber(12);
    getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
    int incVal = getSpi().getStarvationIncrement();
    String jobAttrKey = DFLT_JOB_PRIORITY_ATTRIBUTE_KEY;
    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();
        }
        Integer p = ctx.getJobContext().<String, Integer>getAttribute(jobAttrKey);
        if (p != null)
            assert p == incVal + ((GridTestCollisionTaskSession) ctx.getTaskSession()).getPriority();
    }
    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) 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