Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CE16E182BC for ; Fri, 3 Jul 2015 14:09:33 +0000 (UTC) Received: (qmail 98562 invoked by uid 500); 3 Jul 2015 14:09:33 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 98533 invoked by uid 500); 3 Jul 2015 14:09:33 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 98520 invoked by uid 99); 3 Jul 2015 14:09:33 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Jul 2015 14:09:33 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 43A6EC0482 for ; Fri, 3 Jul 2015 14:09:33 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.771 X-Spam-Level: * X-Spam-Status: No, score=1.771 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id K7CuoarCM0xM for ; Fri, 3 Jul 2015 14:09:26 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with SMTP id 4C13224971 for ; Fri, 3 Jul 2015 14:09:26 +0000 (UTC) Received: (qmail 98511 invoked by uid 99); 3 Jul 2015 14:09:26 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 03 Jul 2015 14:09:26 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C5B96E03FA; Fri, 3 Jul 2015 14:09:25 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.incubator.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: incubator-ignite git commit: # ignite-648: improve framework (callable) Date: Fri, 3 Jul 2015 14:09:25 +0000 (UTC) Repository: incubator-ignite Updated Branches: refs/heads/ignite-648 48db19a26 -> 5b9e082be # ignite-648: improve framework (callable) Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/5b9e082b Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/5b9e082b Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/5b9e082b Branch: refs/heads/ignite-648 Commit: 5b9e082be82ba108c5c2f1d38cd2d047efc51ce4 Parents: 48db19a Author: ashutak Authored: Fri Jul 3 17:09:23 2015 +0300 Committer: ashutak Committed: Fri Jul 3 17:09:23 2015 +0300 ---------------------------------------------------------------------- .../cache/GridCacheAbstractFullApiSelfTest.java | 54 +++---- .../testframework/junits/GridAbstractTest.java | 139 +++++++++++-------- 2 files changed, 99 insertions(+), 94 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5b9e082b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java index 8630ea7..7db882c 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFullApiSelfTest.java @@ -4026,44 +4026,26 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract * @return Collection of keys for which given cache is primary. */ protected List primaryKeysForCache(final IgniteCache cache, final int cnt, final int startFrom) { - Ignite grid = cache.unwrap(Ignite.class); + return executeOnLocalOrRemoteJvm(cache, new TestCacheCallable>() { + @Override public List call(Ignite ignite, IgniteCache cache) throws Exception { + List found = new ArrayList<>(); - if (!(cache instanceof IgniteCacheProcessProxy)) - return primaryKeysForCache0(grid.name(), cnt, startFrom); - else { - final IgniteProcessProxy proxy = (IgniteProcessProxy)grid; - - final String name = proxy.name(); - - return proxy.remoteCompute().call(new IgniteCallable>() { - @Override public List call() throws Exception { - return primaryKeysForCache0(name, cnt, startFrom); - } - }); - } - } - - private List primaryKeysForCache0(String name, int cnt, int startFrom) { - List found = new ArrayList<>(); + Affinity affinity = ignite.affinity(cache.getName()); - IgniteEx ignite = grid(name); + for (int i = startFrom; i < startFrom + 100_000; i++) { + String key = "key" + i; - final IgniteCache cache = ignite.cache(null); + if (affinity.isPrimary(ignite.cluster().localNode(), key)) { + found.add(key); - Affinity affinity = ignite.affinity(cache.getName()); - - for (int i = startFrom; i < startFrom + 100_000; i++) { - String key = "key" + i; - - if (affinity.isPrimary(ignite.cluster().localNode(), key)) { - found.add(key); + if (found.size() == cnt) + return found; + } + } - if (found.size() == cnt) - return found; + throw new IgniteException("Unable to find " + cnt + " keys as primary for cache."); } - } - - throw new IgniteException("Unable to find " + cnt + " keys as primary for cache."); + }); } /** @@ -4255,14 +4237,14 @@ public abstract class GridCacheAbstractFullApiSelfTest extends GridCacheAbstract */ private void checkIteratorsCleared() { for (int j = 0; j < gridCount(); j++) { - runOnLocalOrRemoteJvm(j, new IndexSerializableJob() { - @Override public void run(int i) throws Exception { - GridCacheQueryManager queries = context(i).queries(); + executeOnLocalOrRemoteJvm(j, new TestIgniteIdxRunnable() { + @Override public void run(int idx) throws Exception { + GridCacheQueryManager queries = context(idx).queries(); Map map = GridTestUtils.getFieldValue(queries, GridCacheQueryManager.class, "qryIters"); for (Object obj : map.values()) - assertEquals("Iterators not removed for grid " + i, 0, ((Map)obj).size()); + assertEquals("Iterators not removed for grid " + idx, 0, ((Map)obj).size()); } }); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5b9e082b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java index 94fa248..6fb0b2b 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java @@ -1368,12 +1368,9 @@ public abstract class GridAbstractTest extends TestCase { * @return True to run nodes in separate jvms. * @see IgniteNodeRunner * @see IgniteProcessProxy - * @see #runRemotely(int, IndexSerializableJob) - * @see #runRemotely(IgniteProcessProxy, IgniteSerializableJob) - * @see #runRemotely(IgniteCacheProcessProxy, CacheSerializiableJob) - * @see #runOnLocalOrRemoteJvm(int, IndexSerializableJob) - * @see #runOnLocalOrRemoteJvm(Ignite, IgniteSerializableJob) - * @see #runOnLocalOrRemoteJvm(IgniteCache, CacheSerializiableJob) + * @see #executeOnLocalOrRemoteJvm(int, TestIgniteIdxCallable) + * @see #executeOnLocalOrRemoteJvm(Ignite, TestIgniteCallable) + * @see #executeOnLocalOrRemoteJvm(IgniteCache, TestCacheCallable) */ protected boolean isMultiJvm() { return false; @@ -1424,18 +1421,18 @@ public abstract class GridAbstractTest extends TestCase { * @param idx Grid index. * @param job Job. */ - public void runOnLocalOrRemoteJvm(final int idx, final IndexSerializableJob job) { + public R executeOnLocalOrRemoteJvm(final int idx, final TestIgniteIdxCallable job) { IgniteEx ignite = grid(idx); if (!isMultiJvmObject(ignite)) try { - job.run(idx); + return job.call(idx); } catch (Exception e) { throw new IgniteException(e); } else - runRemotely(idx, job); + return executeRemotely(idx, job); } /** @@ -1444,36 +1441,36 @@ public abstract class GridAbstractTest extends TestCase { * @param ignite Ignite. * @param job Job. */ - public void runOnLocalOrRemoteJvm(Ignite ignite, final IgniteSerializableJob job) { + public R executeOnLocalOrRemoteJvm(Ignite ignite, final TestIgniteCallable job) { if (!isMultiJvmObject(ignite)) try { - job.run(ignite); + return job.call(ignite); } catch (Exception e) { throw new IgniteException(e); } else - runRemotely((IgniteProcessProxy)ignite, job); + return executeRemotely((IgniteProcessProxy)ignite, job); } /** - * Runs job on local jvm or on remote jvm in multi jvm case. + * Calls job on local jvm or on remote jvm in multi jvm case. * * @param cache Cache. * @param job Job. */ - public void runOnLocalOrRemoteJvm(IgniteCache cache, CacheSerializiableJob job) { + public R executeOnLocalOrRemoteJvm(IgniteCache cache, TestCacheCallable job) { Ignite ignite = cache.unwrap(Ignite.class); if (!isMultiJvmObject(ignite)) try { - job.run(ignite, cache); + return job.call(ignite, cache); } catch (Exception e) { throw new IgniteException(e); } else - runRemotely((IgniteCacheProcessProxy)cache, job); + return executeRemotely((IgniteCacheProcessProxy)cache, job); } /** @@ -1482,7 +1479,7 @@ public abstract class GridAbstractTest extends TestCase { * @param idx Grid index. * @param job Job. */ - public void runRemotely(final int idx, final IndexSerializableJob job) { + public R executeRemotely(final int idx, final TestIgniteIdxCallable job) { IgniteEx ignite = grid(idx); if (!isMultiJvmObject(ignite)) @@ -1490,14 +1487,9 @@ public abstract class GridAbstractTest extends TestCase { IgniteProcessProxy proxy = (IgniteProcessProxy)ignite; - proxy.remoteCompute().run(new CAX() { - @Override public void applyx() throws IgniteCheckedException { - try { - job.run(idx); - } - catch (Exception e) { - throw new IgniteCheckedException(e); - } + return proxy.remoteCompute().call(new IgniteCallable() { + @Override public R call() throws Exception { + return job.call(idx); } }); } @@ -1508,19 +1500,14 @@ public abstract class GridAbstractTest extends TestCase { * @param proxy Ignite. * @param job Job. */ - public static void runRemotely(IgniteProcessProxy proxy, final IgniteSerializableJob job) { + public static R executeRemotely(IgniteProcessProxy proxy, final TestIgniteCallable job) { final UUID id = proxy.getId(); - proxy.remoteCompute().run(new CAX() { - @Override public void applyx() throws IgniteCheckedException { + return proxy.remoteCompute().call(new IgniteCallable() { + @Override public R call() throws Exception { Ignite ignite = Ignition.ignite(id); - try { - job.run(ignite); - } - catch (Exception e) { - throw new IgniteCheckedException(e); - } + return job.call(ignite); } }); } @@ -1531,23 +1518,19 @@ public abstract class GridAbstractTest extends TestCase { * @param cache Cache. * @param job Job. */ - public static void runRemotely(IgniteCacheProcessProxy cache, final CacheSerializiableJob job) { + public static R executeRemotely(IgniteCacheProcessProxy cache, + final TestCacheCallable job) { IgniteProcessProxy proxy = (IgniteProcessProxy)cache.unwrap(Ignite.class); final UUID id = proxy.getId(); final String cacheName = cache.getName(); - proxy.remoteCompute().run(new CAX() { - @Override public void applyx() throws IgniteCheckedException { + return proxy.remoteCompute().call(new IgniteCallable() { + @Override public R call() throws Exception { Ignite ignite = Ignition.ignite(id); IgniteCache cache = ignite.cache(cacheName); - try { - job.run(ignite, cache); - } - catch (Exception e) { - throw new IgniteCheckedException(e); - } + return job.call(ignite, cache); } }); } @@ -1866,34 +1849,74 @@ public abstract class GridAbstractTest extends TestCase { } } - /** - * Serializable runnable. - */ - public static interface IgniteSerializableJob extends Serializable { + /** */ + public static interface TestIgniteCallable extends Serializable { /** * @param ignite Ignite. */ - void run(Ignite ignite) throws Exception; + R call(Ignite ignite) throws Exception; } - /** - * Serializiable runnable. - */ - public static interface IndexSerializableJob extends Serializable { + /** */ + public abstract static class TestIgniteRunnable implements TestIgniteCallable { + /** {@inheritDoc} */ + @Override public Object call(Ignite ignite) throws Exception { + run(ignite); + + return null; + } + + /** + * @param ignite Ignite. + */ + public abstract void run(Ignite ignite) throws Exception; + } + + /** */ + public static interface TestIgniteIdxCallable extends Serializable { /** * @param idx Grid index. */ - void run(int idx) throws Exception; + R call(int idx) throws Exception; } - /** - * Serializiable runnable. - */ - public static interface CacheSerializiableJob extends Serializable { + /** */ + public abstract static class TestIgniteIdxRunnable implements TestIgniteIdxCallable { + /** {@inheritDoc} */ + @Override public Object call(int idx) throws Exception { + run(idx); + + return null; + } + + /** + * @param idx Index. + */ + public abstract void run(int idx) throws Exception; + } + + /** */ + public static interface TestCacheCallable extends Serializable { + /** + * @param ignite Ignite. + * @param cache Cache. + */ + R call(Ignite ignite, IgniteCache cache) throws Exception; + } + + /** */ + public abstract static class TestTestCacheRunnable implements TestCacheCallable { + /** {@inheritDoc} */ + @Override public Object call(Ignite ignite, IgniteCache cache) throws Exception { + run(ignite, cache); + + return null; + } + /** * @param ignite Ignite. * @param cache Cache. */ - void run(Ignite ignite, IgniteCache cache) throws Exception; + public abstract void run(Ignite ignite, IgniteCache cache) throws Exception; } }