Search in sources :

Example 11 with GridTestCollisionJobContext

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

the class GridFifoQueueCollisionSpiSelfTest method testCollision0.

/**
 * @throws Exception If failed.
 */
public void testCollision0() throws Exception {
    int activeCnt = 2;
    assert getSpi().getParallelJobsNumber() > activeCnt;
    GridCollisionTestContext cntx = createContext(activeCnt, getSpi().getParallelJobsNumber() - activeCnt);
    Collection<CollisionJobContext> activeJobs = cntx.activeJobs();
    Collection<CollisionJobContext> passiveJobs = cntx.waitingJobs();
    getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
    for (CollisionJobContext ctx : passiveJobs) {
        assert ((GridTestCollisionJobContext) ctx).isActivated();
        assert !((GridTestCollisionJobContext) ctx).isCanceled();
    }
    int i = 0;
    for (CollisionJobContext ctx : activeJobs) {
        if (i++ < activeCnt)
            assert !((GridTestCollisionJobContext) ctx).isActivated() : i;
        else
            assert ((GridTestCollisionJobContext) ctx).isActivated() : i;
        assert !((GridTestCollisionJobContext) ctx).isCanceled();
    }
}
Also used : GridCollisionTestContext(org.apache.ignite.spi.collision.GridCollisionTestContext) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext)

Example 12 with GridTestCollisionJobContext

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

the class GridFifoQueueCollisionSpiSelfTest method testCollision1.

/**
 * @throws Exception If failed.
 */
public void testCollision1() throws Exception {
    getSpi().setParallelJobsNumber(32);
    GridCollisionTestContext cntx = createContext(0, 33);
    Collection<CollisionJobContext> activeJobs = cntx.activeJobs();
    Collection<CollisionJobContext> passiveJobs = cntx.waitingJobs();
    getSpi().onCollision(cntx);
    for (CollisionJobContext ctx : passiveJobs) {
        if (((GridTestCollisionJobContext) ctx).getIndex() == 32) {
            assert !((GridTestCollisionJobContext) ctx).isActivated();
            assert !((GridTestCollisionJobContext) ctx).isCanceled();
        } else {
            assert ((GridTestCollisionJobContext) ctx).isActivated();
            assert !((GridTestCollisionJobContext) ctx).isCanceled();
        }
    }
    assert activeJobs.size() == 32;
}
Also used : GridCollisionTestContext(org.apache.ignite.spi.collision.GridCollisionTestContext) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext)

Example 13 with GridTestCollisionJobContext

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

the class GridFifoQueueCollisionSpiSelfTest method testCollision2.

/**
 * @throws Exception If failed.
 */
public void testCollision2() throws Exception {
    getSpi().setParallelJobsNumber(3);
    GridCollisionTestContext cntx = createContext(11, 0);
    Collection<CollisionJobContext> activeJobs = cntx.activeJobs();
    Collection<CollisionJobContext> passiveJobs = cntx.waitingJobs();
    getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
    for (CollisionJobContext ctx : activeJobs) {
        assert !((GridTestCollisionJobContext) ctx).isActivated();
        assert !((GridTestCollisionJobContext) ctx).isCanceled();
    }
    assert passiveJobs.isEmpty();
}
Also used : GridCollisionTestContext(org.apache.ignite.spi.collision.GridCollisionTestContext) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext)

Example 14 with GridTestCollisionJobContext

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

the class GridFifoQueueCollisionSpiSelfTest method testCollision3.

/**
 * @throws Exception If failed.
 */
public void testCollision3() throws Exception {
    getSpi().setParallelJobsNumber(15);
    GridCollisionTestContext cntx = createContext(10, 10);
    Collection<CollisionJobContext> activeJobs = cntx.activeJobs();
    Collection<CollisionJobContext> passiveJobs = cntx.waitingJobs();
    getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
    int i = 0;
    for (CollisionJobContext ctx : activeJobs) {
        if (i++ < 10)
            assert !((GridTestCollisionJobContext) ctx).isActivated();
        else
            assert ((GridTestCollisionJobContext) ctx).isActivated();
        assert !((GridTestCollisionJobContext) ctx).isCanceled();
    }
    for (CollisionJobContext ctx : passiveJobs) {
        if (((GridTestCollisionJobContext) ctx).getIndex() < 5) {
            assert ((GridTestCollisionJobContext) ctx).isActivated();
            assert !((GridTestCollisionJobContext) ctx).isCanceled();
        } else {
            assert !((GridTestCollisionJobContext) ctx).isActivated();
            assert !((GridTestCollisionJobContext) ctx).isCanceled();
        }
    }
}
Also used : GridCollisionTestContext(org.apache.ignite.spi.collision.GridCollisionTestContext) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext)

Example 15 with GridTestCollisionJobContext

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

the class GridJobStealingCollisionSpiSelfTest method testOnePassiveZeroActive.

/**
 * @throws Exception If test failed.
 */
public void testOnePassiveZeroActive() throws Exception {
    List<CollisionJobContext> waitCtxs = new ArrayList<>(1);
    // Add passive.
    Collections.addAll(waitCtxs, new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid()));
    Collection<CollisionJobContext> activeCtxs = Collections.emptyList();
    ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Rejected.
    checkActivated((GridTestCollisionJobContext) waitCtxs.get(0));
    // 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)

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