@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);
@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");
/** * @param seed Seed. */ public GridRandom(long seed) { setSeed(seed); }
@Override public void applyx() throws IgniteCheckedException { GridRandom rnd = new GridRandom(); g = rnd.nextInt(locks.length()); if (rnd.nextBoolean()) { IgniteCache<?, ?> cache = grid(g).cache("pu"); qry = new SqlFieldsQuery(QRY_0).setDistributedJoins(true); boolean smallPageSize = rnd.nextBoolean();
@Override public void applyx() throws IgniteCheckedException { GridRandom rnd = new GridRandom(); boolean smallPageSize = rnd.nextBoolean();
int[] pSet = createRange(range.get(0), 1 + rnd.nextInt(range.get(1) - 1));
/** * @param orig Originator. */ protected void doTestPartitionsQuery(Ignite orig) { IgniteCache<ClientKey, Client> cl = orig.cache("cl"); for (int regionId = 1; regionId <= PARTS_PER_REGION.length; regionId++) { log().info("Running test queries for region " + regionId); List<Integer> range = REGION_TO_PART_MAP.get(regionId); int[] parts = createRange(range.get(0), range.get(1)); int off = rnd.nextInt(parts.length); int p1 = parts[off], p2 = parts[(off + (1 + rnd.nextInt(parts.length-1))) % parts.length]; log().info("Parts: " + p1 + " " + p2); SqlQuery<ClientKey, Client> qry = new SqlQuery<>(Client.class, "1=1"); qry.setPartitions(p1, p2); try { List<Cache.Entry<ClientKey, Client>> clients = cl.query(qry).getAll(); // Query must produce only results from two partitions. for (Cache.Entry<ClientKey, Client> client : clients) { int p = orig.affinity("cl").partition(client.getKey()); assertTrue("Incorrect partition for key", p == p1 || p == p2); } if (regionId == UNMAPPED_REGION) fail(); } catch (CacheException ignored) { if (regionId != UNMAPPED_REGION) fail(); } } }
@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);
@SuppressWarnings({"BusyWait"}) @Override public Object call() throws Exception { try { GridRandom rnd = new GridRandom(); g = rnd.nextInt(locks.length()); Thread.sleep(rnd.nextInt(nodeLifeTime)); Thread.sleep(rnd.nextInt(nodeLifeTime));
/** * @param seed Seed. */ public GridRandom(long seed) { setSeed(seed); }
Random rnd = new GridRandom();
s.execute("create index on c.c(c)"); GridRandom rnd = new GridRandom(); Ignite ignite = ignite(0); a.put(i, insert(s, new A(rnd.nextInt(50), rnd.nextInt(100), rnd.nextInt(150)))); b.put(i, insert(s, new B(rnd.nextInt(100), rnd.nextInt(50), rnd.nextInt(150)))); c.put(i, insert(s, new C(rnd.nextInt(150), rnd.nextInt(100), rnd.nextInt(50))));
/** */ @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); } } } } }
GridRandom rnd = new GridRandom(); int r = rnd.nextInt(3);
@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");
GridRandom rnd = new GridRandom(); switch (rnd.nextInt(2)) { case 1: if (q.size() > 0) { cnt += rnd.nextInt(q.size() - 1); int cnt = rnd.nextInt(50); int x = rnd.nextInt();
@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));
/** * 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)); }