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