@Override public Void call() throws Exception { Ignite node = ignite(nodeIdx.getAndIncrement()); int cnt = 0; while (!done.get()) { for (String cacheName : cacheNames) { // TODO IGNITE-6754 add SQL and SCAN support. Map<Integer, Integer> res = readAllByMode(node.cache(cacheName), vals.keySet(), GET, INTEGER_CODEC); assertEquals(vals, res); } cnt++; } log.info("Finished [node=" + node.name() + ", cnt=" + cnt + ']'); return null; } }, NODES - 1, "get-thread");
@Override public Void call() throws Exception { Ignite node = ignite(idx.incrementAndGet() % NODES); b.await(); boolean sleep = iter % 2 == 0; if (sleep) Thread.sleep(ThreadLocalRandom.current().nextLong(100) + 1); switch (op) { case GET_OR_CREATE_CACHE: node.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME)); break; case GET_OR_CREATE_CACHES: node.getOrCreateCaches(cacheConfigurations()); break; } return null; } }, THREADS, "start-cache");
/** * Stops streamer. * * @throws IgniteException If failed. */ public void stop() throws IgniteException { if (stopped) return; stopped = true; getIgnite().<K, V>dataStreamer(cacheName).close(true); getIgnite().close(); }
@Override public String call() throws Exception { assertFalse(ignite.configuration().isClientMode()); return ignite.name(); } });
@Override public void run() { ex1.active(true); try { checkTopology(2); startLatch.countDown(); IgniteCache<Object, Object> cache1 = ex1.cache(DEFAULT_CACHE_NAME); int key = keyCnt.get(); while (!stop.get()) { if (key > 0 && (key % 500 == 0)) { U.sleep(5); System.out.println("key = " + key); } cache1.put(key, -key); key = keyCnt.incrementAndGet(); } } catch (Throwable th) { th.printStackTrace(); } doneLatch.countDown(); } });
@Override public void run() { startLatch.countDown(); try { startLatch.await(); } catch (InterruptedException e) { e.printStackTrace(); } //busy spinning after waking up from startLatch.await // to reduce probability that one thread starts significantly earlier than the other while (!busySpinFlag) { if (trickCompilerVar.get() < 0) break; } Ignition.localIgnite().cache(DEFAULT_CACHE_NAME).put(2, bOrg2); } });
@Override public boolean apply(UUID nodeId, Object msg) { try { log.info("Received new message [msg=" + msg + ", senderNodeId=" + nodeId + ']'); if (!nodeId.equals(ignite2.cluster().localNode().id())) { log.error("Unexpected sender node: " + nodeId); error.set(true); return false; } rcvMsgs.add(msg); return true; } finally { rcvLatch.countDown(); } } });
@Override public boolean apply(Event evt) { if (stopping.get()) return true; info(evt.message()); UUID id = ((DiscoveryEvent) evt).eventNode().id(); if (id.equals(g1.cluster().localNode().id())) latch2_1.countDown(); else if (id.equals(g2.cluster().localNode().id())) latch2_2.countDown(); else assert false : "Event fired for unknown node."; return true; } },
/** * @throws Exception If failed. */ @Test public void testNodeJoin() throws Exception { latch = new CountDownLatch(MSG_CNT * (GRID_CNT + 1)); listen(grid(0).cluster(), null, true); try { Ignite g = startGrid("anotherGrid"); send(); assert latch.await(2, SECONDS); Thread.sleep(500); assertEquals(MSG_CNT * (GRID_CNT + 1), cnt.get()); List<UUID> allNodes0 = new ArrayList<>(allNodes); allNodes0.add(g.cluster().localNode().id()); Collections.sort(allNodes0); checkNodes(allNodes0); } finally { stopGrid("anotherGrid"); } }
@Override public Object call() throws Exception { pingLatch.countDown(); pingRes.set(pingingNode.configuration().getDiscoverySpi().pingNode( failedNodeId)); return null; } }, 1);
@Override public Object call() throws Exception { int nodeId = nodeIdx.getAndIncrement(); IgniteCache<Integer, Integer> cache = grid(nodeId).cache(DEFAULT_CACHE_NAME); int cntr = 0; while (!done.get()) { int part = ThreadLocalRandom.current().nextInt(ignite(nodeId).affinity(DEFAULT_CACHE_NAME).partitions()); if (cntr++ % 100 == 0) info("Running query [node=" + nodeId + ", part=" + part + ']'); try (QueryCursor<Cache.Entry<Integer, Integer>> cur = cache.query(new ScanQuery<Integer, Integer>(part).setPageSize(5))) { doTestScanQueryCursor(cur, part); } } return null; } }, GRID_CNT);
@Override public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) throws CacheEntryListenerException { for (CacheEntryEvent<? extends Integer, ? extends Integer> e : evts) { cntr.incrementAndGet(); ClusterNode node = ((Ignite)e.getSource().unwrap(Ignite.class)).cluster().localNode(); Set<Integer> set = maps.get(node); if (set == null) { set = new ConcurrentSkipListSet<>(); Set<Integer> oldVal = maps.putIfAbsent(node, set); set = oldVal != null ? oldVal : set; } if (!set.add(e.getValue())) doubleNtfFail.set(false); } } };
/** {@inheritDoc} */ @Override public boolean apply(UUID nodeId, Object msg) { assertNotNull(ignite); assertNotNull(ignite.configuration().getNodeId()); X.println("Received message [nodeId=" + nodeId + ", locNodeId=" + ignite.cluster().localNode().id() + ']'); assertEquals(sourceNodeId, nodeId); assertEquals(MSG, msg); nodes.add(ignite.configuration().getNodeId()); cnt.incrementAndGet(); latch.countDown(); return ret; } }
/** {@inheritDoc} */ @Override protected void receive(UUID nodeId, Object msg) throws Throwable { assertNotNull(ignite()); UUID locNodeId = ignite().cluster().localNode().id(); X.println("Received message [nodeId=" + nodeId + ", locNodeId=" + locNodeId + ']'); assertEquals(sourceNodeId, nodeId); assertEquals(MSG, msg); nodes.add(locNodeId); cnt.incrementAndGet(); latch.countDown(); } }
@Nullable @Override public Object call() throws Exception { startLatch.await(); info("Started evicting..."); for (int i = 0; i < 3000 && !done.get(); i++) { Cache.Entry<Integer, Object> entry = cache1.getEntry(i); if (entry != null) ignite1.cache(DEFAULT_CACHE_NAME).localEvict(Collections.<Object>singleton(entry.getKey())); else info("Entry is null."); } info("Finished evicting."); return null; } },
@Override public Object call() throws Exception { int idx = cntr.getAndIncrement() % 2; IgniteCache<Object, Object> cache = ignite(idx).cache(DEFAULT_CACHE_NAME); long cntr = 0; while (!stop.get()) { cache.size(); if (cntr++ % 1000 == 0) log.info("Iteration: " + cntr); } return null; } }, 10, "size-thread");
/** * @param num Task number. * @throws InterruptedException If interrupted. * @throws IgniteCheckedException If failed. */ private void checkTask(int num) throws InterruptedException, IgniteCheckedException { Ignite ignite = G.ignite(getTestIgniteInstanceName()); ComputeTaskFuture<?> fut = executeAsync(ignite.compute(), GridTaskSessionTestTask.class, num); boolean await = startSignal[num].await(WAIT_TIME, TimeUnit.MILLISECONDS); // Wait until jobs begin execution. assert await : "Jobs did not start."; assert fut != null; Object res = fut.get(); assert "interrupt-task-data".equals(res) : "Invalid task result: " + res; await = stopSignal[num].await(WAIT_TIME, TimeUnit.MILLISECONDS); // Wait for all jobs to finish. assert await : "Jobs did not cancel [interruptCount=" + Arrays.toString(interruptCnt) + ']'; int cnt = interruptCnt[num].get(); assert cnt == SPLIT_COUNT - 1 : "Invalid interrupt count value: " + cnt; }
/** {@inheritDoc} */ @Override protected Object executeJob(int gridSize, String type) { log.info(">>> Starting new grid node [currGridSize=" + gridSize + ", arg=" + type + "]"); if (type == null) throw new IllegalArgumentException("Node type to start should be specified."); IgniteConfiguration cfg = getConfig(type); // Generate unique for this VM Ignite instance name. String igniteInstanceName = cfg.getIgniteInstanceName() + " (" + UUID.randomUUID() + ")"; // Update Ignite instance name (required to be unique). cfg.setIgniteInstanceName(igniteInstanceName); // Start new node in current VM. Ignite g = G.start(cfg); log.info(">>> Grid started [nodeId=" + g.cluster().localNode().id() + ", name='" + g.name() + "']"); return true; }