use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.
the class GridJobStealingCollisionSpiAttributesSelfTest method testDiffAttribute.
/**
* @throws Exception If test failed.
*/
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.testframework.GridTestNode in project ignite by apache.
the class GridJobStealingCollisionSpiStartStopSelfTest 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 AbstractAffinityFunctionSelfTest method checkRandomReassignment.
/**
* @param backups Backups.
*/
protected void checkRandomReassignment(int backups) {
AffinityFunction aff = affinityFunction();
Random rnd = new Random();
int maxNodes = 50;
List<ClusterNode> nodes = new ArrayList<>(maxNodes);
List<List<ClusterNode>> prev = null;
int state = 0;
int i = 0;
while (true) {
boolean add;
if (nodes.size() < 2) {
// Returned back to one node?
if (state == 1)
return;
add = true;
} else if (nodes.size() == maxNodes) {
if (state == 0)
state = 1;
add = false;
} else {
// Nodes size in [2, maxNodes - 1].
if (state == 0)
// 66% to add, 33% to remove.
add = rnd.nextInt(3) != 0;
else
// 33% to add, 66% to remove.
add = rnd.nextInt(3) == 0;
}
DiscoveryEvent discoEvt;
if (add) {
ClusterNode addedNode = new GridTestNode(UUID.randomUUID());
nodes.add(addedNode);
discoEvt = new DiscoveryEvent(addedNode, "", EventType.EVT_NODE_JOINED, addedNode);
} else {
ClusterNode rmvNode = nodes.remove(rnd.nextInt(nodes.size()));
discoEvt = new DiscoveryEvent(rmvNode, "", EventType.EVT_NODE_LEFT, rmvNode);
}
info("======================================");
info("Assigning partitions [iter=" + i + ", discoEvt=" + discoEvt + ", nodesSize=" + nodes.size() + ']');
info("======================================");
List<List<ClusterNode>> assignment = aff.assignPartitions(new GridAffinityFunctionContextImpl(nodes, prev, discoEvt, new AffinityTopologyVersion(i), backups));
verifyAssignment(assignment, backups, aff.partitions(), nodes.size());
prev = assignment;
i++;
}
}
use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.
the class GridTopologyHeapSizeSelfTest method testTopologyHeapSizeForNodesWithDifferentMacs.
/** */
public void testTopologyHeapSizeForNodesWithDifferentMacs() {
GridTestNode node1 = getNode("123456789ABC", 1000);
GridTestNode node2 = getNode("CBA987654321", 1000);
double size1 = U.heapSize(node1, 10);
double size2 = U.heapSize(node2, 10);
double allSize = U.heapSize(F.asList((ClusterNode) node1, node2), 10);
assertEquals(size1 + size2, allSize, 1E-5);
}
use of org.apache.ignite.testframework.GridTestNode in project ignite by apache.
the class GridTopologyHeapSizeSelfTest method getNode.
/**
* Creates test node with specified attributes.
*
* @param mac Node mac addresses.
* @param pid Node PID.
* @return Node.
*/
private GridTestNode getNode(String mac, int pid) {
ClusterMetricsSnapshot metrics = new ClusterMetricsSnapshot();
metrics.setHeapMemoryMaximum(1024 * 1024 * 1024);
metrics.setHeapMemoryInitialized(1024 * 1024 * 1024);
GridTestNode node = new GridTestNode(UUID.randomUUID(), metrics);
node.addAttribute(ATTR_MACS, mac);
node.addAttribute(ATTR_JVM_PID, pid);
return node;
}
Aggregations