/** * Sends optional message. If message is {@code null} - it's no-op. * * @param nodeId ID of the node to send message to. * @param respMsg Message to send. * @throws IgniteException Thrown in case of any errors. */ private void send(UUID nodeId, @Nullable Object respMsg) throws IgniteException { assert nodeId != null; if (respMsg != null) { ClusterNode node = ignite.cluster().node(nodeId); if (node != null) ignite.message(ignite.cluster().forNode(node)).send(null, respMsg); // Can still fail. else throw new IgniteException("Failed to send message since destination node has " + "left topology (ignoring) [nodeId=" +nodeId + ", respMsg=" + respMsg + ']'); } }
/** * @throws Exception Thrown in case of failure. */ @Test public void testAnonymousUnicast() throws Exception { Ignite g = grid(0); assert g.cluster().nodes().size() == NODES_CNT; execCntr.set(0); ClusterNode rmt = F.first(g.cluster().forRemotes().nodes()); compute(g.cluster().forNode(rmt)).run(new CARemote() { @Override public void apply() { log.info("UNICASTING...."); ignite.countDownLatch("unicast", 1, false, true).countDown(); execCntr.incrementAndGet(); } }); assertTrue(g.countDownLatch("unicast", 1, false, true).await(2000)); assertEquals(0, execCntr.get()); }
/** * * @throws Exception Thrown in case of failure. */ @Test public void testAnonymousUnicastRequest() throws Exception { Ignite g = grid(0); assert g.cluster().nodes().size() == NODES_CNT; execCntr.set(0); ClusterNode rmt = F.first(g.cluster().forRemotes().nodes()); final ClusterNode loc = g.cluster().localNode(); compute(g.cluster().forNode(rmt)).run(new CARemote() { @Override public void apply() { message(grid(1).cluster().forNode(loc)).localListen(null, new IgniteBiPredicate<UUID, String>() { @Override public boolean apply(UUID uuid, String s) { log.info("Received test message [nodeId: " + uuid + ", s=" + s + ']'); ignite.countDownLatch("messagesPending", 1, false, true).countDown(); execCntr.incrementAndGet(); return false; } }); } }); message(g.cluster().forNode(rmt)).send(null, "TESTING..."); assertTrue(g.countDownLatch("messagesPending", 1, false, true).await(2000)); assertEquals(0, execCntr.get()); }
compute(G.ignite(node.id()).cluster().forNode(node)).call(new IgniteCallable<Void>() {
/** * @throws Exception If failed. */ @Test public void testYoungest() throws Exception { ClusterGroup youngest = ignite.cluster().forYoungest(); ClusterNode node = null; long maxOrder = Long.MIN_VALUE; for (ClusterNode n : ignite.cluster().nodes()) { if (n.order() > maxOrder) { node = n; maxOrder = n.order(); } } assertEquals(youngest.node(), ignite.cluster().forNode(node).node()); ClusterGroup emptyGrp = ignite.cluster().forAttribute("nonExistent", "val"); assertEquals(0, emptyGrp.forYoungest().nodes().size()); }
/** * @throws Exception If failed. */ @Test public void testOldest() throws Exception { ClusterGroup oldest = ignite.cluster().forOldest(); ClusterNode node = null; long minOrder = Long.MAX_VALUE; for (ClusterNode n : ignite.cluster().nodes()) { if (n.order() < minOrder) { node = n; minOrder = n.order(); } } assertEquals(oldest.node(), ignite.cluster().forNode(node).node()); ClusterGroup emptyGrp = ignite.cluster().forAttribute("nonExistent", "val"); assertEquals(0, emptyGrp.forOldest().nodes().size()); }
final UUID checkNodeId = node.id(); compute(G.ignite(checkNodeId).cluster().forNode(node)).call(new IgniteCallable<Void>() {
final UUID checkNodeId = node.id(); compute(G.ignite(checkNodeId).cluster().forNode(node)).call(new IgniteCallable<Void>() {
/** * @throws Exception If failed. */ @Test public void testRemoteNotStickProxyInvocation() throws Exception { final String name = "testRemoteNotStickProxyInvocation"; final Ignite ignite = grid(0); ignite.services().deployNodeSingleton(name, new MapServiceImpl<String, Integer>()); // Get remote proxy. MapService<Integer, String> svc = ignite.services(ignite.cluster().forRemotes()). serviceProxy(name, MapService.class, false); // Make sure service is a local instance. assertFalse(svc instanceof Service); for (int i = 0; i < nodeCount(); i++) svc.put(i, Integer.toString(i)); int size = 0; for (ClusterNode n : ignite.cluster().forRemotes().nodes()) { MapService<Integer, String> map = ignite.services(ignite.cluster().forNode(n)). serviceProxy(name, MapService.class, false); // Make sure service is a local instance. assertFalse(map instanceof Service); size += map.size(); } assertEquals(nodeCount(), size); }
/** * @throws Exception If failed. */ @Test public void testRemoteStickyProxyInvocation() throws Exception { final String name = "testRemoteStickyProxyInvocation"; final Ignite ignite = grid(0); ignite.services().deployNodeSingleton(name, new MapServiceImpl<String, Integer>()); // Get remote proxy. MapService<Integer, String> svc = ignite.services(ignite.cluster().forRemotes()). serviceProxy(name, MapService.class, true); // Make sure service is a local instance. assertFalse(svc instanceof Service); for (int i = 0; i < nodeCount(); i++) svc.put(i, Integer.toString(i)); int size = 0; for (ClusterNode n : ignite.cluster().forRemotes().nodes()) { MapService<Integer, String> map = ignite.services(ignite.cluster().forNode(n)). serviceProxy(name, MapService.class, false); // Make sure service is a local instance. assertFalse(map instanceof Service); if (map.size() != 0) size += map.size(); } assertEquals(nodeCount(), size); }
/** * @throws Exception If failed. */ @Test public void testClusterNodeMetrics() throws Exception { final Ignite ignite0 = grid(); final Ignite ignite1 = startGrid(1); GridTestUtils.waitForCondition(new GridAbsPredicate() { @Override public boolean apply() { return ignite0.cluster().nodes().size() == 2 && ignite1.cluster().nodes().size() == 2; } }, 3000L); ClusterMetrics metrics0 = ignite0.cluster().localNode().metrics(); ClusterMetrics nodesMetrics = ignite0.cluster().forNode(ignite0.cluster().localNode(), ignite1.cluster().localNode()).metrics(); assertEquals(metrics0.getTotalCpus(), nodesMetrics.getTotalCpus()); assertEquals(1, metrics0.getTotalNodes()); assertEquals(2, nodesMetrics.getTotalNodes()); assert metrics0.getHeapMemoryUsed() > 0; assert metrics0.getHeapMemoryTotal() > 0; }
/** * @throws Exception If failed. */ @Test public void testNodeSingletonRemoteStickyProxy() throws Exception { String name = "testNodeSingletonRemoteStickyProxy"; Ignite ignite = randomGrid(); // Deploy only on remote nodes. ignite.services(ignite.cluster().forRemotes()).deployNodeSingleton(name, new CounterServiceImpl()); // Get local proxy. CounterService svc = ignite.services().serviceProxy(name, CounterService.class, true); for (int i = 0; i < 10; i++) svc.increment(); assertEquals(10, svc.get()); int total = 0; for (ClusterNode n : ignite.cluster().forRemotes().nodes()) { CounterService rmtSvc = ignite.services(ignite.cluster().forNode(n)).serviceProxy(name, CounterService.class, false); int cnt = rmtSvc.localIncrements(); assertTrue("Invalid local increments: " + cnt, cnt == 10 || cnt == 0); total += rmtSvc.localIncrements(); } assertEquals(10, total); }
/** * @throws Exception If failed. */ @Test public void testNodeSingletonRemoteNotStickyProxy() throws Exception { String name = "testNodeSingletonRemoteNotStickyProxy"; Ignite ignite = randomGrid(); // Deploy only on remote nodes. ignite.services(ignite.cluster().forRemotes()).deployNodeSingleton(name, new CounterServiceImpl()); info("Deployed service: " + name); // Get local proxy. CounterService svc = ignite.services().serviceProxy(name, CounterService.class, false); for (int i = 0; i < 10; i++) svc.increment(); assertEquals(10, svc.get()); int total = 0; for (ClusterNode n : ignite.cluster().forRemotes().nodes()) { CounterService rmtSvc = ignite.services(ignite.cluster().forNode(n)).serviceProxy(name, CounterService.class, false); int cnt = rmtSvc.localIncrements(); // Since deployment is not stick, count on each node must be less than 10. assertTrue("Invalid local increments: " + cnt, cnt != 10); total += cnt; } assertEquals(10, total); }
/** * @throws Exception If failed. */ @Test public void testNodeSingletonProxy() throws Exception { String name = "testNodeSingletonProxy"; Ignite ignite = randomGrid(); ignite.services().deployNodeSingleton(name, new CounterServiceImpl()); CounterService svc = ignite.services().serviceProxy(name, CounterService.class, false); for (int i = 0; i < 10; i++) svc.increment(); assertEquals(10, svc.get()); assertEquals(10, svc.localIncrements()); assertEquals(10, ignite.services(ignite.cluster().forLocal()). serviceProxy(name, CounterService.class, false).localIncrements()); // Make sure that remote proxies were not called. for (ClusterNode n : ignite.cluster().forRemotes().nodes()) { CounterService rmtSvc = ignite.services(ignite.cluster().forNode(n)).serviceProxy(name, CounterService.class, false); assertEquals(0, rmtSvc.localIncrements()); } }
/** * Sends optional message. If message is {@code null} - it's no-op. * * @param nodeId ID of the node to send message to. * @param respMsg Message to send. * @throws IgniteException Thrown in case of any errors. */ private void send(UUID nodeId, @Nullable Object respMsg) throws IgniteException { assert nodeId != null; if (respMsg != null) { ClusterNode node = ignite.cluster().node(nodeId); if (node != null) ignite.message(ignite.cluster().forNode(node)).send(null, respMsg); // Can still fail. else throw new IgniteException("Failed to send message since destination node has " + "left topology (ignoring) [nodeId=" +nodeId + ", respMsg=" + respMsg + ']'); } }