http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationReplicatedCacheSuit.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationReplicatedCacheSuit.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationReplicatedCacheSuit.java deleted file mode 100644 index 127fe9a..0000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/standbycluster/extended/GridActivationReplicatedCacheSuit.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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.persistence.standbycluster.extended; - -import junit.framework.TestSuite; -import org.apache.ignite.internal.processors.cache.distributed.replicated.CacheReplicatedRendezvousAffinityExcludeNeighborsMultiNodeFullApiSelfTest; -import org.apache.ignite.internal.processors.cache.distributed.replicated.CacheReplicatedRendezvousAffinityMultiNodeFullApiSelfTest; -import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCacheReplicatedAtomicFullApiSelfTest; -import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCacheReplicatedAtomicMultiNodeFullApiSelfTest; -import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCacheReplicatedFullApiSelfTest; -import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCacheReplicatedMultiNodeFullApiSelfTest; -import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCacheReplicatedMultiNodeP2PDisabledFullApiSelfTest; -import org.apache.ignite.internal.processors.cache.distributed.replicated.GridCacheReplicatedNearOnlyMultiNodeFullApiSelfTest; - -/** - * - */ -public class GridActivationReplicatedCacheSuit extends GridActivationCacheAbstractTestSuit { - static { - addTest(CacheReplicatedRendezvousAffinityExcludeNeighborsMultiNodeFullApiSelfTest.class); - addTest(CacheReplicatedRendezvousAffinityMultiNodeFullApiSelfTest.class); - addTest(GridCacheReplicatedAtomicFullApiSelfTest.class); - addTest(GridCacheReplicatedFullApiSelfTest.class); - addTest(GridCacheReplicatedMultiNodeFullApiSelfTest.class); - addTest(GridCacheReplicatedAtomicMultiNodeFullApiSelfTest.class); - addTest(GridCacheReplicatedMultiNodeP2PDisabledFullApiSelfTest.class); - addTest(GridCacheReplicatedNearOnlyMultiNodeFullApiSelfTest.class); - -// tests.add(transform(GridCacheReplicatedAtomicMultiJvmFullApiSelfTest.class)); -// tests.add(transform(GridCacheReplicatedAtomicPrimaryWriteOrderMultiJvmFullApiSelfTest.class)); -// tests.add(transform(GridCacheReplicatedMultiJvmFullApiSelfTest.class)); -// tests.add(transform(GridCacheReplicatedMultiJvmP2PDisabledFullApiSelfTest.class)); -// tests.add(transform(GridCacheReplicatedNearOnlyMultiJvmFullApiSelfTest.class)); -// tests.add(transform(GridCacheReplicatedOffHeapMultiJvmFullApiSelfTest.class)); -// tests.add(transform(GridCacheReplicatedOffHeapTieredMultiJvmFullApiSelfTest.class)); - } - - /** - * - */ - public static TestSuite suite() { - TestSuite suite = buildSuite(); - - suite.setName("Activation Stand-by Cluster After Primary Cluster Stopped Check Replicated Cache"); - - return suite; - } -}
http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/internal/util/future/GridFutureListenPerformanceTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/future/GridFutureListenPerformanceTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/future/GridFutureListenPerformanceTest.java deleted file mode 100644 index 42d1838..0000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/future/GridFutureListenPerformanceTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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.util.future; - -import java.util.Date; -import java.util.Random; -import java.util.concurrent.Callable; -import java.util.concurrent.ConcurrentLinkedDeque; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.LongAdder; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.IgniteInternalFuture; -import org.apache.ignite.lang.IgniteInClosure; - -/** - * - */ -public class GridFutureListenPerformanceTest { - /** */ - private static volatile boolean done; - - /** - * @param args Args. - * @throws InterruptedException If failed. - */ - public static void main(String[] args) throws InterruptedException { - final LongAdder cnt = new LongAdder(); - - final ConcurrentLinkedDeque<GridFutureAdapter<Object>> futs = new ConcurrentLinkedDeque<>(); - - ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); - - Thread statThread = new Thread() { - @SuppressWarnings("BusyWait") - @Override public void run() { - while (!done) { - try { - Thread.sleep(5000); - } - catch (InterruptedException ignored) { - return; - } - - System.out.println(new Date() + " Notifications per sec: " + (cnt.sumThenReset() / 5)); - } - } - }; - - statThread.setDaemon(true); - - statThread.start(); - - for (int i = 0; i < Runtime.getRuntime().availableProcessors() ; i++) { - pool.submit(new Callable<Object>() { - @Override public Object call() throws Exception { - Random rnd = new Random(); - - while (!done) { - for (int j = 0; j < rnd.nextInt(10); j++) { - GridFutureAdapter<Object> fut = new GridFutureAdapter<>(); - - futs.add(fut); - - for (int k = 1; k < rnd.nextInt(3); k++) { - fut.listen(new IgniteInClosure<IgniteInternalFuture<Object>>() { - @Override public void apply(IgniteInternalFuture<Object> t) { - try { - t.get(); - } - catch (IgniteCheckedException e) { - e.printStackTrace(); - } - - cnt.increment(); - } - }); - } - } - - GridFutureAdapter<Object> fut; - - while ((fut = futs.poll()) != null) - fut.onDone(); - } - - return null; - } - }); - } - - Thread.sleep(5 * 60 * 1000); - - done = true; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveAbstractTest.java new file mode 100644 index 0000000..3907e85 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveAbstractTest.java @@ -0,0 +1,149 @@ +/* + * 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.util.tostring; + +import javax.cache.processor.MutableEntry; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.cache.CacheEntryProcessor; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.SensitiveInfoTestLoggerProxy; +import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest; + +/** + * Tests for property {@link IgniteSystemProperties#IGNITE_TO_STRING_INCLUDE_SENSITIVE}. + */ +public abstract class IncludeSensitiveAbstractTest extends GridCacheAbstractSelfTest { + /** Number of test entries */ + private static final int ENTRY_CNT = 10; + + /** + * @param i Index. + * @return Marked key by index. + */ + private static Long key(int i) { + return SensitiveInfoTestLoggerProxy.SENSITIVE_KEY_MARKER + i; + } + + /** + * @param i Index. + * @return Marked value by index. + */ + private static String value(int i) { + return SensitiveInfoTestLoggerProxy.SENSITIVE_VAL_MARKER + i; + } + + /** {@inheritDoc} */ + @Override protected int gridCount() { + return 3; + } + + /** {@inheritDoc} */ + @Override protected CacheConfiguration cacheConfiguration(IgniteConfiguration cfg, String cacheName) { + CacheConfiguration ccfg = super.cacheConfiguration(cfg, cacheName); + + ccfg.setBackups(1); + + return ccfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + System.setProperty(IgniteSystemProperties.IGNITE_TO_STRING_INCLUDE_SENSITIVE, "false"); + + SensitiveInfoTestLoggerProxy.enableSensitiveMarkerAssertions(true); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + System.clearProperty(IgniteSystemProperties.IGNITE_TO_STRING_INCLUDE_SENSITIVE); + + SensitiveInfoTestLoggerProxy.enableSensitiveMarkerAssertions(false); + + super.afterTestsStopped(); + } + + /** Start transaction. */ + protected void startTx() { + // No-op. + } + + /** Commit transaction. */ + protected void commitTx() { + // No-op. + } + + /** + * Tests basic cache operations. + * + * @throws Exception If failed. + */ + public void test() throws Exception { + IgniteCache<Long, String> cache = grid(0).cache(DEFAULT_CACHE_NAME); + + startTx(); + + for (int i = 1; i < ENTRY_CNT; ++i) + cache.put(key(i), value(i)); + + commitTx(); + + cache.get(key(ENTRY_CNT / 2)); + + for (int i = 1; i < ENTRY_CNT; ++i) + cache.invoke(key(i), new TestEntryProcessor()); + + stopGrid(1); + + cache.rebalance().get(); + + for (int i = 0; i < ENTRY_CNT; ++i) + cache.get(key(i)); + + startGrid(1); + + cache.rebalance().get(); + + startTx(); + + for (int i = 1; i < ENTRY_CNT; ++i) + cache.remove(key(i)); + + commitTx(); + } + + /** + * + */ + static class TestEntryProcessor implements CacheEntryProcessor<Long, String, Object> { + /** {@inheritDoc} */ + @Override public Object process(MutableEntry<Long, String> entry, Object... args) { + long key = entry.getKey(); + + if (key % 2 == 0) + entry.remove(); + else + entry.setValue(entry.getValue() + "-"); + + return null; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveAtomicTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveAtomicTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveAtomicTest.java index 145c923..c9a84fe 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveAtomicTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveAtomicTest.java @@ -21,7 +21,7 @@ import org.apache.ignite.cache.CacheAtomicityMode; /** * */ -public class IncludeSensitiveAtomicTest extends IncludeSensitiveTest { +public class IncludeSensitiveAtomicTest extends IncludeSensitiveAbstractTest { /** {@inheritDoc} */ @Override protected CacheAtomicityMode atomicityMode() { return CacheAtomicityMode.ATOMIC; http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveTest.java deleted file mode 100644 index 7328350..0000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveTest.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * 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.util.tostring; - -import javax.cache.processor.MutableEntry; -import org.apache.ignite.IgniteCache; -import org.apache.ignite.IgniteSystemProperties; -import org.apache.ignite.cache.CacheEntryProcessor; -import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.internal.SensitiveInfoTestLoggerProxy; -import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest; - -/** - * Tests for property {@link IgniteSystemProperties#IGNITE_TO_STRING_INCLUDE_SENSITIVE}. - */ -public abstract class IncludeSensitiveTest extends GridCacheAbstractSelfTest { - /** Number of test entries */ - private static final int ENTRY_CNT = 10; - - /** - * @param i Index. - * @return Marked key by index. - */ - private static Long key(int i) { - return SensitiveInfoTestLoggerProxy.SENSITIVE_KEY_MARKER + i; - } - - /** - * @param i Index. - * @return Marked value by index. - */ - private static String value(int i) { - return SensitiveInfoTestLoggerProxy.SENSITIVE_VAL_MARKER + i; - } - - /** {@inheritDoc} */ - @Override protected int gridCount() { - return 3; - } - - /** {@inheritDoc} */ - @Override protected CacheConfiguration cacheConfiguration(IgniteConfiguration cfg, String cacheName) { - CacheConfiguration ccfg = super.cacheConfiguration(cfg, cacheName); - - ccfg.setBackups(1); - - return ccfg; - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - super.beforeTestsStarted(); - - System.setProperty(IgniteSystemProperties.IGNITE_TO_STRING_INCLUDE_SENSITIVE, "false"); - - SensitiveInfoTestLoggerProxy.enableSensitiveMarkerAssertions(true); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - System.clearProperty(IgniteSystemProperties.IGNITE_TO_STRING_INCLUDE_SENSITIVE); - - SensitiveInfoTestLoggerProxy.enableSensitiveMarkerAssertions(false); - - super.afterTestsStopped(); - } - - /** Start transaction. */ - protected void startTx() { - // No-op. - } - - /** Commit transaction. */ - protected void commitTx() { - // No-op. - } - - /** - * Tests basic cache operations. - * - * @throws Exception If failed. - */ - public void test() throws Exception { - IgniteCache<Long, String> cache = grid(0).cache(DEFAULT_CACHE_NAME); - - startTx(); - - for (int i = 1; i < ENTRY_CNT; ++i) - cache.put(key(i), value(i)); - - commitTx(); - - cache.get(key(ENTRY_CNT / 2)); - - for (int i = 1; i < ENTRY_CNT; ++i) - cache.invoke(key(i), new TestEntryProcessor()); - - stopGrid(1); - - cache.rebalance().get(); - - for (int i = 0; i < ENTRY_CNT; ++i) - cache.get(key(i)); - - startGrid(1); - - cache.rebalance().get(); - - startTx(); - - for (int i = 1; i < ENTRY_CNT; ++i) - cache.remove(key(i)); - - commitTx(); - } - - /** - * - */ - static class TestEntryProcessor implements CacheEntryProcessor<Long, String, Object> { - /** {@inheritDoc} */ - @Override public Object process(MutableEntry<Long, String> entry, Object... args) { - long key = entry.getKey(); - - if (key % 2 == 0) - entry.remove(); - else - entry.setValue(entry.getValue() + "-"); - - return null; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveTransactionalTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveTransactionalTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveTransactionalTest.java index 0327171..2918768 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveTransactionalTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/IncludeSensitiveTransactionalTest.java @@ -22,7 +22,7 @@ import org.apache.ignite.transactions.Transaction; /** * */ -public class IncludeSensitiveTransactionalTest extends IncludeSensitiveTest { +public class IncludeSensitiveTransactionalTest extends IncludeSensitiveAbstractTest { /** Active transaction. */ private Transaction tx; http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/lang/GridMetadataAwareAdapterLoadSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/lang/GridMetadataAwareAdapterLoadSelfTest.java b/modules/core/src/test/java/org/apache/ignite/lang/GridMetadataAwareAdapterLoadSelfTest.java deleted file mode 100644 index 0105242..0000000 --- a/modules/core/src/test/java/org/apache/ignite/lang/GridMetadataAwareAdapterLoadSelfTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * 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.lang; - -import java.util.UUID; -import org.apache.ignite.internal.IgniteInterruptedCheckedException; -import org.apache.ignite.internal.processors.cache.eviction.GridCacheMockEntry; -import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; - -/** - * Check how much memory and time required to fill 1_000_000 entries with meta. - * Do not include this test to suits. - */ -public class GridMetadataAwareAdapterLoadSelfTest extends GridCommonAbstractTest { - /** Creates test. */ - public GridMetadataAwareAdapterLoadSelfTest() { - super(/*start grid*/false); - } - - private static final String KEY_VALUE = "test"; - - /** - * Junit. - * - * @throws Exception - */ - public void test() throws Exception { - String[] dic = new String[1_000_000]; - - for (int i = 0; i < 1_000_000; i++) - dic[i] = String.valueOf(i); - - doTest(-1, "all 10 keys ", dic); - doTest(0, "all 3 keys ", dic); - doTest(1, "first key only ", dic); - doTest(2, "second key only ", dic); - doTest(3, "third key only ", dic); - doTest(4, "tenth key only ", dic); - doTest(5, "random (1-3) key", dic); - doTest(6, "no meta ", dic); - } - - public void doTest(int c, String message, String[] dic) throws IgniteInterruptedCheckedException { - UUID[] uuids = new UUID[10]; - - for (int j = 0; j < 10; j++) - uuids[j] = UUID.randomUUID(); - - for (int t = 0; t < 2; t++) { - long mTotal = 0; - long tTotal = 0; - - for (int k = 0; k < 20; k++) { - System.gc(); - - U.sleep(500); - - GridCacheMockEntry[] entries = new GridCacheMockEntry[1_000_000]; - - long mBefore = Runtime.getRuntime().freeMemory(); - long tBefore = System.currentTimeMillis(); - - for (int i = 0; i < 1_000_000; i++) { - GridCacheMockEntry<String, String> entry = new GridCacheMockEntry<>(KEY_VALUE); - switch (c) {//commented lines for old API - case -1: - for (int j = 9; j >= 0; j--) - //entry.addMeta(uuids[j], dic[i]); - entry.addMeta(j, dic[i]); - break; - case 0: - for (int j = 2; j >= 0; j--) - //entry.addMeta(uuids[j], dic[i]); - entry.addMeta(j, dic[i]); - break; - case 1: - //entry.addMeta(uuids[0], dic[i]); - entry.addMeta(0, dic[i]); - break; - case 2: - //entry.addMeta(uuids[1], dic[i]); - entry.addMeta(1, dic[i]); - break; - case 3: - //entry.addMeta(uuids[2], dic[i]); - entry.addMeta(2, dic[i]); - break; - case 4: - //entry.addMeta(uuids[9], dic[i]); - entry.addMeta(9, dic[i]); - break; - case 5: - //entry.addMeta(uuids[i % 3], dic[i]); - entry.addMeta(i % 3, dic[i]); - break; - case 6: - - break; - } - - entries[i] = entry; - } - - long mAfter = Runtime.getRuntime().freeMemory(); - long tAfter = System.currentTimeMillis(); - - if (k >= 10) { - mTotal += (mBefore - mAfter); - tTotal += (tAfter - tBefore); - } - } - - log.info(message + " [time=" + tTotal + " ms, memory=" + mTotal / 1_000_000_0 + "." + mTotal % 1_000_000_0 + " mb]"); - } - - log.info(" "); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/lang/GridMetadataAwareAdapterLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/lang/GridMetadataAwareAdapterLoadTest.java b/modules/core/src/test/java/org/apache/ignite/lang/GridMetadataAwareAdapterLoadTest.java new file mode 100644 index 0000000..f411f31 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/lang/GridMetadataAwareAdapterLoadTest.java @@ -0,0 +1,134 @@ +/* + * 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.lang; + +import java.util.UUID; +import org.apache.ignite.internal.IgniteInterruptedCheckedException; +import org.apache.ignite.internal.processors.cache.eviction.GridCacheMockEntry; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +/** + * Check how much memory and time required to fill 1_000_000 entries with meta. + * Do not include this test to suits. + */ +public class GridMetadataAwareAdapterLoadTest extends GridCommonAbstractTest { + /** Creates test. */ + public GridMetadataAwareAdapterLoadTest() { + super(/*start grid*/false); + } + + private static final String KEY_VALUE = "test"; + + /** + * Junit. + * + * @throws Exception + */ + public void test() throws Exception { + String[] dic = new String[1_000_000]; + + for (int i = 0; i < 1_000_000; i++) + dic[i] = String.valueOf(i); + + doTest(-1, "all 10 keys ", dic); + doTest(0, "all 3 keys ", dic); + doTest(1, "first key only ", dic); + doTest(2, "second key only ", dic); + doTest(3, "third key only ", dic); + doTest(4, "tenth key only ", dic); + doTest(5, "random (1-3) key", dic); + doTest(6, "no meta ", dic); + } + + public void doTest(int c, String message, String[] dic) throws IgniteInterruptedCheckedException { + UUID[] uuids = new UUID[10]; + + for (int j = 0; j < 10; j++) + uuids[j] = UUID.randomUUID(); + + for (int t = 0; t < 2; t++) { + long mTotal = 0; + long tTotal = 0; + + for (int k = 0; k < 20; k++) { + System.gc(); + + U.sleep(500); + + GridCacheMockEntry[] entries = new GridCacheMockEntry[1_000_000]; + + long mBefore = Runtime.getRuntime().freeMemory(); + long tBefore = System.currentTimeMillis(); + + for (int i = 0; i < 1_000_000; i++) { + GridCacheMockEntry<String, String> entry = new GridCacheMockEntry<>(KEY_VALUE); + switch (c) {//commented lines for old API + case -1: + for (int j = 9; j >= 0; j--) + //entry.addMeta(uuids[j], dic[i]); + entry.addMeta(j, dic[i]); + break; + case 0: + for (int j = 2; j >= 0; j--) + //entry.addMeta(uuids[j], dic[i]); + entry.addMeta(j, dic[i]); + break; + case 1: + //entry.addMeta(uuids[0], dic[i]); + entry.addMeta(0, dic[i]); + break; + case 2: + //entry.addMeta(uuids[1], dic[i]); + entry.addMeta(1, dic[i]); + break; + case 3: + //entry.addMeta(uuids[2], dic[i]); + entry.addMeta(2, dic[i]); + break; + case 4: + //entry.addMeta(uuids[9], dic[i]); + entry.addMeta(9, dic[i]); + break; + case 5: + //entry.addMeta(uuids[i % 3], dic[i]); + entry.addMeta(i % 3, dic[i]); + break; + case 6: + + break; + } + + entries[i] = entry; + } + + long mAfter = Runtime.getRuntime().freeMemory(); + long tAfter = System.currentTimeMillis(); + + if (k >= 10) { + mTotal += (mBefore - mAfter); + tTotal += (tAfter - tBefore); + } + } + + log.info(message + " [time=" + tTotal + " ms, memory=" + mTotal / 1_000_000_0 + "." + mTotal % 1_000_000_0 + " mb]"); + } + + log.info(" "); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/loadtest/GridLoadTestStatistics.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/loadtest/GridLoadTestStatistics.java b/modules/core/src/test/java/org/apache/ignite/loadtest/GridLoadTestStatistics.java deleted file mode 100644 index 5d517a4..0000000 --- a/modules/core/src/test/java/org/apache/ignite/loadtest/GridLoadTestStatistics.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * 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.loadtest; - -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicInteger; -import org.apache.ignite.compute.ComputeTaskFuture; -import org.apache.ignite.internal.util.typedef.F; -import org.jetbrains.annotations.Nullable; - -/** - * Load test statistics. - */ -public class GridLoadTestStatistics { - /** */ - private long taskCnt; - - /** */ - private long jobCnt; - - /** */ - private float avgTaskTime; - - /** */ - private float avgJobTime; - - /** */ - private float minTaskTime = Float.MAX_VALUE; - - /** */ - private float minJobTime = Float.MAX_VALUE; - - /** */ - private float maxTaskTime; - - /** */ - private float maxJobTime; - - /** */ - private long totalTime; - - /** */ - private final Map<UUID, AtomicInteger> nodeCnts = new LinkedHashMap<UUID, AtomicInteger>() { - /** {@inheritDoc} */ - @Override protected boolean removeEldestEntry(Map.Entry<UUID, AtomicInteger> eldest) { - return size() > 20; - } - }; - - /** */ - private final StringBuilder buf = new StringBuilder(); - - /** - * @param fut Task future. - * @param jobNum Job count. - * @param taskTime Task execution time. - * @return Task count. - */ - @SuppressWarnings("unchecked") - public synchronized long onTaskCompleted(@Nullable ComputeTaskFuture<?> fut, int jobNum, long taskTime) { - taskCnt++; - - jobCnt += jobNum; - - totalTime += taskTime; - - avgTaskTime = Math.round(1000.0f * totalTime / taskCnt) / 1000.0f; - avgJobTime = Math.round(1000.0f * totalTime / jobCnt) / 1000.0f; - - if (taskTime > maxTaskTime) - maxTaskTime = taskTime; - - if (taskTime < minTaskTime) - minTaskTime = taskTime; - - float jobTime = Math.round(1000.0f * taskTime / jobNum) / 1000.0f; - - if (jobTime > maxJobTime) - maxJobTime = jobTime; - - if (jobTime < minJobTime) - minJobTime = jobTime; - - if (fut != null) { - Iterable<UUID> nodeIds = (Iterable<UUID>)fut.getTaskSession().getAttribute("nodes"); - - if (nodeIds != null) { - for (UUID id : nodeIds) { - AtomicInteger cnt; - - synchronized (nodeCnts) { - cnt = F.addIfAbsent(nodeCnts, id, F.newAtomicInt()); - } - - assert cnt != null; - - cnt.incrementAndGet(); - } - } - } - - return taskCnt; - } - - /** - * @return Task count. - */ - public synchronized long getTaskCount() { - return taskCnt; - } - - /** - * @return Job count. - */ - public synchronized long getJobCount() { - return jobCnt; - } - - /** - * @return Average task time. - */ - public synchronized float getAverageTaskTime() { - return avgTaskTime; - } - - /** - * @return Average job time. - */ - public synchronized float getAverageJobTime() { - return avgJobTime; - } - - /** - * @return Minimum task time. - */ - public synchronized float getMinTaskTime() { - return minTaskTime; - } - - /** - * @return Minimum job time. - */ - public synchronized float getMinJobTime() { - return minJobTime; - } - - /** - * @return Maximum task time. - */ - public synchronized float getMaxTaskTime() { - return maxTaskTime; - } - - /** - * - * @return Maximum job time. - */ - public synchronized float getMaxJobTime() { - return maxJobTime; - } - - /** - * @return Test start time. - */ - public synchronized long getTotalTime() { - return totalTime; - } - - /** {@inheritDoc} */ - @Override public synchronized String toString() { - Map<UUID, AtomicInteger> nodeCnts; - - synchronized (this.nodeCnts) { - nodeCnts = new HashMap<>(this.nodeCnts); - } - - buf.setLength(0); - - buf.append(getClass().getSimpleName()); - buf.append(" [taskCnt=").append(taskCnt); - buf.append(", jobCnt=").append(jobCnt); - buf.append(", avgTaskTime=").append(avgTaskTime); - buf.append(", avgJobTime=").append(avgJobTime); - buf.append(", maxTaskTime=").append(maxTaskTime); - buf.append(", maxJobTime=").append(maxJobTime); - buf.append(", minTaskTime=").append(minTaskTime); - buf.append(", minJobTime=").append(minJobTime); - buf.append(", totalTime=").append(totalTime); - buf.append(", nodeCnts=").append(nodeCnts); - buf.append(']'); - - return buf.toString(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/loadtest/GridSingleExecutionTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/loadtest/GridSingleExecutionTest.java b/modules/core/src/test/java/org/apache/ignite/loadtest/GridSingleExecutionTest.java deleted file mode 100644 index 59eb1ef..0000000 --- a/modules/core/src/test/java/org/apache/ignite/loadtest/GridSingleExecutionTest.java +++ /dev/null @@ -1,341 +0,0 @@ -/* - * 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.loadtest; - -import java.io.File; -import java.io.IOException; -import java.io.Serializable; -import java.net.MalformedURLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import org.apache.ignite.Ignite; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.IgniteLogger; -import org.apache.ignite.IgniteSystemProperties; -import org.apache.ignite.compute.ComputeJob; -import org.apache.ignite.compute.ComputeJobAdapter; -import org.apache.ignite.compute.ComputeJobResult; -import org.apache.ignite.compute.ComputeJobResultPolicy; -import org.apache.ignite.compute.ComputeTaskFuture; -import org.apache.ignite.compute.ComputeTaskSession; -import org.apache.ignite.compute.ComputeTaskSplitAdapter; -import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.internal.util.typedef.G; -import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.resources.LoggerResource; -import org.apache.ignite.resources.TaskSessionResource; -import org.apache.ignite.testframework.GridTestUtils; -import org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger; -import org.apache.log4j.Appender; -import org.apache.log4j.ConsoleAppender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -import org.apache.log4j.RollingFileAppender; -import org.apache.log4j.varia.LevelRangeFilter; -import org.apache.log4j.varia.NullAppender; -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.FileSystemXmlApplicationContext; - -/** - * Single execution test. - */ -public final class GridSingleExecutionTest { - /** */ - public static final int JOB_COUNT = 50; - - /** - * Private constructor because class has only static - * methods and was considered as utility one by StyleChecker. - */ - private GridSingleExecutionTest() { - // No-op. - } - - /** - * @param args Command line arguments. - * @throws Exception If failed. - */ - @SuppressWarnings({"CallToSystemExit"}) - public static void main(String[] args) throws Exception { - System.setProperty(IgniteSystemProperties.IGNITE_UPDATE_NOTIFIER, "false"); - - System.out.println("Starting master node [params=" + Arrays.toString(args) + ']'); - - if (args.length < 2) { - System.out.println("Log file name must be provided as first argument."); - - System.exit(1); - } - else if (args.length >= 2) { - for (IgniteConfiguration cfg: getConfigurations(args[1], args[0])) - G.start(cfg); - } - - boolean useSes = false; - - if (args.length == 3) { - if ("-session".equals(args[2].trim())) - useSes = true; - } - - try { - Ignite ignite = G.ignite(); - - // Execute Hello World task. - ComputeTaskFuture<Object> fut = ignite.compute().executeAsync(!useSes ? TestTask.class : TestSessionTask.class, null); - - if (useSes) { - fut.getTaskSession().setAttribute("attr1", 1); - fut.getTaskSession().setAttribute("attr2", 2); - } - - // Wait for task completion. - fut.get(); - - System.out.println("Task executed."); - } - finally { - G.stop(true); - - System.out.println("Master node stopped."); - } - } - - /** - * Initializes logger. - * - * @param log Log file name. - * @return Logger. - * @throws IgniteCheckedException If file initialization failed. - */ - private static IgniteLogger initLogger(String log) throws IgniteCheckedException { - - Logger impl = Logger.getRootLogger(); - - impl.removeAllAppenders(); - - String fileName = U.getIgniteHome() + "/work/log/" + log; - - // Configure output that should go to System.out - RollingFileAppender fileApp; - - String fmt = "[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"; - - try { - fileApp = new RollingFileAppender(new PatternLayout(fmt), fileName); - - fileApp.setMaxBackupIndex(0); - - fileApp.rollOver(); - } - catch (IOException e) { - throw new IgniteCheckedException("Unable to initialize file appender.", e); - } - - LevelRangeFilter lvlFilter = new LevelRangeFilter(); - - lvlFilter.setLevelMin(Level.DEBUG); - - fileApp.addFilter(lvlFilter); - - impl.addAppender(fileApp); - - // Configure output that should go to System.out - ConsoleAppender conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT); - - lvlFilter = new LevelRangeFilter(); - - lvlFilter.setLevelMin(Level.INFO); - lvlFilter.setLevelMax(Level.INFO); - - conApp.addFilter(lvlFilter); - - impl.addAppender(conApp); - - // Configure output that should go to System.err - conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_ERR); - - conApp.setThreshold(Level.WARN); - - impl.addAppender(conApp); - - impl.setLevel(Level.INFO); - - Logger.getLogger("org.apache.ignite").setLevel(Level.DEBUG); - - return new GridTestLog4jLogger(false); - } - - /** - * Initializes configurations. - * - * @param springCfgPath Configuration file path. - * @param log Log file name. - * @return List of configurations. - * @throws IgniteCheckedException If failed.. - */ - @SuppressWarnings("unchecked") - private static Iterable<IgniteConfiguration> getConfigurations(String springCfgPath, String log) throws IgniteCheckedException { - File path = GridTestUtils.resolveIgnitePath(springCfgPath); - - if (path == null) { - throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + - ". Note that this path should be either absolute path or a relative path to IGNITE_HOME."); - } - - if (!path.isFile()) - throw new IgniteCheckedException("Provided file path is not a file: " + path); - - // Add no-op logger to remove no-appender warning. - Appender app = new NullAppender(); - - Logger.getRootLogger().addAppender(app); - - ApplicationContext springCtx; - - try { - springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString()); - } - catch (BeansException | MalformedURLException e) { - throw new IgniteCheckedException("Failed to instantiate Spring XML application context: " + e.getMessage(), e); - } - - Map cfgMap; - - try { - // Note: Spring is not generics-friendly. - cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class); - } - catch (BeansException e) { - throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + - e.getMessage() + ']', e); - } - - if (cfgMap == null) - throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path); - - // Remove previously added no-op logger. - Logger.getRootLogger().removeAppender(app); - - if (cfgMap.isEmpty()) - throw new IgniteCheckedException("Can't find grid factory configuration in: " + path); - - Collection<IgniteConfiguration> res = new ArrayList<>(); - - for (IgniteConfiguration cfg : (Collection<IgniteConfiguration>)cfgMap.values()) { - UUID nodeId = UUID.randomUUID(); - - cfg.setNodeId(nodeId); - - cfg.setGridLogger(initLogger(log)); - - res.add(cfg); - } - - return res; - } - - /** */ - public static class TestTask extends ComputeTaskSplitAdapter<Object, Object> { - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) { - Collection<ComputeJob> jobs = new ArrayList<>(JOB_COUNT); - - for (int i = 0; i < JOB_COUNT; i++) { - jobs.add(new ComputeJobAdapter(i) { - @LoggerResource - private IgniteLogger log; - - @Override public Serializable execute() { - if (log.isInfoEnabled()) - log.info("Executing job [index=" + argument(0) + ']'); - - return argument(0); - } - }); - } - - return jobs; - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) { - assert results != null : "Unexpected result [results=" + results + ']'; - assert results.size() == JOB_COUNT : "Unexpected result [results=" + results + ']'; - - return null; - } - } - - /** */ - public static class TestSessionTask extends ComputeTaskSplitAdapter<Object, Object> { - /** */ - @TaskSessionResource - private ComputeTaskSession ses; - - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) { - Collection<ComputeJob> jobs = new ArrayList<>(JOB_COUNT); - - for (int i = 0; i < JOB_COUNT; i++) { - jobs.add(new ComputeJobAdapter(i) { - @LoggerResource - private IgniteLogger log; - - @Override public Serializable execute() { - if (log.isInfoEnabled()) - log.info("Executing job [index=" + argument(0) + ']'); - - ses.setAttribute("attr3", 3); - ses.setAttribute("attr4", 4); - - return argument(0); - } - }); - } - - ses.setAttribute("attr5", 5); - ses.setAttribute("attr6", 6); - - return jobs; - } - - /** {@inheritDoc} */ - @Override public ComputeJobResultPolicy result(ComputeJobResult res, - List<ComputeJobResult> received) { - ses.setAttribute("attr7", 7); - ses.setAttribute("attr8", 8); - - return super.result(res, received); - } - - /** {@inheritDoc} */ - @Override public Object reduce(List<ComputeJobResult> results) { - assert results != null : "Unexpected result [results=" + results + ']'; - assert results.size() == JOB_COUNT : "Unexpected result [results=" + results + ']'; - - return null; - } - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/loadtest/package-info.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/loadtest/package-info.java b/modules/core/src/test/java/org/apache/ignite/loadtest/package-info.java deleted file mode 100644 index 4f294b2..0000000 --- a/modules/core/src/test/java/org/apache/ignite/loadtest/package-info.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * 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 description. --> - * Contains internal tests or test related classes and interfaces. - */ -package org.apache.ignite.loadtest; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/loadtests/GridLoadTestStatistics.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/GridLoadTestStatistics.java b/modules/core/src/test/java/org/apache/ignite/loadtests/GridLoadTestStatistics.java new file mode 100644 index 0000000..e2494a6 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/GridLoadTestStatistics.java @@ -0,0 +1,212 @@ +/* + * 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.loadtests; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ignite.compute.ComputeTaskFuture; +import org.apache.ignite.internal.util.typedef.F; +import org.jetbrains.annotations.Nullable; + +/** + * Load test statistics. + */ +public class GridLoadTestStatistics { + /** */ + private long taskCnt; + + /** */ + private long jobCnt; + + /** */ + private float avgTaskTime; + + /** */ + private float avgJobTime; + + /** */ + private float minTaskTime = Float.MAX_VALUE; + + /** */ + private float minJobTime = Float.MAX_VALUE; + + /** */ + private float maxTaskTime; + + /** */ + private float maxJobTime; + + /** */ + private long totalTime; + + /** */ + private final Map<UUID, AtomicInteger> nodeCnts = new LinkedHashMap<UUID, AtomicInteger>() { + /** {@inheritDoc} */ + @Override protected boolean removeEldestEntry(Map.Entry<UUID, AtomicInteger> eldest) { + return size() > 20; + } + }; + + /** */ + private final StringBuilder buf = new StringBuilder(); + + /** + * @param fut Task future. + * @param jobNum Job count. + * @param taskTime Task execution time. + * @return Task count. + */ + @SuppressWarnings("unchecked") + public synchronized long onTaskCompleted(@Nullable ComputeTaskFuture<?> fut, int jobNum, long taskTime) { + taskCnt++; + + jobCnt += jobNum; + + totalTime += taskTime; + + avgTaskTime = Math.round(1000.0f * totalTime / taskCnt) / 1000.0f; + avgJobTime = Math.round(1000.0f * totalTime / jobCnt) / 1000.0f; + + if (taskTime > maxTaskTime) + maxTaskTime = taskTime; + + if (taskTime < minTaskTime) + minTaskTime = taskTime; + + float jobTime = Math.round(1000.0f * taskTime / jobNum) / 1000.0f; + + if (jobTime > maxJobTime) + maxJobTime = jobTime; + + if (jobTime < minJobTime) + minJobTime = jobTime; + + if (fut != null) { + Iterable<UUID> nodeIds = (Iterable<UUID>)fut.getTaskSession().getAttribute("nodes"); + + if (nodeIds != null) { + for (UUID id : nodeIds) { + AtomicInteger cnt; + + synchronized (nodeCnts) { + cnt = F.addIfAbsent(nodeCnts, id, F.newAtomicInt()); + } + + assert cnt != null; + + cnt.incrementAndGet(); + } + } + } + + return taskCnt; + } + + /** + * @return Task count. + */ + public synchronized long getTaskCount() { + return taskCnt; + } + + /** + * @return Job count. + */ + public synchronized long getJobCount() { + return jobCnt; + } + + /** + * @return Average task time. + */ + public synchronized float getAverageTaskTime() { + return avgTaskTime; + } + + /** + * @return Average job time. + */ + public synchronized float getAverageJobTime() { + return avgJobTime; + } + + /** + * @return Minimum task time. + */ + public synchronized float getMinTaskTime() { + return minTaskTime; + } + + /** + * @return Minimum job time. + */ + public synchronized float getMinJobTime() { + return minJobTime; + } + + /** + * @return Maximum task time. + */ + public synchronized float getMaxTaskTime() { + return maxTaskTime; + } + + /** + * + * @return Maximum job time. + */ + public synchronized float getMaxJobTime() { + return maxJobTime; + } + + /** + * @return Test start time. + */ + public synchronized long getTotalTime() { + return totalTime; + } + + /** {@inheritDoc} */ + @Override public synchronized String toString() { + Map<UUID, AtomicInteger> nodeCnts; + + synchronized (this.nodeCnts) { + nodeCnts = new HashMap<>(this.nodeCnts); + } + + buf.setLength(0); + + buf.append(getClass().getSimpleName()); + buf.append(" [taskCnt=").append(taskCnt); + buf.append(", jobCnt=").append(jobCnt); + buf.append(", avgTaskTime=").append(avgTaskTime); + buf.append(", avgJobTime=").append(avgJobTime); + buf.append(", maxTaskTime=").append(maxTaskTime); + buf.append(", maxJobTime=").append(maxJobTime); + buf.append(", minTaskTime=").append(minTaskTime); + buf.append(", minJobTime=").append(minJobTime); + buf.append(", totalTime=").append(totalTime); + buf.append(", nodeCnts=").append(nodeCnts); + buf.append(']'); + + return buf.toString(); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/loadtests/GridSingleExecutionTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/GridSingleExecutionTest.java b/modules/core/src/test/java/org/apache/ignite/loadtests/GridSingleExecutionTest.java new file mode 100644 index 0000000..1c8ce2b --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/GridSingleExecutionTest.java @@ -0,0 +1,341 @@ +/* + * 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.loadtests; + +import java.io.File; +import java.io.IOException; +import java.io.Serializable; +import java.net.MalformedURLException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.IgniteLogger; +import org.apache.ignite.IgniteSystemProperties; +import org.apache.ignite.compute.ComputeJob; +import org.apache.ignite.compute.ComputeJobAdapter; +import org.apache.ignite.compute.ComputeJobResult; +import org.apache.ignite.compute.ComputeJobResultPolicy; +import org.apache.ignite.compute.ComputeTaskFuture; +import org.apache.ignite.compute.ComputeTaskSession; +import org.apache.ignite.compute.ComputeTaskSplitAdapter; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.util.typedef.G; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.resources.LoggerResource; +import org.apache.ignite.resources.TaskSessionResource; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger; +import org.apache.log4j.Appender; +import org.apache.log4j.ConsoleAppender; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.log4j.PatternLayout; +import org.apache.log4j.RollingFileAppender; +import org.apache.log4j.varia.LevelRangeFilter; +import org.apache.log4j.varia.NullAppender; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.FileSystemXmlApplicationContext; + +/** + * Single execution test. + */ +public final class GridSingleExecutionTest { + /** */ + public static final int JOB_COUNT = 50; + + /** + * Private constructor because class has only static + * methods and was considered as utility one by StyleChecker. + */ + private GridSingleExecutionTest() { + // No-op. + } + + /** + * @param args Command line arguments. + * @throws Exception If failed. + */ + @SuppressWarnings({"CallToSystemExit"}) + public static void main(String[] args) throws Exception { + System.setProperty(IgniteSystemProperties.IGNITE_UPDATE_NOTIFIER, "false"); + + System.out.println("Starting master node [params=" + Arrays.toString(args) + ']'); + + if (args.length < 2) { + System.out.println("Log file name must be provided as first argument."); + + System.exit(1); + } + else if (args.length >= 2) { + for (IgniteConfiguration cfg: getConfigurations(args[1], args[0])) + G.start(cfg); + } + + boolean useSes = false; + + if (args.length == 3) { + if ("-session".equals(args[2].trim())) + useSes = true; + } + + try { + Ignite ignite = G.ignite(); + + // Execute Hello World task. + ComputeTaskFuture<Object> fut = ignite.compute().executeAsync(!useSes ? TestTask.class : TestSessionTask.class, null); + + if (useSes) { + fut.getTaskSession().setAttribute("attr1", 1); + fut.getTaskSession().setAttribute("attr2", 2); + } + + // Wait for task completion. + fut.get(); + + System.out.println("Task executed."); + } + finally { + G.stop(true); + + System.out.println("Master node stopped."); + } + } + + /** + * Initializes logger. + * + * @param log Log file name. + * @return Logger. + * @throws IgniteCheckedException If file initialization failed. + */ + private static IgniteLogger initLogger(String log) throws IgniteCheckedException { + + Logger impl = Logger.getRootLogger(); + + impl.removeAllAppenders(); + + String fileName = U.getIgniteHome() + "/work/log/" + log; + + // Configure output that should go to System.out + RollingFileAppender fileApp; + + String fmt = "[%d{ISO8601}][%-5p][%t][%c{1}] %m%n"; + + try { + fileApp = new RollingFileAppender(new PatternLayout(fmt), fileName); + + fileApp.setMaxBackupIndex(0); + + fileApp.rollOver(); + } + catch (IOException e) { + throw new IgniteCheckedException("Unable to initialize file appender.", e); + } + + LevelRangeFilter lvlFilter = new LevelRangeFilter(); + + lvlFilter.setLevelMin(Level.DEBUG); + + fileApp.addFilter(lvlFilter); + + impl.addAppender(fileApp); + + // Configure output that should go to System.out + ConsoleAppender conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_OUT); + + lvlFilter = new LevelRangeFilter(); + + lvlFilter.setLevelMin(Level.INFO); + lvlFilter.setLevelMax(Level.INFO); + + conApp.addFilter(lvlFilter); + + impl.addAppender(conApp); + + // Configure output that should go to System.err + conApp = new ConsoleAppender(new PatternLayout(fmt), ConsoleAppender.SYSTEM_ERR); + + conApp.setThreshold(Level.WARN); + + impl.addAppender(conApp); + + impl.setLevel(Level.INFO); + + Logger.getLogger("org.apache.ignite").setLevel(Level.DEBUG); + + return new GridTestLog4jLogger(false); + } + + /** + * Initializes configurations. + * + * @param springCfgPath Configuration file path. + * @param log Log file name. + * @return List of configurations. + * @throws IgniteCheckedException If failed.. + */ + @SuppressWarnings("unchecked") + private static Iterable<IgniteConfiguration> getConfigurations(String springCfgPath, String log) throws IgniteCheckedException { + File path = GridTestUtils.resolveIgnitePath(springCfgPath); + + if (path == null) { + throw new IgniteCheckedException("Spring XML configuration file path is invalid: " + new File(springCfgPath) + + ". Note that this path should be either absolute path or a relative path to IGNITE_HOME."); + } + + if (!path.isFile()) + throw new IgniteCheckedException("Provided file path is not a file: " + path); + + // Add no-op logger to remove no-appender warning. + Appender app = new NullAppender(); + + Logger.getRootLogger().addAppender(app); + + ApplicationContext springCtx; + + try { + springCtx = new FileSystemXmlApplicationContext(path.toURI().toURL().toString()); + } + catch (BeansException | MalformedURLException e) { + throw new IgniteCheckedException("Failed to instantiate Spring XML application context: " + e.getMessage(), e); + } + + Map cfgMap; + + try { + // Note: Spring is not generics-friendly. + cfgMap = springCtx.getBeansOfType(IgniteConfiguration.class); + } + catch (BeansException e) { + throw new IgniteCheckedException("Failed to instantiate bean [type=" + IgniteConfiguration.class + ", err=" + + e.getMessage() + ']', e); + } + + if (cfgMap == null) + throw new IgniteCheckedException("Failed to find a single grid factory configuration in: " + path); + + // Remove previously added no-op logger. + Logger.getRootLogger().removeAppender(app); + + if (cfgMap.isEmpty()) + throw new IgniteCheckedException("Can't find grid factory configuration in: " + path); + + Collection<IgniteConfiguration> res = new ArrayList<>(); + + for (IgniteConfiguration cfg : (Collection<IgniteConfiguration>)cfgMap.values()) { + UUID nodeId = UUID.randomUUID(); + + cfg.setNodeId(nodeId); + + cfg.setGridLogger(initLogger(log)); + + res.add(cfg); + } + + return res; + } + + /** */ + public static class TestTask extends ComputeTaskSplitAdapter<Object, Object> { + /** {@inheritDoc} */ + @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) { + Collection<ComputeJob> jobs = new ArrayList<>(JOB_COUNT); + + for (int i = 0; i < JOB_COUNT; i++) { + jobs.add(new ComputeJobAdapter(i) { + @LoggerResource + private IgniteLogger log; + + @Override public Serializable execute() { + if (log.isInfoEnabled()) + log.info("Executing job [index=" + argument(0) + ']'); + + return argument(0); + } + }); + } + + return jobs; + } + + /** {@inheritDoc} */ + @Override public Object reduce(List<ComputeJobResult> results) { + assert results != null : "Unexpected result [results=" + results + ']'; + assert results.size() == JOB_COUNT : "Unexpected result [results=" + results + ']'; + + return null; + } + } + + /** */ + public static class TestSessionTask extends ComputeTaskSplitAdapter<Object, Object> { + /** */ + @TaskSessionResource + private ComputeTaskSession ses; + + /** {@inheritDoc} */ + @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) { + Collection<ComputeJob> jobs = new ArrayList<>(JOB_COUNT); + + for (int i = 0; i < JOB_COUNT; i++) { + jobs.add(new ComputeJobAdapter(i) { + @LoggerResource + private IgniteLogger log; + + @Override public Serializable execute() { + if (log.isInfoEnabled()) + log.info("Executing job [index=" + argument(0) + ']'); + + ses.setAttribute("attr3", 3); + ses.setAttribute("attr4", 4); + + return argument(0); + } + }); + } + + ses.setAttribute("attr5", 5); + ses.setAttribute("attr6", 6); + + return jobs; + } + + /** {@inheritDoc} */ + @Override public ComputeJobResultPolicy result(ComputeJobResult res, + List<ComputeJobResult> received) { + ses.setAttribute("attr7", 7); + ses.setAttribute("attr8", 8); + + return super.result(res, received); + } + + /** {@inheritDoc} */ + @Override public Object reduce(List<ComputeJobResult> results) { + assert results != null : "Unexpected result [results=" + results + ']'; + assert results.size() == JOB_COUNT : "Unexpected result [results=" + results + ']'; + + return null; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/loadtests/direct/multisplit/GridMultiSplitsLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/direct/multisplit/GridMultiSplitsLoadTest.java b/modules/core/src/test/java/org/apache/ignite/loadtests/direct/multisplit/GridMultiSplitsLoadTest.java index c764f67..2d1aaa4 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/direct/multisplit/GridMultiSplitsLoadTest.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/direct/multisplit/GridMultiSplitsLoadTest.java @@ -22,7 +22,7 @@ import org.apache.ignite.IgniteException; import org.apache.ignite.compute.ComputeTaskFuture; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.util.typedef.G; -import org.apache.ignite.loadtest.GridLoadTestStatistics; +import org.apache.ignite.loadtests.GridLoadTestStatistics; import org.apache.ignite.spi.communication.CommunicationSpi; import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi; import org.apache.ignite.spi.discovery.DiscoverySpi; @@ -151,4 +151,4 @@ public class GridMultiSplitsLoadTest extends GridCommonAbstractTest { return num * factorial(num -1); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/loadtests/direct/multisplit/GridMultiSplitsRedeployLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/direct/multisplit/GridMultiSplitsRedeployLoadTest.java b/modules/core/src/test/java/org/apache/ignite/loadtests/direct/multisplit/GridMultiSplitsRedeployLoadTest.java index 4f4124f..0cb0895 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/direct/multisplit/GridMultiSplitsRedeployLoadTest.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/direct/multisplit/GridMultiSplitsRedeployLoadTest.java @@ -22,7 +22,7 @@ import org.apache.ignite.IgniteException; import org.apache.ignite.compute.ComputeTaskFuture; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.util.typedef.G; -import org.apache.ignite.loadtest.GridLoadTestStatistics; +import org.apache.ignite.loadtests.GridLoadTestStatistics; import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.config.GridTestProperties; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; @@ -156,4 +156,4 @@ public class GridMultiSplitsRedeployLoadTest extends GridCommonAbstractTest { return num == 1 ? 1 : num * factorial(num - 1); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/loadtests/direct/newnodes/GridSingleSplitsNewNodesAbstractLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/direct/newnodes/GridSingleSplitsNewNodesAbstractLoadTest.java b/modules/core/src/test/java/org/apache/ignite/loadtests/direct/newnodes/GridSingleSplitsNewNodesAbstractLoadTest.java index fedb4ac..aac3c30 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/direct/newnodes/GridSingleSplitsNewNodesAbstractLoadTest.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/direct/newnodes/GridSingleSplitsNewNodesAbstractLoadTest.java @@ -22,7 +22,7 @@ import org.apache.ignite.Ignite; import org.apache.ignite.compute.ComputeTaskFuture; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.util.typedef.G; -import org.apache.ignite.loadtest.GridLoadTestStatistics; +import org.apache.ignite.loadtests.GridLoadTestStatistics; import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi; import org.apache.ignite.spi.discovery.DiscoverySpi; import org.apache.ignite.testframework.GridTestUtils; http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/loadtests/direct/redeploy/GridSingleSplitsRedeployLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/direct/redeploy/GridSingleSplitsRedeployLoadTest.java b/modules/core/src/test/java/org/apache/ignite/loadtests/direct/redeploy/GridSingleSplitsRedeployLoadTest.java index 210e78e..057a1c8 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/direct/redeploy/GridSingleSplitsRedeployLoadTest.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/direct/redeploy/GridSingleSplitsRedeployLoadTest.java @@ -24,7 +24,7 @@ import org.apache.ignite.compute.ComputeTaskFuture; import org.apache.ignite.configuration.DeploymentMode; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.util.typedef.G; -import org.apache.ignite.loadtest.GridLoadTestStatistics; +import org.apache.ignite.loadtests.GridLoadTestStatistics; import org.apache.ignite.spi.communication.CommunicationSpi; import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi; import org.apache.ignite.spi.discovery.DiscoverySpi; @@ -171,4 +171,4 @@ public class GridSingleSplitsRedeployLoadTest extends GridCommonAbstractTest { private Class<? extends ComputeTask<?, ?>> loadTaskClass() throws Exception { return (Class<? extends ComputeTask<?, ?>>)getExternalClassLoader().loadClass(TASK_NAME); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/loadtests/direct/session/GridSessionLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/direct/session/GridSessionLoadTest.java b/modules/core/src/test/java/org/apache/ignite/loadtests/direct/session/GridSessionLoadTest.java index 14c9794..d46158b 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/direct/session/GridSessionLoadTest.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/direct/session/GridSessionLoadTest.java @@ -21,7 +21,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.apache.ignite.Ignite; import org.apache.ignite.compute.ComputeTaskFuture; import org.apache.ignite.internal.util.typedef.G; -import org.apache.ignite.loadtest.GridLoadTestStatistics; +import org.apache.ignite.loadtests.GridLoadTestStatistics; import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.config.GridTestProperties; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; @@ -109,4 +109,4 @@ public class GridSessionLoadTest extends GridCommonAbstractTest { if (failed.get()) fail(); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/loadtests/direct/stealing/GridStealingLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/direct/stealing/GridStealingLoadTest.java b/modules/core/src/test/java/org/apache/ignite/loadtests/direct/stealing/GridStealingLoadTest.java index 79ed3ed..ace423a 100644 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/direct/stealing/GridStealingLoadTest.java +++ b/modules/core/src/test/java/org/apache/ignite/loadtests/direct/stealing/GridStealingLoadTest.java @@ -23,7 +23,7 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.ignite.Ignite; import org.apache.ignite.compute.ComputeTaskFuture; import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.loadtest.GridLoadTestStatistics; +import org.apache.ignite.loadtests.GridLoadTestStatistics; import org.apache.ignite.spi.collision.jobstealing.JobStealingCollisionSpi; import org.apache.ignite.spi.discovery.DiscoverySpi; import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; @@ -147,4 +147,4 @@ public class GridStealingLoadTest extends GridCommonAbstractTest { info("Stolen jobs: " + stolen.get()); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/ignite/blob/de9227d7/modules/core/src/test/java/org/apache/ignite/loadtests/offheap/GridOffHeapMapPerformanceAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/loadtests/offheap/GridOffHeapMapPerformanceAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/loadtests/offheap/GridOffHeapMapPerformanceAbstractTest.java deleted file mode 100644 index 4064482..0000000 --- a/modules/core/src/test/java/org/apache/ignite/loadtests/offheap/GridOffHeapMapPerformanceAbstractTest.java +++ /dev/null @@ -1,294 +0,0 @@ -/* - * 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.loadtests.offheap; - -import java.util.HashMap; -import java.util.Map; -import java.util.Random; -import org.apache.ignite.internal.util.offheap.GridOffHeapEvictListener; -import org.apache.ignite.internal.util.offheap.GridOffHeapMap; -import org.apache.ignite.internal.util.offheap.GridOffHeapOutOfMemoryException; -import org.apache.ignite.internal.util.typedef.T3; -import org.apache.ignite.internal.util.typedef.X; -import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; - -/** - * Tests off-heap map. - */ -public abstract class GridOffHeapMapPerformanceAbstractTest extends GridCommonAbstractTest { - /** Random. */ - private static final Random RAND = new Random(); - - /** */ - protected static final int LOAD_CNT = 1024 * 1024; - - /** Sample map. */ - private static Map<String, T3<String, byte[], byte[]>> kvMap = - new HashMap<>(LOAD_CNT); - - /** Unsafe map. */ - private GridOffHeapMap map; - - /** */ - protected float load = 0.75f; - - /** */ - protected int initCap = 1024 * 1024 * 1024; - - /** */ - protected int concurrency = 16; - - /** */ - protected short lruStripes = 16; - - /** */ - protected GridOffHeapEvictListener evictClo; - - /** */ - protected long mem = 12L * 1024L * 1024L * 1024L; - - /** */ - protected long dur = 60 * 1000;//2 * 60 * 60 * 1000; - - /** - * - */ - protected GridOffHeapMapPerformanceAbstractTest() { - super(false); - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - map = newMap(); - - if (kvMap.isEmpty()) - for (int i = 0; i < LOAD_CNT; i++) { - String k = string(); - String v = string(); - - kvMap.put(k, new T3<>(v, k.getBytes(), v.getBytes())); - } - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - if (map != null) - map.destruct(); - } - - /** - * @return New map. - */ - protected abstract GridOffHeapMap newMap(); - - /** - * @param key Key. - * @return Hash. - */ - private int hash(Object key) { - return hash(key.hashCode()); - } - - /** - * @param h Hashcode. - * @return Hash. - */ - private int hash(int h) { - // Apply base step of MurmurHash; see http://code.google.com/p/smhasher/ - // Despite two multiplies, this is often faster than others - // with comparable bit-spread properties. - h ^= h >>> 16; - h *= 0x85ebca6b; - h ^= h >>> 13; - h *= 0xc2b2ae35; - - return (h >>> 16) ^ h; - } - - /** - * - * @return New Object. - */ - private String string() { - String key = ""; - - for (int i = 0; i < 3; i++) - key += RAND.nextLong(); - - return key; - } - - /** - * Test plain hash map. - */ - public void testHashMapPutRemove() { - Map<String, String> map = new HashMap<>(LOAD_CNT); - - info("Starting standard HashMap performance test..."); - - long cnt = 0; - - long start = System.currentTimeMillis(); - - boolean rmv = false; - - boolean done = false; - - while (!done) { - for (Map.Entry<String, T3<String, byte[], byte[]>> e : kvMap.entrySet()) { - String key = e.getKey(); - T3<String, byte[], byte[]> t = e.getValue(); - - try { - if (rmv) - map.remove(key); - else - map.put(key, t.get1()); - } - catch (GridOffHeapOutOfMemoryException ex) { - error("Map put failed for count: " + cnt, ex); - - throw ex; - } - - if (cnt > 0 && cnt % 10000000 == 0) { - long cur = System.currentTimeMillis(); - - long throughput = cnt * 1000 / (cur - start); - - X.println("Insert [cnt=" + cnt + ", ops/sec=" + throughput + ']'); - - if ((cur - start) > dur) { - done = true; - - break; - } - } - - cnt++; - } - - rmv = !rmv; - } - } - - /** - * - */ - public void testInsertRemoveLoad() { - info("Starting insert performance test..."); - - long cnt = 0; - - long start = System.currentTimeMillis(); - - boolean rmv = false; - - boolean done = false; - - while (!done) { - for (Map.Entry<String, T3<String, byte[], byte[]>> e : kvMap.entrySet()) { - String key = e.getKey(); - T3<String, byte[], byte[]> t = e.getValue(); - - try { - if (rmv) - map.remove(hash(key), t.get2()); - else - map.insert(hash(key), t.get2(), t.get3()); - } - catch (GridOffHeapOutOfMemoryException ex) { - error("Map put failed for count: " + cnt, ex); - - throw ex; - } - - if (cnt > 0 && cnt % 10000000 == 0) { - long cur = System.currentTimeMillis(); - - long throughput = cnt * 1000 / (cur - start); - - X.println("Insert [cnt=" + cnt + ", ops/sec=" + throughput + ']'); - - if ((cur - start) > dur) { - done = true; - - break; - } - } - - cnt++; - } - - rmv = !rmv; - } - } - - - /** - * - */ - public void testPutRemoveLoad() { - info("Starting put performance test..."); - - long cnt = 0; - - long start = System.currentTimeMillis(); - - boolean rmv = false; - - boolean done = false; - - while (!done) { - for (Map.Entry<String, T3<String, byte[], byte[]>> e : kvMap.entrySet()) { - String key = e.getKey(); - T3<String, byte[], byte[]> t = e.getValue(); - - try { - if (rmv) - map.remove(hash(key), t.get2()); - else - map.put(hash(key), t.get2(), t.get3()); - } - catch (GridOffHeapOutOfMemoryException ex) { - error("Map put failed for count: " + cnt, ex); - - throw ex; - } - - if (cnt > 0 && cnt % 10000000 == 0) { - long cur = System.currentTimeMillis(); - - long throughput = cnt * 1000 / (cur - start); - - X.println("Put [cnt=" + cnt + ", ops/sec=" + throughput + ']'); - - if ((cur - start) > dur) { - done = true; - - break; - } - } - - cnt++; - } - - rmv = cnt % 3 == 0; - } - } -} \ No newline at end of file
