use of org.apache.ignite.internal.util.GridRandom in project ignite by apache.
the class IgniteCacheQueryNodeRestartSelfTest2 method fillCaches.
/**
*
*/
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));
}
}
use of org.apache.ignite.internal.util.GridRandom in project ignite by apache.
the class GridRandomSelfTest method testRandom.
/**
*/
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);
}
}
}
}
use of org.apache.ignite.internal.util.GridRandom in project ignite by apache.
the class HadoopSkipListSelfTest method testMultiThreaded.
/**
* @throws Exception if failed.
*/
public void testMultiThreaded() throws Exception {
GridUnsafeMemory mem = new GridUnsafeMemory(0);
X.println("___ Started");
Random rnd = new GridRandom();
for (int i = 0; i < 20; i++) {
HadoopJobInfo job = new JobInfo();
final HadoopTaskContext taskCtx = new TaskContext();
final HadoopMultimap m = new HadoopSkipList(job, mem);
final ConcurrentMap<Integer, Collection<Integer>> mm = new ConcurrentHashMap<>();
X.println("___ MT");
multithreaded(new Callable<Object>() {
@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));
HadoopTaskInput in = m.input(taskCtx);
int prevKey = Integer.MIN_VALUE;
while (in.next()) {
IntWritable key = (IntWritable) in.key();
assertTrue(key.get() > prevKey);
prevKey = key.get();
Iterator<?> valsIter = in.values();
Collection<Integer> vals = mm.remove(key.get());
assertNotNull(vals);
while (valsIter.hasNext()) {
IntWritable val = (IntWritable) valsIter.next();
assertTrue(vals.remove(val.get()));
}
assertTrue(vals.isEmpty());
}
in.close();
m.close();
assertEquals(0, mem.allocatedSize());
}
}
use of org.apache.ignite.internal.util.GridRandom in project ignite by apache.
the class GridCacheQuerySimpleBenchmark method testPerformance.
/**
* @throws Exception If failed.
*/
public void testPerformance() throws Exception {
Random rnd = new GridRandom();
final IgniteCache<Long, Person> c = ignite.cache("offheap-cache");
X.println("___ PUT start");
final int cnt = 100_000;
final int maxSalary = cnt / 10;
for (long i = 0; i < cnt; i++) c.put(i, new Person(rnd.nextInt(maxSalary), "Vasya " + i));
X.println("___ PUT end");
final AtomicBoolean end = new AtomicBoolean();
final LongAdder8 puts = new LongAdder8();
IgniteInternalFuture<?> fut0 = multithreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Random rnd = new GridRandom();
while (!end.get()) {
long i = rnd.nextInt(cnt);
c.put(i, new Person(rnd.nextInt(maxSalary), "Vasya " + i));
puts.increment();
}
return null;
}
}, 10);
final LongAdder8 qrys = new LongAdder8();
IgniteInternalFuture<?> fut1 = multithreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Random rnd = new GridRandom();
while (!end.get()) {
int salary = rnd.nextInt(maxSalary);
c.query(new SqlFieldsQuery("select name from Person where salary = ?").setArgs(salary)).getAll();
qrys.increment();
}
return null;
}
}, 10);
int runTimeSec = 600;
for (int s = 0; s < runTimeSec; s++) {
Thread.sleep(1000);
long puts0 = puts.sum();
long qrys0 = qrys.sum();
puts.add(-puts0);
qrys.add(-qrys0);
X.println("___ puts: " + puts0 + " qrys: " + qrys0);
}
end.set(true);
fut0.get();
fut1.get();
X.println("___ STOP");
}
use of org.apache.ignite.internal.util.GridRandom in project ignite by apache.
the class IgniteCacheCollocatedQuerySelfTest method testColocatedQueryWrong.
/**
* Correct affinity.
*/
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);
// Random affinity.
c.put(new AffinityUuid(rnd.nextInt(PRODUCTS)), p);
}
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));
}
Aggregations