Search in sources :

Example 1 with GridCollisionTestContext

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollisionAttributeName.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings({ "TooBroadScope" })
@Test
public void testCollisionAttributeName() throws Exception {
    String taskAttrKey = "testTaskPriority";
    String jobAttrKey = "testJobPriority";
    List<CollisionJobContext> activeJobs = makeContextList(taskAttrKey);
    List<CollisionJobContext> passiveJobs = makeContextList(taskAttrKey);
    getSpi().setParallelJobsNumber(12);
    getSpi().setPriorityAttributeKey(taskAttrKey);
    getSpi().setJobPriorityAttributeKey(jobAttrKey);
    getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
    int incVal = getSpi().getStarvationIncrement();
    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().getAttribute(jobAttrKey);
        if (p != null)
            assert p == incVal + ((GridTestCollisionTaskSession) ctx.getTaskSession()).getPriority();
    }
    for (CollisionJobContext ctx : activeJobs) {
        assert !((GridTestCollisionJobContext) ctx).isActivated();
        assert !((GridTestCollisionJobContext) ctx).isCanceled();
    }
    getSpi().setPriorityAttributeKey(DFLT_PRIORITY_ATTRIBUTE_KEY);
    getSpi().setJobPriorityAttributeKey(DFLT_JOB_PRIORITY_ATTRIBUTE_KEY);
}
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) GridSpiAbstractTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest) Test(org.junit.Test) GridSpiTest(org.apache.ignite.testframework.junits.spi.GridSpiTest)

Example 2 with GridCollisionTestContext

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollisionEmpty.

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

Example 3 with GridCollisionTestContext

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

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollision.

/**
 * @throws Exception If failed.
 */
@Test
public void testCollision() throws Exception {
    List<CollisionJobContext> activeJobs = makeContextList(null);
    List<CollisionJobContext> passiveJobs = makeContextList(null);
    getSpi().setParallelJobsNumber(20);
    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) GridSpiAbstractTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest) Test(org.junit.Test) GridSpiTest(org.apache.ignite.testframework.junits.spi.GridSpiTest)

Example 5 with GridCollisionTestContext

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollision3.

/**
 * @throws Exception If failed.
 */
@Test
public void testCollision3() throws Exception {
    List<CollisionJobContext> activeJobs = makeContextList(null);
    List<CollisionJobContext> passiveJobs = makeContextList(null);
    getSpi().setParallelJobsNumber(5);
    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) 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)32 GridCollisionTestContext (org.apache.ignite.spi.collision.GridCollisionTestContext)32 GridSpiAbstractTest (org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest)31 GridSpiTest (org.apache.ignite.testframework.junits.spi.GridSpiTest)31 Test (org.junit.Test)31 GridTestCollisionJobContext (org.apache.ignite.spi.collision.GridTestCollisionJobContext)25 Serializable (java.io.Serializable)16 ClusterNode (org.apache.ignite.cluster.ClusterNode)13 ArrayList (java.util.ArrayList)9 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 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1