use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class IgniteReplaceIndexedValue1Benchmark method test.
/**
* {@inheritDoc}
*/
@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
IgniteCache<Integer, Object> cache = cacheForOperation();
cache.replace(rnd.nextInt(args.range()), new Person1(rnd.nextInt(args.range())));
return true;
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class IntMaxValueEntriesTest method test.
/**
* {@inheritDoc}
*/
@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
final IgniteCache<Integer, Object> cache = cache();
final IgniteDataStreamer<Integer, Object> stmr = ignite().dataStreamer(cache.getName());
final List<Thread> threads = new ArrayList<>(THREADS);
final LongAdder addedCnt = new LongAdder();
int delta = (int) ((KEYS_HI + Math.abs(KEYS_LO)) / THREADS);
System.out.println("Delta: " + delta);
for (int i = 0; i < THREADS; i++) {
final int lo = i == 0 ? KEYS_LO : delta * i + 1;
final int hi = i == THREADS - 1 ? (int) KEYS_HI : (int) ((long) delta * (i + 1));
Thread t = new Thread(new Runnable() {
@Override
public void run() {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
byte val = (byte) rnd.nextInt();
println("Start from " + lo + " to " + hi);
for (int j = lo, k = 0; j < hi; j++, k++) {
stmr.addData(j, val++);
addedCnt.increment();
if (k % REPORT_DELTA == 0)
println(addedCnt.sum() + " entries");
}
println("Thread finished. " + addedCnt.sum() + " entries.");
}
});
threads.add(t);
t.start();
}
for (Thread thread : threads) thread.join();
println("All threads finished. " + addedCnt.sum() + " entries.");
println("Streamer flush");
stmr.flush();
println("Streamer flushed");
println("Calculating cache size");
println("Cache size: " + cache.size());
println("Calculating long cache size");
println("Cache size long: " + cache.sizeLong());
Thread.sleep(10000);
println("Iterating started");
long cnt = 0;
for (Cache.Entry<Integer, Object> ignored : cache) {
cnt++;
if (cnt > 0 && cnt % REPORT_DELTA == 0)
println("Iterated via " + cnt + " entries");
}
println("Iterated via " + cnt + " entries");
cache.destroy();
return true;
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class IgniteSqlMergeQueryBenchmark method test.
/**
* {@inheritDoc}
*/
@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
if (rnd.nextBoolean()) {
double salary = rnd.nextDouble() * args.range() * 1000;
double maxSalary = salary + 1000;
Collection<Cache.Entry<Integer, Object>> entries = executeQuery(salary, maxSalary);
for (Cache.Entry<Integer, Object> entry : entries) {
Object o = entry.getValue();
double s = o instanceof Person ? ((Person) o).getSalary() : ((BinaryObject) o).<Double>field("salary");
if (s < salary || s > maxSalary)
throw new Exception("Invalid person retrieved [min=" + salary + ", max=" + maxSalary + ", person=" + o + ']');
}
qryCnt.getAndIncrement();
} else {
int i = rnd.nextInt(args.range());
cache.query(new SqlFieldsQuery("merge into Person(_key, id, firstName, lastName, salary) " + "values (?, ?, ?, ?, ?)").setArgs(i, i, "firstName" + i, "lastName" + i, (double) i * 1000));
putCnt.getAndIncrement();
}
return true;
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class QueryFactory method randomCsvLine.
/**
* Generates CSV line containing specified id and random values.
* This line corresponds 1 row of the test table,
* which will be inserted in the end.
*
* @param id key in the test table.
* @return generated comma-separated line.
*/
public String randomCsvLine(long id) {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
StringBuilder line = new StringBuilder().append(id);
for (int vi = 1; vi <= valFieldsCnt; vi++) {
line.append(',');
if (vi % 2 == 1)
line.append(rnd.nextLong());
else
line.append('"').append(rnd.nextLong()).append('"');
}
return line.toString();
}
use of java.util.concurrent.ThreadLocalRandom in project ignite by apache.
the class InlineIndexHelperTest method testCompareMixed2.
/**
*/
public void testCompareMixed2() throws Exception {
int strCnt = 1000;
int symbCnt = 20;
int inlineSize = symbCnt * 4 + 3;
ThreadLocalRandom rnd = ThreadLocalRandom.current();
String[] strings = new String[strCnt];
for (int i = 0; i < strings.length; i++) strings[i] = randomString(symbCnt);
Arrays.sort(strings);
for (int i = 0; i < 100; i++) {
int i1 = rnd.nextInt(strings.length);
int i2 = rnd.nextInt(strings.length);
assertEquals(Integer.compare(i1, i2), putAndCompare(strings[i1], strings[i2], inlineSize));
}
}
Aggregations