Repository: ignite Updated Branches: refs/heads/ignite-1607 84a5b2349 -> 834096d2e
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/834096d2 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/834096d2 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/834096d2 Branch: refs/heads/ignite-1607 Commit: 834096d2ed2958729dfc3ed5086ab29f8dfe58fd Parents: 84a5b23 Author: sboikov <[email protected]> Authored: Wed Oct 28 10:01:25 2015 +0300 Committer: sboikov <[email protected]> Committed: Wed Oct 28 10:01:25 2015 +0300 ---------------------------------------------------------------------- .../IgniteAccountSerializableTxBenchmark.java | 43 ++++++++++-------- .../cache/IgniteAccountTxBenchmark.java | 47 +++++++++++--------- .../ignite/yardstick/cache/model/Account.java | 14 +++--- 3 files changed, 58 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/834096d2/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 index 8cd113f..32e7653 100644 --- 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 @@ -17,8 +17,9 @@ package org.apache.ignite.yardstick.cache; +import java.util.HashSet; import java.util.Map; -import org.apache.ignite.internal.util.typedef.F; +import java.util.Set; import org.apache.ignite.transactions.Transaction; import org.apache.ignite.transactions.TransactionOptimisticException; import org.apache.ignite.yardstick.cache.model.Account; @@ -30,36 +31,42 @@ import static org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE; * */ public class IgniteAccountSerializableTxBenchmark extends IgniteAccountTxAbstractBenchmark { + /** */ + private static final int ACCOUNT_NUMBER = 3; + /** {@inheritDoc} */ @Override public boolean test(Map<Object, Object> ctx) throws Exception { - int key1 = nextRandom(args.range()); - - int key2; + Set<Integer> accountIds = new HashSet<>(); - do { - key2 = nextRandom(args.range()); - } - while (key2 == key1); + while (accountIds.size() < ACCOUNT_NUMBER) + accountIds.add(nextRandom(args.range())); while (true) { try (Transaction tx = txs.txStart(OPTIMISTIC, SERIALIZABLE)) { - Map<Integer, Account> map = (Map)cache.getAll(F.asSet(key1, key2)); + Map<Integer, Account> accounts = (Map)cache.getAll(accountIds); - Account a1 = map.get(key1); + if (accounts.size() != ACCOUNT_NUMBER) + throw new Exception("Failed to find accounts: " + accountIds); - if (a1 == null) - throw new Exception("Failed to find account " + key1); + Integer fromId = accountIds.iterator().next(); - Account a2 = map.get(key2); + int fromBalance = accounts.get(fromId).balance(); - if (a2 == null) - throw new Exception("Failed to find account " + key2); + for (Integer id : accountIds) { + if (id.equals(fromId)) + continue; - if (a1.value() > 0) { - cache.put(key1, new Account(a1.value() - 1)); - cache.put(key2, new Account(a2.value() + 1)); + Account account = accounts.get(id); + + if (fromBalance > 0) { + fromBalance--; + + cache.put(id, new Account(account.balance() + 1)); + } } + cache.put(fromId, new Account(fromBalance)); + tx.commit(); } catch (TransactionOptimisticException e) { http://git-wip-us.apache.org/repos/asf/ignite/blob/834096d2/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 index 8228bd5..78e675e 100644 --- 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 @@ -18,6 +18,8 @@ package org.apache.ignite.yardstick.cache; import java.util.Map; +import java.util.Set; +import java.util.TreeSet; import org.apache.ignite.transactions.Transaction; import org.apache.ignite.yardstick.cache.model.Account; @@ -28,39 +30,42 @@ import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_REA * */ public class IgniteAccountTxBenchmark extends IgniteAccountTxAbstractBenchmark { + /** */ + private static final int ACCOUNT_NUMBER = 3; + /** {@inheritDoc} */ + @SuppressWarnings("unchecked") @Override public boolean test(Map<Object, Object> ctx) throws Exception { - int key1 = nextRandom(args.range()); + Set<Integer> accountIds = new TreeSet<>(); - int key2; + while (accountIds.size() < ACCOUNT_NUMBER) + accountIds.add(nextRandom(args.range())); - do { - key2 = nextRandom(args.range()); - } - while (key2 == key1); + try (Transaction tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) { + Map<Integer, Account> accounts = (Map)cache.getAll(accountIds); - if (key2 > key1) { - int tmp = key2; - key2 = key1; - key1 = tmp; - } + if (accounts.size() != ACCOUNT_NUMBER) + throw new Exception("Failed to find accounts: " + accountIds); - try (Transaction tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) { - Account a1 = (Account)cache.get(key1); + Integer fromId = accountIds.iterator().next(); + + int fromBalance = accounts.get(fromId).balance(); - if (a1 == null) - throw new Exception("Failed to find account " + key1); + for (Integer id : accountIds) { + if (id.equals(fromId)) + continue; - Account a2 = (Account)cache.get(key2); + Account account = accounts.get(id); - if (a2 == null) - throw new Exception("Failed to find account " + key2); + if (fromBalance > 0) { + fromBalance--; - if (a1.value() > 0) { - cache.put(key1, new Account(a1.value() - 1)); - cache.put(key2, new Account(a2.value() + 1)); + cache.put(id, new Account(account.balance() + 1)); + } } + cache.put(fromId, new Account(fromBalance)); + tx.commit(); } http://git-wip-us.apache.org/repos/asf/ignite/blob/834096d2/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 index c58c171..3d5d9f8 100644 --- 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 @@ -24,19 +24,19 @@ import java.io.Serializable; */ public class Account implements Serializable { /** */ - private final int val; + private final int balance; /** - * @param val Value. + * @param balance Balance. */ - public Account(int val) { - this.val = val; + public Account(int balance) { + this.balance = balance; } /** - * @return Value. + * @return Balance. */ - public int value() { - return val; + public int balance() { + return balance; } }
