Search in sources :

Example 1 with HashSet

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();
}
Also used : Transaction(jetbrains.exodus.env.Transaction) HashSet(jetbrains.exodus.core.dataStructures.hash.HashSet) Test(org.junit.Test)

Example 2 with HashSet

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));
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) HashSet(jetbrains.exodus.core.dataStructures.hash.HashSet) Test(org.junit.Test)

Example 3 with HashSet

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);
    }
}
Also used : EntityIteratorWithPropId(jetbrains.exodus.entitystore.iterate.EntityIteratorWithPropId) HashSet(jetbrains.exodus.core.dataStructures.hash.HashSet)

Example 4 with HashSet

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();
        }
    }
}
Also used : SecureRandom(java.security.SecureRandom) EntityIterableHandleBase(jetbrains.exodus.entitystore.iterate.EntityIterableHandleBase) HashSet(jetbrains.exodus.core.dataStructures.hash.HashSet)

Example 5 with HashSet

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();
    }
}
Also used : Environment(jetbrains.exodus.env.Environment) Index(jetbrains.exodus.query.metadata.Index) HashSet(jetbrains.exodus.core.dataStructures.hash.HashSet)

Aggregations

HashSet (jetbrains.exodus.core.dataStructures.hash.HashSet)7 Test (org.junit.Test)3 ArrayByteIterable (jetbrains.exodus.ArrayByteIterable)2 ByteIterable (jetbrains.exodus.ByteIterable)2 SecureRandom (java.security.SecureRandom)1 EntityIterableHandleBase (jetbrains.exodus.entitystore.iterate.EntityIterableHandleBase)1 EntityIteratorWithPropId (jetbrains.exodus.entitystore.iterate.EntityIteratorWithPropId)1 Environment (jetbrains.exodus.env.Environment)1 Transaction (jetbrains.exodus.env.Transaction)1 Index (jetbrains.exodus.query.metadata.Index)1 StopwordAnalyzerBase (org.apache.lucene.analysis.StopwordAnalyzerBase)1 EnglishAnalyzer (org.apache.lucene.analysis.en.EnglishAnalyzer)1