use of org.apache.ignite.spi.collision.GridCollisionTestContext in project ignite by apache.
the class GridJobStealingCollisionSpiSelfTest method testMultiplePassiveZeroActive.
/**
* @throws Exception If test failed.
*/
@Test
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.GridCollisionTestContext 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.GridCollisionTestContext in project ignite by apache.
the class GridJobStealingCollisionSpiSelfTest method testTwoPassiveJobs.
/**
* @throws Exception If test failed.
*/
@Test
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.GridCollisionTestContext in project ignite by apache.
the class GridJobStealingCollisionSpiSelfTest method testOnePassiveZeroActive.
/**
* @throws Exception If test failed.
*/
@Test
public void testOnePassiveZeroActive() throws Exception {
List<CollisionJobContext> waitCtxs = new ArrayList<>(1);
// Add passive.
Collections.addAll(waitCtxs, new GridTestCollisionJobContext(createTaskSession(), IgniteUuid.randomUuid()));
Collection<CollisionJobContext> activeCtxs = Collections.emptyList();
ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
// Rejected.
checkActivated((GridTestCollisionJobContext) waitCtxs.get(0));
// 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 GridJobStealingCollisionSpiSelfTest method testZeroPassiveOneActive.
/**
* @throws Exception If test failed.
*/
@Test
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;
}
Aggregations