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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations