use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.
the class GridAlwaysFailoverSpiSelfTest method testMaxAttempts.
/**
* @throws Exception If failed.
*/
public void testMaxAttempts() throws Exception {
AlwaysFailoverSpi spi = getSpi();
spi.setMaximumFailoverAttempts(1);
List<ClusterNode> nodes = new ArrayList<>();
nodes.add(new GridTestNode(UUID.randomUUID()));
nodes.add(new GridTestNode(UUID.randomUUID()));
ComputeJobResult jobRes = new GridTestJobResult(nodes.get(0));
// First attempt.
ClusterNode node = spi.failover(new GridFailoverTestContext(new GridTestTaskSession(), jobRes), nodes);
assert node != null;
assert node.equals(nodes.get(1));
checkFailedNodes(jobRes, 1);
// Second attempt (exceeds default max attempts of 1).
node = spi.failover(new GridFailoverTestContext(new GridTestTaskSession(), jobRes), nodes);
assert node == null;
checkFailedNodes(jobRes, 1);
}
use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.
the class GridJobStealingFailoverSpiOneNodeSelfTest method initSpiContext.
/** {@inheritDoc} */
@Override
protected GridSpiTestContext initSpiContext() throws Exception {
GridSpiTestContext ctx = super.initSpiContext();
ctx.setLocalNode(addSpiDependency(new GridTestNode(UUID.randomUUID())));
ctx.addNode(addSpiDependency(new GridTestNode(UUID.randomUUID())));
return ctx;
}
use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.
the class GridWeightedRandomLoadBalancingSpiSelfTest method testSingleNode.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "ObjectEquality" })
public void testSingleNode() throws Exception {
List<ClusterNode> nodes = Collections.singletonList((ClusterNode) new GridTestNode(UUID.randomUUID()));
ClusterNode node = getSpi().getBalancedNode(new GridTestTaskSession(), nodes, new GridTestJob());
assert nodes.contains(node);
// Verify that same instance is returned every time.
ClusterNode balancedNode = getSpi().getBalancedNode(new GridTestTaskSession(), nodes, new GridTestJob());
assert node == balancedNode;
}
use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.
the class GridWeightedRandomLoadBalancingSpiWeightedSelfTest method testWeights.
/**
* @throws Exception If test failed.
*/
public void testWeights() throws Exception {
List<ClusterNode> nodes = new ArrayList<>();
for (int i = 0; i < 10; i++) {
GridTestNode node = new GridTestNode(UUID.randomUUID());
node.addAttribute(U.spiAttribute(getSpi(), NODE_WEIGHT_ATTR_NAME), i + 1);
nodes.add(node);
}
// Seal it.
nodes = Collections.unmodifiableList(nodes);
int[] cnts = new int[10];
// Invoke load balancer a large number of times, so statistics won't lie.
for (int i = 0; i < 100000; i++) {
ClusterNode node = getSpi().getBalancedNode(new GridTestTaskSession(IgniteUuid.randomUuid()), nodes, new GridTestJob());
int weight = (Integer) node.attribute(U.spiAttribute(getSpi(), NODE_WEIGHT_ATTR_NAME));
// Increment number of times a node was picked.
cnts[weight - 1]++;
}
for (int i = 0; i < cnts.length - 1; i++) {
assert cnts[i] < cnts[i + 1] : "Invalid node counts for index [idx=" + i + ", cnts[i]=" + cnts[i] + ", cnts[i+1]=" + cnts[i + 1] + ']';
}
info("Node counts: " + Arrays.toString(cnts));
}
use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.
the class GridTcpCommunicationSpiLanTest method beforeTestsStarted.
/** {@inheritDoc} */
@Override
protected void beforeTestsStarted() throws Exception {
spi = createSpi();
spiRsrc = new IgniteTestResources(getMBeanServer());
locNode = new GridTestNode(spiRsrc.getNodeId());
GridSpiTestContext ctx = initSpiContext();
ctx.setLocalNode(locNode);
info(">>> Initialized context: nodeId=" + ctx.localNode().id());
spiRsrc.inject(spi);
lsnr = new MessageListener(spiRsrc.getNodeId());
spi.setListener(lsnr);
Map<String, Object> attrs = spi.getNodeAttributes();
locNode.setAttributes(attrs);
spi.spiStart(getTestIgniteInstanceName());
spi.onContextInitialized(ctx);
IgniteTestResources remoteRsrc = new IgniteTestResources();
remoteNode = new GridTestNode(remoteRsrc.getNodeId());
remoteNode.setAttributes(attrs);
remoteNode.setAttribute(U.spiAttribute(spi, TcpCommunicationSpi.ATTR_ADDRS), Collections.singleton(remoteAddr));
ctx.remoteNodes().add(remoteNode);
}
Aggregations