use of org.apache.ignite.spi.collision.GridTestCollisionJobContext in project ignite by apache.
the class GridJobStealingCollisionSpiSelfTest method testTwoPassiveJobs.
/**
* @throws Exception If test failed.
*/
public void testTwoPassiveJobs() throws Exception {
final List<CollisionJobContext> waitCtxs = new ArrayList<>(2);
final List<CollisionJobContext> activeCtxs = new ArrayList<>(1);
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));
ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
// Activated.
checkActivated((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 testZeroPassiveOneActive.
/**
* @throws Exception If test failed.
*/
public void testZeroPassiveOneActive() throws Exception {
Collection<CollisionJobContext> empty = Collections.emptyList();
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, empty));
// Active job.
checkNoAction((GridTestCollisionJobContext) activeCtxs.get(0));
// 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 testMaxHopsExceeded.
/**
* @throws Exception If test failed.
*/
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.GridTestCollisionJobContext in project ignite by apache.
the class GridPriorityQueueCollisionSpiSelfTest method testCollisionWithWrongPriorityAttribute.
/**
* @throws Exception If failed.
*/
public void testCollisionWithWrongPriorityAttribute() throws Exception {
List<CollisionJobContext> activeJobs = makeContextList(null);
List<CollisionJobContext> passiveJobs = makeContextList(null);
for (CollisionJobContext ctx : passiveJobs) {
if (((GridTestCollisionTaskSession) ctx.getTaskSession()).getPriority() >= 8) {
((GridTestCollisionJobContext) ctx).setTaskSession(new GridTestCollisionTaskSession(100, DFLT_PRIORITY_ATTRIBUTE_KEY) {
@SuppressWarnings("unchecked")
@Override
public <K, V> V getAttribute(K key) {
if (getPriorityAttributeKey() != null && getPriorityAttributeKey().equals(key))
return (V) "wrong-attr";
return null;
}
});
((GridTestCollisionJobContext) ctx).setJobContext(new GridTestJobContext() {
@SuppressWarnings({ "unchecked", "RedundantTypeArguments" })
@Override
public <K, V> V getAttribute(K key) {
if (DFLT_JOB_PRIORITY_ATTRIBUTE_KEY.equals(key))
return (V) "wrong-attr";
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.GridTestCollisionJobContext in project ignite by apache.
the class GridPriorityQueueCollisionSpiSelfTest method testCollision2.
/**
* @throws Exception If failed.
*/
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