Search in sources :

Example 26 with CollisionJobContext

use of org.apache.ignite.spi.collision.CollisionJobContext 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)

Example 27 with CollisionJobContext

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

the class GridJobStealingCollisionSpiSelfTest method testZeroPassiveOneActive.

/**
     * @throws Exception If test failed.
     */
public void testZeroPassiveOneActive() throws Exception {
    Collection<CollisionJobContext> empty = Collections.emptyList();
    List<CollisionJobContext> activeCtxs = new ArrayList<>(1);
    // Add active.
    Collections.addAll(activeCtxs, new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid()));
    ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, empty));
    // Active job.
    checkNoAction((GridTestCollisionJobContext) activeCtxs.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)

Example 28 with CollisionJobContext

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

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

use of org.apache.ignite.spi.collision.CollisionJobContext 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)

Aggregations

CollisionJobContext (org.apache.ignite.spi.collision.CollisionJobContext)35 GridCollisionTestContext (org.apache.ignite.spi.collision.GridCollisionTestContext)32 GridTestCollisionJobContext (org.apache.ignite.spi.collision.GridTestCollisionJobContext)25 Serializable (java.io.Serializable)16 ClusterNode (org.apache.ignite.cluster.ClusterNode)13 ArrayList (java.util.ArrayList)10 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 Iterator (java.util.Iterator)1 Entry (java.util.Map.Entry)1 UUID (java.util.UUID)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteSpiContext (org.apache.ignite.spi.IgniteSpiContext)1