/** {@inheritDoc} */ @Override protected Void run(VisorComputeCancelSessionsTaskArg arg) { Set<IgniteUuid> sesIds = arg.getSessionIds(); if (sesIds != null && !sesIds.isEmpty()) { IgniteCompute compute = ignite.compute(ignite.cluster().forLocal()); Map<IgniteUuid, ComputeTaskFuture<Object>> futs = compute.activeTaskFutures(); for (IgniteUuid sesId : sesIds) { ComputeTaskFuture<Object> fut = futs.get(sesId); if (fut != null) fut.cancel(); } } return null; }
/** * JUnit. * * @throws Exception If failed. */ @Test public void testGetAndIncrement() throws Exception { Collection<Long> res = new HashSet<>(); String seqName = UUID.randomUUID().toString(); for (int i = 0; i < GRID_CNT; i++) { Set<Long> retVal = compute(grid(i).cluster().forLocal()). call(new GetAndIncrementJob(seqName, RETRIES)); for (Long l : retVal) assert !res.contains(l) : "Value already was used " + l; res.addAll(retVal); } assert res.size() == GRID_CNT * RETRIES; int gapSize = 0; for (long i = 0; i < GRID_CNT * RETRIES; i++) { if (!res.contains(i)) gapSize++; else gapSize = 0; assert gapSize <= BATCH_SIZE + 1 : "Gap above id " + i + " is " + gapSize + " more than batch size: " + (BATCH_SIZE + 1); } }
/** * JUnit. * * @throws Exception If failed. */ @Test public void testIncrementAndGet() throws Exception { Collection<Long> res = new HashSet<>(); String seqName = UUID.randomUUID().toString(); for (int i = 0; i < GRID_CNT; i++) { Set<Long> retVal = compute(grid(i).cluster().forLocal()). call(new IncrementAndGetJob(seqName, RETRIES)); for (Long l : retVal) assert !res.contains(l) : "Value already was used " + l; res.addAll(retVal); } assert res.size() == GRID_CNT * RETRIES; int gapSize = 0; for (long i = 1; i <= GRID_CNT * RETRIES; i++) { if (!res.contains(i)) gapSize++; else gapSize = 0; assert gapSize <= BATCH_SIZE : "Gap above id " + i + " is " + gapSize + "more than batch size: " + BATCH_SIZE; } }
/** * @param loc Enforce local. * @return Local node cluster group. */ private ClusterGroup projection(boolean loc) { GridCacheContext<K, V> ctx = getContextSafe(); if (loc || ctx.isLocal() || ctx.isReplicatedAffinityNode()) return ctx.kernalContext().grid().cluster().forLocal(); if (ctx.isReplicated()) return ctx.kernalContext().grid().cluster().forDataNodes(cacheName).forRandom(); return null; }
/** * @throws Exception If failed. */ @Test public void testStopLocalListenByCallback() throws Exception { final AtomicInteger cnt = new AtomicInteger(); final CountDownLatch latch = new CountDownLatch(1); grid(0).events().localListen( new P1<Event>() { @Override public boolean apply(Event evt) { info("Local event [" + evt.shortDisplay() + ']'); assertEquals(EVT_JOB_STARTED, evt.type()); cnt.incrementAndGet(); latch.countDown(); return false; } }, EVT_JOB_STARTED); compute(grid(0).cluster().forLocal()).run(F.noop()); assert latch.await(10, SECONDS) : latch; assertEquals(1, cnt.get()); compute(grid(0).cluster().forLocal()).run(F.noop()); U.sleep(500); assertEquals(1, cnt.get()); }
/** * Single server test. * * @param async Async message send flag. * @throws Exception If failed. */ private void localServerInternal(boolean async) throws Exception { int messages = MSGS; Ignite ignite = grid(SERVER_NODE_IDX); LATCH = new CountDownLatch(messages); ClusterGroup grp = grid(SERVER_NODE_IDX).cluster().forLocal(); UUID opId = registerListener(grp); try { for (int i = 0; i < messages; i++) sendMessage(ignite, grp, value(i), async); assertTrue(LATCH.await(10, TimeUnit.SECONDS)); } finally { ignite.message().stopRemoteListen(opId); } }
/** * Single server test with local listener. * @throws Exception If failed. */ private void localListenerInternal() throws Exception { int messages = MSGS; Ignite ignite = grid(SERVER_NODE_IDX); LATCH = new CountDownLatch(messages); ClusterGroup grp = grid(SERVER_NODE_IDX).cluster().forLocal(); MessageListener c = new MessageListener(); try { ignite.message(grp).localListen("localListenerTopic", c); for (int i = 0; i < messages; i++) ignite.message(grp).send("localListenerTopic", value(i)); assertTrue(LATCH.await(10, TimeUnit.SECONDS)); } finally { ignite.message().stopLocalListen("localListenerTopic", c); } }
final CountDownLatch latch = new CountDownLatch(1); UUID consumeId = events(grid(0).cluster().forLocal()).remoteListen( new P2<UUID, Event>() { @Override public boolean apply(UUID nodeId, Event evt) {
IgniteFuture readFut = ignite2.compute(ignite2.cluster().forLocal()).callAsync(new IgniteCallable<Object>() { @Override public Object call() throws Exception { barrier.await(MAX_AWAIT, TimeUnit.MILLISECONDS);
/** {@inheritDoc} */ @Override protected Void run(VisorComputeCancelSessionsTaskArg arg) { Set<IgniteUuid> sesIds = arg.getSessionIds(); if (sesIds != null && !sesIds.isEmpty()) { IgniteCompute compute = ignite.compute(ignite.cluster().forLocal()); Map<IgniteUuid, ComputeTaskFuture<Object>> futs = compute.activeTaskFutures(); for (IgniteUuid sesId : sesIds) { ComputeTaskFuture<Object> fut = futs.get(sesId); if (fut != null) fut.cancel(); } } return null; }
/** * @param loc Enforce local. * @return Local node cluster group. */ private ClusterGroup projection(boolean loc) { if (loc || ctx.isLocal() || ctx.isReplicatedAffinityNode()) return ctx.kernalContext().grid().cluster().forLocal(); if (ctx.isReplicated()) return ctx.kernalContext().grid().cluster().forDataNodes(ctx.name()).forRandom(); return null; }