use of org.apache.ignite.spi.collision.GridTestCollisionJobContext in project ignite by apache.
the class GridJobStealingCollisionSpiCustomTopologySelfTest method testThiefNodeNotInTopology.
/**
* @throws Exception If test failed.
*/
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.GridTestCollisionJobContext in project ignite by apache.
the class GridJobStealingCollisionSpiSelfTest method testOnePassiveOneActiveJobs.
/**
* @throws Exception If test failed.
*/
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;
}
use of org.apache.ignite.spi.collision.GridTestCollisionJobContext 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.GridTestCollisionJobContext in project ignite by apache.
the class GridPriorityQueueCollisionSpiSelfTest method testCollision4.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "TooBroadScope" })
public void testCollision4() throws Exception {
List<CollisionJobContext> activeJobs = makeContextList(null, false);
List<CollisionJobContext> passiveJobs = makeContextList(null, false);
int incVal = 2;
getSpi().setParallelJobsNumber(12);
getSpi().setStarvationIncrement(incVal);
getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
String jobAttrKey = DFLT_JOB_PRIORITY_ATTRIBUTE_KEY;
for (CollisionJobContext ctx : passiveJobs) {
int taskP = ((GridTestCollisionTaskSession) ctx.getTaskSession()).getPriority();
if (taskP >= 8) {
assert ((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
} else {
assert !((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
}
if (taskP < 5) {
Integer p = ctx.getJobContext().getAttribute(jobAttrKey);
assert p != null;
assert p == incVal + taskP;
}
}
for (CollisionJobContext ctx : activeJobs) {
assert !((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
}
getSpi().setStarvationIncrement(DFLT_STARVATION_INCREMENT);
}
use of org.apache.ignite.spi.collision.GridTestCollisionJobContext in project ignite by apache.
the class GridPriorityQueueCollisionSpiSelfTest method testCollision5.
/**
* @throws Exception If failed.
*/
public void testCollision5() throws Exception {
List<CollisionJobContext> activeJobs = makeContextList(null, false);
List<CollisionJobContext> passiveJobs = makeContextList(null, false);
getSpi().setParallelJobsNumber(12);
getSpi().setStarvationPreventionEnabled(false);
getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
String jobAttrKey = DFLT_JOB_PRIORITY_ATTRIBUTE_KEY;
for (CollisionJobContext ctx : passiveJobs) {
int taskP = ((GridTestCollisionTaskSession) ctx.getTaskSession()).getPriority();
if (taskP >= 8) {
assert ((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
} else {
assert !((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
}
assert ctx.getJobContext().<String, Integer>getAttribute(jobAttrKey) == null;
}
for (CollisionJobContext ctx : activeJobs) {
assert !((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
}
}
Aggregations