use of org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate in project ignite by apache.
the class GridCacheColocatedDebugTest method checkPutsMultithreaded.
/**
* @param loc Local puts.
* @param remote Remote puts.
* @param maxIterCnt Number of iterations.
* @throws Exception If failed.
*/
public void checkPutsMultithreaded(boolean loc, boolean remote, final long maxIterCnt) throws Exception {
storeEnabled = false;
assert loc || remote;
startGridsMultiThreaded(3);
try {
final Ignite g0 = grid(0);
Ignite g1 = grid(1);
final Collection<Integer> keys = new ConcurrentLinkedQueue<>();
if (loc) {
Integer key = -1;
for (int i = 0; i < 20; i++) {
key = forPrimary(g0, key);
keys.add(key);
}
}
if (remote) {
Integer key = -1;
for (int i = 0; i < 20; i++) {
key = forPrimary(g1, key);
keys.add(key);
}
}
final AtomicLong iterCnt = new AtomicLong();
final int keysCnt = 10;
IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {
@Override
public void run() {
// Make thread-local copy to shuffle keys.
List<Integer> threadKeys = new ArrayList<>(keys);
long threadId = Thread.currentThread().getId();
long itNum;
while ((itNum = iterCnt.getAndIncrement()) < maxIterCnt) {
Collections.shuffle(threadKeys);
List<Integer> iterKeys = threadKeys.subList(0, keysCnt);
Collections.sort(iterKeys);
Map<Integer, String> vals = U.newLinkedHashMap(keysCnt);
for (Integer key : iterKeys) vals.put(key, String.valueOf(key) + threadId);
jcache(0).putAll(vals);
if (itNum > 0 && itNum % 5000 == 0)
info(">>> " + itNum + " iterations completed.");
}
}
}, THREAD_CNT);
fut.get();
Thread.sleep(1000);
// Check that all transactions are committed.
for (int i = 0; i < 3; i++) {
GridCacheAdapter<Object, Object> cache = ((IgniteKernal) grid(i)).internalCache(DEFAULT_CACHE_NAME);
for (Integer key : keys) {
GridCacheEntryEx entry = cache.peekEx(key);
if (entry != null) {
Collection<GridCacheMvccCandidate> locCands = entry.localCandidates();
Collection<GridCacheMvccCandidate> rmtCands = entry.remoteMvccSnapshot();
assert locCands == null || locCands.isEmpty() : "Local candidates is not empty [idx=" + i + ", entry=" + entry + ']';
assert rmtCands == null || rmtCands.isEmpty() : "Remote candidates is not empty [idx=" + i + ", entry=" + entry + ']';
}
}
}
} finally {
stopAllGrids();
}
}
Aggregations