use of org.apache.ignite.spi.collision.GridCollisionTestContext in project ignite by apache.
the class GridPriorityQueueCollisionSpiSelfTest method testCollision5.
/**
* @throws Exception If failed.
*/
@Test
public void testCollision5() throws Exception {
List<CollisionJobContext> activeJobs = makeContextList(null, false);
List<CollisionJobContext> passiveJobs = makeContextList(null, false);
getSpi().setParallelJobsNumber(12);
getSpi().setStarvationPreventionEnabled(false);
getSpi().onCollision(new GridCollisionTestContext(activeJobs, passiveJobs));
String jobAttrKey = DFLT_JOB_PRIORITY_ATTRIBUTE_KEY;
for (CollisionJobContext ctx : passiveJobs) {
int taskP = ((GridTestCollisionTaskSession) ctx.getTaskSession()).getPriority();
if (taskP >= 8) {
assert ((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
} else {
assert !((GridTestCollisionJobContext) ctx).isActivated();
assert !((GridTestCollisionJobContext) ctx).isCanceled();
}
assert ctx.getJobContext().<String, Integer>getAttribute(jobAttrKey) == null;
}
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 testEmptyLocalAttribute.
/**
* @throws Exception If test failed.
*/
@Test
public void testEmptyLocalAttribute() 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();
GridTestNode rmtNode = (GridTestNode) F.first(getSpiContext().remoteNodes());
rmtNode.setAttribute("useCollision", true);
getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
// Cleanup.
rmtNode.removeAttribute("useCollision");
// 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 testIsStealingOff.
/**
* @throws Exception If test failed.
*/
@Test
public void testIsStealingOff() 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(false);
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 off
assert msg == null;
}
use of org.apache.ignite.spi.collision.GridCollisionTestContext in project ignite by apache.
the class GridJobStealingCollisionSpiAttributesSelfTest method testDiffAttribute.
/**
* @throws Exception If test failed.
*/
@Test
public void testDiffAttribute() throws Exception {
List<CollisionJobContext> waitCtxs = Collections.emptyList();
Collection<CollisionJobContext> activeCtxs = Collections.emptyList();
GridTestNode rmtNode = (GridTestNode) F.first(getSpiContext().remoteNodes());
rmtNode.setAttribute("useCollision1", true);
getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
// Set up the same attribute and value as for remote node.
getSpi().setStealingAttributes(F.asMap("useCollision2", true));
getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
// Cleanup
rmtNode.removeAttribute("useCollision1");
// Set up the same attribute and value as for remote node.
getSpi().setStealingAttributes(Collections.<String, Serializable>emptyMap());
// 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 testEmptyRemoteAttribute.
/**
* @throws Exception If test failed.
*/
@Test
public void testEmptyRemoteAttribute() throws Exception {
List<CollisionJobContext> waitCtxs = Collections.emptyList();
Collection<CollisionJobContext> activeCtxs = Collections.emptyList();
ClusterNode rmtNode = F.first(getSpiContext().remoteNodes());
getSpiContext().triggerMessage(rmtNode, new JobStealingRequest(1));
// Set up the same attribute and value as for remote node.
getSpi().setStealingAttributes(F.asMap("useCollision", true));
getSpi().onCollision(new GridCollisionTestContext(activeCtxs, waitCtxs));
// Set up the same attribute and value as for remote node.
getSpi().setStealingAttributes(Collections.<String, Serializable>emptyMap());
// Make sure that no message was sent.
Serializable msg = getSpiContext().removeSentMessage(rmtNode);
// Message should not be sent to remote node at it does not have attribute
assert msg == null;
}
Aggregations