http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/968c3cf8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryEmbeddedValue.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryEmbeddedValue.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryEmbeddedValue.java new file mode 100644 index 0000000..d8606ad --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryEmbeddedValue.java @@ -0,0 +1,49 @@ +/* + * 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.cache.query.*; + +import java.io.*; + +/** + * Query embedded value. + */ +@SuppressWarnings("unused") +public class GridCacheQueryEmbeddedValue implements Serializable { + /** Query embedded field. */ + @GridCacheQuerySqlField + private int embeddedField1 = 55; + + /** Query embedded field. */ + @GridCacheQuerySqlField(groups = {"grp1"}) + private int embeddedField2 = 11; + + /** */ + @GridCacheQuerySqlField + private Val embeddedField3 = new Val(); + + /** + */ + @SuppressWarnings("PublicInnerClass") + public static class Val implements Serializable { + /** */ + @GridCacheQuerySqlField + private Long x = 3L; + } +}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/968c3cf8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryIndexSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryIndexSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryIndexSelfTest.java new file mode 100644 index 0000000..ffbbb97 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryIndexSelfTest.java @@ -0,0 +1,124 @@ +/* + * 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.cache.*; +import org.apache.ignite.cache.query.*; +import org.apache.ignite.internal.util.typedef.internal.*; + +import java.util.*; + +import static org.apache.ignite.cache.GridCacheMode.*; + +/** + * Tests for cache query index. + */ +public class GridCacheQueryIndexSelfTest extends GridCacheAbstractSelfTest { + /** Grid count. */ + private static final int GRID_CNT = 2; + + /** Entry count. */ + private static final int ENTRY_CNT = 10; + + /** {@inheritDoc} */ + @Override protected int gridCount() { + return GRID_CNT; + } + + /** {@inheritDoc} */ + @Override protected GridCacheMode cacheMode() { + return PARTITIONED; + } + + /** + * @throws Exception If failed. + */ + public void testWithoutStoreLoad() throws Exception { + GridCache<Integer, CacheValue> cache = grid(0).cache(null); + + for (int i = 0; i < ENTRY_CNT; i++) + cache.put(i, new CacheValue(i)); + + checkCache(cache); + checkQuery(cache, false); + } + + /** + * @throws Exception If failed. + */ + public void testWithStoreLoad() throws Exception { + for (int i = 0; i < ENTRY_CNT; i++) + putToStore(i, new CacheValue(i)); + + GridCache<Integer, CacheValue> cache0 = grid(0).cache(null); + + cache0.loadCache(null, 0); + + checkCache(cache0); + checkQuery(cache0, true); + } + + /** + * @param cache Cache. + * @throws Exception If failed. + */ + private void checkCache(GridCacheProjection<Integer,CacheValue> cache) throws Exception { + assert cache.entrySet().size() == ENTRY_CNT : "Expected: " + ENTRY_CNT + ", but was: " + cache.size(); + assert cache.keySet().size() == ENTRY_CNT : "Expected: " + ENTRY_CNT + ", but was: " + cache.size(); + assert cache.values().size() == ENTRY_CNT : "Expected: " + ENTRY_CNT + ", but was: " + cache.size(); + assert cache.size() == ENTRY_CNT : "Expected: " + ENTRY_CNT + ", but was: " + cache.size(); + } + + /** + * @param cache Cache. + * @param backups Include backups flag. + * @throws Exception If failed. + */ + private void checkQuery(GridCacheProjection<Integer, CacheValue> cache, boolean backups) throws Exception { + GridCacheQuery<Map.Entry<Integer, CacheValue>> qry = cache.queries().createSqlQuery( + CacheValue.class, "val >= 5"); + + if (backups) + qry.includeBackups(true); + + Collection<Map.Entry<Integer, CacheValue>> queried = qry.execute().get(); + + assertEquals("Unexpected query result: " + queried, 5, queried.size()); + } + + /** + * Test cache value. + */ + private static class CacheValue { + @GridCacheQuerySqlField + private final int val; + + CacheValue(int val) { + this.val = val; + } + + int value() { + return val; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(CacheValue.class, this); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/968c3cf8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryIndexingDisabledSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryIndexingDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryIndexingDisabledSelfTest.java new file mode 100644 index 0000000..0538bd2 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryIndexingDisabledSelfTest.java @@ -0,0 +1,98 @@ +/* + * 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.apache.ignite.cache.*; +import org.apache.ignite.cache.query.*; +import org.apache.ignite.testframework.*; + +import java.util.*; +import java.util.concurrent.*; + +/** + * + */ +public class GridCacheQueryIndexingDisabledSelfTest extends GridCacheAbstractSelfTest { + /** {@inheritDoc} */ + @Override protected int gridCount() { + return 2; + } + + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception { + CacheConfiguration ccfg = super.cacheConfiguration(gridName); + + ccfg.setCacheMode(GridCacheMode.PARTITIONED); + ccfg.setQueryIndexEnabled(false); + + return ccfg; + } + + /** + * @param c Closure. + */ + private void doTest(Callable<Object> c) { + GridTestUtils.assertThrows(log, c, IgniteCheckedException.class, "Indexing is disabled for cache: null"); + } + + /** + * @throws IgniteCheckedException If failed. + */ + public void testSqlFieldsQuery() throws IgniteCheckedException { + doTest(new Callable<Object>() { + @Override public Object call() throws IgniteCheckedException { + return cache().queries().createSqlFieldsQuery("select * from dual").execute() + .get(); + } + }); + } + + /** + * @throws IgniteCheckedException If failed. + */ + public void testTextQuery() throws IgniteCheckedException { + doTest(new Callable<Object>() { + @Override public Object call() throws IgniteCheckedException { + return cache().queries().createFullTextQuery(String.class, "text") + .execute().get(); + } + }); + } + + /** + * @throws IgniteCheckedException If failed. + */ + public void testSqlQuery() throws IgniteCheckedException { + doTest(new Callable<Object>() { + @Override public Object call() throws IgniteCheckedException { + return cache().queries().createSqlQuery(String.class, "1 = 1") + .execute().get(); + } + }); + } + + /** + * @throws IgniteCheckedException If failed. + */ + public void testScanQuery() throws IgniteCheckedException { + GridCacheQuery<Map.Entry<String, Integer>> qry = cache().queries().createScanQuery(null); + + qry.execute().get(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/968c3cf8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryInternalKeysSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryInternalKeysSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryInternalKeysSelfTest.java new file mode 100644 index 0000000..d531325 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheQueryInternalKeysSelfTest.java @@ -0,0 +1,112 @@ +/* + * 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.apache.ignite.cache.*; +import org.apache.ignite.cluster.*; +import org.apache.ignite.internal.*; +import org.apache.ignite.internal.processors.cache.datastructures.*; +import org.apache.ignite.internal.processors.cache.distributed.near.*; +import org.apache.ignite.internal.util.typedef.*; +import org.jetbrains.annotations.*; + +import java.util.*; + +import static org.apache.ignite.cache.GridCacheMode.*; +import static org.apache.ignite.cache.GridCachePreloadMode.*; + +/** + * Test for http://gridgain.jira.com/browse/GG-3979. + */ +public class GridCacheQueryInternalKeysSelfTest extends GridCacheAbstractSelfTest { + /** Grid count. */ + private static final int GRID_CNT = 2; + + /** Entry count. */ + private static final int ENTRY_CNT = 10; + + /** {@inheritDoc} */ + @Override protected int gridCount() { + return GRID_CNT; + } + + /** {@inheritDoc} */ + @Override protected GridCacheMode cacheMode() { + return PARTITIONED; + } + + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception { + CacheConfiguration cc = super.cacheConfiguration(gridName); + + cc.setQueryIndexEnabled(false); + cc.setPreloadMode(SYNC); + + return cc; + } + + /** + * @throws Exception If failed. + */ + @SuppressWarnings("unchecked") + public void testInternalKeysPreloading() throws Exception { + try { + GridCache<Object, Object> cache = grid(0).cache(null); + + for (int i = 0; i < ENTRY_CNT; i++) + cache.dataStructures().queue("queue" + i, Integer.MAX_VALUE, false, true); + + startGrid(GRID_CNT); // Start additional node. + + for (int i = 0; i < ENTRY_CNT; i++) { + GridCacheQueueHeaderKey internalKey = new GridCacheQueueHeaderKey("queue" + i); + + Collection<ClusterNode> nodes = cache.affinity().mapKeyToPrimaryAndBackups(internalKey); + + for (ClusterNode n : nodes) { + Ignite g = findGridForNodeId(n.id()); + + assertNotNull(g); + + assertTrue("Affinity node doesn't contain internal key [key=" + internalKey + ", node=" + n + ']', + ((GridNearCacheAdapter)((GridKernal)g).internalCache()).dht().containsKey(internalKey, null)); + } + } + } + finally { + stopGrid(GRID_CNT); + } + } + + /** + * Finds the {@link org.apache.ignite.Ignite}, which has a local node + * with given ID. + * + * @param nodeId ID for grid's local node. + * @return A grid instance or {@code null}, if the grid + * is not found. + */ + @Nullable private Ignite findGridForNodeId(final UUID nodeId) { + return F.find(G.allGrids(), null, new P1<Ignite>() { + @Override public boolean apply(Ignite e) { + return nodeId.equals(e.cluster().localNode().id()); + } + }); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/968c3cf8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReferenceCleanupSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReferenceCleanupSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReferenceCleanupSelfTest.java new file mode 100644 index 0000000..c8f0c02 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReferenceCleanupSelfTest.java @@ -0,0 +1,502 @@ +/* + * 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.apache.ignite.cache.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.marshaller.optimized.*; +import org.apache.ignite.transactions.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.testframework.*; +import org.apache.ignite.testframework.junits.common.*; + +import java.lang.ref.*; +import java.util.*; +import java.util.concurrent.*; + +import static org.apache.ignite.cache.GridCacheAtomicityMode.*; +import static org.apache.ignite.cache.GridCacheDistributionMode.*; +import static org.apache.ignite.testframework.GridTestUtils.*; + +/** + * + */ +public class GridCacheReferenceCleanupSelfTest extends GridCommonAbstractTest { + /** */ + private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** Cache mode for the current test. */ + private GridCacheMode mode; + + /** */ + private boolean cancel; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(ipFinder); + + cfg.setDiscoverySpi(disco); + + CacheConfiguration cacheCfg = defaultCacheConfiguration(); + + cacheCfg.setCacheMode(mode); + cacheCfg.setWriteSynchronizationMode(GridCacheWriteSynchronizationMode.FULL_SYNC); + cacheCfg.setAtomicityMode(TRANSACTIONAL); + cacheCfg.setDistributionMode(NEAR_PARTITIONED); + + cfg.setCacheConfiguration(cacheCfg); + + cfg.setMarshaller(new IgniteOptimizedMarshaller(false)); + + return cfg; + } + + /** @throws Exception If failed. */ + public void testAtomicLongPartitioned() throws Exception { + mode = GridCacheMode.PARTITIONED; + + startGrids(2); + + try { + checkReferenceCleanup(atomicLongCallable()); + } + finally { + stopAllGrids(); + } + } + + /** @throws Exception If failed. */ + public void testAtomicLongReplicated() throws Exception { + mode = GridCacheMode.REPLICATED; + + startGrids(2); + + try { + checkReferenceCleanup(atomicLongCallable()); + } + finally { + stopAllGrids(); + } + } + + /** @throws Exception If failed. */ + public void testAtomicLongLocal() throws Exception { + mode = GridCacheMode.LOCAL; + + try { + checkReferenceCleanup(atomicLongCallable()); + } + finally { + stopAllGrids(); + } + } + + /** @throws Exception If failed. */ + public void testOneAsyncOpPartitioned() throws Exception { + mode = GridCacheMode.PARTITIONED; + + startGrids(2); + + try { + checkReferenceCleanup(oneAsyncOpCallable()); + } + finally { + stopAllGrids(); + } + } + + /** @throws Exception If failed. */ + public void testOneAsyncOpReplicated() throws Exception { + mode = GridCacheMode.REPLICATED; + + startGrids(2); + + try { + checkReferenceCleanup(oneAsyncOpCallable()); + } + finally { + stopAllGrids(); + } + } + + /** @throws Exception If failed. */ + public void testOneAsyncOpLocal() throws Exception { + mode = GridCacheMode.LOCAL; + + try { + checkReferenceCleanup(oneAsyncOpCallable()); + } + finally { + stopAllGrids(); + } + } + + /** @throws Exception If failed. */ + public void testSeveralAsyncOpsPartitioned() throws Exception { + mode = GridCacheMode.PARTITIONED; + + startGrids(2); + + try { + checkReferenceCleanup(severalAsyncOpsCallable()); + } + finally { + stopAllGrids(); + } + } + + /** @throws Exception If failed. */ + public void testSeveralAsyncOpsReplicated() throws Exception { + mode = GridCacheMode.REPLICATED; + + startGrids(2); + + try { + checkReferenceCleanup(severalAsyncOpsCallable()); + } + finally { + stopAllGrids(); + } + } + + /** @throws Exception If failed. */ + public void testSeveralAsyncOpsLocal() throws Exception { + mode = GridCacheMode.LOCAL; + + try { + checkReferenceCleanup(severalAsyncOpsCallable()); + } + finally { + stopAllGrids(); + } + } + + /** @throws Exception If failed. */ + public void testSyncOpAsyncCommitPartitioned() throws Exception { + mode = GridCacheMode.PARTITIONED; + + startGrids(2); + + try { + checkReferenceCleanup(syncOpAsyncCommitCallable()); + } + finally { + stopAllGrids(); + } + } + + /** @throws Exception If failed. */ + public void testSyncOpAsyncCommitReplicated() throws Exception { + mode = GridCacheMode.REPLICATED; + + startGrids(2); + + try { + checkReferenceCleanup(syncOpAsyncCommitCallable()); + } + finally { + stopAllGrids(); + } + } + + /** @throws Exception If failed. */ + public void testSyncOpAsyncCommitLocal() throws Exception { + mode = GridCacheMode.LOCAL; + + try { + checkReferenceCleanup(syncOpAsyncCommitCallable()); + } + finally { + stopAllGrids(); + } + } + + /** @throws Exception If failed. */ + public void testAsyncOpsAsyncCommitPartitioned() throws Exception { + mode = GridCacheMode.PARTITIONED; + + startGrids(2); + + try { + checkReferenceCleanup(asyncOpsAsyncCommitCallable()); + } + finally { + stopAllGrids(); + } + } + + /** @throws Exception If failed. */ + public void testAsyncOpsAsyncCommitReplicated() throws Exception { + mode = GridCacheMode.REPLICATED; + + startGrids(2); + + try { + checkReferenceCleanup(asyncOpsAsyncCommitCallable()); + } + finally { + stopAllGrids(); + } + } + + /** @throws Exception If failed. */ + public void testAsyncOpsAsyncCommitLocal() throws Exception { + mode = GridCacheMode.LOCAL; + + try { + checkReferenceCleanup(asyncOpsAsyncCommitCallable()); + } + finally { + stopAllGrids(); + } + } + + /** + * @param call Callable. + * @throws Exception If failed. + */ + public void checkReferenceCleanup(Callable<Collection<WeakReference<Object>>> call) throws Exception { + for (boolean cancel : new boolean[] {true, false}) { + this.cancel = cancel; + + final Collection<WeakReference<Object>> refs = call.call(); + + GridTestUtils.retryAssert(log, 10, 1000, new CA() { + @Override public void apply() { + System.gc(); + System.gc(); + System.gc(); + + for (WeakReference<?> ref : refs) + assertNull(ref.get()); + } + }); + } + } + + /** + * Crates callable for atomic long test. + * + * @return Callable. + * @throws Exception If failed. + */ + private Callable<Collection<WeakReference<Object>>> atomicLongCallable() throws Exception { + return new Callable<Collection<WeakReference<Object>>>() { + @Override public Collection<WeakReference<Object>> call() throws Exception { + Collection<WeakReference<Object>> refs = new ArrayList<>(); + + Ignite g = startGrid(); + + try { + GridCache<Integer, TestValue> cache = g.cache(null); + + refs.add(new WeakReference<Object>(cacheContext(cache))); + + Map<Integer, TestValue> m = new HashMap<>(); + + for (int i = 0; i < 10; i++) { + TestValue val = new TestValue(i); + + refs.add(new WeakReference<Object>(val)); + + m.put(i, val); + + cache.dataStructures().atomicLong("testLong" + i, 0, true).incrementAndGet(); + } + + cache.putAll(m); + } + finally { + G.stop(g.name(), cancel); + } + + return refs; + } + }; + } + + /** + * Crates callable for one async op test. + * + * @return Callable. + * @throws Exception If failed. + */ + private Callable<Collection<WeakReference<Object>>> oneAsyncOpCallable() throws Exception { + return new Callable<Collection<WeakReference<Object>>>() { + @Override public Collection<WeakReference<Object>> call() throws Exception { + Collection<WeakReference<Object>> refs = new ArrayList<>(); + + Ignite g = startGrid(); + + try { + GridCache<Integer, TestValue> cache = g.cache(null); + + refs.add(new WeakReference<Object>(cacheContext(cache))); + + TestValue val = new TestValue(0); + + refs.add(new WeakReference<Object>(val)); + + cache.putxAsync(0, val).get(); + } + finally { + G.stop(g.name(), cancel); + } + + return refs; + } + }; + } + + /** + * Crates callable for several async ops test. + * + * @return Callable. + * @throws Exception If failed. + */ + private Callable<Collection<WeakReference<Object>>> severalAsyncOpsCallable() throws Exception { + return new Callable<Collection<WeakReference<Object>>>() { + @Override public Collection<WeakReference<Object>> call() throws Exception { + Collection<WeakReference<Object>> refs = new ArrayList<>(); + + Ignite g = startGrid(); + + try { + GridCache<Integer, TestValue> cache = g.cache(null); + + refs.add(new WeakReference<Object>(cacheContext(cache))); + + Collection<IgniteFuture<?>> futs = new ArrayList<>(1000); + + for (int i = 0; i < 1000; i++) { + TestValue val = new TestValue(i); + + refs.add(new WeakReference<Object>(val)); + + futs.add(cache.putxAsync(i, val)); + } + + for (IgniteFuture<?> fut : futs) + fut.get(); + } + finally { + G.stop(g.name(), cancel); + } + + return refs; + } + }; + } + + /** + * Crates callable for sync op with async commit test. + * + * @return Callable. + * @throws Exception If failed. + */ + private Callable<Collection<WeakReference<Object>>> syncOpAsyncCommitCallable() throws Exception { + return new Callable<Collection<WeakReference<Object>>>() { + @Override public Collection<WeakReference<Object>> call() throws Exception { + Collection<WeakReference<Object>> refs = new ArrayList<>(); + + Ignite g = startGrid(); + + try { + GridCache<Integer, TestValue> cache = g.cache(null); + + refs.add(new WeakReference<Object>(cacheContext(cache))); + + IgniteTx tx = cache.txStart(); + + TestValue val = new TestValue(0); + + refs.add(new WeakReference<Object>(val)); + + cache.putx(0, val); + + tx.commit(); + } + finally { + G.stop(g.name(), cancel); + } + + return refs; + } + }; + } + + /** + * Crates callable for async ops with async commit test. + * + * @return Callable. + * @throws Exception If failed. + */ + private Callable<Collection<WeakReference<Object>>> asyncOpsAsyncCommitCallable() throws Exception { + return new Callable<Collection<WeakReference<Object>>>() { + @Override public Collection<WeakReference<Object>> call() throws Exception { + Collection<WeakReference<Object>> refs = new ArrayList<>(); + + Ignite g = startGrid(); + + try { + GridCache<Integer, TestValue> cache = g.cache(null); + + refs.add(new WeakReference<Object>(cacheContext(cache))); + + IgniteTx tx = cache.txStart(); + + for (int i = 0; i < 1000; i++) { + TestValue val = new TestValue(i); + + refs.add(new WeakReference<Object>(val)); + + cache.putxAsync(i, val); + } + + tx.commit(); + } + finally { + G.stop(g.name(), cancel); + } + + return refs; + } + }; + } + + /** Test value class. Created mostly to simplify heap dump analysis. */ + private static class TestValue { + /** */ + @SuppressWarnings("UnusedDeclaration") + private final int i; + + /** @param i Value. */ + private TestValue(int i) { + this.i = i; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/968c3cf8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReloadSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReloadSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReloadSelfTest.java new file mode 100644 index 0000000..46c35c2 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReloadSelfTest.java @@ -0,0 +1,178 @@ +/* + * 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.apache.ignite.cache.*; +import org.apache.ignite.cache.eviction.lru.*; +import org.apache.ignite.cache.store.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.apache.ignite.testframework.junits.common.*; + +import javax.cache.*; +import javax.cache.configuration.*; +import java.util.*; + +import static org.apache.ignite.cache.GridCacheMode.*; +import static org.apache.ignite.cache.GridCacheDistributionMode.*; + +/** + * Checks that GridCacheProjection.reload() operations are performed correctly. + */ +public class GridCacheReloadSelfTest extends GridCommonAbstractTest { + /** Maximum allowed number of cache entries. */ + public static final int MAX_CACHE_ENTRIES = 500; + + /** Number of entries to load from store. */ + public static final int N_ENTRIES = 5000; + + /** Cache name. */ + private static final String CACHE_NAME = "test"; + + /** Cache mode. */ + private GridCacheMode cacheMode; + + /** Near enabled flag. */ + private boolean nearEnabled = true; + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + cacheMode = null; + nearEnabled = true; + } + + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setLocalHost("127.0.0.1"); + + TcpDiscoverySpi discoSpi = new TcpDiscoverySpi(); + + TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder(); + ipFinder.setAddresses(Collections.singleton("127.0.0.1:47500")); + + discoSpi.setIpFinder(ipFinder); + + cfg.setDiscoverySpi(discoSpi); + + CacheConfiguration cacheCfg = defaultCacheConfiguration(); + cacheCfg.setName(CACHE_NAME); + cacheCfg.setCacheMode(cacheMode); + cacheCfg.setEvictionPolicy(new GridCacheLruEvictionPolicy(MAX_CACHE_ENTRIES)); + cacheCfg.setDistributionMode(nearEnabled ? NEAR_PARTITIONED : PARTITIONED_ONLY); + + final CacheStore store = new CacheStoreAdapter<Integer, Integer>() { + @Override public Integer load(Integer key) { + return key; + } + + @Override public void write(Cache.Entry<? extends Integer, ? extends Integer> e) { + //No-op. + } + + @Override public void delete(Object key) { + //No-op. + } + }; + + cacheCfg.setCacheStoreFactory(new FactoryBuilder.SingletonFactory(store)); + cacheCfg.setReadThrough(true); + cacheCfg.setWriteThrough(true); + cacheCfg.setLoadPreviousValue(true); + + if (cacheMode == PARTITIONED) + cacheCfg.setBackups(1); + + cfg.setCacheConfiguration(cacheCfg); + + return cfg; + } + + /** + * Checks that eviction works with reload() on local cache. + * + * @throws Exception If error occurs. + */ + public void testReloadEvictionLocalCache() throws Exception { + cacheMode = GridCacheMode.LOCAL; + + doTest(); + } + + /** + * Checks that eviction works with reload() on partitioned cache + * with near enabled. + * + * @throws Exception If error occurs. + */ + //TODO: Active when ticket GG-3926 will be ready. + public void _testReloadEvictionPartitionedCacheNearEnabled() throws Exception { + cacheMode = PARTITIONED; + + doTest(); + } + + /** + * Checks that eviction works with reload() on partitioned cache + * with near disabled. + * + * @throws Exception If error occurs. + */ + public void testReloadEvictionPartitionedCacheNearDisabled() throws Exception { + cacheMode = PARTITIONED; + nearEnabled = false; + + doTest(); + } + + /** + * Checks that eviction works with reload() on replicated cache. + * + * @throws Exception If error occurs. + */ + public void testReloadEvictionReplicatedCache() throws Exception { + cacheMode = GridCacheMode.REPLICATED; + + doTest(); + } + + /** + * Actual test logic. + * + * @throws Exception If error occurs. + */ + private void doTest() throws Exception { + Ignite ignite = startGrid(); + + try { + GridCache<Integer, Integer> cache = ignite.cache(CACHE_NAME); + + for (int i = 0; i < N_ENTRIES; i++) + cache.reload(i); + + assertEquals(MAX_CACHE_ENTRIES, cache.size()); + } + finally { + stopGrid(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/968c3cf8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReplicatedSynchronousCommitTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReplicatedSynchronousCommitTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReplicatedSynchronousCommitTest.java new file mode 100644 index 0000000..d176dd7 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReplicatedSynchronousCommitTest.java @@ -0,0 +1,202 @@ +/* + * 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.apache.ignite.cache.*; +import org.apache.ignite.cluster.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.processors.cache.distributed.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.spi.*; +import org.apache.ignite.internal.managers.communication.*; +import org.apache.ignite.spi.communication.tcp.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.apache.ignite.internal.util.direct.*; +import org.apache.ignite.testframework.junits.common.*; +import org.jdk8.backport.*; +import org.jetbrains.annotations.*; + +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + +import static org.apache.ignite.cache.GridCacheWriteSynchronizationMode.*; + +/** + * Test cases for preload tests. + */ +public class GridCacheReplicatedSynchronousCommitTest extends GridCommonAbstractTest { + /** */ + private static final int ADDITION_CACHE_NUMBER = 2; + + /** */ + private static final String NO_COMMIT = "no_commit"; + + /** */ + private final Collection<TestCommunicationSpi> commSpis = new ConcurrentLinkedDeque8<>(); + + /** */ + private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** + * + */ + public GridCacheReplicatedSynchronousCommitTest() { + super(false /*start grid. */); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration c = super.getConfiguration(gridName); + + CacheConfiguration cc = defaultCacheConfiguration(); + + cc.setCacheMode(GridCacheMode.REPLICATED); + + cc.setWriteSynchronizationMode(FULL_SYNC); + + c.setCacheConfiguration(cc); + + TestCommunicationSpi commSpi = new TestCommunicationSpi(gridName.equals(NO_COMMIT)); + + c.setCommunicationSpi(commSpi); + + commSpis.add(commSpi); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(ipFinder); + + c.setDiscoverySpi(disco); + + return c; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + commSpis.clear(); + } + + /** + * @throws Exception If test failed. + */ + public void testSynchronousCommit() throws Exception { + try { + Ignite firstIgnite = startGrid("1"); + + GridCache<Integer, String> firstCache = firstIgnite.cache(null); + + for (int i = 0; i < ADDITION_CACHE_NUMBER; i++) + startGrid(String.valueOf(i + 2)); + + firstCache.put(1, "val1"); + + int cnt = 0; + + for (TestCommunicationSpi commSpi : commSpis) + cnt += commSpi.messagesCount(); + + assert cnt == ADDITION_CACHE_NUMBER; + } + finally { + stopAllGrids(); + } + } + + /** + * @throws Exception If test failed. + */ + public void testSynchronousCommitNodeLeave() throws Exception { + try { + Ignite ignite1 = startGrid("1"); + + startGrid(NO_COMMIT); + + Ignite ignite3 = startGrid("3"); + + GridCache<Integer, String> cache1 = ignite1.cache(null); + GridCache<Integer, String> cache3 = ignite3.cache(null); + + IgniteFuture<?> fut = multithreadedAsync( + new Callable<Object>() { + @Nullable @Override public Object call() throws Exception { + Thread.sleep(1000); + + stopGrid(NO_COMMIT); + + return null; + } + }, + 1); + + cache1.put(1, "val1"); + + assert cache3.get(1) != null; + + fut.get(); + } + finally { + stopAllGrids(); + } + } + + /** + * + */ + private static class TestCommunicationSpi extends TcpCommunicationSpi { + /** */ + private final AtomicInteger msgCnt = new AtomicInteger(); + + /** */ + private boolean noCommit; + + /** + * @param noCommit Send Commit or not. + */ + private TestCommunicationSpi(boolean noCommit) { + this.noCommit = noCommit; + } + + /** + * @return Number of transaction finish messages that was sent. + */ + public int messagesCount() { + return msgCnt.get(); + } + + /** {@inheritDoc} */ + @Override public void sendMessage(ClusterNode node, GridTcpCommunicationMessageAdapter msg) + throws IgniteSpiException { + Object obj = ((GridIoMessage)msg).message(); + + if (obj instanceof GridDistributedTxFinishResponse) { + msgCnt.incrementAndGet(); + + if (noCommit) + return; + } + + super.sendMessage(node, msg); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/968c3cf8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReplicatedTxStoreExceptionSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReplicatedTxStoreExceptionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReplicatedTxStoreExceptionSelfTest.java new file mode 100644 index 0000000..88f6f89 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReplicatedTxStoreExceptionSelfTest.java @@ -0,0 +1,38 @@ +/* + * 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.cache.*; + +import static org.apache.ignite.cache.GridCacheDistributionMode.*; +import static org.apache.ignite.cache.GridCacheMode.*; + +/** + * + */ +public class GridCacheReplicatedTxStoreExceptionSelfTest extends IgniteTxStoreExceptionAbstractSelfTest { + /** {@inheritDoc} */ + @Override protected GridCacheMode cacheMode() { + return REPLICATED; + } + + /** {@inheritDoc} */ + @Override protected GridCacheDistributionMode distributionMode() { + return PARTITIONED_ONLY; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/968c3cf8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReturnValueTransferSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReturnValueTransferSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReturnValueTransferSelfTest.java new file mode 100644 index 0000000..def252d --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheReturnValueTransferSelfTest.java @@ -0,0 +1,207 @@ +/* + * 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.apache.ignite.cache.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.processors.cache.*; +import org.apache.ignite.testframework.junits.common.*; + +import javax.cache.processor.*; +import java.io.*; +import java.util.*; + +import static org.apache.ignite.cache.GridCacheAtomicWriteOrderMode.*; +import static org.apache.ignite.cache.GridCacheAtomicityMode.*; +import static org.apache.ignite.cache.GridCacheFlag.*; +import static org.apache.ignite.cache.GridCacheMode.*; + +/** + * Tests transform for extra traffic. + */ +public class GridCacheReturnValueTransferSelfTest extends GridCommonAbstractTest { + /** Distribution mode. */ + private GridCacheDistributionMode distroMode; + + /** Atomicity mode. */ + private GridCacheAtomicityMode atomicityMode; + + /** Atomic write order mode. */ + private GridCacheAtomicWriteOrderMode writeOrderMode; + + /** Number of backups. */ + private int backups; + + /** Fail deserialization flag. */ + private static volatile boolean failDeserialization; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setBackups(backups); + ccfg.setCacheMode(PARTITIONED); + ccfg.setAtomicityMode(atomicityMode); + ccfg.setAtomicWriteOrderMode(writeOrderMode); + + ccfg.setDistributionMode(distroMode); + + cfg.setCacheConfiguration(ccfg); + + return cfg; + } + + /** + * @throws Exception If failed. + */ + public void testTransformAtomicPrimaryNoBackups() throws Exception { + checkTransform(ATOMIC, PRIMARY, 0); + } + + /** + * @throws Exception If failed. + */ + public void testTransformAtomicClockNoBackups() throws Exception { + checkTransform(ATOMIC, CLOCK, 0); + } + + /** + * @throws Exception If failed. + */ + public void testTransformAtomicPrimaryOneBackup() throws Exception { + checkTransform(ATOMIC, PRIMARY, 1); + } + + /** + * @throws Exception If failed. + */ + public void testTransformAtomicClockOneBackup() throws Exception { + checkTransform(ATOMIC, CLOCK, 1); + } + + /** + * @throws Exception If failed. + * TODO gg-8273 enable when fixed + */ + public void _testTransformTransactionalNoBackups() throws Exception { + checkTransform(TRANSACTIONAL, PRIMARY, 0); + } + + /** + * @throws Exception If failed. + * TODO gg-8273 enable when fixed + */ + public void _testTransformTransactionalOneBackup() throws Exception { + checkTransform(TRANSACTIONAL, PRIMARY, 1); + } + + /** + * @param mode Atomicity mode. + * @param order Atomic cache write order mode. + * @param b Number of backups. + * @throws Exception If failed. + */ + private void checkTransform(GridCacheAtomicityMode mode, GridCacheAtomicWriteOrderMode order, int b) + throws Exception { + try { + atomicityMode = mode; + + backups = b; + + writeOrderMode = order; + + distroMode = GridCacheDistributionMode.PARTITIONED_ONLY; + + startGrids(2); + + distroMode = GridCacheDistributionMode.CLIENT_ONLY; + + startGrid(2); + + failDeserialization = false; + + // Get client grid. + IgniteCache<Integer, TestObject> cache = grid(2).jcache(null); + + if (backups > 0 && atomicityMode == ATOMIC) + cache = ((IgniteCacheProxy<Integer, TestObject>)cache).flagsOn(FORCE_TRANSFORM_BACKUP); + + for (int i = 0; i < 100; i++) + cache.put(i, new TestObject()); + + failDeserialization = true; + + info(">>>>>> Transforming"); + + // Transform (check non-existent keys also). + for (int i = 0; i < 200; i++) + cache.invoke(i, new Transform()); + + Set<Integer> keys = new HashSet<>(); + + // Check transformAll. + for (int i = 0; i < 300; i++) + keys.add(i); + + cache.invokeAll(keys, new Transform()); + + // Avoid errors during stop. + failDeserialization = false; + } + finally { + stopAllGrids(); + } + } + + /** + * + */ + private static class Transform implements EntryProcessor<Integer, TestObject, Void>, Serializable { + /** {@inheritDoc} */ + @Override public Void process(MutableEntry<Integer, TestObject> entry, Object... args) { + entry.setValue(new TestObject()); + + return null; + } + } + + /** + * + */ + private static class TestObject implements Externalizable { + /** + * + */ + public TestObject() { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void writeExternal(ObjectOutput out) throws IOException { + assert !failDeserialization; + } + + /** {@inheritDoc} */ + @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + assert !failDeserialization; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/968c3cf8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSlowTxWarnTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSlowTxWarnTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSlowTxWarnTest.java new file mode 100644 index 0000000..cc6d1a5 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSlowTxWarnTest.java @@ -0,0 +1,148 @@ +/* + * 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.apache.ignite.cache.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.*; +import org.apache.ignite.internal.processors.cache.*; +import org.apache.ignite.transactions.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.apache.ignite.testframework.junits.common.*; + +import static org.apache.ignite.cache.GridCacheMode.*; + +/** + * Test to check slow TX warning timeout defined by + * {@link org.apache.ignite.IgniteSystemProperties#GG_SLOW_TX_WARN_TIMEOUT} + * system property. + */ +public class GridCacheSlowTxWarnTest extends GridCommonAbstractTest { + /** IP finder. */ + private static final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration c = super.getConfiguration(gridName); + + CacheConfiguration cc1 = defaultCacheConfiguration(); + + cc1.setName("partitioned"); + cc1.setCacheMode(PARTITIONED); + cc1.setBackups(1); + + CacheConfiguration cc2 = defaultCacheConfiguration(); + + cc2.setName("replicated"); + cc2.setCacheMode(REPLICATED); + + CacheConfiguration cc3 = defaultCacheConfiguration(); + + cc3.setName("local"); + cc3.setCacheMode(LOCAL); + + c.setCacheConfiguration(cc1, cc2, cc3); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(ipFinder); + + c.setDiscoverySpi(disco); + + return c; + } + + /** + * @throws Exception If failed. + */ + public void testWarningOutput() throws Exception { + try { + GridKernal g = (GridKernal)startGrid(1); + + info(">>> Slow tx timeout is not set, long-live txs simulated."); + + checkCache(g, "partitioned", true, false); + checkCache(g, "replicated", true, false); + checkCache(g, "local", true, false); + + info(">>> Slow tx timeout is set, long-live tx simulated."); + + checkCache(g, "partitioned", true, true); + checkCache(g, "replicated", true, true); + checkCache(g, "local", true, true); + + info(">>> Slow tx timeout is set, no long-live txs."); + + checkCache(g, "partitioned", false, true); + checkCache(g, "replicated", false, true); + checkCache(g, "local", false, true); + } + finally { + stopAllGrids(); + } + } + + /** + * @param g Grid. + * @param cacheName Cache. + * @param simulateTimeout Simulate timeout. + * @param configureTimeout Alter configuration of TX manager. + * @throws Exception If failed. + */ + private void checkCache(Ignite g, String cacheName, boolean simulateTimeout, + boolean configureTimeout) throws Exception { + if (configureTimeout) { + GridCacheAdapter<Integer, Integer> cache = ((GridKernal)g).internalCache(cacheName); + + cache.context().tm().slowTxWarnTimeout(500); + } + + GridCache<Object, Object> cache1 = g.cache(cacheName); + + IgniteTx tx = cache1.txStart(); + + try { + cache1.put(1, 1); + + if (simulateTimeout) + Thread.sleep(800); + + tx.commit(); + } + finally { + tx.close(); + } + + tx = cache1.txStart(); + + try { + cache1.put(1, 1); + + if (simulateTimeout) + Thread.sleep(800); + + tx.rollback(); + } + finally { + tx.close(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/968c3cf8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStopSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStopSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStopSelfTest.java new file mode 100644 index 0000000..5e45233 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStopSelfTest.java @@ -0,0 +1,201 @@ +/* + * 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.apache.ignite.cache.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.apache.ignite.transactions.*; +import org.apache.ignite.testframework.*; +import org.apache.ignite.testframework.junits.common.*; + +import java.util.*; +import java.util.concurrent.*; + +import static org.apache.ignite.cache.GridCacheAtomicityMode.*; +import static org.apache.ignite.cache.GridCacheMode.*; + +/** + * Tests correct cache stopping. + */ +public class GridCacheStopSelfTest extends GridCommonAbstractTest { + /** */ + private static final String EXPECTED_MSG = "Grid is in invalid state to perform this operation. " + + "It either not started yet or has already being or have stopped"; + + /** */ + private boolean atomic; + + /** */ + private boolean replicated; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + TcpDiscoverySpi disc = new TcpDiscoverySpi(); + + disc.setIpFinder(new TcpDiscoveryVmIpFinder(true)); + + cfg.setDiscoverySpi(disc); + + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setCacheMode(replicated ? REPLICATED : PARTITIONED); + + ccfg.setAtomicityMode(atomic ? ATOMIC : TRANSACTIONAL); + + ccfg.setQueryIndexEnabled(true); + ccfg.setSwapEnabled(true); + + cfg.setCacheConfiguration(ccfg); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + } + + /** + * @throws Exception If failed. + */ + public void testStopExplicitTransactions() throws Exception { + testStop(true); + } + + /** + * @throws Exception If failed. + */ + public void testStopImplicitTransactions() throws Exception { + testStop(false); + } + + /** + * @throws Exception If failed. + */ + public void testStopExplicitTransactionsReplicated() throws Exception { + replicated = true; + + testStop(true); + } + + /** + * @throws Exception If failed. + */ + public void testStopImplicitTransactionsReplicated() throws Exception { + replicated = true; + + testStop(false); + } + + /** + * @throws Exception If failed. + */ + public void testStopAtomic() throws Exception { + atomic = true; + + testStop(false); + } + + /** + * @param startTx If {@code true} starts transactions. + * @throws Exception If failed. + */ + private void testStop(final boolean startTx) throws Exception { + for (int i = 0; i < 10; i++) { + startGrid(0); + + final int PUT_THREADS = 50; + + final CountDownLatch stopLatch = new CountDownLatch(1); + + final CountDownLatch readyLatch = new CountDownLatch(PUT_THREADS); + + final GridCache<Integer, Integer> cache = grid(0).cache(null); + + assertNotNull(cache); + + assertEquals(atomic ? ATOMIC : TRANSACTIONAL, cache.configuration().getAtomicityMode()); + assertEquals(replicated ? REPLICATED : PARTITIONED, cache.configuration().getCacheMode()); + + Collection<IgniteFuture<?>> putFuts = new ArrayList<>(); + + for (int j = 0; j < PUT_THREADS; j++) { + final int key = j; + + putFuts.add(GridTestUtils.runAsync(new Callable<Void>() { + @Override public Void call() throws Exception { + if (startTx) { + try (IgniteTx tx = cache.txStart()) { + cache.put(key, key); + + readyLatch.countDown(); + + stopLatch.await(); + + tx.commit(); + } + } + else { + readyLatch.countDown(); + + stopLatch.await(); + + cache.put(key, key); + } + + return null; + } + })); + } + + readyLatch.await(); + + stopLatch.countDown(); + + stopGrid(0); + + for (IgniteFuture<?> fut : putFuts) { + try { + fut.get(); + } + catch (IgniteCheckedException e) { + if (!e.getMessage().startsWith(EXPECTED_MSG)) + e.printStackTrace(); + + assertTrue("Unexpected error message: " + e.getMessage(), e.getMessage().startsWith(EXPECTED_MSG)); + } + } + + try { + cache.put(1, 1); + } + catch (IllegalStateException e) { + if (!e.getMessage().startsWith(EXPECTED_MSG)) + e.printStackTrace(); + + assertTrue("Unexpected error message: " + e.getMessage(), e.getMessage().startsWith(EXPECTED_MSG)); + } + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/968c3cf8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStorePutxSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStorePutxSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStorePutxSelfTest.java new file mode 100644 index 0000000..de10e72 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStorePutxSelfTest.java @@ -0,0 +1,159 @@ +/* + * 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.cache.*; +import org.apache.ignite.cache.store.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.apache.ignite.transactions.*; +import org.apache.ignite.testframework.junits.common.*; +import org.jetbrains.annotations.*; + +import javax.cache.*; +import javax.cache.configuration.*; +import java.util.*; +import java.util.concurrent.atomic.*; + +import static org.apache.ignite.cache.GridCacheAtomicityMode.*; +import static org.apache.ignite.cache.GridCacheMode.*; +import static org.apache.ignite.cache.GridCacheWriteSynchronizationMode.*; + +/** + * Tests for reproduce problem with GG-6895: + * putx calls CacheStore.load() when null GridPredicate passed in to avoid IDE warnings + */ +public class GridCacheStorePutxSelfTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static AtomicInteger loads; + + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setCacheMode(PARTITIONED); + ccfg.setAtomicityMode(TRANSACTIONAL); + ccfg.setWriteSynchronizationMode(FULL_SYNC); + ccfg.setCacheStoreFactory(new FactoryBuilder.SingletonFactory(new TestStore())); + ccfg.setReadThrough(true); + ccfg.setWriteThrough(true); + ccfg.setLoadPreviousValue(true); + + cfg.setCacheConfiguration(ccfg); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(IP_FINDER); + + cfg.setDiscoverySpi(disco); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + loads = new AtomicInteger(); + + startGrid(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopGrid(); + } + + /** + * @throws Exception If failed. + */ + public void testPutxShouldNotTriggerLoad() throws Exception { + assertTrue(cache().putx(1, 1)); + assertTrue(cache().putx(2, 2, (IgnitePredicate)null)); + + assertEquals(0, loads.get()); + } + + /** + * @throws Exception If failed. + */ + public void testPutxShouldNotTriggerLoadWithTx() throws Exception { + GridCache<Integer, Integer> cache = cache(); + + try (IgniteTx tx = cache.txStart()) { + assertTrue(cache.putx(1, 1)); + assertTrue(cache.putx(2, 2, (IgnitePredicate)null)); + + tx.commit(); + } + + assertEquals(0, loads.get()); + } + + /** */ + private static class TestStore extends CacheStore<Integer, Integer> { + /** {@inheritDoc} */ + @Nullable @Override public Integer load(Integer key) { + loads.incrementAndGet(); + + return null; + } + + /** {@inheritDoc} */ + @Override public void loadCache(IgniteBiInClosure<Integer, Integer> clo, @Nullable Object... args) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public Map<Integer, Integer> loadAll(Iterable<? extends Integer> keys) { + return Collections.emptyMap(); + } + + /** {@inheritDoc} */ + @Override public void write(Cache.Entry<? extends Integer, ? extends Integer> entry) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void writeAll(Collection<Cache.Entry<? extends Integer, ? extends Integer>> entries) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void delete(Object key) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void deleteAll(Collection<?> keys) { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void txEnd(boolean commit) { + // No-op. + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/968c3cf8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreValueBytesSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreValueBytesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreValueBytesSelfTest.java new file mode 100644 index 0000000..32522d4 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheStoreValueBytesSelfTest.java @@ -0,0 +1,112 @@ +/* + * 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.apache.ignite.cache.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.internal.*; +import org.apache.ignite.internal.processors.cache.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.apache.ignite.testframework.junits.common.*; + +import static org.apache.ignite.cache.GridCacheMode.*; +import static org.apache.ignite.cache.GridCacheWriteSynchronizationMode.*; + +/** + * Test for {@link org.apache.ignite.cache.CacheConfiguration#isStoreValueBytes()}. + */ +public class GridCacheStoreValueBytesSelfTest extends GridCommonAbstractTest { + /** */ + private boolean storeValBytes; + + /** VM ip finder for TCP discovery. */ + private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(ipFinder); + + cfg.setDiscoverySpi(disco); + + CacheConfiguration ccfg = defaultCacheConfiguration(); + + ccfg.setCacheMode(REPLICATED); + ccfg.setWriteSynchronizationMode(FULL_SYNC); + ccfg.setStoreValueBytes(storeValBytes); + + cfg.setCacheConfiguration(ccfg); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + } + + /** + * JUnit. + * + * @throws Exception If failed. + */ + public void testDisabled() throws Exception { + storeValBytes = false; + + Ignite g0 = startGrid(0); + Ignite g1 = startGrid(1); + + GridCache<Integer, String> c = g0.cache(null); + + c.put(1, "Cached value"); + + GridCacheEntryEx<Object, Object> entry = ((GridKernal)g1).internalCache().peekEx(1); + + assert entry != null; + assert entry.valueBytes().isNull(); + } + + /** + * JUnit. + * + * @throws Exception If failed. + */ + public void testEnabled() throws Exception { + storeValBytes = true; + + Ignite g0 = startGrid(0); + Ignite g1 = startGrid(1); + + GridCache<Integer, String> c = g0.cache(null); + + c.put(1, "Cached value"); + + GridCacheEntryEx<Object, Object> entry = ((GridKernal)g1).internalCache().peekEx(1); + + assert entry != null; + assert entry.valueBytes() != null; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/968c3cf8/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapPreloadSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapPreloadSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapPreloadSelfTest.java new file mode 100644 index 0000000..16de630 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSwapPreloadSelfTest.java @@ -0,0 +1,223 @@ +/* + * 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.cache.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; +import org.apache.ignite.testframework.junits.common.*; +import org.jetbrains.annotations.*; + +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + +import static org.apache.ignite.cache.GridCacheAtomicityMode.*; +import static org.apache.ignite.cache.GridCacheMode.*; +import static org.apache.ignite.cache.GridCachePreloadMode.*; + +/** + * Test for cache swap preloading. + */ +public class GridCacheSwapPreloadSelfTest extends GridCommonAbstractTest { + /** Entry count. */ + private static final int ENTRY_CNT = 15000; + + /** */ + private final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true); + + /** */ + private GridCacheMode cacheMode; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + TcpDiscoverySpi disco = new TcpDiscoverySpi(); + + disco.setIpFinder(ipFinder); + + cfg.setDiscoverySpi(disco); + + cfg.setNetworkTimeout(2000); + + CacheConfiguration cacheCfg = defaultCacheConfiguration(); + + cacheCfg.setWriteSynchronizationMode(GridCacheWriteSynchronizationMode.FULL_SYNC); + cacheCfg.setSwapEnabled(true); + cacheCfg.setCacheMode(cacheMode); + cacheCfg.setPreloadMode(SYNC); + cacheCfg.setEvictSynchronized(false); + cacheCfg.setEvictNearSynchronized(false); + cacheCfg.setAtomicityMode(TRANSACTIONAL); + + if (cacheMode == PARTITIONED) + cacheCfg.setBackups(1); + + cfg.setCacheConfiguration(cacheCfg); + + return cfg; + } + + /** @throws Exception If failed. */ + public void testSwapReplicated() throws Exception { + cacheMode = REPLICATED; + + checkSwap(); + } + + /** @throws Exception If failed. */ + public void testSwapPartitioned() throws Exception { + cacheMode = PARTITIONED; + + checkSwap(); + } + + /** @throws Exception If failed. */ + private void checkSwap() throws Exception { + try { + startGrid(0); + + GridCache<Integer, Integer> cache = grid(0).cache(null); + + // Populate. + for (int i = 0; i < ENTRY_CNT; i++) + cache.put(i, i); + + info("Put finished."); + + // Evict all. + cache.evictAll(); + + info("Evict finished."); + + for (int i = 0; i < ENTRY_CNT; i++) + assertNull(cache.peek(i)); + + assert cache.isEmpty(); + + startGrid(1); + + int size = grid(1).cache(null).size(); + + info("New node cache size: " + size); + + assertEquals(ENTRY_CNT, size); + } + finally { + stopAllGrids(); + } + } + + /** + * TODO: GG-4804 Swap preloading test failed with NotNull assertion, TODO: GG-4804 while key should have been found + * either in swap or in cache + * + * @throws Exception If failed. + */ + public void _testSwapReplicatedMultithreaded() throws Exception { + cacheMode = REPLICATED; + + checkSwapMultithreaded(); + } + + /** @throws Exception If failed. */ + public void testSwapPartitionedMultithreaded() throws Exception { + cacheMode = PARTITIONED; + + checkSwapMultithreaded(); + } + + /** @throws Exception If failed. */ + private void checkSwapMultithreaded() throws Exception { + final AtomicBoolean done = new AtomicBoolean(); + IgniteFuture<?> fut = null; + + try { + startGrid(0); + + final GridCache<Integer, Integer> cache = grid(0).cache(null); + + assertNotNull(cache); + + // Populate. + for (int i = 0; i < ENTRY_CNT; i++) + cache.put(i, i); + + cache.evictAll(); + + fut = multithreadedAsync(new Callable<Object>() { + @Nullable @Override public Object call() throws Exception { + Random rnd = new Random(); + + while (!done.get()) { + int key = rnd.nextInt(ENTRY_CNT); + + Integer i = cache.get(key); + + assertNotNull(i); + assertEquals(Integer.valueOf(key), i); + + boolean b = cache.evict(rnd.nextInt(ENTRY_CNT)); + + assert b; + } + + return null; + } + }, 10); + + startGrid(1); + + done.set(true); + + int size = grid(1).cache(null).size(); + + info("New node cache size: " + size); + + if (size != ENTRY_CNT) { + Iterable<Integer> keySet = new TreeSet<>(grid(1).<Integer, Integer>cache(null).keySet()); + + int next = 0; + + for (Integer i : keySet) { + while (next < i) + info("Missing key: " + next++); + + next++; + } + } + + assertEquals(ENTRY_CNT, size); + } + finally { + done.set(true); + + try { + if (fut != null) + fut.get(); + } + finally { + stopAllGrids(); + } + } + } +}