use of jetbrains.exodus.core.dataStructures.hash.HashSet in project xodus by JetBrains.
the class VfsFileTests method testNumberOfFiles.
@Test
public void testNumberOfFiles() {
final Transaction txn = env.beginTransaction();
final HashSet<String> files = new HashSet<>();
final int numberOfFiles = (int) (Math.random() * 1000 + 5000);
for (int i = 0; i < numberOfFiles; ++i) {
final String file = "file" + Math.random();
if (!files.contains(file)) {
files.add(file);
vfs.createFile(txn, file);
}
}
Assert.assertEquals(files.size(), vfs.getNumberOfFiles(txn));
txn.commit();
}
use of jetbrains.exodus.core.dataStructures.hash.HashSet in project xodus by JetBrains.
the class TreeCursorNoDuplicatesTest method testInsertDeletes2.
@Test
public void testInsertDeletes2() {
final ByteIterable value = value("value");
final Set<String> keys = new HashSet<>();
tm = createMutableTree(false, 1);
for (int i = 0; i < 10000; ++i) {
final String key = rndString();
if (keys.add(key)) {
Assert.assertTrue(tm.add(key(key), value));
}
if (keys.size() > 1000) {
final String obsoleteKey = keys.iterator().next();
keys.remove(obsoleteKey);
Assert.assertTrue(tm.delete(key(obsoleteKey)));
}
}
testCursorOrder(new TreeSet<>(keys));
}
use of jetbrains.exodus.core.dataStructures.hash.HashSet in project xodus by JetBrains.
the class EntityFromLinkSetTests method testSimple.
public void testSimple() {
final StoreTransaction txn = getStoreTransaction();
final Entity i1 = txn.newEntity("Issue");
final Entity i2 = txn.newEntity("Issue");
final Entity i3 = txn.newEntity("Issue");
final Entity i4 = txn.newEntity("Issue");
i1.addLink("dup", i2);
i1.addLink("hup", i3);
i1.addLink("hup", i4);
i2.addLink("dup", i3);
txn.flush();
final Set<String> names = new HashSet<>(2);
names.add("dup");
names.add("hup");
EntityIteratorWithPropId it;
for (int i = 0; i < 2; i++) {
it = (EntityIteratorWithPropId) i1.getLinks(names).iterator();
assertTrue(it.hasNext());
assertEquals(i2, it.next());
assertEquals("dup", it.currentLinkName());
assertTrue(it.hasNext());
assertEquals(i3, it.next());
assertEquals("hup", it.currentLinkName());
assertTrue(it.hasNext());
assertEquals(i4, it.next());
assertEquals("hup", it.currentLinkName());
assertFalse(it.hasNext());
getEntityStore().getAsyncProcessor().waitForJobs(100);
}
for (int i = 0; i < 2; i++) {
it = (EntityIteratorWithPropId) i2.getLinks(names).iterator();
assertTrue(it.hasNext());
assertEquals(i3, it.next());
assertEquals("dup", it.currentLinkName());
assertFalse(it.hasNext());
getEntityStore().getAsyncProcessor().waitForJobs(100);
}
}
use of jetbrains.exodus.core.dataStructures.hash.HashSet in project xodus by JetBrains.
the class EntityIterableHandleTests method testDistribution.
public void testDistribution() {
final SecureRandom rnd = new SecureRandom();
final Set<EntityIterableHandleBase.EntityIterableHandleHash> set = new HashSet<>();
for (int i = 0; i < 1000000; ++i) {
final EntityIterableHandleBase.EntityIterableHandleHash h = new EntityIterableHandleBase.EntityIterableHandleHash(getEntityStore());
h.apply("00000000000000000000000000000000");
final int intsCount = rnd.nextInt(40) + 10;
for (int j = 0; j < intsCount; ++j) {
h.applyDelimiter();
h.apply(rnd.nextInt() & 0xff);
}
h.computeHashCode();
// in case of poor distribution, birthday paradox will give assertion quite soon
if (!set.add(h)) {
Assert.fail();
}
}
}
use of jetbrains.exodus.core.dataStructures.hash.HashSet in project xodus by JetBrains.
the class UniqueKeyIndicesEngine method updateUniqueKeyIndices.
public void updateUniqueKeyIndices(@NotNull final Iterable<Index> indices) {
final Environment environment = persistentStore.getEnvironment();
environment.suspendGC();
try {
persistentStore.executeInTransaction(txn -> {
final PersistentStoreTransaction t = (PersistentStoreTransaction) txn;
final PersistentStoreTransaction snapshot = t.getSnapshot();
try {
final Collection<String> indexNames = new HashSet<>();
for (final String dbName : environment.getAllStoreNames(t.getEnvironmentTransaction())) {
if (isUniqueKeyIndexName(dbName)) {
indexNames.add(dbName);
}
}
for (final Index index : indices) {
final String indexName = getUniqueKeyIndexName(index);
if (indexNames.contains(indexName)) {
indexNames.remove(indexName);
} else {
createUniqueKeyIndex(t, snapshot, index);
}
}
// remove obsolete indices
for (final String indexName : indexNames) {
removeObsoleteUniqueKeyIndex(t, indexName);
}
if (logger.isTraceEnabled()) {
logger.trace("Flush index persistent transaction " + t);
}
t.flush();
} finally {
// reading snapshot is obsolete now
snapshot.abort();
}
});
} finally {
environment.resumeGC();
}
}
Aggregations