/** * @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; }
node.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
node.setAttribute(IgniteNodeAttributes.ATTR_CLIENT_MODE, false);
/** * @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); }
/** {@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); }
/** * 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()); }
node.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
/** {@inheritDoc} */ @Override protected GridSpiTestContext initSpiContext() throws Exception { GridSpiTestContext ctx = super.initSpiContext(); for (int i = 0; i < RMT_NODE_CNT; i++) { GridTestNode node = new GridTestNode(UUID.randomUUID()); node.setAttribute("load", (double)(i + 1)); ctx.addNode(node); } return ctx; }
/** * @throws Exception If failed. */ @SuppressWarnings({"ObjectEquality"}) @Test public void testSingleNodeZeroWeight() throws Exception { GridTestNode node = (GridTestNode)getSpiContext().nodes().iterator().next(); node.addAttribute("load", 0d); List<ClusterNode> nodes = Collections.singletonList((ClusterNode)node); ComputeTaskSession ses = new GridTestTaskSession(IgniteUuid.randomUuid()); GridTestNode pick1 = (GridTestNode)getSpi().getBalancedNode(ses, nodes, new GridTestJob()); pick1.setAttribute("used", true); assert nodes.contains(pick1); // Verify that same instance is returned every time. ClusterNode pick2 = getSpi().getBalancedNode(ses, nodes, new GridTestJob()); assert pick1 == pick2; }
/** * @throws Exception If failed. */ @SuppressWarnings({"ObjectEquality"}) @Test public void testSingleNodeSameSession() throws Exception { GridTestNode node = (GridTestNode)getSpiContext().nodes().iterator().next(); node.addAttribute("load", 1d); List<ClusterNode> nodes = Collections.singletonList((ClusterNode)node); ComputeTaskSession ses = new GridTestTaskSession(IgniteUuid.randomUuid()); GridTestNode pick1 = (GridTestNode)getSpi().getBalancedNode(ses, nodes, new GridTestJob()); pick1.setAttribute("used", true); assert nodes.contains(pick1); // Verify that same instance is returned every time. ClusterNode pick2 = getSpi().getBalancedNode(ses, nodes, new GridTestJob()); assert pick1 == pick2; }
node.setAttribute("used", true);
/** * @throws Exception If failed. */ @SuppressWarnings({"ObjectEquality"}) @Test public void testSingleNodeDifferentSession() throws Exception { GridTestNode node = (GridTestNode)getSpiContext().nodes().iterator().next(); node.addAttribute("load", 2d); List<ClusterNode> nodes = Collections.singletonList((ClusterNode)node); GridTestNode pick1 = (GridTestNode)getSpi().getBalancedNode(new GridTestTaskSession(IgniteUuid.randomUuid()), nodes, new GridTestJob()); pick1.setAttribute("used", true); assert nodes.contains(pick1); // Verify that same instance is returned every time. ClusterNode pick2 = getSpi().getBalancedNode(new GridTestTaskSession(IgniteUuid.randomUuid()), nodes, new GridTestJob()); assert pick1 == pick2; } }
/** * @throws Exception If test failed. */ @Test 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); // 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()); 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; }
/** * @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 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); }
/** * @throws Exception If test failed. */ @Test 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); // Message should be sent to remote node because it has the same // attributes. assert msg == null; }
node -> ((GridTestNode)node).setAttribute(GRP_ATTR, ODD_GRP));