Search in sources :

Example 21 with GridCollisionTestContext

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

the class GridJobStealingCollisionSpiSelfTest method testMaxHopsExceeded.

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

Example 22 with GridCollisionTestContext

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollision1.

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

Example 23 with GridCollisionTestContext

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollision0.

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

Example 24 with GridCollisionTestContext

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

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollision2.

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