use of org.apache.ignite.spi.collision.GridCollisionTestContext in project ignite by apache.
the class GridJobStealingCollisionSpiSelfTest method testMaxHopsExceeded.
/**
* @throws Exception If test failed.
*/
@Test
public void testMaxHopsExceeded() throws Exception {
Collection<CollisionJobContext> waitCtxs = new ArrayList<>(2);
GridTestCollisionJobContext excluded = new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid());
GridTestCollisionJobContext ctx1 = new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid());
GridTestCollisionJobContext ctx2 = new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid());
Collections.addAll(waitCtxs, ctx1, excluded, ctx2);
Collection<CollisionJobContext> activeCtxs = new ArrayList<>(1);
// Add active.
Collections.addAll(activeCtxs, new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid()));
ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
// Exceed hops.
excluded.getJobContext().setAttribute(STEALING_ATTEMPT_COUNT_ATTR, 1);
// Emulate message to steal 2 jobs.
getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(2));
getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
// Make sure that none happened to 1st job.
checkNoAction(excluded);
// Rejected.
checkRejected(ctx1, rmtNode);
checkRejected(ctx2, rmtNode);
// 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 GridPriorityQueueCollisionSpiSelfTest method testCollision1.
/**
* @throws Exception If failed.
*/
@Test
public void testCollision1() throws Exception {
List<CollisionJobContext> activeJobs = makeContextList(null);
List<CollisionJobContext> passiveJobs = makeContextList(null);
getSpi().setParallelJobsNumber(12);
getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
int incVal = getSpi().getStarvationIncrement();
String jobAttrKey = DFLT_JOB_PRIORITY_ATTRIBUTE_KEY;
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().<String, Integer>getAttribute(jobAttrKey);
if (p != null)
assert p == incVal + ((GridTestCollisionTaskSession) ctx.getTaskSession()).getPriority();
}
for (CollisionJobContext ctx : activeJobs) {
assert !((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
}
}
use of org.apache.ignite.spi.collision.GridCollisionTestContext in project ignite by apache.
the class GridPriorityQueueCollisionSpiSelfTest method testCollision0.
/**
* @throws Exception If failed.
*/
@Test
public void testCollision0() throws Exception {
List<CollisionJobContext> activeJobs = makeContextList(null);
List<CollisionJobContext> passiveJobs = makeContextList(null);
getSpi().setParallelJobsNumber(30);
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.GridCollisionTestContext in project ignite by apache.
the class GridPriorityQueueCollisionSpiSelfTest method testCollisionWithoutPriorityAttribute.
/**
* @throws Exception If failed.
*/
@Test
public void testCollisionWithoutPriorityAttribute() throws Exception {
List<CollisionJobContext> activeJobs = makeContextList(null);
List<CollisionJobContext> passiveJobs = makeContextList(null);
for (CollisionJobContext ctx : passiveJobs) {
if (((GridTestCollisionTaskSession) ctx.getTaskSession()).getPriority() >= 8) {
((GridTestCollisionTaskSession) ctx.getTaskSession()).setPriorityAttributeKey("bad-attr-name");
((GridTestCollisionJobContext) ctx).setJobContext(new GridTestJobContext() {
@SuppressWarnings({ "RedundantTypeArguments" })
@Override
public <K, V> V getAttribute(K key) {
if (DFLT_JOB_PRIORITY_ATTRIBUTE_KEY.equals(key))
return null;
return super.<K, V>getAttribute(key);
}
});
}
}
getSpi().setParallelJobsNumber(12);
getSpi().setDefaultPriority(100);
getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
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();
}
}
for (CollisionJobContext ctx : activeJobs) {
assert !((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
}
}
use of org.apache.ignite.spi.collision.GridCollisionTestContext in project ignite by apache.
the class GridPriorityQueueCollisionSpiSelfTest method testCollision2.
/**
* @throws Exception If failed.
*/
@Test
public void testCollision2() throws Exception {
List<CollisionJobContext> activeJobs = makeContextList(null);
List<CollisionJobContext> passiveJobs = makeContextList(null);
getSpi().setParallelJobsNumber(10);
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();
}
}
Aggregations