/** * @param nodesCnt Nodes count to test. */ public ServiceReassignmentFunctionSelfTest(int nodesCnt) { assertTrue(nodesCnt > 0); nodes = new ArrayList<>(); processors = new ArrayList<>(); for (int i = 0; i < nodesCnt; i++) nodes.add(new GridTestNode(UUID.randomUUID())); for (int i = 0; i < nodesCnt; i++) processors.add(mockServiceProcessor()); }
/** * Adds Collision SPI attribute. * * @param node Node to add attribute to. * @throws Exception If failed. */ private void addSpiDependency(GridTestNode node) throws Exception { node.addAttribute(ATTR_SPI_CLASS, JobStealingCollisionSpi.class.getName()); node.setAttribute(U.spiAttribute(getSpi(), ATTR_SPI_CLASS), getSpi().getClass().getName()); }
/** * @param id Node ID. */ public GridTestNode(UUID id) { this.id = id; initAttributes(); }
/** * @param nodesCnt Count of nodes to generate. * @return Nodes list. */ private List<ClusterNode> createBaseNodes(int nodesCnt) { List<ClusterNode> nodes = new ArrayList<>(nodesCnt); for (int i = 0; i < nodesCnt; i++) { GridTestNode node = new GridTestNode(UUID.randomUUID()); // two neighbours nodes node.setAttribute(IgniteNodeAttributes.ATTR_MACS, MAC_PREF + i / 2); nodes.add(node); } return nodes; }
/** * 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(1024L * 1024 * 1024); metrics.setHeapMemoryInitialized(1024L * 1024 * 1024); GridTestNode node = new GridTestNode(UUID.randomUUID(), metrics); node.addAttribute(ATTR_MACS, mac); node.addAttribute(ATTR_JVM_PID, pid); return node; } }
GridTestNode node = new GridTestNode(rsrcs.getNodeId()); node.order(i); node.setAttributes(spi.getNodeAttributes()); node.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
GridTestNode node = new GridTestNode(rsrcs.getNodeId()); node.setAttributes(spi.getNodeAttributes()); node.order(i);
/** {@inheritDoc} */ @Override protected GridSpiTestContext initSpiContext() throws Exception { GridSpiTestContext ctx = super.initSpiContext(); GridTestNode locNode = new GridTestNode(UUID.randomUUID()); addSpiDependency(locNode); ctx.setLocalNode(locNode); GridTestNode rmtNode = new GridTestNode(UUID.randomUUID()); addSpiDependency(rmtNode); rmtNode.setAttribute(U.spiAttribute(getSpi(), WAIT_JOBS_THRESHOLD_NODE_ATTR), getWaitJobsThreshold()); ClusterMetricsSnapshot metrics = new ClusterMetricsSnapshot(); metrics.setCurrentWaitingJobs(2); rmtNode.setMetrics(metrics); ctx.addNode(rmtNode); return ctx; }
/** {@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); }
/** * @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); // Message should be sent to remote node because it has the same // attributes. assert msg != null; }
/** {@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; }
GridTestNode fakeNode = new GridTestNode(UUID.randomUUID(), null); fakeNode.consistentId(getTestIgniteInstanceName(nodes.size()));
nodes, new GridTestJob()); int idx = ((Double)node.attribute("load")).intValue() - 1; node.setAttribute("used", true);
/** * Adds Failover SPI attribute. * * @param node Node to add attribute to. */ private void addSpiDependency(GridTestNode node) { node.addAttribute(IgniteNodeAttributes.ATTR_SPI_CLASS, JobStealingCollisionSpi.class.getName()); } }
@Override public void run() { try { while (cntr.getAndIncrement() < msgCnt) { GridTestMessage msg = new GridTestMessage(locNode.id(), msgId.getAndIncrement(), 0); msg.payload(new byte[13 * 1024]); spi.sendMessage(remoteNode, msg); } } catch (IgniteException e) { fail("Unable to send message: " + e.getMessage()); } } }, THREAD_CNT, "message-sender");
node -> ((GridTestNode)node).setAttribute(GRP_ATTR, ODD_GRP));
GridTestNode node = new GridTestNode(rsrcs.getNodeId()); node.setAttribute(IgniteNodeAttributes.ATTR_CLIENT_MODE, false); node.order(i + 1); node.setAttributes(spi.getNodeAttributes());
GridTestNode node = new GridTestNode(rsrcs.getNodeId()); node.setAttributes(spi.getNodeAttributes()); node.order(i);
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { super.beforeTest(); rmtNode = new GridTestNode(UUID.randomUUID()); addSpiDependency(rmtNode); rmtNode.setAttribute(U.spiAttribute(getSpi(), WAIT_JOBS_THRESHOLD_NODE_ATTR), getWaitJobsThreshold()); ClusterMetricsSnapshot metrics = new ClusterMetricsSnapshot(); metrics.setCurrentWaitingJobs(2); rmtNode.setMetrics(metrics); getSpiContext().addNode(rmtNode); getSpi().setStealingEnabled(true); }
/** * @param nodes Topology. * @param iter Iteration count. * @return Discovery event. */ @NotNull private DiscoveryEvent addNode(List<ClusterNode> nodes, int iter) { GridTestNode node = new GridTestNode(UUID.randomUUID()); // two neighbours nodes node.setAttribute(IgniteNodeAttributes.ATTR_MACS, MAC_PREF + "_add_" + iter / 4); nodes.add(node); return new DiscoveryEvent(nodes.get(0), "", EventType.EVT_NODE_JOINED, node); }