# sprint-1 Added test for IGNITE-114.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/3c948bee Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/3c948bee Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/3c948bee Branch: refs/heads/ignite-42 Commit: 3c948bee10681971ba0c74d61a4f98fde822ba56 Parents: e466b24 Author: sboikov <semen.boi...@inria.fr> Authored: Wed Jan 21 20:46:00 2015 +0300 Committer: sboikov <semen.boi...@inria.fr> Committed: Wed Jan 21 20:46:00 2015 +0300 ---------------------------------------------------------------------- .../cache/IgniteCacheInvokeReadThroughTest.java | 121 +++++++++++++++++++ .../bamboo/GridDataGridTestSuite.java | 3 + 2 files changed, 124 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3c948bee/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInvokeReadThroughTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInvokeReadThroughTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInvokeReadThroughTest.java new file mode 100644 index 0000000..4bdc029 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInvokeReadThroughTest.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache; + +import org.apache.ignite.*; +import org.gridgain.grid.cache.*; +import org.gridgain.grid.cache.store.*; + +import javax.cache.processor.*; + +import static org.gridgain.grid.cache.GridCacheAtomicityMode.*; +import static org.gridgain.grid.cache.GridCacheDistributionMode.*; +import static org.gridgain.grid.cache.GridCacheMode.*; + +/** + * + */ +public class IgniteCacheInvokeReadThroughTest extends IgniteCacheAbstractTest { + /** */ + private static volatile boolean failed; + + /** {@inheritDoc} */ + @Override protected int gridCount() { + return 3; + } + + /** {@inheritDoc} */ + @Override protected GridCacheMode cacheMode() { + return PARTITIONED; + } + + /** {@inheritDoc} */ + @Override protected GridCacheAtomicityMode atomicityMode() { + return TRANSACTIONAL; + } + + /** {@inheritDoc} */ + @Override protected GridCacheDistributionMode distributionMode() { + return PARTITIONED_ONLY; + } + + /** {@inheritDoc} */ + @Override protected GridCacheStore<?, ?> cacheStore() { + return new TestStore(); + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + failed = false; + } + + /** + * @throws Exception If failed. + */ + public void testInvokeReadThrough() throws Exception { + IgniteCache<Integer, Integer> cache = jcache(0); + + checkReadThrough(cache, primaryKey(cache)); + + checkReadThrough(cache, backupKey(cache)); + + checkReadThrough(cache, nearKey(cache)); + } + + /** + * @param cache Cache. + * @param key Key. + */ + private void checkReadThrough(IgniteCache<Integer, Integer> cache, Integer key) { + log.info("Test [key=" + key + ']'); + + storeMap.put(key, key); + + Object ret = cache.invoke(key, new EntryProcessor<Integer, Integer, Object>() { + @Override public Object process(MutableEntry<Integer, Integer> entry, Object... args) { + if (!entry.exists()) { + failed = true; + + fail(); + } + + Integer val = entry.getValue(); + + if (!val.equals(entry.getKey())) { + failed = true; + + assertEquals(val, entry.getKey()); + } + + entry.setValue(val + 1); + + return val; + } + }); + + assertEquals(key, ret); + + for (int i = 0; i < gridCount(); i++) + assertEquals("Unexpected value for node: " + i, key + 1, jcache(i).get(key)); + + assertFalse(failed); + } +} + http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/3c948bee/modules/core/src/test/java/org/gridgain/testsuites/bamboo/GridDataGridTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/gridgain/testsuites/bamboo/GridDataGridTestSuite.java b/modules/core/src/test/java/org/gridgain/testsuites/bamboo/GridDataGridTestSuite.java index 32d0d05..51da16f 100644 --- a/modules/core/src/test/java/org/gridgain/testsuites/bamboo/GridDataGridTestSuite.java +++ b/modules/core/src/test/java/org/gridgain/testsuites/bamboo/GridDataGridTestSuite.java @@ -335,6 +335,9 @@ public class GridDataGridTestSuite extends TestSuite { suite.addTestSuite(GridCacheMultinodeUpdateAtomicSelfTest.class); suite.addTestSuite(GridCacheMultinodeUpdateAtomicNearEnabledSelfTest.class); + // TODO: IGNITE-114. + // suite.addTestSuite(IgniteCacheInvokeReadThroughTest.class); + return suite; } }