Search in sources :

Example 6 with CollisionJobContext

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

the class GridJobStealingCollisionSpiSelfTest method testMultiplePassiveOneActive.

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

Example 7 with CollisionJobContext

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

the class GridJobStealingCollisionSpiAttributesSelfTest method testSameAttribute.

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

Example 8 with CollisionJobContext

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

the class GridJobStealingCollisionSpiAttributesSelfTest method testEmptyRemoteAttribute.

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

Example 9 with CollisionJobContext

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

the class GridJobStealingCollisionSpiAttributesSelfTest method testEmptyLocalAttribute.

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

Example 10 with CollisionJobContext

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

the class GridJobStealingCollisionSpiAttributesSelfTest method testIsStealingOff.

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

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