Search in sources :

Example 6 with GridCollisionTestContext

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollision5.

/**
 * @throws Exception If failed.
 */
@Test
public void testCollision5() throws Exception {
    List<CollisionJobContext> activeJobs = makeContextList(null, false);
    List<CollisionJobContext> passiveJobs = makeContextList(null, false);
    getSpi().setParallelJobsNumber(12);
    getSpi().setStarvationPreventionEnabled(false);
    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();
        }
        assert ctx.getJobContext().<String, Integer>getAttribute(jobAttrKey) == null;
    }
    for (CollisionJobContext ctx : activeJobs) {
        assert !((GridTestCollisionJobContext) ctx).isActivated();
        assert !((GridTestCollisionJobContext) ctx).isCanceled();
    }
}
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 7 with GridCollisionTestContext

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

the class GridJobStealingCollisionSpiAttributesSelfTest method testEmptyLocalAttribute.

/**
 * @throws Exception If test failed.
 */
@Test
public void testEmptyLocalAttribute() throws Exception {
    // Collision SPI does not allow to send more than 1 message in a
    // certain period of time (see getMessageExpireTime() method).
    // Thus we have to wait for the message to be expired.
    Thread.sleep(50);
    List<CollisionJobContext> waitCtxs = Collections.emptyList();
    Collection<CollisionJobContext> activeCtxs = Collections.emptyList();
    GridTestNode rmtNode = (GridTestNode) F.first(getSpiContext().remoteNodes());
    rmtNode.setAttribute("useCollision", true);
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Cleanup.
    rmtNode.removeAttribute("useCollision");
    // 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) GridSpiAbstractTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest) Test(org.junit.Test) GridSpiTest(org.apache.ignite.testframework.junits.spi.GridSpiTest)

Example 8 with GridCollisionTestContext

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

the class GridJobStealingCollisionSpiAttributesSelfTest method testIsStealingOff.

/**
 * @throws Exception If test failed.
 */
@Test
public void testIsStealingOff() throws Exception {
    // Collision SPI does not allow to send more than 1 message in a
    // certain period of time (see getMessageExpireTime() method).
    // Thus we have to wait for the message to be expired.
    Thread.sleep(50);
    List<CollisionJobContext> waitCtxs = Collections.emptyList();
    Collection<CollisionJobContext> activeCtxs = Collections.emptyList();
    ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
    getSpi().setStealingEnabled(false);
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Make sure that no message was sent.
    Serializable msg = getSpiContext().removeSentMessage(rmtNode);
    // Message should not be sent to remote node because stealing is off
    assert msg == null;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Serializable(java.io.Serializable) 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 9 with GridCollisionTestContext

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

the class GridJobStealingCollisionSpiAttributesSelfTest method testDiffAttribute.

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

Example 10 with GridCollisionTestContext

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

the class GridJobStealingCollisionSpiAttributesSelfTest method testEmptyRemoteAttribute.

/**
 * @throws Exception If test failed.
 */
@Test
public void testEmptyRemoteAttribute() throws Exception {
    List<CollisionJobContext> waitCtxs = Collections.emptyList();
    Collection<CollisionJobContext> activeCtxs = Collections.emptyList();
    ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
    // Set up the same attribute and value as for remote node.
    getSpi().setStealingAttributes(F.asMap("useCollision", true));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // 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);
    // Message should not be sent to remote node at it does not have attribute
    assert msg == null;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Serializable(java.io.Serializable) 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