Search in sources :

Example 26 with GridCollisionTestContext

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

the class GridPriorityQueueCollisionSpiSelfTest method testCollisionWithWrongPriorityAttribute.

/**
 * @throws Exception If failed.
 */
@Test
public void testCollisionWithWrongPriorityAttribute() throws Exception {
    List<CollisionJobContext> activeJobs = makeContextList(null);
    List<CollisionJobContext> passiveJobs = makeContextList(null);
    for (CollisionJobContext ctx : passiveJobs) {
        if (((GridTestCollisionTaskSession) ctx.getTaskSession()).getPriority() >= 8) {
            ((GridTestCollisionJobContext) ctx).setTaskSession(new GridTestCollisionTaskSession(100, DFLT_PRIORITY_ATTRIBUTE_KEY) {

                @Override
                public <K, V> V getAttribute(K key) {
                    if (getPriorityAttributeKey() != null && getPriorityAttributeKey().equals(key))
                        return (V) "wrong-attr";
                    return null;
                }
            });
            ((GridTestCollisionJobContext) ctx).setJobContext(new GridTestJobContext() {

                @SuppressWarnings({ "RedundantTypeArguments" })
                @Override
                public <K, V> V getAttribute(K key) {
                    if (DFLT_JOB_PRIORITY_ATTRIBUTE_KEY.equals(key))
                        return (V) "wrong-attr";
                    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 27 with GridCollisionTestContext

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

the class GridJobStealingCollisionSpiAttributesSelfTest method testBothEmptyAttribute.

/**
 * @throws Exception If test failed.
 */
@Test
public void testBothEmptyAttribute() 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());
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Make sure that no message was sent.
    Serializable msg = getSpiContext().removeSentMessage(rmtNode);
    // attributes.
    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 28 with GridCollisionTestContext

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

the class GridJobStealingCollisionSpiAttributesSelfTest method testIsStealingOn.

/**
 * @throws Exception If test failed.
 */
@Test
public void testIsStealingOn() 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(true);
    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 on
    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 29 with GridCollisionTestContext

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

the class GridFifoQueueCollisionSpiSelfTest method testCollision1.

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

Example 30 with GridCollisionTestContext

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

the class GridFifoQueueCollisionSpiSelfTest method testCollision0.

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

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