use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.
the class GridJobStealingCollisionSpiCustomTopologySelfTest method initSpiContext.
/** {@inheritDoc} */
@Override
protected GridSpiTestContext initSpiContext() throws Exception {
GridSpiTestContext ctx = super.initSpiContext();
GridTestNode locNode = new GridTestNode(UUID.randomUUID());
ctx.setLocalNode(locNode);
rmtNode1 = new GridTestNode(UUID.randomUUID());
rmtNode2 = new GridTestNode(UUID.randomUUID());
addSpiDependency(locNode);
addSpiDependency(rmtNode1);
addSpiDependency(rmtNode2);
ClusterMetricsSnapshot metrics = new ClusterMetricsSnapshot();
metrics.setCurrentWaitingJobs(2);
rmtNode1.setMetrics(metrics);
rmtNode2.setMetrics(metrics);
ctx.addNode(rmtNode1);
ctx.addNode(rmtNode2);
return ctx;
}
use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.
the class GridJobStealingCollisionSpiAttributesSelfTest method testSameAttribute.
/**
* @throws Exception If test failed.
*/
public void testSameAttribute() throws Exception {
List<CollisionJobContext> waitCtxs = Collections.emptyList();
Collection<CollisionJobContext> activeCtxs = Collections.emptyList();
GridTestNode rmtNode = (GridTestNode) getSpiContext().remoteNodes().iterator().next();
rmtNode.setAttribute("useCollision", true);
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));
// Cleanup
rmtNode.removeAttribute("useCollision");
// 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.testframework.GridTestNode in project ignite by apache.
the class GridJobStealingCollisionSpiAttributesSelfTest method testEmptyLocalAttribute.
/**
* @throws Exception If test failed.
*/
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.testframework.GridTestNode in project ignite by apache.
the class GridJobStealingCollisionSpiAttributesSelfTest method initSpiContext.
/** {@inheritDoc} */
@Override
protected GridSpiTestContext initSpiContext() throws Exception {
GridSpiTestContext ctx = super.initSpiContext();
GridTestNode locNode = new GridTestNode(UUID.randomUUID());
addSpiDependency(locNode);
ctx.setLocalNode(locNode);
return ctx;
}
use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.
the class GridTcpCommunicationSpiConcurrentConnectSelfTest method startSpis.
/**
* @param lsnr Message listener.
* @throws Exception If failed.
*/
private void startSpis(MessageListener lsnr) throws Exception {
spis.clear();
nodes.clear();
spiRsrcs.clear();
Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
for (int i = 0; i < SPI_CNT; i++) {
CommunicationSpi<Message> spi = createSpi();
GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
IgniteTestResources rsrcs = new IgniteTestResources();
GridTestNode node = new GridTestNode(rsrcs.getNodeId());
node.order(i + 1);
GridSpiTestContext ctx = initSpiContext();
ctx.setLocalNode(node);
info(">>> Initialized context: nodeId=" + ctx.localNode().id());
spiRsrcs.add(rsrcs);
rsrcs.inject(spi);
if (useSsl) {
IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
IgniteConfiguration cfg = ignite.configuration().setSslContextFactory(GridTestUtils.sslFactory());
ignite.setStaticCfg(cfg);
}
spi.setListener(lsnr);
node.setAttributes(spi.getNodeAttributes());
nodes.add(node);
spi.spiStart(getTestIgniteInstanceName() + (i + 1));
spis.add(spi);
spi.onContextInitialized(ctx);
ctxs.put(node, ctx);
}
// For each context set remote nodes.
for (Map.Entry<ClusterNode, GridSpiTestContext> e : ctxs.entrySet()) {
for (ClusterNode n : nodes) {
if (!n.equals(e.getKey()))
e.getValue().remoteNodes().add(n);
}
}
}
Aggregations