http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7e3c81b4/modules/core/src/test/java/org/apache/ignite/loadtests/cache/GridCacheDataStructuresLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/cache/GridCacheDataStructuresLoadTest.java b/modules/core/src/test/java/org/apache/ignite/loadtests/cache/GridCacheDataStructuresLoadTest.java index a389200..2efb06b 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/cache/GridCacheDataStructuresLoadTest.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/cache/GridCacheDataStructuresLoadTest.java @@ -19,9 +19,15 @@ package org.apache.ignite.loadtests.cache; import org.apache.ignite.*; import org.apache.ignite.cache.*; +import org.apache.ignite.configuration.*; import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.testframework.*; +import org.apache.ignite.transactions.*; +import org.jetbrains.annotations.*; import java.util.*; +import java.util.concurrent.*; /** * Cache data structures load test. @@ -45,6 +51,9 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad /** Count down latch name. */ private static final String TEST_LATCH_NAME = "test-latch"; + /** */ + private static final IgniteCollectionConfiguration colCfg = new IgniteCollectionConfiguration(); + /** Maximum added value. */ private static final int MAX_INT = 1000; @@ -75,11 +84,11 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad } /** Atomic long write closure. */ - private final CIX1<CacheProjection<Integer, Integer>> longWriteClos = - new CIX1<CacheProjection<Integer, Integer>>() { - @Override public void applyx(CacheProjection<Integer, Integer> cache) + private final CIX1<Ignite> longWriteClos = + new CIX1<Ignite>() { + @Override public void applyx(Ignite ignite) throws IgniteCheckedException { - IgniteAtomicLong al = cache.cache().dataStructures().atomicLong(TEST_LONG_NAME, 0, true); + IgniteAtomicLong al = ignite.atomicLong(TEST_LONG_NAME, 0, true); for (int i = 0; i < operationsPerTx; i++) { al.addAndGet(RAND.nextInt(MAX_INT)); @@ -93,11 +102,11 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad }; /** Atomic long read closure. */ - private final CIX1<CacheProjection<Integer, Integer>> longReadClos = - new CIX1<CacheProjection<Integer, Integer>>() { - @Override public void applyx(CacheProjection<Integer, Integer> cache) + private final CIX1<Ignite> longReadClos = + new CIX1<Ignite>() { + @Override public void applyx(Ignite ignite) throws IgniteCheckedException { - IgniteAtomicLong al = cache.cache().dataStructures().atomicLong(TEST_LONG_NAME, 0, true); + IgniteAtomicLong al = ignite.atomicLong(TEST_LONG_NAME, 0, true); for (int i = 0; i < operationsPerTx; i++) { al.get(); @@ -111,11 +120,11 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad }; /** Atomic reference write closure. */ - private final CIX1<CacheProjection<Integer, Integer>> refWriteClos = - new CIX1<CacheProjection<Integer, Integer>>() { - @Override public void applyx(CacheProjection<Integer, Integer> cache) + private final CIX1<Ignite> refWriteClos = + new CIX1<Ignite>() { + @Override public void applyx(Ignite ignite) throws IgniteCheckedException { - IgniteAtomicReference<Integer> ar = cache.cache().dataStructures().atomicReference(TEST_REF_NAME, + IgniteAtomicReference<Integer> ar = ignite.atomicReference(TEST_REF_NAME, null, true); for (int i = 0; i < operationsPerTx; i++) { @@ -130,11 +139,11 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad }; /** Atomic reference read closure. */ - private final CIX1<CacheProjection<Integer, Integer>> refReadClos = - new CIX1<CacheProjection<Integer, Integer>>() { - @Override public void applyx(CacheProjection<Integer, Integer> cache) + private final CIX1<Ignite> refReadClos = + new CIX1<Ignite>() { + @Override public void applyx(Ignite ignite) throws IgniteCheckedException { - IgniteAtomicReference<Integer> ar = cache.cache().dataStructures().atomicReference(TEST_REF_NAME, null, + IgniteAtomicReference<Integer> ar = ignite.atomicReference(TEST_REF_NAME, null, true); for (int i = 0; i < operationsPerTx; i++) { @@ -149,11 +158,11 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad }; /** Atomic sequence write closure. */ - private final CIX1<CacheProjection<Integer, Integer>> seqWriteClos = - new CIX1<CacheProjection<Integer, Integer>>() { - @Override public void applyx(CacheProjection<Integer, Integer> cache) + private final CIX1<Ignite> seqWriteClos = + new CIX1<Ignite>() { + @Override public void applyx(Ignite ignite) throws IgniteCheckedException { - IgniteAtomicSequence as = cache.cache().dataStructures().atomicSequence(TEST_SEQ_NAME, 0, true); + IgniteAtomicSequence as = ignite.atomicSequence(TEST_SEQ_NAME, 0, true); for (int i = 0; i < operationsPerTx; i++) { as.addAndGet(RAND.nextInt(MAX_INT) + 1); @@ -167,11 +176,11 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad }; /** Atomic sequence read closure. */ - private final CIX1<CacheProjection<Integer, Integer>> seqReadClos = - new CIX1<CacheProjection<Integer, Integer>>() { - @Override public void applyx(CacheProjection<Integer, Integer> cache) + private final CIX1<Ignite> seqReadClos = + new CIX1<Ignite>() { + @Override public void applyx(Ignite ignite) throws IgniteCheckedException { - IgniteAtomicSequence as = cache.cache().dataStructures().atomicSequence(TEST_SEQ_NAME, 0, true); + IgniteAtomicSequence as = ignite.atomicSequence(TEST_SEQ_NAME, 0, true); for (int i = 0; i < operationsPerTx; i++) { as.get(); @@ -185,11 +194,11 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad }; /** Atomic stamped write closure. */ - private final CIX1<CacheProjection<Integer, Integer>> stampWriteClos = - new CIX1<CacheProjection<Integer, Integer>>() { - @Override public void applyx(CacheProjection<Integer, Integer> cache) + private final CIX1<Ignite> stampWriteClos = + new CIX1<Ignite>() { + @Override public void applyx(Ignite ignite) throws IgniteCheckedException { - IgniteAtomicStamped<Integer, Integer> as = cache.cache().dataStructures().atomicStamped(TEST_STAMP_NAME, + IgniteAtomicStamped<Integer, Integer> as = ignite.atomicStamped(TEST_STAMP_NAME, 0, 0, true); for (int i = 0; i < operationsPerTx; i++) { @@ -204,11 +213,11 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad }; /** Atomic stamped read closure. */ - private final CIX1<CacheProjection<Integer, Integer>> stampReadClos = - new CIX1<CacheProjection<Integer, Integer>>() { - @Override public void applyx(CacheProjection<Integer, Integer> cache) + private final CIX1<Ignite> stampReadClos = + new CIX1<Ignite>() { + @Override public void applyx(Ignite ignite) throws IgniteCheckedException { - IgniteAtomicStamped<Integer, Integer> as = cache.cache().dataStructures().atomicStamped(TEST_STAMP_NAME, + IgniteAtomicStamped<Integer, Integer> as = ignite.atomicStamped(TEST_STAMP_NAME, 0, 0, true); for (int i = 0; i < operationsPerTx; i++) { @@ -223,11 +232,11 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad }; /** Queue write closure. */ - private final CIX1<CacheProjection<Integer, Integer>> queueWriteClos = - new CIX1<CacheProjection<Integer, Integer>>() { - @Override public void applyx(CacheProjection<Integer, Integer> cache) + private final CIX1<Ignite> queueWriteClos = + new CIX1<Ignite>() { + @Override public void applyx(Ignite ignite) throws IgniteCheckedException { - IgniteQueue<Integer> q = cache.cache().dataStructures().queue(TEST_QUEUE_NAME, 0, true, true); + IgniteQueue<Integer> q = ignite.queue(TEST_QUEUE_NAME, colCfg, 0, true); for (int i = 0; i < operationsPerTx; i++) { q.put(RAND.nextInt(MAX_INT)); @@ -241,11 +250,11 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad }; /** Queue read closure. */ - private final CIX1<CacheProjection<Integer, Integer>> queueReadClos = - new CIX1<CacheProjection<Integer, Integer>>() { - @Override public void applyx(CacheProjection<Integer, Integer> cache) + private final CIX1<Ignite> queueReadClos = + new CIX1<Ignite>() { + @Override public void applyx(Ignite ignite) throws IgniteCheckedException { - IgniteQueue<Integer> q = cache.cache().dataStructures().queue(TEST_QUEUE_NAME, 0, true, true); + IgniteQueue<Integer> q = ignite.queue(TEST_QUEUE_NAME, colCfg, 0, true); for (int i = 0; i < operationsPerTx; i++) { q.peek(); @@ -259,12 +268,11 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad }; /** Count down latch write closure. */ - private final CIX1<CacheProjection<Integer, Integer>> latchWriteClos = - new CIX1<CacheProjection<Integer, Integer>>() { - @Override public void applyx(CacheProjection<Integer, Integer> cache) + private final CIX1<Ignite> latchWriteClos = + new CIX1<Ignite>() { + @Override public void applyx(Ignite ignite) throws IgniteCheckedException { - IgniteCountDownLatch l = cache.cache().dataStructures().countDownLatch(TEST_LATCH_NAME, LATCH_INIT_CNT, - true, true); + IgniteCountDownLatch l = ignite.countDownLatch(TEST_LATCH_NAME, LATCH_INIT_CNT, true, true); for (int i = 0; i < operationsPerTx; i++) { l.countDown(); @@ -278,12 +286,11 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad }; /** Count down latch read closure. */ - private final CIX1<CacheProjection<Integer, Integer>> latchReadClos = - new CIX1<CacheProjection<Integer, Integer>>() { - @Override public void applyx(CacheProjection<Integer, Integer> cache) + private final CIX1<Ignite> latchReadClos = + new CIX1<Ignite>() { + @Override public void applyx(Ignite ignite) throws IgniteCheckedException { - IgniteCountDownLatch l = cache.cache().dataStructures().countDownLatch(TEST_LATCH_NAME, LATCH_INIT_CNT, - true, true); + IgniteCountDownLatch l = ignite.countDownLatch(TEST_LATCH_NAME, LATCH_INIT_CNT, true, true); for (int i = 0; i < operationsPerTx; i++) { l.count(); @@ -316,7 +323,7 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad if (LONG) { info("Testing atomic long..."); - test.loadTest(test.longWriteClos, test.longReadClos); + test.loadTestIgnite(test.longWriteClos, test.longReadClos); } System.gc(); @@ -324,7 +331,7 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad if (REF) { info("Testing atomic reference..."); - test.loadTest(test.refWriteClos, test.refReadClos); + test.loadTestIgnite(test.refWriteClos, test.refReadClos); } System.gc(); @@ -332,7 +339,7 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad if (SEQ) { info("Testing atomic sequence..."); - test.loadTest(test.seqWriteClos, test.seqReadClos); + test.loadTestIgnite(test.seqWriteClos, test.seqReadClos); } System.gc(); @@ -340,7 +347,7 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad if (STAMP) { info("Testing atomic stamped..."); - test.loadTest(test.stampWriteClos, test.stampReadClos); + test.loadTestIgnite(test.stampWriteClos, test.stampReadClos); } System.gc(); @@ -348,7 +355,7 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad if (QUEUE) { info("Testing queue..."); - test.loadTest(test.queueWriteClos, test.queueReadClos); + test.loadTestIgnite(test.queueWriteClos, test.queueReadClos); } System.gc(); @@ -356,8 +363,91 @@ public final class GridCacheDataStructuresLoadTest extends GridCacheAbstractLoad if (LATCH) { info("Testing count down latch..."); - test.loadTest(test.latchWriteClos, test.latchReadClos); + test.loadTestIgnite(test.latchWriteClos, test.latchReadClos); } } } + + /** + * @param writeClos Write closure. + * @param readClos ReadClosure. + */ + protected void loadTestIgnite(final CIX1<Ignite> writeClos, final CIX1<Ignite> readClos) { + info("Read threads: " + readThreads()); + info("Write threads: " + writeThreads()); + info("Test duration (ms): " + testDuration); + + final Ignite ignite = G.ignite(); + + final GridCache<Integer, Integer> cache = ignite.cache(null); + + assert cache != null; + + try { + IgniteFuture<?> f1 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() { + @Nullable @Override public Object call() throws Exception { + long start = System.currentTimeMillis(); + + while (!done.get()) { + if (tx) { + try (IgniteTx tx = cache.txStart()) { + writeClos.apply(ignite); + + tx.commit(); + } + } + else + writeClos.apply(ignite); + } + + writeTime.addAndGet(System.currentTimeMillis() - start); + + return null; + } + }, writeThreads(), "cache-load-test-worker"); + + IgniteFuture<?> f2 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() { + @Nullable @Override public Object call() throws Exception { + long start = System.currentTimeMillis(); + + while(!done.get()) { + if (tx) { + try (IgniteTx tx = cache.txStart()) { + readClos.apply(ignite); + + tx.commit(); + } + } + else + readClos.apply(ignite); + } + + readTime.addAndGet(System.currentTimeMillis() - start); + + return null; + } + }, readThreads(), "cache-load-test-worker"); + + Thread.sleep(testDuration); + + done.set(true); + + f1.get(); + f2.get(); + + info("Test stats: "); + info(" total-threads = " + threads); + info(" write-ratio = " + writeRatio); + info(" total-runs = " + (reads.get() + writes.get())); + info(" total-reads = " + reads); + info(" total-writes = " + writes); + info(" read-time (ms) = " + readTime); + info(" write-time (ms) = " + writeTime); + info(" avg-read-time (ms) = " + ((double)readTime.get() / reads.get())); + info(" avg-write-time (ms) = " + ((double)writeTime.get() / writes.get())); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } }
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7e3c81b4/modules/core/src/test/java/org/apache/ignite/marshaller/GridMarshallerAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/marshaller/GridMarshallerAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/marshaller/GridMarshallerAbstractTest.java index 624a784..cb2b21f 100644 --- a/modules/core/src/test/java/org/apache/ignite/marshaller/GridMarshallerAbstractTest.java +++ b/modules/core/src/test/java/org/apache/ignite/marshaller/GridMarshallerAbstractTest.java @@ -802,36 +802,6 @@ public abstract class GridMarshallerAbstractTest extends GridCommonAbstractTest /** * @throws Exception If failed. */ - public void testDataStructures() throws Exception { - CacheDataStructures dataStructures = grid().cache(CACHE_NAME).dataStructures(); - - IgniteAtomicLong atomicLong = dataStructures.atomicLong("test", 0, true); - - assert atomicLong != null; - - atomicLong.addAndGet(1); - - GridMarshallerTestBean inBean = newTestBean(dataStructures); - - byte[] buf = marshal(inBean); - - GridMarshallerTestBean outBean = unmarshal(buf); - - assert inBean.getObjectField() != null; - assert outBean.getObjectField() != null; - - assert inBean.getObjectField().getClass().equals(GridCacheDataStructuresProxy.class); - assert outBean.getObjectField().getClass().equals(GridCacheDataStructuresProxy.class); - - assert inBean != outBean; - assert inBean.equals(outBean); - - outBean.checkNullResources(); - } - - /** - * @throws Exception If failed. - */ public void testAffinity() throws Exception { GridCache<String, String> cache = grid().cache(CACHE_NAME); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7e3c81b4/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFieldsQuerySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFieldsQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFieldsQuerySelfTest.java index 0364cab..3dd4d00 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFieldsQuerySelfTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractFieldsQuerySelfTest.java @@ -22,6 +22,7 @@ import org.apache.ignite.cache.*; import org.apache.ignite.cache.affinity.*; import org.apache.ignite.cache.query.*; import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.processors.datastructures.*; import org.apache.ignite.lang.*; import org.apache.ignite.marshaller.optimized.*; import org.apache.ignite.spi.discovery.*; @@ -178,8 +179,8 @@ public abstract class GridCacheAbstractFieldsQuerySelfTest extends GridCommonAbs /** @throws Exception If failed. */ public void testCacheMetaData() throws Exception { - // Create data structure to test filtering of internal objects. - grid(0).cache(null).dataStructures().atomicLong("LONG", 0, true); + // Put internal key to test filtering of internal objects. + grid(0).cache(null).put(new GridCacheInternalKeyImpl("test"), 1); Collection<GridCacheSqlMetadata> metas = ((GridCacheQueriesEx<?, ?>)grid(0).cache(null).queries()).sqlMetadata(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7e3c81b4/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java ---------------------------------------------------------------------- diff --git a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java index c22bc2f..cb41930 100644 --- a/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java +++ b/modules/rest-http/src/main/java/org/apache/ignite/internal/processors/rest/protocols/http/jetty/GridJettyRestHandler.java @@ -292,14 +292,29 @@ public class GridJettyRestHandler extends AbstractHandler { * * @param cmd Command. * @param params Parameters. + * @param req Servlet request. * @return REST request. * @throws IgniteCheckedException If creation failed. */ - @Nullable private GridRestRequest createRequest(GridRestCommand cmd, Map<String, Object> params, + @Nullable private GridRestRequest createRequest(GridRestCommand cmd, + Map<String, Object> params, ServletRequest req) throws IgniteCheckedException { GridRestRequest restReq; switch (cmd) { + case CACHE_DECREMENT: + case CACHE_INCREMENT: { + DataStructuresRequest restReq0 = new DataStructuresRequest(); + + restReq0.key(params.get("key")); + restReq0.initial(longValue("init", params, null)); + restReq0.delta(longValue("delta", params, null)); + + restReq = restReq0; + + break; + } + case CACHE_GET: case CACHE_GET_ALL: case CACHE_PUT: @@ -310,13 +325,11 @@ public class GridJettyRestHandler extends AbstractHandler { case CACHE_CAS: case CACHE_METRICS: case CACHE_REPLACE: - case CACHE_DECREMENT: - case CACHE_INCREMENT: case CACHE_APPEND: case CACHE_PREPEND: { GridRestCacheRequest restReq0 = new GridRestCacheRequest(); - restReq0.cacheName((String) params.get("cacheName")); + restReq0.cacheName((String)params.get("cacheName")); restReq0.key(params.get("key")); restReq0.value(params.get("val")); restReq0.value2(params.get("val2")); @@ -328,8 +341,6 @@ public class GridJettyRestHandler extends AbstractHandler { restReq0.cacheFlags(intValue("cacheFlags", params, 0)); restReq0.ttl(longValue("exp", params, null)); - restReq0.initial(longValue("init", params, null)); - restReq0.delta(longValue("delta", params, null)); if (cmd == CACHE_GET_ALL || cmd == CACHE_PUT_ALL || cmd == CACHE_REMOVE_ALL) { List<Object> keys = values("k", params); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7e3c81b4/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarAffinityRoutingSpec.scala ---------------------------------------------------------------------- diff --git a/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarAffinityRoutingSpec.scala b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarAffinityRoutingSpec.scala index 7062984..e9d95c0 100644 --- a/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarAffinityRoutingSpec.scala +++ b/modules/scalar/src/test/scala/org/apache/ignite/scalar/tests/ScalarAffinityRoutingSpec.scala @@ -17,6 +17,7 @@ package org.apache.ignite.scalar.tests +import org.apache.ignite.Ignition import org.apache.ignite.scalar.scalar import org.apache.ignite.scalar.scalar._ import org.junit.runner.RunWith @@ -38,7 +39,7 @@ class ScalarAffinityRoutingSpec extends FlatSpec with ShouldMatchers with Before c += (1 -> 1) c += (2 -> 2) - val cnt = c.dataStructures().atomicLong("affinityRun", 0, true) + val cnt = Ignition.ignite.atomicLong("affinityRun", 0, true) grid$.affinityRun$(CACHE_NAME, 0, () => { cnt.incrementAndGet() }, null) grid$.affinityRun$(CACHE_NAME, 1, () => { cnt.incrementAndGet() }, null) @@ -54,7 +55,7 @@ class ScalarAffinityRoutingSpec extends FlatSpec with ShouldMatchers with Before c += (1 -> 1) c += (2 -> 2) - val cnt = c.dataStructures().atomicLong("affinityRunAsync", 0, true) + val cnt = Ignition.ignite.atomicLong("affinityRunAsync", 0, true) grid$.affinityRunAsync$(CACHE_NAME, 0, () => { cnt.incrementAndGet() }, null).get grid$.affinityRunAsync$(CACHE_NAME, 1, () => { cnt.incrementAndGet() }, null).get