@Override public void test(Factory factory, Ignite ignite) throws Exception { IgniteRunnable job = (IgniteRunnable)factory.create(); ignite.compute().run(job); // All checks are inside the run() method of the job. Collection<IgniteRunnable> jobs = new ArrayList<>(MAX_JOB_COUNT); for (int i = 0; i < MAX_JOB_COUNT; ++i) jobs.add((IgniteRunnable)factory.create()); ignite.compute().run(jobs); // All checks are inside the run() method of the job. } });
/** * @param cnt Counter. * @throws Exception If failed. */ private void run2(AtomicInteger cnt) throws Exception { Collection<IgniteRunnable> jobs = F.asList(runJob); IgniteFuture<Void> fut = compute(prj).runAsync(jobs); waitForExecution(fut); cnt.set(0); compute(prj).run(jobs); waitForValue(cnt, jobs.size()); }
@Override public Object call() throws Exception { g.compute().withNoFailover().run(r); return null; } },
@Override public void run() { ignite(0).compute().run(new IncrementClosure()); } }, THREAD_NUM);
/** {@inheritDoc} */ @Override public void localListen(final IgnitePredicate<? extends Event> lsnr, final int... types) { igniteProxy.remoteCompute().run(new LocalListenTask(lsnr, types)); }
@Override public Void call() throws Exception { int idx = b.await(); Ignite node = ignite(idx % 3); IgniteCompute comp = node.compute(node.cluster().forRemotes()); comp.run(new TestJob()); return null; }
/** * @throws Exception If failed. */ @Test public void testCacheSizeOnPublicThreadpoolStarvation() throws Exception { grid(0).compute().run(new IgniteRunnable() { @Override public void run() { grid(0).cache(CACHE_NAME).size(); } }); } }
/** * Test that Binarylizable IgniteRunnable with ComputeJobMasterLeaveAware interface is serialized * using BinaryMarshaller. * * @throws Exception If failed. */ @Test public void testMasterLeaveAwareRunnable() throws Exception { Ignite ignite = startGrid(1); startGrid(2); final TestBinarylizableMasterLeaveAwareRunnable runnable = new TestBinarylizableMasterLeaveAwareRunnable(); ignite.compute(ignite.cluster().forRemotes()).run(runnable); assert TestBinarylizableRunnable.executed.get(); assert TestBinarylizableRunnable.writeCalled.get(); assert TestBinarylizableRunnable.readCalled.get(); assert TestBinarylizableMasterLeaveAwareRunnable.writeCalled.get(); assert TestBinarylizableMasterLeaveAwareRunnable.readCalled.get(); }
/** * Test that Binarylizable IgniteRunnable is serialized using BinaryMarshaller. * * @throws Exception If failed. */ @Test public void testRunnable() throws Exception { Ignite ignite = startGrid(1); startGrid(2); final TestBinarylizableRunnable runnable = new TestBinarylizableRunnable(); ignite.compute(ignite.cluster().forRemotes()).run(runnable); assert TestBinarylizableRunnable.executed.get(); assert TestBinarylizableRunnable.writeCalled.get(); assert TestBinarylizableRunnable.readCalled.get(); }
/** * JUnit. * * @throws Exception If failed. */ @Test public void testMarshalling() throws Exception { String seqName = UUID.randomUUID().toString(); final IgniteAtomicSequence seq = grid(0).atomicSequence(seqName, 0, true); grid(1).compute().run(new CAX() { @Override public void applyx() { assertNotNull(seq); for (int i = 0; i < RETRIES; i++) seq.incrementAndGet(); } }); }
latch = new CountDownLatch(3); grid().compute().run(new IgniteRunnable() { @Override public void run() {
/** * @throws Exception If failed. */ @Test public void testEnableWithDefaults() throws Exception { inclEvtTypes = null; try { Ignite g = startGrid(); final AtomicInteger cnt = new AtomicInteger(); g.events().localListen(new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { cnt.incrementAndGet(); return true; } }, EVT_TASK_STARTED); g.compute().run(F.noop()); assertEquals(0, cnt.get()); g.events().enableLocal(EVT_TASK_STARTED); g.compute().run(F.noop()); assertEquals(1, cnt.get()); } finally { stopAllGrids(); } }
/** * @throws Exception If failed. */ @Test public void testEnableWithIncludes() throws Exception { inclEvtTypes = new int[] { EVT_TASK_STARTED, EVT_TASK_FINISHED }; try { Ignite g = startGrid(); final AtomicInteger cnt = new AtomicInteger(); g.events().localListen(new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { cnt.incrementAndGet(); return true; } }, EVT_TASK_STARTED, EVT_TASK_FINISHED, EVT_JOB_STARTED); g.compute().run(F.noop()); assertEquals(2, cnt.get()); g.events().enableLocal(EVT_TASK_FINISHED, EVT_JOB_STARTED); g.compute().run(F.noop()); assertEquals(5, cnt.get()); } finally { stopAllGrids(); } }
/** * @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()); }
/** * @throws Exception If failed. */ @Test public void testDisableWithIncludes() throws Exception { inclEvtTypes = null; try { Ignite g = startGrid(); g.events().enableLocal(EVT_TASK_STARTED, EVT_TASK_FINISHED, EVT_JOB_STARTED); final AtomicInteger cnt = new AtomicInteger(); g.events().localListen(new IgnitePredicate<Event>() { @Override public boolean apply(Event evt) { cnt.incrementAndGet(); return true; } }, EVT_TASK_STARTED, EVT_TASK_FINISHED, EVT_JOB_STARTED); g.compute().run(F.noop()); assertEquals(3, cnt.get()); g.events().disableLocal(EVT_TASK_STARTED, EVT_TASK_FINISHED, EVT_JOB_FAILED); g.compute().run(F.noop()); assertEquals(4, cnt.get()); } finally { stopAllGrids(); } }
/** * @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 If failed. */ @Test public void testAffinityWithPut() throws Exception { waitTopologyUpdate(); Ignite mg = grid(0); IgniteCache<Integer, String> mc = mg.cache(DEFAULT_CACHE_NAME); int keyCnt = 10; printAffinity(mg, keyCnt); info("Registering event listener..."); // Register event listener on remote nodes. compute(mg.cluster().forRemotes()).run(new ListenerJob(keyCnt, mg.name())); for (int i = 0; i < keyCnt; i++) { if (failFlag.get()) fail("testAffinityWithPut failed."); info("Before putting key [key=" + i + ", igniteInstanceName=" + mg.name() + ']'); mc.put(i, Integer.toString(i)); if (failFlag.get()) fail("testAffinityWithPut failed."); } Thread.sleep(1000); if (failFlag.get()) fail("testAffinityWithPut failed."); }
/** * @throws Exception If failed. */ @Test public void testCompute() throws Exception { IgniteConfiguration cfg = optimize(getConfiguration("g1")); try (Ignite g1 = G.start(cfg)) { IgniteCompute compute = compute(grid().cluster().forNode(g1.cluster().localNode())); compute.run(new IgniteRunnable() { @Override public void run() { // No-op. } }); GridMarshallerTestBean inBean = newTestBean(compute); byte[] buf = marshal(inBean); GridMarshallerTestBean outBean = unmarshal(buf); assert inBean.getObjectField() != null; assert outBean.getObjectField() != null; assert inBean.getObjectField().getClass().equals(IgniteComputeImpl.class); assert outBean.getObjectField().getClass().equals(IgniteComputeImpl.class); assert inBean != outBean; assert inBean.equals(outBean); ClusterGroup inPrj = compute.clusterGroup(); ClusterGroup outPrj = ((IgniteCompute)outBean.getObjectField()).clusterGroup(); assert inPrj.getClass().equals(outPrj.getClass()); assert F.eqNotOrdered(inPrj.nodes(), outPrj.nodes()); outBean.checkNullResources(); } }
/** {@inheritDoc} */ @Override public void close() throws IgniteException { if (locJvmGrid != null) { final CountDownLatch rmtNodeStoppedLatch = new CountDownLatch(1); locJvmGrid.events().localListen(new IgnitePredicateX<Event>() { @Override public boolean applyx(Event e) { if (((DiscoveryEvent)e).eventNode().id().equals(id)) { rmtNodeStoppedLatch.countDown(); return false; } return true; } }, EventType.EVT_NODE_LEFT, EventType.EVT_NODE_FAILED); compute().run(new StopGridTask(localJvmGrid().name(), true)); try { assert U.await(rmtNodeStoppedLatch, 15, TimeUnit.SECONDS) : "NodeId=" + id; } catch (IgniteInterruptedCheckedException e) { throw new IgniteException(e); } } try { getProcess().kill(); } catch (Exception e) { X.printerr("Could not kill process after close.", e); } }
/** * * @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()); }