use of org.apache.ignite.internal.util.IgniteRandom in project ignite-3 by apache.
the class ItBplusTreeSelfTest method doTestMassiveRemove.
private void doTestMassiveRemove(final boolean canGetRow) throws Exception {
final int threads = 64;
final int keys = 3000;
final AtomicLongArray rmvd = new AtomicLongArray(keys);
final TestTree tree = createTestTree(canGetRow);
// Put keys in reverse order to have a better balance in the tree (lower height).
for (long i = keys - 1; i >= 0; i--) {
tree.put(i);
// println(tree.printTree());
}
assertEquals(keys, tree.size());
tree.validateTree();
info("Remove...");
try {
runMultiThreaded(() -> {
Random rnd = new IgniteRandom();
for (; ; ) {
int idx = 0;
boolean found = false;
for (int i = 0, shift = rnd.nextInt(keys); i < keys; i++) {
idx = (i + shift) % keys;
if (rmvd.get(idx) == 0 && rmvd.compareAndSet(idx, 0, 1)) {
found = true;
break;
}
}
if (!found) {
break;
}
assertEquals(Long.valueOf(idx), tree.remove((long) idx));
if (canGetRow) {
rmvdIds.add((long) idx);
}
}
return null;
}, threads, "remove");
assertEquals(0, tree.size());
tree.validateTree();
} finally {
rmvdIds.clear();
}
}
use of org.apache.ignite.internal.util.IgniteRandom in project ignite-3 by apache.
the class ItBplusTreeSelfTest method doTestMassivePut.
private void doTestMassivePut(final boolean canGetRow) throws Exception {
final int threads = 16;
// We may fail to insert more on small pages size because of tree height.
final int keys = 26;
final TestTree tree = createTestTree(canGetRow);
info("Put...");
final AtomicLongArray k = new AtomicLongArray(keys);
runMultiThreaded(() -> {
Random rnd = new IgniteRandom();
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");
assertEquals(keys, tree.size());
tree.validateTree();
IgniteCursor<Long> c = tree.find(null, null);
long x = 0;
while (c.next()) {
assertEquals(Long.valueOf(x++), c.get());
}
assertEquals(keys, x);
assertNoLocks();
}
Aggregations