Repository: ignite Updated Branches: refs/heads/ignite-1607 ca8d0364e -> 8fbca39bf
ignite-1607 WIP Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/8fbca39b Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/8fbca39b Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/8fbca39b Branch: refs/heads/ignite-1607 Commit: 8fbca39bf8df2f3c1071871b6f8d2978c23c20a3 Parents: ca8d036 Author: sboikov <[email protected]> Authored: Wed Oct 21 12:24:09 2015 +0300 Committer: sboikov <[email protected]> Committed: Wed Oct 21 12:35:04 2015 +0300 ---------------------------------------------------------------------- .../testsuites/IgniteCacheTestSuite4.java | 6 -- .../testsuites/IgniteCacheTestSuite5.java | 40 +++++++++++ .../IgniteAccountSerializableTxBenchmark.java | 74 ++++++++++++++++++++ .../cache/IgniteAccountTxAbstractBenchmark.java | 61 ++++++++++++++++ .../cache/IgniteAccountTxBenchmark.java | 69 ++++++++++++++++++ .../ignite/yardstick/cache/model/Account.java | 42 +++++++++++ 6 files changed, 286 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/8fbca39b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java index 149603e..b89bffd 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite4.java @@ -21,7 +21,6 @@ import junit.framework.TestSuite; import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListenerSelfTest; import org.apache.ignite.internal.processors.GridCacheTxLoadFromStoreOnLockSelfTest; import org.apache.ignite.internal.processors.cache.CacheClientStoreSelfTest; -import org.apache.ignite.internal.processors.cache.CacheNearReaderUpdateTest; import org.apache.ignite.internal.processors.cache.CacheOffheapMapEntrySelfTest; import org.apache.ignite.internal.processors.cache.CacheReadThroughAtomicRestartSelfTest; import org.apache.ignite.internal.processors.cache.CacheReadThroughLocalAtomicRestartSelfTest; @@ -30,7 +29,6 @@ import org.apache.ignite.internal.processors.cache.CacheReadThroughReplicatedAto import org.apache.ignite.internal.processors.cache.CacheReadThroughReplicatedRestartSelfTest; import org.apache.ignite.internal.processors.cache.CacheReadThroughRestartSelfTest; import org.apache.ignite.internal.processors.cache.CacheRemoveAllSelfTest; -import org.apache.ignite.internal.processors.cache.CacheSerializableTransactionsTest; import org.apache.ignite.internal.processors.cache.CacheStopAndDestroySelfTest; import org.apache.ignite.internal.processors.cache.CacheStoreUsageMultinodeDynamicStartAtomicTest; import org.apache.ignite.internal.processors.cache.CacheStoreUsageMultinodeDynamicStartTxTest; @@ -141,10 +139,6 @@ public class IgniteCacheTestSuite4 extends TestSuite { public static TestSuite suite() throws Exception { TestSuite suite = new TestSuite("IgniteCache Test Suite part 4"); - suite.addTestSuite(CacheSerializableTransactionsTest.class); - - suite.addTestSuite(CacheNearReaderUpdateTest.class); - // Multi node update. suite.addTestSuite(GridCacheMultinodeUpdateSelfTest.class); suite.addTestSuite(GridCacheMultinodeUpdateNearEnabledSelfTest.class); http://git-wip-us.apache.org/repos/asf/ignite/blob/8fbca39b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java new file mode 100644 index 0000000..0f86c4c --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java @@ -0,0 +1,40 @@ +/* + * 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.testsuites; + +import junit.framework.TestSuite; +import org.apache.ignite.internal.processors.cache.CacheNearReaderUpdateTest; +import org.apache.ignite.internal.processors.cache.CacheSerializableTransactionsTest; + +/** + * Test suite. + */ +public class IgniteCacheTestSuite5 extends TestSuite { + /** + * @return IgniteCache test suite. + * @throws Exception Thrown in case of the failure. + */ + public static TestSuite suite() throws Exception { + TestSuite suite = new TestSuite("IgniteCache Test Suite part 5"); + + suite.addTestSuite(CacheSerializableTransactionsTest.class); + suite.addTestSuite(CacheNearReaderUpdateTest.class); + + return suite; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/8fbca39b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteAccountSerializableTxBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteAccountSerializableTxBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteAccountSerializableTxBenchmark.java new file mode 100644 index 0000000..8cd113f --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteAccountSerializableTxBenchmark.java @@ -0,0 +1,74 @@ +/* + * 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.yardstick.cache; + +import java.util.Map; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.transactions.Transaction; +import org.apache.ignite.transactions.TransactionOptimisticException; +import org.apache.ignite.yardstick.cache.model.Account; + +import static org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE; + +/** + * + */ +public class IgniteAccountSerializableTxBenchmark extends IgniteAccountTxAbstractBenchmark { + /** {@inheritDoc} */ + @Override public boolean test(Map<Object, Object> ctx) throws Exception { + int key1 = nextRandom(args.range()); + + int key2; + + do { + key2 = nextRandom(args.range()); + } + while (key2 == key1); + + while (true) { + try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { + Map<Integer, Account> map = (Map)cache.getAll(F.asSet(key1, key2)); + + Account a1 = map.get(key1); + + if (a1 == null) + throw new Exception("Failed to find account " + key1); + + Account a2 = map.get(key2); + + if (a2 == null) + throw new Exception("Failed to find account " + key2); + + if (a1.value() > 0) { + cache.put(key1, new Account(a1.value() - 1)); + cache.put(key2, new Account(a2.value() + 1)); + } + + tx.commit(); + } + catch (TransactionOptimisticException e) { + continue; + } + + break; + } + + return true; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/8fbca39b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteAccountTxAbstractBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteAccountTxAbstractBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteAccountTxAbstractBenchmark.java new file mode 100644 index 0000000..0266a3c --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteAccountTxAbstractBenchmark.java @@ -0,0 +1,61 @@ +/* + * 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.yardstick.cache; + +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.IgniteTransactions; +import org.apache.ignite.yardstick.cache.model.Account; +import org.yardstickframework.BenchmarkConfiguration; + +import static org.yardstickframework.BenchmarkUtils.println; + +/** + * + */ +public abstract class IgniteAccountTxAbstractBenchmark extends IgniteCacheAbstractBenchmark { + /** */ + protected IgniteTransactions txs; + + /** {@inheritDoc} */ + @Override public void setUp(BenchmarkConfiguration cfg) throws Exception { + super.setUp(cfg); + + txs = ignite().transactions(); + + println(cfg, "Populating data..."); + + long start = System.nanoTime(); + + try (IgniteDataStreamer<Integer, Account> dataLdr = ignite().dataStreamer(cache.getName())) { + for (int i = 0; i < args.range() && !Thread.currentThread().isInterrupted(); i++) { + dataLdr.addData(i, new Account(100_000)); + + if (i % 100000 == 0) + println(cfg, "Populated accounts: " + i); + } + } + + println(cfg, "Finished populating data in " + ((System.nanoTime() - start) / 1_000_000) + " ms."); + } + + /** {@inheritDoc} */ + @Override protected IgniteCache<Integer, Object> cache() { + return ignite().cache("tx"); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/8fbca39b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteAccountTxBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteAccountTxBenchmark.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteAccountTxBenchmark.java new file mode 100644 index 0000000..8228bd5 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/IgniteAccountTxBenchmark.java @@ -0,0 +1,69 @@ +/* + * 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.yardstick.cache; + +import java.util.Map; +import org.apache.ignite.transactions.Transaction; +import org.apache.ignite.yardstick.cache.model.Account; + +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ; + +/** + * + */ +public class IgniteAccountTxBenchmark extends IgniteAccountTxAbstractBenchmark { + /** {@inheritDoc} */ + @Override public boolean test(Map<Object, Object> ctx) throws Exception { + int key1 = nextRandom(args.range()); + + int key2; + + do { + key2 = nextRandom(args.range()); + } + while (key2 == key1); + + if (key2 > key1) { + int tmp = key2; + key2 = key1; + key1 = tmp; + } + + try (Transaction tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) { + Account a1 = (Account)cache.get(key1); + + if (a1 == null) + throw new Exception("Failed to find account " + key1); + + Account a2 = (Account)cache.get(key2); + + if (a2 == null) + throw new Exception("Failed to find account " + key2); + + if (a1.value() > 0) { + cache.put(key1, new Account(a1.value() - 1)); + cache.put(key2, new Account(a2.value() + 1)); + } + + tx.commit(); + } + + return true; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/8fbca39b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/Account.java ---------------------------------------------------------------------- diff --git a/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/Account.java b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/Account.java new file mode 100644 index 0000000..c58c171 --- /dev/null +++ b/modules/yardstick/src/main/java/org/apache/ignite/yardstick/cache/model/Account.java @@ -0,0 +1,42 @@ +/* + * 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.yardstick.cache.model; + +import java.io.Serializable; + +/** + * + */ +public class Account implements Serializable { + /** */ + private final int val; + + /** + * @param val Value. + */ + public Account(int val) { + this.val = val; + } + + /** + * @return Value. + */ + public int value() { + return val; + } +}
