Search in sources :

Example 1 with GridTestJobContext

use of org.apache.ignite.GridTestJobContext 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 2 with GridTestJobContext

use of org.apache.ignite.GridTestJobContext 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)

Aggregations

GridTestJobContext (org.apache.ignite.GridTestJobContext)2 CollisionJobContext (org.apache.ignite.spi.collision.CollisionJobContext)2 GridCollisionTestContext (org.apache.ignite.spi.collision.GridCollisionTestContext)2 GridTestCollisionJobContext (org.apache.ignite.spi.collision.GridTestCollisionJobContext)2 GridTestCollisionTaskSession (org.apache.ignite.spi.collision.GridTestCollisionTaskSession)2