use of org.apache.ignite.spi.collision.CollisionJobContext in project ignite by apache.
the class GridFifoQueueCollisionSpiSelfTest method testCollision1.
/**
* @throws Exception If failed.
*/
public void testCollision1() throws Exception {
getSpi().setParallelJobsNumber(32);
GridCollisionTestContext cntx = createContext(0, 33);
Collection<CollisionJobContext> activeJobs = cntx.activeJobs();
Collection<CollisionJobContext> passiveJobs = cntx.waitingJobs();
getSpi().onCollision(cntx);
for (CollisionJobContext ctx : passiveJobs) {
if (((GridTestCollisionJobContext) ctx).getIndex() == 32) {
assert !((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
} else {
assert ((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
}
}
assert activeJobs.size() == 32;
}
use of org.apache.ignite.spi.collision.CollisionJobContext in project ignite by apache.
the class GridJobStealingCollisionSpiAttributesSelfTest method testIsStealingOn.
/**
* @throws Exception If test failed.
*/
public void testIsStealingOn() throws Exception {
// Collision SPI does not allow to send more than 1 message in a
// certain period of time (see getMessageExpireTime() method).
// Thus we have to wait for the message to be expired.
Thread.sleep(50);
List<CollisionJobContext> waitCtxs = Collections.emptyList();
Collection<CollisionJobContext> activeCtxs = Collections.emptyList();
ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
getSpi().setStealingEnabled(true);
getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
// Make sure that no message was sent.
Serializable msg = getSpiContext().removeSentMessage(rmtNode);
// Message should not be sent to remote node because stealing is on
assert msg != null;
}
use of org.apache.ignite.spi.collision.CollisionJobContext in project ignite by apache.
the class GridJobStealingCollisionSpiAttributesSelfTest method testBothEmptyAttribute.
/**
* @throws Exception If test failed.
*/
public void testBothEmptyAttribute() throws Exception {
// Collision SPI does not allow to send more than 1 message in a
// certain period of time (see getMessageExpireTime() method).
// Thus we have to wait for the message to be expired.
Thread.sleep(50);
List<CollisionJobContext> waitCtxs = Collections.emptyList();
Collection<CollisionJobContext> activeCtxs = Collections.emptyList();
ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
// 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 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.CollisionJobContext 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;
}
Aggregations