use of org.apache.ignite.spi.collision.CollisionJobContext in project ignite by apache.
the class GridFifoQueueCollisionSpiSelfTest method createContext.
/**
* Prepare test context.
*
* @param activeNum Number of active jobs in context.
* @param passiveNum Number of passive jobs in context.
* @return New context with the given numbers of jobs, which will update when one of jobs get activated.
*/
private GridCollisionTestContext createContext(int activeNum, int passiveNum) {
final Collection<CollisionJobContext> activeJobs = new ConcurrentLinkedQueue<>();
for (int i = 0; i < activeNum; i++) activeJobs.add(new GridTestCollisionJobContext(new GridTestCollisionTaskSession(), i));
final Collection<CollisionJobContext> passiveJobs = new ConcurrentLinkedQueue<>();
for (int i = 0; i < passiveNum; i++) passiveJobs.add(new GridTestCollisionJobContext(new GridTestCollisionTaskSession(), i, new CI1<GridTestCollisionJobContext>() {
@Override
public void apply(GridTestCollisionJobContext c) {
passiveJobs.remove(c);
activeJobs.add(c);
}
}));
return new GridCollisionTestContext(activeJobs, passiveJobs);
}
use of org.apache.ignite.spi.collision.CollisionJobContext in project ignite by apache.
the class GridJobStealingCollisionSpiAttributesSelfTest method testDiffAttribute.
/**
* @throws Exception If test failed.
*/
public void testDiffAttribute() throws Exception {
List<CollisionJobContext> waitCtxs = Collections.emptyList();
Collection<CollisionJobContext> activeCtxs = Collections.emptyList();
GridTestNode rmtNode = (GridTestNode) F.first(getSpiContext().remoteNodes());
rmtNode.setAttribute("useCollision1", true);
getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
// Set up the same attribute and value as for remote node.
getSpi().setStealingAttributes(F.asMap("useCollision2", true));
getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
// Cleanup
rmtNode.removeAttribute("useCollision1");
// 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 GridPriorityQueueCollisionSpiSelfTest method testCollision3.
/**
* @throws Exception If failed.
*/
public void testCollision3() throws Exception {
List<CollisionJobContext> activeJobs = makeContextList(null);
List<CollisionJobContext> passiveJobs = makeContextList(null);
getSpi().setParallelJobsNumber(5);
getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
for (CollisionJobContext ctx : passiveJobs) {
assert !((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
}
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 GridPriorityQueueCollisionSpiSelfTest method testCollision.
/**
* @throws Exception If failed.
*/
public void testCollision() throws Exception {
List<CollisionJobContext> activeJobs = makeContextList(null);
List<CollisionJobContext> passiveJobs = makeContextList(null);
getSpi().setParallelJobsNumber(20);
getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
for (CollisionJobContext ctx : passiveJobs) {
assert ((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
}
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 GridPriorityQueueCollisionSpiSelfTest method testCollisionAttributeName.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "TooBroadScope" })
public void testCollisionAttributeName() throws Exception {
String taskAttrKey = "testTaskPriority";
String jobAttrKey = "testJobPriority";
List<CollisionJobContext> activeJobs = makeContextList(taskAttrKey);
List<CollisionJobContext> passiveJobs = makeContextList(taskAttrKey);
getSpi().setParallelJobsNumber(12);
getSpi().setPriorityAttributeKey(taskAttrKey);
getSpi().setJobPriorityAttributeKey(jobAttrKey);
getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
int incVal = getSpi().getStarvationIncrement();
for (CollisionJobContext ctx : passiveJobs) {
if (((GridTestCollisionTaskSession) ctx.getTaskSession()).getPriority() >= 8) {
assert ((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
} else {
assert !((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
}
Integer p = ctx.getJobContext().getAttribute(jobAttrKey);
if (p != null)
assert p == incVal + ((GridTestCollisionTaskSession) ctx.getTaskSession()).getPriority();
}
for (CollisionJobContext ctx : activeJobs) {
assert !((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
}
getSpi().setPriorityAttributeKey(DFLT_PRIORITY_ATTRIBUTE_KEY);
getSpi().setJobPriorityAttributeKey(DFLT_JOB_PRIORITY_ATTRIBUTE_KEY);
}
Aggregations