Repository: incubator-ignite Updated Branches: refs/heads/ignite-45 a6a5e48ad -> 67d65527a
# IGNITE-403 Added IgniteCacheStartStopLoadTest Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/67d65527 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/67d65527 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/67d65527 Branch: refs/heads/ignite-45 Commit: 67d65527ae1ab500ded74a3858ec164cc62ab6a4 Parents: a6a5e48 Author: sevdokimov <sevdoki...@gridgain.com> Authored: Tue Mar 10 14:29:00 2015 +0300 Committer: sevdokimov <sevdoki...@gridgain.com> Committed: Tue Mar 10 14:29:00 2015 +0300 ---------------------------------------------------------------------- .../processors/cache/IgniteCacheProxy.java | 13 +- .../cache/IgniteCacheStartStopLoadTest.java | 137 +++++++++++++++++++ .../ignite/testframework/GridTestUtils.java | 25 ++++ 3 files changed, 172 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/67d65527/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java index cddae65..7d17e16 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java @@ -1251,12 +1251,19 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K, V return getCacheManager() == null; } + /** + * + */ + public GridCacheProjectionEx delegate() { + return delegate; + } + /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public <T> T unwrap(Class<T> clazz) { - if (clazz.isAssignableFrom(IgniteCache.class)) + if (clazz.isAssignableFrom(getClass())) return (T)this; - else if (clazz.isAssignableFrom(Ignite.class)) + else if (clazz.isAssignableFrom(IgniteEx.class)) return (T)ctx.grid(); throw new IllegalArgumentException("Unwrapping to class is not supported: " + clazz); @@ -1457,7 +1464,7 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K, V /** * Closeable iterator. */ - private static abstract class ClIter<X, Y> extends GridCloseableIteratorAdapter<Y> { + private abstract static class ClIter<X, Y> extends GridCloseableIteratorAdapter<Y> { /** */ private X cur; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/67d65527/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStartStopLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStartStopLoadTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStartStopLoadTest.java new file mode 100644 index 0000000..28cd09b --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStartStopLoadTest.java @@ -0,0 +1,137 @@ +/* + * 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.configuration.*; +import org.apache.ignite.internal.*; +import org.apache.ignite.testframework.*; +import org.apache.ignite.testframework.junits.common.*; + +import java.util.*; +import java.util.concurrent.*; +import java.util.concurrent.atomic.*; + +/** + * Test for dynamic cache start. + */ +@SuppressWarnings("unchecked") +public class IgniteCacheStartStopLoadTest extends GridCommonAbstractTest { + /** */ + private static final long DURATION = 60_000L; + + /** */ + private static final int CACHE_COUNT = 1; + + /** */ + private static final String[] CACHE_NAMES = new String[CACHE_COUNT]; + + /** */ + static { + for (int i = 0; i < CACHE_NAMES.length; i++) + CACHE_NAMES[i] = "cache_" + i; + } + + /** */ + private WeakHashMap<Object, Boolean> weakMap; + + /** {@inheritDoc} */ + @Override protected long getTestTimeout() { + return DURATION + 20_000L; + } + + /** + * @return Number of nodes for this test. + */ + public int nodeCount() { + return 4; + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + return super.getConfiguration(gridName); + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + startGridsMultiThreaded(nodeCount()); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + stopAllGrids(); + } + + /** + * @throws Exception If failed. + */ + public void testMemoryLeaks() throws Exception { + final IgniteKernal kernal = (IgniteKernal)grid(0); + + long startTime = System.currentTimeMillis(); + + while ((System.currentTimeMillis() - startTime) < DURATION) { + final AtomicInteger idx = new AtomicInteger(); + + final Collection<IgniteInternalFuture<?>> futs = new ConcurrentLinkedDeque<>(); + + GridTestUtils.runMultiThreaded(new Callable<Object>() { + @Override public Object call() throws Exception { + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setName(CACHE_NAMES[idx.getAndIncrement()]); + + futs.add(kernal.context().cache().dynamicStartCache(ccfg)); + + return null; + } + }, CACHE_COUNT, "cache-starter"); + + for (IgniteInternalFuture<?> fut : futs) + fut.get(); + + for (int i = 0; i < nodeCount(); i++) { + for (String cacheName : CACHE_NAMES) + assert ignite(i).jcache(cacheName) != null; + } + + if (weakMap == null) { + weakMap = new WeakHashMap<>(); + + IgniteCache<Object, Object> cache = ignite(0).jcache(CACHE_NAMES[0]); + + Object obj = new Date(); + + cache.put(1, obj); + + weakMap.put(((IgniteCacheProxy)cache).delegate(), Boolean.TRUE); + weakMap.put(obj, Boolean.TRUE); + } + + futs.clear(); + + for (String cacheName : CACHE_NAMES) + futs.add(kernal.context().cache().dynamicStopCache(cacheName)); + + for (IgniteInternalFuture<?> fut : futs) + fut.get(); + } + + assert weakMap.isEmpty() : weakMap; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/67d65527/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java index 85a31ae..02c25c6 100644 --- a/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java +++ b/modules/core/src/test/java/org/apache/ignite/testframework/GridTestUtils.java @@ -40,6 +40,7 @@ import javax.cache.*; import javax.net.ssl.*; import java.io.*; import java.lang.annotation.*; +import java.lang.ref.*; import java.lang.reflect.*; import java.net.*; import java.nio.file.attribute.*; @@ -1435,6 +1436,30 @@ public final class GridTestUtils { } /** + * Prompt to execute garbage collector. + * {@code System.gc();} is not guaranteed to gerbade collection, this method try to fill memory to crowd out dead + * objects. + */ + public static void runGC() { + System.gc(); + + ReferenceQueue queue = new ReferenceQueue(); + + List<SoftReference> refs = new ArrayList<>(); + + while (true) { + byte[] bytes = new byte[128 * 1024]; + + refs.add(new SoftReference<>(bytes, queue)); + + if (queue.poll() != null) + break; + } + + System.gc(); + } + + /** * @return Path to apache ignite. */ public static String apacheIgniteTestPath() {