use of org.apache.ignite.spi.collision.CollisionJobContext 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.CollisionJobContext in project ignite by apache.
the class GridPriorityQueueCollisionSpiSelfTest method testCollisionEmpty.
/**
* @throws Exception If failed.
*/
public void testCollisionEmpty() throws Exception {
Collection<CollisionJobContext> activeJobs = new ArrayList<>();
Collection<CollisionJobContext> passiveJobs = new ArrayList<>();
getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
assert activeJobs.isEmpty();
assert passiveJobs.isEmpty();
}
use of org.apache.ignite.spi.collision.CollisionJobContext 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();
}
}
use of org.apache.ignite.spi.collision.CollisionJobContext in project ignite by apache.
the class GridJobStealingCollisionSpiSelfTest method testMultiplePassiveZeroActive.
/**
* @throws Exception If test failed.
*/
public void testMultiplePassiveZeroActive() throws Exception {
final List<CollisionJobContext> waitCtxs = new ArrayList<>(2);
final List<CollisionJobContext> activeCtxs = new ArrayList<>(2);
CI1<GridTestCollisionJobContext> lsnr = new CI1<GridTestCollisionJobContext>() {
@Override
public void apply(GridTestCollisionJobContext c) {
if (waitCtxs.remove(c))
activeCtxs.add(c);
}
};
Collections.addAll(waitCtxs, new GridTestCollisionJobContext(createTaskSession(), 1, lsnr), new GridTestCollisionJobContext(createTaskSession(), 2, lsnr), new GridTestCollisionJobContext(createTaskSession(), 3, lsnr));
ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
// Emulate message to steal 2 jobs.
getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(2));
getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
// Make sure that one job got activated.
checkActivated((GridTestCollisionJobContext) activeCtxs.get(0));
// Rejected.
checkRejected((GridTestCollisionJobContext) waitCtxs.get(0), rmtNode);
checkRejected((GridTestCollisionJobContext) waitCtxs.get(1), rmtNode);
// 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 GridJobStealingCollisionSpiSelfTest method testZeroPassiveZeroActive.
/**
* @throws Exception If test failed.
*/
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;
}
Aggregations