use of jetbrains.exodus.util.Random in project xodus by JetBrains.
the class LoggableTests method testCompressedLongByteIterator2.
@Test
public void testCompressedLongByteIterator2() {
final Random rnd = new Random();
for (int i = 0; i < 10000; ++i) {
final long l = Math.abs(rnd.nextLong());
Assert.assertEquals(l, CompressedUnsignedLongByteIterable.getLong(CompressedUnsignedLongByteIterable.getIterable(l)));
}
}
use of jetbrains.exodus.util.Random in project xodus by JetBrains.
the class TreeCursorDuplicatesTest method test_xd_347_like.
@Test
public void test_xd_347_like() {
tm = createMutableTree(true, 1);
final int count = 20000;
long value = 0;
final LongHashMap<LongHashSet> values = new LongHashMap<>();
final Random rnd = new Random();
for (int i = 0; i < count; ++i, ++value) {
if (i > count / 2) {
final Pair<Long, LongHashSet>[] pair = new Pair[1];
values.forEachEntry((ObjectProcedure<Map.Entry<Long, LongHashSet>>) object -> {
pair[0] = new Pair<>(object.getKey(), object.getValue());
return false;
});
final Pair<Long, LongHashSet> p = pair[0];
final LongHashSet oldSet = p.getSecond();
final long oldValue = oldSet.iterator().nextLong();
final Long oldKey = p.getFirst();
try (ITreeCursor cursor = tm.openCursor()) {
if (!cursor.getSearchBoth(key(oldKey), value(oldValue))) {
Assert.assertTrue(cursor.getSearchBoth(key(oldKey), value(oldValue)));
}
cursor.deleteCurrent();
}
Assert.assertTrue(oldSet.remove(oldValue));
if (oldSet.isEmpty()) {
Assert.assertEquals(oldSet, values.remove(oldKey));
}
}
final long key = System.currentTimeMillis() + rnd.nextInt(count / 10);
LongHashSet keyValues = values.get(key);
if (keyValues == null) {
keyValues = new LongHashSet();
values.put(key, keyValues);
}
Assert.assertTrue(keyValues.add(value));
tm.put(key(key), value(value));
}
}
use of jetbrains.exodus.util.Random in project xodus by JetBrains.
the class TreeCursorNoDuplicatesTest method xd_333.
@Test
public void xd_333() {
rnd = new Random(0);
final ByteIterable value = value("value");
tm = createMutableTree(false, 1);
final TreeSet<String> keys = new TreeSet<>();
for (int i = 0; i < 15; ++i) {
final String key = rndString();
tm.put(key(key), value);
keys.add(key);
}
/*final long address = saveTree();
reopen();
final ITree t = openTree(address, false);*/
testCursorOrder(keys);
}
use of jetbrains.exodus.util.Random in project xodus by JetBrains.
the class FindTests method testFindComparableSet.
public void testFindComparableSet() {
final StoreTransaction txn = getStoreTransactionSafe();
final Entity issue = txn.newEntity("Issue");
final ComparableSet<Integer> randomSet = new ComparableSet<>();
final Random rnd = new Random();
final int setSize = 20;
for (int i = 0; i < setSize; ++i) {
randomSet.addItem(rnd.nextInt());
}
for (int i = 0; i < 1000; ++i) {
Assert.assertEquals(setSize, randomSet.size());
issue.setProperty("randomSet", randomSet);
randomSet.forEach((item, index) -> Assert.assertEquals(issue, txn.find("Issue", "randomSet", item).getFirst()));
Assert.assertTrue(randomSet.removeItem(randomSet.iterator().next()));
while (true) {
final int newItem = rnd.nextInt();
if (randomSet.addItem(newItem)) {
Assert.assertTrue(txn.find("Issue", "randomSet", newItem).isEmpty());
break;
}
}
if (i % 20 == 19) {
txn.flush();
}
}
}
use of jetbrains.exodus.util.Random in project xodus by JetBrains.
the class StressTests method test_xd_347_like.
public void test_xd_347_like() {
final PersistentEntityStoreImpl store = getEntityStore();
final List<Entity> issues = store.computeInTransaction(new StoreTransactionalComputable<List<Entity>>() {
@Override
public List<Entity> compute(@NotNull final StoreTransaction txn) {
final List<Entity> result = new ArrayList<>();
for (final Entity issue : txn.getAll("Issue")) {
result.add(issue);
}
while (result.size() < 10000) {
result.add(txn.newEntity("Issue"));
}
return result;
}
});
final Random rnd = new Random();
final int count = 300;
for (int i = 0; i < count; ++i) {
store.executeInTransaction(new StoreTransactionalExecutable() {
@Override
public void execute(@NotNull final StoreTransaction txn) {
for (int j = 0; j < 100; ++j) {
issues.get(rnd.nextInt(issues.size())).setProperty("created", System.currentTimeMillis());
issues.get(rnd.nextInt(issues.size())).setProperty("updated", System.currentTimeMillis());
}
}
});
if (i % 10 == 0) {
System.out.print((i * 100 / count) + "%\r");
}
}
}
Aggregations