use of org.aion.p2p.INode in project aion by aionnetwork.
the class NodeMgrTest method testTempNodeMax.
@Test
public void testTempNodeMax() {
String[] nodes_max = new String[MAX_TEMP_NODES];
int ip = 0;
int port = 10000;
for (int i = 0; i < nodes_max.length; i++) {
nodes_max[i] = "p2p://" + UUID.randomUUID() + "@255.255.255." + ip++ + ":" + port++;
}
for (String nodeL : nodes_max) {
INode node = Node.parseP2p(nodeL);
assertNotNull(node);
nMgr.addTempNode(node);
nMgr.seedIpAdd(node.getIpStr());
}
assertEquals(MAX_TEMP_NODES, nMgr.tempNodesSize());
// future nodes will be rejected due to the reached limit
ip = 0;
for (int i = 0; i < nodes_max.length; i++) {
nodes_max[i] = "p2p://" + UUID.randomUUID() + "@255.255.254." + ip++ + ":" + port++;
}
for (String nodeL : nodes_max) {
INode node = Node.parseP2p(nodeL);
assertNotNull(node);
nMgr.addTempNode(node);
nMgr.seedIpAdd(node.getIpStr());
assertEquals(MAX_TEMP_NODES, nMgr.tempNodesSize());
}
}
use of org.aion.p2p.INode in project aion by aionnetwork.
the class NodeMgrTest method testGetRandom.
@Test(timeout = 30_000)
public void testGetRandom() {
assertNull(nMgr.getRandom());
INode node = nMgr.allocNode(ip2, 1);
addNodetoInbound(node, UUID.fromString(nodeId1));
nMgr.movePeerToActive(node.getChannel().hashCode(), "inbound");
INode nodeRandom = nMgr.getRandom();
assertNotNull(node);
assertEquals(node, nodeRandom);
}
use of org.aion.p2p.INode in project aion by aionnetwork.
the class NodeMgrTest method testGetActiveNodesList.
@Test(timeout = 30_000)
public void testGetActiveNodesList() {
INode node = nMgr.allocNode(ip2, 1);
node.setChannel(channel);
node.setId(nodeId2.getBytes(StandardCharsets.UTF_8));
nMgr.addInboundNode(node);
assertEquals(0, nMgr.activeNodesSize());
nMgr.movePeerToActive(channel.hashCode(), "inbound");
assertEquals(1, nMgr.activeNodesSize());
List<INode> active = nMgr.getActiveNodesList();
for (INode activeN : active) {
assertEquals(ip2, activeN.getIpStr());
}
}
use of org.aion.p2p.INode in project aion by aionnetwork.
the class NodeMgrTest method testDumpNodeInfo2.
@Test(timeout = 30_000)
public void testDumpNodeInfo2() {
String dump = nMgr.dumpNodeInfo("testId", false);
assertNotNull(dump);
nMgr.seedIpAdd(ip1);
INode node = nMgr.allocNode(ip1, 1);
byte[] rHash = new byte[32];
r.nextBytes(rHash);
node.updateStatus(r.nextLong(), rHash, BigInteger.ONE, (byte) r.nextInt(), (short) r.nextInt(), r.nextInt(), r.nextInt());
addNodetoOutbound(node, UUID.randomUUID());
nMgr.movePeerToActive(node.getIdHash(), "outbound");
String dump2 = nMgr.dumpNodeInfo("testId", false);
assertTrue(dump2.length() > dump.length());
String dump3 = nMgr.dumpNodeInfo("testId", true);
assertEquals(dump3.length(), dump2.length());
}
use of org.aion.p2p.INode in project aion by aionnetwork.
the class NodeMgrTest method testMovePeerToActiveFromOutbound.
@Test
public void testMovePeerToActiveFromOutbound() {
INode node = nMgr.allocNode(ip2, 1);
node.setChannel(channel);
addNodetoOutbound(node, UUID.fromString(nodeId1));
// wrong type & key
nMgr.movePeerToActive(node.getIdHash(), "inbound");
assertTrue(nMgr.getActiveNodesMap().isEmpty());
// move first node
nMgr.movePeerToActive(node.getIdHash(), "outbound");
assertEquals(1, nMgr.getActiveNodesMap().size());
// move different node
node = nMgr.allocNode(ip1, 1);
addNodetoOutbound(node, UUID.fromString(nodeId2));
nMgr.movePeerToActive(node.getIdHash(), "outbound");
assertEquals(2, nMgr.getActiveNodesMap().size());
// move same node again
nMgr.movePeerToActive(node.getIdHash(), "outbound");
assertEquals(2, nMgr.getActiveNodesMap().size());
}
Aggregations