/** * @param ignite Ignite instance. * @param timeout Timeout. * @param param Parameter. * @throws Exception If failed. */ private Collection<Object> runJob2(ClassLoader testClassLoader, Ignite ignite, long timeout, int param) throws Exception { Constructor ctor = testClassLoader.loadClass(RUN_CLS2).getConstructor(int.class); return ignite.compute().withTimeout(timeout).broadcast((IgniteCallable<Object>)ctor.newInstance(param)); } }
/** * @param ignite Ignite instance. * @param timeout Timeout. * @param param Parameter. * @throws Exception If failed. */ private Collection<Object> runJob1(ClassLoader testClassLoader, Ignite ignite, long timeout, int param) throws Exception { Constructor ctor = testClassLoader.loadClass(RUN_CLS1).getConstructor(int.class); return ignite.compute().withTimeout(timeout).broadcast((IgniteCallable<Object>)ctor.newInstance(param)); }
/** * @param ignite Ignite instance. * @param timeout Timeout. * @param param Parameter. * @throws Exception If failed. */ private Collection<Object> runJob0(ClassLoader testClassLoader, Ignite ignite, long timeout, int param) throws Exception { Constructor ctor = testClassLoader.loadClass(RUN_CLS).getConstructor(int.class); return ignite.compute().withTimeout(timeout).broadcast((IgniteCallable<Object>)ctor.newInstance(param)); }
/** * @param ignite Ignite instance. * @param timeout Timeout. * @throws Exception If failed. */ private void runJob1(Ignite ignite, long timeout) throws Exception { ClassLoader testClassLoader1 = new GridTestExternalClassLoader(new URL[] { new URL(GridTestProperties.getProperty("p2p.uri.cls"))}, RUN_CLS, RUN_CLS2); Constructor ctor = testClassLoader1.loadClass(RUN_CLS1).getConstructor(); ignite.compute().withTimeout(timeout).broadcast((IgniteCallable<?>)ctor.newInstance()); }
/** * @param ignite Ignite instance. * @param timeout Timeout. * @throws Exception If failed. */ private void runJob0(Ignite ignite, long timeout) throws Exception { ClassLoader testClassLoader = new GridTestExternalClassLoader(new URL[] { new URL(GridTestProperties.getProperty("p2p.uri.cls"))}, RUN_CLS1, RUN_CLS2); Constructor ctor = testClassLoader.loadClass(RUN_CLS).getConstructor(); ignite.compute().withTimeout(timeout).broadcast((IgniteCallable<?>)ctor.newInstance()); }
/** * @param ignite Ignite instance. * @param timeout Timeout. * @throws Exception If failed. */ private void runJob2(Ignite ignite, long timeout) throws Exception { ClassLoader testClassLoader = new GridTestExternalClassLoader(new URL[] { new URL(GridTestProperties.getProperty("p2p.uri.cls"))}, RUN_CLS, RUN_CLS1); Constructor ctor = testClassLoader.loadClass(RUN_CLS2).getConstructor(); ignite.compute().withTimeout(timeout).broadcast((IgniteCallable<?>)ctor.newInstance()); } }
@Override public void run() { while (!finish.get()) { try { ComputeTaskFuture<?> fut = executeAsync( ignite.compute().withTimeout(TIMEOUT), GridTaskTimeoutTestTask.class.getName(), null); fut.get(); assert false : "Task has not been timed out. Future: " + fut; } catch (ComputeTaskTimeoutException ignored) { // Expected. } catch (IgniteCheckedException e) { throw new IllegalStateException(e); //shouldn't happen } finally { int cnt0 = cnt.incrementAndGet(); if (cnt0 % 100 == 0) info("Tasks finished: " + cnt0); } } info("Thread " + Thread.currentThread().getId() + " finishing."); finishLatch.countDown(); } }, N_THREADS);
/** * @param timeout Timeout. * @param job Job. * @return Task future. * @throws Exception If failed. */ private ComputeTaskFuture<?> generateEvents(@Nullable Long timeout, ComputeJob job) throws Exception { return timeout == null ? ignite.compute().executeAsync(GridAllEventsTestTask.class.getName(), job) : ignite.compute().withTimeout(timeout).executeAsync(GridAllEventsTestTask.class.getName(), job); }
/** {@inheritDoc} */ @Override public void run() { try { while (end - System.currentTimeMillis() > 0) { long start = System.currentTimeMillis(); // Pass stealing node id. ComputeTaskFuture<?> fut = ignite.compute().withTimeout(20000). execute(GridStealingLoadTestTask.class.getName(), stealingNodeId); stolen.addAndGet((Integer)fut.get()); long taskCnt = stats.onTaskCompleted(fut, 1, System.currentTimeMillis() - start); if (taskCnt % 500 == 0) info("Stats [stats=" + stats.toString() + ", stolen=" + stolen + ']'); } } catch (Throwable e) { error("Load test failed.", e); failed.set(true); } } }, getThreadCount(), "grid-load-test-thread");
@Override public Object call() throws Exception { grid().compute().withTimeout(100).execute(new TimedOutTask(), null); return null; } },
/** {@inheritDoc} */ @Override public void run() { try { while (end - System.currentTimeMillis() > 0) { long start = System.currentTimeMillis(); ComputeTaskFuture<?> fut = ignite.compute().withTimeout(10000). execute(GridSessionLoadTestTask.class.getName(), ignite.cluster().nodes().size()); Object res = fut.get(); assert (Boolean)res; long taskCnt = stats.onTaskCompleted(fut, 1, System.currentTimeMillis() - start); if (taskCnt % 500 == 0) info(stats.toString()); } } catch (Throwable e) { error("Load test failed.", e); failed.set(true); } } }, getThreadCount(), "grid-load-test-thread");
/** * @param cnt Counter. * @throws Exception If failed. */ private void exec2(AtomicInteger cnt) throws Exception { cnt.set(0); compute(prj).withTimeout(WAIT_TIMEOUT).execute(TestTask.class.getName(), null); waitForValue(cnt, projectionSize()); cnt.set(0); compute(prj).withTimeout(WAIT_TIMEOUT).execute(new TestTask(), null); waitForValue(cnt, projectionSize()); cnt.set(0); compute(prj).withTimeout(WAIT_TIMEOUT).execute(TestTask.class, null); waitForValue(cnt, projectionSize()); }
/** {@inheritDoc} */ @SuppressWarnings("BusyWait") @Override public void run() { while (true) { checkCompletion(); performCancel(); try { Thread.sleep(submitDelay); } catch (InterruptedException ignored) { return; } try { futures.add(ignite.compute().withTimeout(TIMEOUT).executeAsync(GridJobLoadTestTask.class, params)); } catch (IgniteException e) { // Should not be thrown since uses asynchronous execution. throw new IgniteException(e); } } }
/** * @throws Exception If failed. */ @Test public void testAsynchronousTimeout() throws Exception { Ignite ignite = G.ignite(getTestIgniteInstanceName()); ignite.compute().localDeployTask(GridTaskTimeoutTestTask.class, GridTaskTimeoutTestTask.class.getClassLoader()); ComputeTaskFuture<?> fut = executeAsync(ignite.compute().withTimeout(TIMEOUT), GridTaskTimeoutTestTask.class.getName(), null); // Allow timed out events to be executed. Thread.sleep(TIMEOUT + 500); checkTimedOutEvents(fut.getTaskSession().getId()); }
/** * Tests that a job is not cancelled if there are no * available thief nodes in projection. Uses null predicate. * * @throws Exception If failed. */ @Test public void testSingleNodeProjectionNullPredicate() throws Exception { ClusterGroup prj = ignite1.cluster().forNodeIds(Collections.singleton(ignite1.cluster().localNode().id())); executeAsync(compute(prj).withTimeout(TASK_EXEC_TIMEOUT_MS), new JobStealingSpreadTask(2), null). get(TASK_EXEC_TIMEOUT_MS); assertEquals(1, jobDistrMap.keySet().size()); assertEquals(2, jobDistrMap.get(ignite1.cluster().localNode().id()).size()); }
/** * Test 2 jobs on 1 node when one of the predicates is null. * * @throws IgniteCheckedException If test failed. */ @Test public void testTwoJobsPartiallyNullPredicate() throws IgniteCheckedException { IgnitePredicate<ClusterNode> topPred = new IgnitePredicate<ClusterNode>() { @Override public boolean apply(ClusterNode e) { return ignite2.cluster().localNode().id().equals(e.id()); // Limit projection with only grid2. } }; executeAsync(compute(ignite1.cluster().forPredicate(topPred)).withTimeout(TASK_EXEC_TIMEOUT_MS), new JobStealingSpreadTask(2), null).get(TASK_EXEC_TIMEOUT_MS); assertEquals(1, jobDistrMap.keySet().size()); assertEquals(2, jobDistrMap.get(ignite2.cluster().localNode().id()).size()); assertFalse(jobDistrMap.containsKey(ignite1.cluster().localNode().id())); }
/** * @throws Exception If failed. */ @Test public void testSynchronousTimeout() throws Exception { Ignite ignite = G.ignite(getTestIgniteInstanceName()); ignite.compute().localDeployTask(GridTaskTimeoutTestTask.class, GridTaskTimeoutTestTask.class.getClassLoader()); ComputeTaskFuture<?> fut = executeAsync(ignite.compute().withTimeout(TIMEOUT), GridTaskTimeoutTestTask.class.getName(), null); try { fut.get(); assert false : "ComputeTaskTimeoutException was not thrown (synchronous apply)"; } catch (ComputeTaskTimeoutException e) { info("Received expected timeout exception (synchronous apply): " + e); } Thread.sleep(TIMEOUT + 500); checkTimedOutEvents(fut.getTaskSession().getId()); }
/** * @throws Exception If failed. */ @Test public void testJobFail() throws Exception { try { Ignite ignite1 = startGrid(1); Ignite ignite2 = startGrid(2); assert ignite1 != null; assert ignite2 != null; Integer res = ignite1.compute().withTimeout(10000).execute(JobFailTask.class.getName(), "1"); assert res != null; assert res == 1; } finally { stopGrid(1); stopGrid(2); } }
/** * @throws Exception If failed. */ @Test public void testJobSetAttribute() throws Exception { try { Ignite ignite1 = startGrid(1); Ignite ignite2 = startGrid(2); ignite1.compute().localDeployTask(SessionTestTask.class, SessionTestTask.class.getClassLoader()); for (int i = 0; i < TESTS_COUNT; i++) { ComputeTaskFuture<?> fut = ignite1.compute().withTimeout(100000).executeAsync( SessionTestTask.class.getName(), ignite2.cluster().localNode().id()); fut.getTaskSession().setAttribute(TEST_ATTR_KEY, SETS_ATTR_COUNT); Integer res = (Integer)fut.get(); assert res != null && res.equals(SETS_ATTR_COUNT) : "Unexpected result [res=" + res + ", expected=" + SETS_ATTR_COUNT + ']'; info("Session attribute value was correct for test [res=" + res + ", expected=" + SETS_ATTR_COUNT + ']'); } } finally { stopAllGrids(false); } }
/** * @throws Exception If failed. */ @Test public void testWithTimeout() throws Exception { Collection<TestCallableTimeout> jobs = F.asList(new TestCallableTimeout()); boolean timedOut = false; try { // Ensure that we will get timeout exception. grid(0).compute().withTimeout(JOB_TIMEOUT).call(jobs); } catch (ComputeTaskTimeoutException ignore) { timedOut = true; } assert timedOut : "Task has not timed out."; timedOut = false; try { // Previous task invocation cleared the timeout. grid(0).compute().call(jobs); } catch (ComputeTaskTimeoutException ignore) { timedOut = true; } assert !timedOut : "Subsequently called task has timed out."; }