Search in sources :

Example 1 with GridTestCollisionTaskSession

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollision4.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings({ "TooBroadScope" })
@Test
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) GridSpiAbstractTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest) Test(org.junit.Test) GridSpiTest(org.apache.ignite.testframework.junits.spi.GridSpiTest)

Example 2 with GridTestCollisionTaskSession

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollision5.

/**
 * @throws Exception If failed.
 */
@Test
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) GridSpiAbstractTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest) Test(org.junit.Test) GridSpiTest(org.apache.ignite.testframework.junits.spi.GridSpiTest)

Example 3 with GridTestCollisionTaskSession

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

the class GridFifoQueueCollisionSpiSelfTest method createContext.

/**
 * Prepare test context.
 *
 * @param activeNum Number of active jobs in context.
 * @param passiveNum Number of passive jobs in context.
 * @return New context with the given numbers of jobs, which will update when one of jobs get activated.
 */
private GridCollisionTestContext createContext(int activeNum, int passiveNum) {
    final Collection<CollisionJobContext> activeJobs = new ConcurrentLinkedQueue<>();
    for (int i = 0; i < activeNum; i++) activeJobs.add(new GridTestCollisionJobContext(new GridTestCollisionTaskSession(), i));
    final Collection<CollisionJobContext> passiveJobs = new ConcurrentLinkedQueue<>();
    for (int i = 0; i < passiveNum; i++) passiveJobs.add(new GridTestCollisionJobContext(new GridTestCollisionTaskSession(), i, new CI1<GridTestCollisionJobContext>() {

        @Override
        public void apply(GridTestCollisionJobContext c) {
            passiveJobs.remove(c);
            activeJobs.add(c);
        }
    }));
    return new GridCollisionTestContext(activeJobs, passiveJobs);
}
Also used : GridTestCollisionTaskSession(org.apache.ignite.spi.collision.GridTestCollisionTaskSession) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext) GridCollisionTestContext(org.apache.ignite.spi.collision.GridCollisionTestContext) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext)

Example 4 with GridTestCollisionTaskSession

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollisionWithoutPriorityAttribute.

/**
 * @throws Exception If failed.
 */
@Test
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({ "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) GridSpiAbstractTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest) Test(org.junit.Test) GridSpiTest(org.apache.ignite.testframework.junits.spi.GridSpiTest)

Example 5 with GridTestCollisionTaskSession

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollisionWithWrongPriorityAttribute.

/**
 * @throws Exception If failed.
 */
@Test
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) {

                @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({ "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) GridSpiAbstractTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest) Test(org.junit.Test) GridSpiTest(org.apache.ignite.testframework.junits.spi.GridSpiTest)

Aggregations

CollisionJobContext (org.apache.ignite.spi.collision.CollisionJobContext)5 GridCollisionTestContext (org.apache.ignite.spi.collision.GridCollisionTestContext)5 GridTestCollisionJobContext (org.apache.ignite.spi.collision.GridTestCollisionJobContext)5 GridTestCollisionTaskSession (org.apache.ignite.spi.collision.GridTestCollisionTaskSession)5 GridSpiAbstractTest (org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest)4 GridSpiTest (org.apache.ignite.testframework.junits.spi.GridSpiTest)4 Test (org.junit.Test)4 GridTestJobContext (org.apache.ignite.GridTestJobContext)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1