Search in sources :

Example 16 with GridCollisionTestContext

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

the class GridJobStealingCollisionSpiSelfTest method testMultiplePassiveZeroActive.

/**
 * @throws Exception If test failed.
 */
@Test
public void testMultiplePassiveZeroActive() throws Exception {
    final List<CollisionJobContext> waitCtxs = new ArrayList<>(2);
    final List<CollisionJobContext> activeCtxs = new ArrayList<>(2);
    CI1<GridTestCollisionJobContext> lsnr = new CI1<GridTestCollisionJobContext>() {

        @Override
        public void apply(GridTestCollisionJobContext c) {
            if (waitCtxs.remove(c))
                activeCtxs.add(c);
        }
    };
    Collections.addAll(waitCtxs, new GridTestCollisionJobContext(createTaskSession(), 1, lsnr), new GridTestCollisionJobContext(createTaskSession(), 2, lsnr), new GridTestCollisionJobContext(createTaskSession(), 3, lsnr));
    ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
    // Emulate message to steal 2 jobs.
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(2));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Make sure that one job got activated.
    checkActivated((GridTestCollisionJobContext) activeCtxs.get(0));
    // Rejected.
    checkRejected((GridTestCollisionJobContext) waitCtxs.get(0), rmtNode);
    checkRejected((GridTestCollisionJobContext) waitCtxs.get(1), rmtNode);
    // 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) CI1(org.apache.ignite.internal.util.typedef.CI1) 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) GridSpiTest(org.apache.ignite.testframework.junits.spi.GridSpiTest) GridSpiAbstractTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest) Test(org.junit.Test)

Example 17 with GridCollisionTestContext

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

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

the class GridJobStealingCollisionSpiSelfTest method testTwoPassiveJobs.

/**
 * @throws Exception If test failed.
 */
@Test
public void testTwoPassiveJobs() throws Exception {
    final List<CollisionJobContext> waitCtxs = new ArrayList<>(2);
    final List<CollisionJobContext> activeCtxs = new ArrayList<>(1);
    CI1<GridTestCollisionJobContext> lsnr = new CI1<GridTestCollisionJobContext>() {

        @Override
        public void apply(GridTestCollisionJobContext c) {
            if (waitCtxs.remove(c))
                activeCtxs.add(c);
        }
    };
    Collections.addAll(waitCtxs, new GridTestCollisionJobContext(createTaskSession(), 1, lsnr), new GridTestCollisionJobContext(createTaskSession(), 2, lsnr));
    ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Activated.
    checkActivated((GridTestCollisionJobContext) activeCtxs.get(0));
    // Rejected.
    checkRejected((GridTestCollisionJobContext) waitCtxs.get(0), rmtNode);
    // 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) CI1(org.apache.ignite.internal.util.typedef.CI1) 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) GridSpiTest(org.apache.ignite.testframework.junits.spi.GridSpiTest) GridSpiAbstractTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest) Test(org.junit.Test)

Example 19 with GridCollisionTestContext

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

the class GridJobStealingCollisionSpiSelfTest method testOnePassiveZeroActive.

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

Example 20 with GridCollisionTestContext

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

the class GridJobStealingCollisionSpiSelfTest method testZeroPassiveOneActive.

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