/** {@inheritDoc} */ @Override public <R> R affinityCall(IgniteCallable<R> job) { if (!collocated) throw new IgniteException("Failed to execute affinityCall() for non-collocated queue: " + name() + ". This operation is supported only for collocated queues."); return compute.affinityCall(cache.name(), queueKey, job); }
/** {@inheritDoc} */ @Override public <R> R affinityCall(IgniteCallable<R> job) { if (!collocated) throw new IgniteException("Failed to execute affinityCall() for non-collocated set: " + name() + ". This operation is supported only for collocated sets."); return compute.affinityCall(cache.name(), setKey, job); }
@Override public Void call() throws Exception { comp.affinityCall(DEFAULT_CACHE_NAME, 1, new FailCallable()); return null; } }, ClusterGroupEmptyException.class, null);
@Override public Object call() throws Exception { grid(0).compute().affinityCall(NON_DFLT_CACHE_NAME, "key", new FailedCallable("key", MAX_FAILOVER_ATTEMPTS + 1)); return null; } }, ClusterTopologyException.class, "Failed to failover a job to another node");
@Override public Void call() throws Exception { b.await(); while (!fut.isDone()) client.compute().affinityCall(CACHE_NAME, key, new CheckCallable(key, null)); return null; } }, THREADS, "test-thread");
@Override public void run() { if (threadNum.getAndIncrement() % 2 == 0) { while (System.currentTimeMillis() < endTime) { for (final int orgId : orgIds) { if (System.currentTimeMillis() >= endTime) break; grid(0).compute().affinityRun( Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId), new TestAffinityRun(personsCntGetter, orgId)); } } } else { while (System.currentTimeMillis() < endTime) { for (final int orgId : orgIds) { if (System.currentTimeMillis() >= endTime) break; int personsCnt = grid(0).compute().affinityCall( Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId), new TestAffinityCall(personsCntGetter, orgId)); assertEquals(PERS_AT_ORG_CNT, personsCnt); } } } } }, AFFINITY_THREADS_CNT, "affinity-run");
@Override public Object call() throws Exception { try { client.compute().affinityCall("test-cache", 40, new IgniteCallable<Object>() { @Override public Integer call() throws Exception { return 42; } }); } catch (IgniteClientDisconnectedException e) { checkAndWait(e); return true; } return false; } });
@Override public void test(Factory factory, Ignite ignite) throws Exception { ignite.getOrCreateCache("test0"); ignite.getOrCreateCache("test1"); final IgniteCompute comp = ignite.compute(); Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT); for (int i = 0; i < MAX_JOB_COUNT; ++i) { EchoCallable job = (EchoCallable)factory.create(); job.setArg(value(i - 1)); results.add(comp.affinityCall(Arrays.asList("test0", "test1"), 0, job)); } checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass()); assertCollectionsEquals("Results value mismatch", createGoldenResults(), results); } });
@Override public void test(Factory factory, Ignite ignite) throws Exception { ignite.getOrCreateCache(CACHE_NAME); final IgniteCompute comp = ignite.compute(); Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT); for (int i = 0; i < MAX_JOB_COUNT; ++i) { EchoCallable job = (EchoCallable)factory.create(); job.setArg(value(i - 1)); results.add(comp.affinityCall("test", key(0), job)); } checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass()); assertCollectionsEquals("Results value mismatch", createGoldenResults(), results); } });
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { super.beforeTest(); // Workaround for initial update job metadata. grid(0).compute().affinityCall( Arrays.asList(Person.class.getSimpleName(), Organization.class.getSimpleName()), 0, new TestAffinityCall(new PersonsCountGetter() { @Override public int getPersonsCount(IgniteEx ignite, IgniteLogger log, int orgId) throws Exception { return PERS_AT_ORG_CNT; } }, 0)); grid(0).compute().affinityRun( Arrays.asList(Person.class.getSimpleName(), Organization.class.getSimpleName()), 0, new TestAffinityRun(new PersonsCountGetter() { @Override public int getPersonsCount(IgniteEx ignite, IgniteLogger log, int orgId) throws Exception { return PERS_AT_ORG_CNT; } }, 0)); }
@Override public void test(Factory factory, Ignite ignite) throws Exception { ignite.getOrCreateCache("test0"); ignite.getOrCreateCache("test1"); final IgniteCompute comp = ignite.compute(); Collection<Object> results = new ArrayList<>(MAX_JOB_COUNT); for (int i = 0; i < MAX_JOB_COUNT; ++i) { EchoCallable job = (EchoCallable)factory.create(); job.setArg(value(i - 1)); results.add(comp.affinityCall(Arrays.asList("test0", "test1"), key(0), job)); } checkResultsClassCount(MAX_JOB_COUNT - 1, results, value(0).getClass()); assertCollectionsEquals("Results value mismatch", createGoldenResults(), results); } });
/** * JUnit. * * @throws Exception If failed. */ @Test public void testAffinityCall() throws Exception { for (int i = 0; i < KEY_CNT; i++) grid(0).compute().affinityCall(NON_DFLT_CACHE_NAME, i, new CheckCallable(i, i)); }
@Override public void run() { if (threadNum.getAndIncrement() % 2 == 0) { while (System.currentTimeMillis() < endTime) { for (final int orgId : orgIds) { if (System.currentTimeMillis() >= endTime) break; grid(0).compute().affinityRun(Person.class.getSimpleName(), new Person(0, orgId).createKey(), new TestAffinityRun(personsCntGetter, orgId)); } } } else { while (System.currentTimeMillis() < endTime) { for (final int orgId : orgIds) { if (System.currentTimeMillis() >= endTime) break; int personsCnt = grid(0).compute().affinityCall(Person.class.getSimpleName(), new Person(0, orgId).createKey(), new TestAffinityCall(personsCntGetter, orgId)); assertEquals(PERS_AT_ORG_CNT, personsCnt); } } } } }, AFFINITY_THREADS_CNT, "affinity-run");
/** * Run client task. * * @param task Task. * @return Result. */ <T> T runClientTask(IgfsClientAbstractCallable<T> task) { try { return (cfg.isColocateMetadata()) ? clientCompute().affinityCall(metaCacheName, IgfsUtils.ROOT_ID, task) : clientCompute().call(task); } catch (Exception e) { if (X.hasCause(e, ClusterTopologyException.class)) throw new IgfsException("Failed to execute operation because there are no IGFS metadata nodes." , e); IgfsException igfsEx = X.cause(e, IgfsException.class); if (igfsEx != null) throw igfsEx; throw e; } }
/** * @throws Exception If failed. */ @Test public void testAffinityCall() throws Exception { Collection<Integer> res = new ArrayList<>(); for (int i : F.asList(1, 2, 3)) { res.add(grid().compute().affinityCall(DEFAULT_CACHE_NAME, i, new IgniteCallable<Integer>() { @Override public Integer call() { ids.add(this); return 10; } })); } assertEquals(30, F.sumInt(res)); assertEquals(3, ids.size()); }
/** * JUnit. * * @throws Exception If failed. */ @Test public void testAffinityCallComplexKey() throws Exception { for (int i = 0; i < KEY_CNT; i++) { final AffinityTestKey key = new AffinityTestKey(i); grid(0).compute().affinityCall(NON_DFLT_CACHE_NAME, i, new CheckCallable(i, key)); grid(0).compute().affinityCall(NON_DFLT_CACHE_NAME, key, new CheckCallable(i, key)); } }
/** * @throws Exception If failed. */ @Test public void testAffinityCallRestart() throws Exception { assertEquals(MAX_FAILOVER_ATTEMPTS, grid(0).compute().affinityCall(NON_DFLT_CACHE_NAME, "key", new FailedCallable("key", MAX_FAILOVER_ATTEMPTS))); }
grid(0).compute().affinityCall( Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId),
/** * @throws Exception If failed. */ @Test public void testAffinityCall() throws Exception { Affinity<Object> aff = grid(0).affinity(DEFAULT_CACHE_NAME); for (int i = 0; i < 1000; i++) { nodeId.set(null); grid(0).compute().affinityCall(DEFAULT_CACHE_NAME, new TestObject(i), new IgniteCallable<Object>() { @IgniteInstanceResource private Ignite ignite; @Override public Object call() { nodeId.set(ignite.configuration().getNodeId()); return null; } }); assertEquals(aff.mapKeyToNode(i).id(), nodeId.get()); } }
/** * @throws Exception If failed. */ private void affinityCallRestartNode() throws Exception { final int ITERS = 10; for (int i = 0; i < ITERS; i++) { log.info("Iteration: " + i); Integer key = primaryKey(grid(0).cache(CACHE_NAME)); AffinityTopologyVersion topVer = grid(0).context().discovery().topologyVersionEx(); IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() { @Override public Object call() throws Exception { U.sleep(500); stopGrid(0); return null; } }, "stop-thread"); while (!fut.isDone()) grid(1).compute().affinityCall(CACHE_NAME, key, new CheckCallable(key, topVer)); fut.get(); if (i < ITERS - 1) startGrid(0); } stopAllGrids(); }