You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2015/08/26 05:06:32 UTC
[21/50] [abbrv] ignite git commit: Improved test to check data
consistency.
Improved test to check data consistency.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/4df0716d
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/4df0716d
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/4df0716d
Branch: refs/heads/ignite-843
Commit: 4df0716dec4265e8abaf7b67aefb5d798f2fe8b4
Parents: 4b818ae
Author: sboikov <sb...@gridgain.com>
Authored: Mon Aug 24 14:23:11 2015 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Mon Aug 24 14:23:11 2015 +0300
----------------------------------------------------------------------
.../near/IgniteCacheNearOnlyTxTest.java | 82 +++++++++++++-------
1 file changed, 54 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/4df0716d/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheNearOnlyTxTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheNearOnlyTxTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheNearOnlyTxTest.java
index 88e7f03..c79f742 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheNearOnlyTxTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheNearOnlyTxTest.java
@@ -26,6 +26,7 @@ import org.apache.ignite.testframework.*;
import org.apache.ignite.transactions.*;
import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
import static org.apache.ignite.cache.CacheAtomicityMode.*;
import static org.apache.ignite.transactions.TransactionConcurrency.*;
@@ -78,18 +79,31 @@ public class IgniteCacheNearOnlyTxTest extends IgniteCacheAbstractTest {
ignite1.createNearCache(null, new NearCacheConfiguration<>());
- GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
- @Override public Object call() throws Exception {
- IgniteCache cache = ignite1.cache(null);
+ final Integer key = 1;
- int key = 1;
+ final AtomicInteger idx = new AtomicInteger();
- for (int i = 0; i < 100; i++)
- cache.put(key, 1);
+ IgniteCache<Integer, Integer> cache0 = ignite(0).cache(null);
+ IgniteCache<Integer, Integer> cache1 = ignite1.cache(null);
- return null;
- }
- }, 5, "put-thread");
+ for (int i = 0; i < 5; i++) {
+ log.info("Iteration: " + i);
+
+ GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ int val = idx.getAndIncrement();
+
+ IgniteCache<Integer, Integer> cache = ignite1.cache(null);
+
+ for (int i = 0; i < 100; i++)
+ cache.put(key, val);
+
+ return null;
+ }
+ }, 5, "put-thread");
+
+ assertEquals(cache0.localPeek(key), cache1.localPeek(key));
+ }
}
/**
@@ -107,6 +121,7 @@ public class IgniteCacheNearOnlyTxTest extends IgniteCacheAbstractTest {
}
/**
+ * @param optimistic If {@code true} uses optimistic transaction.
* @throws Exception If failed.
*/
private void txMultithreaded(final boolean optimistic) throws Exception {
@@ -116,27 +131,40 @@ public class IgniteCacheNearOnlyTxTest extends IgniteCacheAbstractTest {
ignite1.createNearCache(null, new NearCacheConfiguration<>());
- GridTestUtils.runMultiThreaded(new Callable<Object>() {
- @Override public Object call() throws Exception {
- IgniteCache cache = ignite1.cache(null);
+ final AtomicInteger idx = new AtomicInteger();
- int key = 1;
+ final Integer key = 1;
- IgniteTransactions txs = ignite1.transactions();
+ IgniteCache<Integer, Integer> cache0 = ignite(0).cache(null);
+ IgniteCache<Integer, Integer> cache1 = ignite1.cache(null);
- for (int i = 0; i < 100; i++) {
- try (Transaction tx = txs.txStart(optimistic ? OPTIMISTIC : PESSIMISTIC, REPEATABLE_READ)) {
- cache.get(key);
+ for (int i = 0; i < 5; i++) {
+ log.info("Iteration: " + i);
- cache.put(key, 1);
+ GridTestUtils.runMultiThreaded(new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ IgniteCache<Integer, Integer> cache = ignite1.cache(null);
- tx.commit();
+ IgniteTransactions txs = ignite1.transactions();
+
+ int val = idx.getAndIncrement();
+
+ for (int i = 0; i < 100; i++) {
+ try (Transaction tx = txs.txStart(optimistic ? OPTIMISTIC : PESSIMISTIC, REPEATABLE_READ)) {
+ cache.get(key);
+
+ cache.put(key, val);
+
+ tx.commit();
+ }
}
+
+ return null;
}
+ }, 5, "put-thread");
- return null;
- }
- }, 5, "put-thread");
+ assertEquals(cache0.localPeek(key), cache1.localPeek(key));
+ }
}
/**
@@ -149,11 +177,11 @@ public class IgniteCacheNearOnlyTxTest extends IgniteCacheAbstractTest {
ignite1.createNearCache(null, new NearCacheConfiguration<>());
+ final Integer key = 1;
+
IgniteInternalFuture<?> fut1 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override public Object call() throws Exception {
- IgniteCache cache = ignite1.cache(null);
-
- int key = 1;
+ IgniteCache<Integer, Integer> cache = ignite1.cache(null);
for (int i = 0; i < 100; i++)
cache.put(key, 1);
@@ -164,9 +192,7 @@ public class IgniteCacheNearOnlyTxTest extends IgniteCacheAbstractTest {
IgniteInternalFuture<?> fut2 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override public Object call() throws Exception {
- IgniteCache cache = ignite1.cache(null);
-
- int key = 1;
+ IgniteCache<Integer, Integer> cache = ignite1.cache(null);
IgniteTransactions txs = ignite1.transactions();