@Override public Void call() throws Exception { comp.apply(new FailClosure(), new Object()); return null; } }, ClusterGroupEmptyException.class, null);
/** * @param cnt Counter. * @throws Exception If failed. */ private void call3(AtomicInteger cnt) throws Exception { IgniteFuture<String> fut = compute(prj).applyAsync(clrJob, (String) null); waitForExecution(fut); cnt.set(0); compute(prj).apply(clrJob, (String) null); waitForValue(cnt, 1); }
@Override public Object call() throws Exception { try { client.compute().apply(new IgniteClosure<Integer, Integer>() { @Override public Integer apply(Integer o) { return o + 1; } }, Arrays.asList(1, 2, 3)); } catch (IgniteClientDisconnectedException e) { checkAndWait(e); return true; } return false; } });
/** * @param cnt Counter. * @throws Exception If failed. */ private void forkjoin1(AtomicInteger cnt) throws Exception { Collection<String> args = F.asList("a", "b", "c"); IgniteFuture fut = compute(prj).applyAsync(clrJob, args, rdc); waitForExecution(fut); cnt.set(0); compute(prj).apply(clrJob, args, rdc); waitForValue(cnt, args.size()); }
@Override public void test(Factory factory, Ignite ignite) throws Exception { Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT); for (int i = 0; i < MAX_JOB_COUNT; ++i) { // value(i - 1): use negative argument of the value method to generate nullong value. results.add(ignite.compute().apply((IgniteClosure<Object, Object>)factory.create(), value(i - 1))); } checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass()); assertCollectionsEquals("Results value mismatch", createGoldenResults(), results); } });
/** * @param cnt Counter. * @throws Exception If failed. */ private void call4(AtomicInteger cnt) throws Exception { Collection<String> args = F.asList("a", "b", "c"); IgniteFuture<Collection<String>> fut = compute(prj).applyAsync(clrJob, args); waitForExecution(fut); cnt.set(0); compute(prj).apply(clrJob, args); waitForValue(cnt, args.size()); }
@Override public void test(Factory factory, Ignite ignite) throws Exception { Collection<Object> params = new ArrayList<>(MAX_JOB_COUNT); for (int i = 0; i < MAX_JOB_COUNT; ++i) { // value(i - 1): use negative argument of the value method to generate nullong value. params.add(value(i - 1)); } boolean res = ignite.compute() .apply((IgniteClosure<Object, Object>)factory.create(), params, new IgniteReducer<Object, Boolean>() { private Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT); @Override public boolean collect(@Nullable Object o) { results.add(o); return true; } @Override public Boolean reduce() { checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass()); assertCollectionsEquals("Results value mismatch", createGoldenResults(), results); return true; } }); assertTrue(res); } });
@Override public void test(Factory factory, Ignite ignite) throws Exception { Collection params = new ArrayList<>(MAX_JOB_COUNT); for (int i = 0; i < MAX_JOB_COUNT; ++i) { // value(i - 1): use negative argument of the value method to generate nullong value. params.add(value(i - 1)); } IgniteClosure c = (IgniteClosure)factory.create(); // Use type casting to avoid ambiguous for apply(Callable, Object) vs apply(Callable, Collection<Object>). Collection<Object> results = ignite.compute().apply((IgniteClosure<TestObject, Object>)c, (Collection<TestObject>)params); checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass()); assertCollectionsEquals("Results value mismatch", createGoldenResults(), results); } });
@Override public boolean apply(Event event) { try { cli.compute().apply(new IgniteClosure<String, Void>() { @Override public Void apply(String arg) { return null; } }, "Hello!"); fut.onDone(true); return true; } catch (Exception e) { fut.onDone(e); return false; } } }, EventType.EVT_CLIENT_NODE_RECONNECTED);
/** * Test that Binarylizable IgniteClosure with ComputeJobMasterLeaveAware interface is serialized * using BinaryMarshaller. * * @throws Exception If failed. */ @Test public void testMasterLeaveAwareJob() throws Exception { Ignite ignite = startGrid(1); startGrid(2); final TestBinarylizableMasterLeaveAwareClosure job = new TestBinarylizableMasterLeaveAwareClosure(); ignite.compute(ignite.cluster().forRemotes()).apply(job, new TestBinarylizableObject()); assert TestBinarylizableClosure.executed.get(); assert TestBinarylizableClosure.writeCalled.get(); assert TestBinarylizableClosure.readCalled.get(); assert TestBinarylizableMasterLeaveAwareClosure.writeCalled.get(); assert TestBinarylizableMasterLeaveAwareClosure.readCalled.get(); assert TestBinarylizableObject.writeCalled.get(); assert TestBinarylizableObject.readCalled.get(); }
/** * Test that Binarylizable IgniteClosure is serialized using BinaryMarshaller. * * @throws Exception If failed. */ @Test public void testJob() throws Exception { Ignite ignite = startGrid(1); startGrid(2); final TestBinarylizableClosure closure = new TestBinarylizableClosure(); ignite.compute(ignite.cluster().forRemotes()).apply(closure, new TestBinarylizableObject()); assert TestBinarylizableClosure.executed.get(); assert TestBinarylizableClosure.writeCalled.get(); assert TestBinarylizableClosure.readCalled.get(); assert TestBinarylizableObject.writeCalled.get(); assert TestBinarylizableObject.readCalled.get(); }
/** * @throws Exception If failed. */ @Test public void testCallWithProducer() throws Exception { Collection<Integer> args = Arrays.asList(1, 2, 3); Collection<Integer> res = grid().compute().apply(new C1<Integer, Integer>() { @Override public Integer apply(Integer arg) { ids.add(this); return 10 + arg; } }, args); assertEquals(36, F.sumInt(res)); assertEquals(3, ids.size()); } }
/** * @throws Exception If test failed. */ @Test public void testClearTimeouts() throws Exception { int holdccTimeout = 4000; try { Ignite grid = startGrid(0); TestClearTimeoutsClosure closure = new TestClearTimeoutsClosure(); grid.compute().apply(closure, holdccTimeout); Thread.sleep(holdccTimeout * 2); assert closure.counter == 2; } finally { stopGrid(0); } }
/** * @throws Exception If failed. */ @Test public void testCall() throws Exception { Collection<Integer> res = grid().compute().apply(new C1<Integer, Integer>() { @Override public Integer apply(Integer arg) { ids.add(this); return 10 + arg; } }, F.asList(1, 2, 3)); assertEquals(36, F.sumInt(res)); assertEquals(3, ids.size()); }
/** * @throws Exception If test failed. */ @Test public void testMultipleHoldccCalls() throws Exception { try { Ignite grid = startGrid(0); assertTrue(grid.compute().apply(new TestMultipleHoldccCallsClosure(), (Object)null)); } finally { stopGrid(0); } }
comp.apply(new IgniteClosure<Object, Object>() { @Override public Object apply(Object o) { assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0)); comp.apply(new IgniteClosure<Integer, Object>() { @Override public Object apply(Integer o) { assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0)); comp.apply(new IgniteClosure<Integer, Object>() { @Override public Object apply(Integer o) { assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
@SuppressWarnings("unchecked") private <T, R1, R2> void doApply(final Exchange exchange, final AsyncCallback callback, IgniteCompute compute) throws Exception { IgniteClosure<T, R1> job = exchange.getIn().getBody(IgniteClosure.class); T params = (T) exchange.getIn().getHeader(IgniteConstants.IGNITE_COMPUTE_PARAMS); if (job == null || params == null) { throw new RuntimeCamelException( String.format("Ignite Compute endpoint with APPLY executionType is only " + "supported for IgniteClosure payloads with parameters. The payload type was: %s.", exchange.getIn().getBody().getClass().getName())); } IgniteReducer<R1, R2> reducer = exchange.getIn().getHeader(IgniteConstants.IGNITE_COMPUTE_REDUCER, IgniteReducer.class); if (Collection.class.isAssignableFrom(params.getClass())) { Collection<T> colParams = (Collection<T>) params; if (reducer == null) { compute.apply(job, colParams); } else { compute.apply(job, colParams, reducer); } } else { compute.apply(job, params); } }