@Override public Void call() throws Exception { Random rnd = new GridRandom(); Random age = new GridRandom(); while (!stop.get()) cache.put(rnd.nextInt(2000), new Person(age.nextInt(3000) - 1000)); return null; } }, 20);
@Override public Void call() throws Exception { Random rnd = new GridRandom(); while (!stop.get()) { List<List<?>> res = cache.query( new SqlFieldsQuery("select avg(age) from Person where age > 0")).getAll(); assertEquals(1, res.size()); if (res.get(0).get(0) == null) continue; int avgAge = ((Number)res.get(0).get(0)).intValue(); if (rnd.nextInt(300) == 0) X.println("__ " + avgAge); } return null; } }, 20);
Random rnd = new GridRandom();
/** */ @Test public void testRandom() { for (int i = 0; i < 100; i++) { long seed = ThreadLocalRandom.current().nextLong(); Random rnd1 = new Random(seed); Random rnd2 = new GridRandom(seed); for (int j = 1; j < 100000; j++) { assertEquals(rnd1.nextInt(), rnd2.nextInt()); assertEquals(rnd1.nextInt(j), rnd2.nextInt(j)); assertEquals(rnd1.nextLong(), rnd2.nextLong()); assertEquals(rnd1.nextBoolean(), rnd2.nextBoolean()); if (j % 1000 == 0) { seed = ThreadLocalRandom.current().nextLong(); rnd1.setSeed(seed); rnd2.setSeed(seed); } } } } }
@Override public Object call() throws Exception { Random rnd = new GridRandom(); for (;;) { int idx = 0; boolean found = false; for (int i = 0, shift = rnd.nextInt(keys); i < keys; i++) { idx = (i + shift) % keys; if (k.get(idx) == 0 && k.compareAndSet(idx, 0, 1)) { found = true; break; } } if (!found) break; assertNull(tree.put((long)idx)); assertNoLocks(); } return null; } }, threads, "put");
@Override public Object call() throws Exception { X.println("___ TH in"); Random rnd = new GridRandom(); IntWritable key = new IntWritable(); IntWritable val = new IntWritable(); HadoopMultimap.Adder a = m.startAdding(taskCtx); for (int i = 0; i < 50000; i++) { int k = rnd.nextInt(32000); int v = rnd.nextInt(); key.set(k); val.set(v); a.write(key, val); Collection<Integer> list = mm.get(k); if (list == null) { list = new ConcurrentLinkedQueue<>(); Collection<Integer> old = mm.putIfAbsent(k, list); if (old != null) list = old; } list.add(v); } a.close(); X.println("___ TH out"); return null; } }, 3 + rnd.nextInt(27));
@Override public Object call() throws Exception { X.println("___ TH in"); Random rnd = new GridRandom(); IntWritable key = new IntWritable(); IntWritable val = new IntWritable(); HadoopMultimap.Adder a = m.startAdding(taskCtx); for (int i = 0; i < 50000; i++) { int k = rnd.nextInt(32000); int v = rnd.nextInt(); key.set(k); val.set(v); a.write(key, val); Collection<Integer> list = mm.get(k); if (list == null) { list = new ConcurrentLinkedQueue<>(); Collection<Integer> old = mm.putIfAbsent(k, list); if (old != null) list = old; } list.add(v); } a.close(); X.println("___ TH out"); return null; } }, 3 + rnd.nextInt(27));
@SuppressWarnings({"BusyWait"}) @Override public Object call() throws Exception { try { GridRandom rnd = new GridRandom();
@SuppressWarnings({"BusyWait"}) @Override public Object call() throws Exception { GridRandom rnd = new GridRandom(); while (!restartsDone.get()) { int g; do { g = rnd.nextInt(locks.length()); } while (!locks.compareAndSet(g, 0, -1)); log.info("Stop node: " + g); stopGrid(g); Thread.sleep(rnd.nextInt(nodeLifeTime)); log.info("Start node: " + g); startGrid(g); Thread.sleep(rnd.nextInt(nodeLifeTime)); locks.set(g, 0); int c = restartCnt.incrementAndGet(); if (c % logFreq == 0) info("Node restarts: " + c); } return true; } }, restartThreadsNum, "restart-thread");
/** * Correct affinity. */ @Test public void testColocatedQueryRight() { IgniteCache<AffinityUuid,Purchase> c = ignite(0).cache(DEFAULT_CACHE_NAME); Random rnd = new GridRandom(SEED); for (int i = 0; i < PURCHASES; i++) { Purchase p = new Purchase(); p.productId = rnd.nextInt(PRODUCTS); p.price = rnd.nextInt(MAX_PRICE); c.put(new AffinityUuid(p.productId), p); // Correct affinity. } List<List<?>> res1 = query(c, false); List<List<?>> res2 = query(c, true); X.println("res1: " + res1); X.println("res2: " + res2); assertFalse(res1.isEmpty()); assertEquals(res1.toString(), res2.toString()); // TODO fix type conversion issue }
/** * Correct affinity. */ @Test public void testColocatedQueryWrong() { IgniteCache<AffinityUuid,Purchase> c = ignite(0).cache(DEFAULT_CACHE_NAME); Random rnd = new GridRandom(SEED); for (int i = 0; i < PURCHASES; i++) { Purchase p = new Purchase(); p.productId = rnd.nextInt(PRODUCTS); p.price = rnd.nextInt(MAX_PRICE); c.put(new AffinityUuid(rnd.nextInt(PRODUCTS)), p); // Random affinity. } List<List<?>> res1 = query(c, false); List<List<?>> res2 = query(c, true); X.println("res1: " + res1); X.println("res2: " + res2); assertFalse(res1.isEmpty()); assertFalse(res1.equals(res2)); }
Random rnd = new GridRandom();
Random rnd = new GridRandom();
Random rnd = new GridRandom();
Random rnd = new GridRandom();
GridRandom rnd = new GridRandom();
/** * */ private void fillCaches() { IgniteCache<Integer, Company> co = grid(0).cache("co"); for (int i = 0; i < COMPANY_CNT; i++) co.put(i, new Company(i)); IgniteCache<Integer, Product> pr = grid(0).cache("pr"); Random rnd = new GridRandom(); for (int i = 0; i < PRODUCT_CNT; i++) pr.put(i, new Product(i, rnd.nextInt(COMPANY_CNT))); IgniteCache<Integer, Person> pe = grid(0).cache("pe"); for (int i = 0; i < PERS_CNT; i++) pe.put(i, new Person(i)); IgniteCache<Integer, Purchase> pu = grid(0).cache("pu"); for (int i = 0; i < PURCHASE_CNT; i++) { int persId = rnd.nextInt(PERS_CNT); int prodId = rnd.nextInt(PRODUCT_CNT); pu.put(i, new Purchase(persId, prodId)); } }
/** * */ private void fillCaches() { IgniteCache<Integer, Company> co = grid(0).cache("co"); for (int i = 0; i < COMPANY_CNT; i++) co.put(i, new Company(i)); IgniteCache<Integer, Product> pr = grid(0).cache("pr"); Random rnd = new GridRandom(); for (int i = 0; i < PRODUCT_CNT; i++) pr.put(i, new Product(i, rnd.nextInt(COMPANY_CNT))); IgniteCache<Integer, Person> pe = grid(0).cache("pe"); for (int i = 0; i < PERS_CNT; i++) pe.put(i, new Person(i)); IgniteCache<AffinityKey<Integer>, Purchase> pu = grid(0).cache("pu"); for (int i = 0; i < PURCHASE_CNT; i++) { int persId = rnd.nextInt(PERS_CNT); int prodId = rnd.nextInt(PRODUCT_CNT); pu.put(new AffinityKey<>(i, persId), new Purchase(persId, prodId)); } }
/** * */ private void fillCaches() { IgniteCache<Integer, Company> co = grid(0).cache("co"); for (int i = 0; i < COMPANY_CNT; i++) co.put(i, new Company(i)); IgniteCache<Integer, Product> pr = grid(0).cache("pr"); Random rnd = new GridRandom(); for (int i = 0; i < PRODUCT_CNT; i++) pr.put(i, new Product(i, rnd.nextInt(COMPANY_CNT))); IgniteCache<Integer, Person> pe = grid(0).cache("pe"); for (int i = 0; i < PERS_CNT; i++) pe.put(i, new Person(i)); IgniteCache<AffinityKey<Integer>, Purchase> pu = grid(0).cache("pu"); for (int i = 0; i < PURCHASE_CNT; i++) { int persId = rnd.nextInt(PERS_CNT); int prodId = rnd.nextInt(PRODUCT_CNT); pu.put(new AffinityKey<>(i, persId), new Purchase(persId, prodId)); } }
Random rnd = new GridRandom();