@Override public Void call() throws Exception { comp.affinityRun(DEFAULT_CACHE_NAME, 1, new FailRunnable()); return null; } }, ClusterGroupEmptyException.class, null);
/** {@inheritDoc} */ @Override public void affinityRun(IgniteRunnable job) { if (!collocated) throw new IgniteException("Failed to execute affinityRun() for non-collocated queue: " + name() + ". This operation is supported only for collocated queues."); compute.affinityRun(cache.name(), queueKey, job); }
@Override public Void call() throws Exception { grid(0).compute().affinityRun( Arrays.asList(Organization.class.getSimpleName(), OTHER_CACHE_NAME), new Integer(orgId), new IgniteRunnable() { @Override public void run() { // No-op. } }); return null; } }, IgniteException.class, "Failed partition reservation. Partition is not primary on the node.");
/** {@inheritDoc} */ @Override public void affinityRun(IgniteRunnable job) { if (!collocated) throw new IgniteException("Failed to execute affinityRun() for non-collocated set: " + name() + ". This operation is supported only for collocated sets."); compute.affinityRun(cache.name(), setKey, job); }
@Override public void run() { for (int i = 0; i < PARTS_CNT; ++i) { try { grid(0).compute().affinityRun( Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(i), new NotReservedCacheOpAffinityRun(i, key.getAndIncrement() * KEYS_CNT, cacheName)); } catch (IgniteException e) { checkException(e, ClusterTopologyException.class); } } } }, AFFINITY_THREADS_CNT, "affinity-run");
@Override public void run() { for (int i = 0; i < PARTS_CNT; ++i) { if (System.currentTimeMillis() >= endTime) break; try { grid(0).compute().affinityRun( Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(i), new ReservedPartitionCacheOpAffinityRun(i, key.getAndIncrement() * KEYS_CNT)); } catch (IgniteException e) { checkException(e, ClusterTopologyException.class); } } } }, AFFINITY_THREADS_CNT, "affinity-run");
@Override public Object call() throws Exception { grid(0).compute().affinityRun(NON_DFLT_CACHE_NAME, "key", new FailedRunnable("key", MAX_FAILOVER_ATTEMPTS + 1)); return null; } }, ClusterTopologyException.class, "Failed to failover a job to another node");
@Override public void run() { while (System.currentTimeMillis() < endTime) { int n = 0; try { for (final int orgId : orgIds) { if (System.currentTimeMillis() >= endTime) break; n = jobNum.getAndIncrement(); log.info("+++ Job submitted " + n); grid(0).compute().affinityRun( Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId), new TestRun(n)); } } catch (Exception e) { log.info("+++ Job failed " + n + " " + e.toString()); // No-op. Swallow exceptions on run (e.g. job canceling etc.). } } } }, AFFINITY_THREADS_CNT, "affinity-run");
@Override public void test(Factory factory, Ignite ignite) throws Exception { ignite.getOrCreateCache("test0"); ignite.getOrCreateCache("test1"); final IgniteCompute comp = ignite.compute(); for (int i = 0; i < MAX_JOB_COUNT; ++i) { IgniteRunnable job = (IgniteRunnable)factory.create(); comp.affinityRun(Arrays.asList("test0", "test1"), 0, job); } } });
/** {@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(); for (int i = 0; i < MAX_JOB_COUNT; ++i) { IgniteRunnable job = (IgniteRunnable)factory.create(); comp.affinityRun(Arrays.asList("test0", "test1"), key(0), job); } } });
/** * @throws Exception If failed. */ @Test public void testAffinityRunRestart() throws Exception { grid(0).compute().affinityRun(NON_DFLT_CACHE_NAME, "key", new FailedRunnable("key", MAX_FAILOVER_ATTEMPTS)); }
@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");
/** * JUnit. * * @throws Exception If failed. */ @Test public void testAffinityRun() throws Exception { for (int i = 0; i < KEY_CNT; i++) grid(0).compute().affinityRun(NON_DFLT_CACHE_NAME, i, new CheckRunnable(i, i)); }
@Override public void test(Factory factory, Ignite ignite) throws Exception { ignite.getOrCreateCache(CACHE_NAME); final IgniteCompute comp = ignite.compute(); for (int i = 0; i < MAX_JOB_COUNT; ++i) { IgniteRunnable job = (IgniteRunnable)factory.create(); comp.affinityRun("test", key(0), job); } } });
/** * @throws Exception If failed. */ @Test public void testAffinityRun() throws Exception { for (int i : F.asList(1, 2, 3)) { grid().compute().affinityRun(DEFAULT_CACHE_NAME, i, new IgniteRunnable() { @Override public void run() { ids.add(this); res.addAndGet(10); } }); } assertEquals(30, res.get()); assertEquals(3, ids.size()); }
/** * JUnit. * * @throws Exception If failed. */ @Test public void testAffinityRunComplexKey() throws Exception { for (int i = 0; i < KEY_CNT; i++) { AffinityTestKey key = new AffinityTestKey(i); grid(0).compute().affinityRun(NON_DFLT_CACHE_NAME, i, new CheckRunnable(i, key)); grid(0).compute().affinityRun(NON_DFLT_CACHE_NAME, key, new CheckRunnable(i, key)); } }
/** * @throws Exception If failed. */ @Test public void testReleasePartitionJobUnmarshalingFails() throws Exception { final int orgId = primaryKey(grid(1).cache(Organization.class.getSimpleName())); try { grid(0).compute().affinityRun( Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId), new JobFailUnmarshaling()); fail("Unmarshaling exception must be thrown"); } catch (Exception ignored) { checkPartitionsReservations(grid(1), orgId, 0); } }
/** * @throws Exception If failed. */ @Test public void testPartitionReservation() throws Exception { int orgId = 0; cancelAllJobs = true; // Workaround for initial update job metadata. try { grid(0).compute().affinityRun( Arrays.asList(Organization.class.getSimpleName(), Person.class.getSimpleName()), new Integer(orgId), new TestRun(orgId)); } catch (Exception ignored) { // No-op. Swallow exceptions on run (e.g. job canceling etc.). // The test checks only correct partition release in case CollisionSpi is used. } // All partition must be released in spite of any exceptions during the job executions. cancelAllJobs = false; ClusterNode n = grid(0).context().affinity() .mapKeyToNode(Organization.class.getSimpleName(), orgId); checkPartitionsReservations((IgniteEx)grid(n), orgId, 0); }
/** * @throws Exception If failed. */ @Test public void testAffinityMapper() throws Exception { IgniteCache<Object, Object> cache = startGrid(0).cache(DEFAULT_CACHE_NAME); for (int i = 0; i < KEY_CNT; i++) { cache.put(String.valueOf(i), String.valueOf(i)); cache.put(new TestAffinityKey(i, String.valueOf(i)), i); } assertEquals(1, cache.get(new TestAffinityKey(1, "1"))); startGrid(1); for (int i = 0; i < KEY_CNT; i++) grid(i % 2).compute().affinityRun(DEFAULT_CACHE_NAME, new TestAffinityKey(1, "1"), new NoopClosure()); }