Search in sources :

Example 16 with CollisionJobContext

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

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

the class GridJobStealingCollisionSpiAttributesSelfTest method testDiffAttribute.

/**
    * @throws Exception If test failed.
    */
public void testDiffAttribute() throws Exception {
    List<CollisionJobContext> waitCtxs = Collections.emptyList();
    Collection<CollisionJobContext> activeCtxs = Collections.emptyList();
    GridTestNode rmtNode = (GridTestNode) F.first(getSpiContext().remoteNodes());
    rmtNode.setAttribute("useCollision1", true);
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
    // Set up the same attribute and value as for remote node.
    getSpi().setStealingAttributes(F.asMap("useCollision2", true));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Cleanup
    rmtNode.removeAttribute("useCollision1");
    // Set up the same attribute and value as for remote node.
    getSpi().setStealingAttributes(Collections.<String, Serializable>emptyMap());
    // Make sure that no message was sent.
    Serializable msg = getSpiContext().removeSentMessage(rmtNode);
    // attributes.
    assert msg == null;
}
Also used : Serializable(java.io.Serializable) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) GridCollisionTestContext(org.apache.ignite.spi.collision.GridCollisionTestContext) GridTestNode(org.apache.ignite.testframework.GridTestNode)

Example 18 with CollisionJobContext

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollision3.

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

Example 19 with CollisionJobContext

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollision.

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

Example 20 with CollisionJobContext

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollisionAttributeName.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings({ "TooBroadScope" })
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)

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