Search in sources :

Example 11 with GridCollisionTestContext

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

the class GridJobStealingCollisionSpiAttributesSelfTest method testSameAttribute.

/**
 * @throws Exception If test failed.
 */
@Test
public void testSameAttribute() throws Exception {
    List<CollisionJobContext> waitCtxs = Collections.emptyList();
    Collection<CollisionJobContext> activeCtxs = Collections.emptyList();
    GridTestNode rmtNode = (GridTestNode) getSpiContext().remoteNodes().iterator().next();
    rmtNode.setAttribute("useCollision", true);
    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));
    // Cleanup
    rmtNode.removeAttribute("useCollision");
    // 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 12 with GridCollisionTestContext

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

the class GridJobStealingCollisionSpiCustomTopologySelfTest method testThiefNodeNotInTopology.

/**
 * @throws Exception If test failed.
 */
@Test
public void testThiefNodeNotInTopology() throws Exception {
    List<CollisionJobContext> waitCtxs = new ArrayList<>(2);
    final ClusterNode node = getSpiContext().nodes().iterator().next();
    Collections.addAll(waitCtxs, new GridTestCollisionJobContext(createTaskSession(node), IgniteUuid.randomUuid()), new GridTestCollisionJobContext(createTaskSession(node), IgniteUuid.randomUuid()), new GridTestCollisionJobContext(createTaskSession(node), IgniteUuid.randomUuid()));
    Collection<CollisionJobContext> activeCtxs = new ArrayList<>(1);
    // Add active.
    Collections.addAll(activeCtxs, new GridTestCollisionJobContext(createTaskSession(node), IgniteUuid.randomUuid()));
    // Emulate message to steal 2 jobs.
    getSpiContext().triggerMessage(rmtNode2, new JobStealingRequest(2));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Check no action.
    checkNoAction((GridTestCollisionJobContext) waitCtxs.get(0));
    checkNoAction((GridTestCollisionJobContext) waitCtxs.get(1));
    checkNoAction((GridTestCollisionJobContext) waitCtxs.get(2));
    // Make sure that no message was sent.
    Serializable msg1 = getSpiContext().removeSentMessage(getSpiContext().localNode());
    assert msg1 == null;
    Serializable mgs2 = getSpiContext().removeSentMessage(rmtNode1);
    assert mgs2 == null;
    Serializable msg3 = getSpiContext().removeSentMessage(rmtNode2);
    assert msg3 == null;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) 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 13 with GridCollisionTestContext

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

the class GridJobStealingCollisionSpiSelfTest method testMultiplePassiveOneActive.

/**
 * @throws Exception If test failed.
 */
@Test
public void testMultiplePassiveOneActive() throws Exception {
    List<CollisionJobContext> waitCtxs = new ArrayList<>(2);
    Collections.addAll(waitCtxs, new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid()), new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid()), new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid()));
    Collection<CollisionJobContext> activeCtxs = new ArrayList<>(1);
    // Add active.
    Collections.addAll(activeCtxs, new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid()));
    ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
    // Emulate message to steal 2 jobs.
    getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(2));
    getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
    // Rejected.
    checkRejected((GridTestCollisionJobContext) waitCtxs.get(0), rmtNode);
    checkRejected((GridTestCollisionJobContext) waitCtxs.get(1), rmtNode);
    // Check no action.
    checkNoAction((GridTestCollisionJobContext) waitCtxs.get(2));
    // 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 14 with GridCollisionTestContext

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

the class GridJobStealingCollisionSpiSelfTest method testZeroPassiveZeroActive.

/**
 * @throws Exception If test failed.
 */
@Test
public void testZeroPassiveZeroActive() throws Exception {
    Collection<CollisionJobContext> empty = Collections.emptyList();
    getSpi().onCollision(new GridCollisionTestContext(empty, empty));
    ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
    JobStealingRequest sentMsg = (JobStealingRequest) getSpiContext().getSentMessage(rmtNode);
    assert sentMsg != null;
    assert sentMsg.delta() == 1 : "Invalid sent message: " + sentMsg;
    Serializable msg = getSpiContext().removeSentMessage(rmtNode);
    assert msg != null;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Serializable(java.io.Serializable) CollisionJobContext(org.apache.ignite.spi.collision.CollisionJobContext) GridTestCollisionJobContext(org.apache.ignite.spi.collision.GridTestCollisionJobContext) GridCollisionTestContext(org.apache.ignite.spi.collision.GridCollisionTestContext) GridSpiTest(org.apache.ignite.testframework.junits.spi.GridSpiTest) GridSpiAbstractTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest) Test(org.junit.Test)

Example 15 with GridCollisionTestContext

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

the class GridJobStealingCollisionSpiSelfTest method testOnePassiveOneActiveJobs.

/**
 * @throws Exception If test failed.
 */
@Test
public void testOnePassiveOneActiveJobs() throws Exception {
    List<CollisionJobContext> waitCtxs = new ArrayList<>(1);
    // Add passive.
    Collections.addAll(waitCtxs, new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid()));
    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, waitCtxs));
    // Active job.
    checkNoAction((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) 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