@Override public Void call() throws Exception { Ignite ignite = ignite(idx % GRID_CNT); try { for (int k = 0; k < 50; k++) { barrier.await(); String cacheName = "cache-" + k; IgniteCache<Integer, Integer> cache = getCache(ignite, cacheName); for (int i = 0; i < 100; i++) { while (true) { try { cache.getAndPut(i, i); break; } catch (Exception e) { MvccFeatureChecker.assertMvccWriteConflict(e); } } } barrier.await(); ignite.destroyCache(cacheName); } } catch (Exception e) { err.set(idx, e); } return null; } });
@Override public void run() { try { ThreadLocalRandom locRandom = ThreadLocalRandom.current(); cyclicBarrier.await(); while (!interrupt.get()) { long randomKey = locRandom.nextLong(MAX_KEY_COUNT); TestEntity entity = TestEntity.newTestEntity(locRandom); while (true) { try (Transaction tx = g.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) { cache.put(randomKey, entity); tx.commit(); break; } catch (Exception e) { MvccFeatureChecker.assertMvccWriteConflict(e); } } operationCnt.increment(); } } catch (Throwable e) { log.error("Unexpected exception:", e); throw new RuntimeException(e); } } });
@Override public void apply(Integer idx) { try { b.await(); Ignite node = startGrid(idx + SRVS); if (createCache) { for (int c = 0; c < 5; c++) { for (IgniteCache cache : node.getOrCreateCaches(cacheConfigurations())) { boolean updated = false; while (!updated) { try { cache.put(c, c); updated = true; } catch (Exception e) { assertMvccWriteConflict(e); } } assertEquals(c, cache.get(c)); } } } } catch (Exception e) { throw new IgniteException(e); } } }, CLIENTS, "start-client");
/** * Put random values to cache in multiple threads until time interval given expires. * * @param cache Cache to modify. * @param threadCnt Number ot threads to be used. * @param duration Time interval in milliseconds. * @throws Exception When something goes wrong. */ private void doLoad(IgniteCache<Integer, Integer> cache, int threadCnt, long duration) throws Exception { GridTestUtils.runMultiThreaded(() -> { long stopTs = U.currentTimeMillis() + duration; int keysCnt = getKeysCount(); ThreadLocalRandom rnd = ThreadLocalRandom.current(); do { try { cache.put(rnd.nextInt(keysCnt), rnd.nextInt()); } catch (Exception ex) { MvccFeatureChecker.assertMvccWriteConflict(ex); } } while (U.currentTimeMillis() < stopTs); }, threadCnt, "load-cache"); }
@Override public Object call() throws Exception { final Random rnd = new Random(); for (int i = 0; i < ITERATION_CNT; i++) { int j = rnd.nextInt(keyCnt); while (true) { try (Transaction tx = ignite.transactions().txStart()) { // Put or remove? if (rnd.nextBoolean()) cache.put(j, j); else cache.remove(j); tx.commit(); break; } catch (Exception e) { MvccFeatureChecker.assertMvccWriteConflict(e); } } if (i != 0 && i % 5000 == 0) info("Stats [iterCnt=" + i + ", size=" + cache.size() + ']'); } return null; } },