use of org.apache.ignite.spi.collision.GridCollisionTestContext in project ignite by apache.
the class GridPriorityQueueCollisionSpiSelfTest method testCollisionWithWrongPriorityAttribute.
/**
* @throws Exception If failed.
*/
@Test
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) {
@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({ "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.GridCollisionTestContext in project ignite by apache.
the class GridJobStealingCollisionSpiAttributesSelfTest method testBothEmptyAttribute.
/**
* @throws Exception If test failed.
*/
@Test
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.GridCollisionTestContext in project ignite by apache.
the class GridJobStealingCollisionSpiAttributesSelfTest method testIsStealingOn.
/**
* @throws Exception If test failed.
*/
@Test
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.GridCollisionTestContext in project ignite by apache.
the class GridFifoQueueCollisionSpiSelfTest method testCollision1.
/**
* @throws Exception If failed.
*/
@Test
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.GridCollisionTestContext in project ignite by apache.
the class GridFifoQueueCollisionSpiSelfTest method testCollision0.
/**
* @throws Exception If failed.
*/
@Test
public void testCollision0() throws Exception {
int activeCnt = 2;
assert getSpi().getParallelJobsNumber() > activeCnt;
GridCollisionTestContext cntx = createContext(activeCnt, getSpi().getParallelJobsNumber() - activeCnt);
Collection<CollisionJobContext> activeJobs = cntx.activeJobs();
Collection<CollisionJobContext> passiveJobs = cntx.waitingJobs();
getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
for (CollisionJobContext ctx : passiveJobs) {
assert ((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
}
int i = 0;
for (CollisionJobContext ctx : activeJobs) {
if (i++ < activeCnt)
assert !((GridTestCollisionJobContext) ctx).isActivated() : i;
else
assert ((GridTestCollisionJobContext) ctx).isActivated() : i;
assert !((GridTestCollisionJobContext) ctx).isCanceled();
}
}
Aggregations