Search in sources :

Example 1 with LongHashSet

use of jetbrains.exodus.core.dataStructures.hash.LongHashSet in project xodus by JetBrains.

the class BTreeStructureIdTest method assertStructureIdNotEqual.

public static void assertStructureIdNotEqual(long firstAddress, long secondAddress) {
    ITree firstImTree = new BTree(log, firstAddress, false, 3);
    ITree secondImTree = new BTree(log, secondAddress, false, 3);
    LongIterator it = firstImTree.addressIterator();
    LongHashSet firstSet = new LongHashSet();
    LongHashSet secondSet = new LongHashSet();
    while (it.hasNext()) firstSet.add(log.read(it.next()).getStructureId());
    it = secondImTree.addressIterator();
    while (it.hasNext()) secondSet.add(log.read(it.next()).getStructureId());
    for (long firstStructureId : firstSet) {
        for (long seconfStrutureId : secondSet) {
            if (firstStructureId == seconfStrutureId)
                throw new AssertionError("Structure ids are equal!");
        }
    }
}
Also used : LongHashSet(jetbrains.exodus.core.dataStructures.hash.LongHashSet) ITree(jetbrains.exodus.tree.ITree) LongIterator(jetbrains.exodus.tree.LongIterator)

Example 2 with LongHashSet

use of jetbrains.exodus.core.dataStructures.hash.LongHashSet 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));
    }
}
Also used : java.util(java.util) Pair(jetbrains.exodus.core.dataStructures.Pair) Random(jetbrains.exodus.util.Random) LongHashSet(jetbrains.exodus.core.dataStructures.hash.LongHashSet) Test(org.junit.Test) Cursor(jetbrains.exodus.env.Cursor) Assert(org.junit.Assert) ObjectProcedure(jetbrains.exodus.core.dataStructures.hash.ObjectProcedure) LongHashMap(jetbrains.exodus.core.dataStructures.hash.LongHashMap) Before(org.junit.Before) LongHashSet(jetbrains.exodus.core.dataStructures.hash.LongHashSet) Random(jetbrains.exodus.util.Random) LongHashMap(jetbrains.exodus.core.dataStructures.hash.LongHashMap) Pair(jetbrains.exodus.core.dataStructures.Pair) Test(org.junit.Test)

Example 3 with LongHashSet

use of jetbrains.exodus.core.dataStructures.hash.LongHashSet in project xodus by JetBrains.

the class StoreTest method concurrentPutLikeJetPass.

private void concurrentPutLikeJetPass(@NotNull final StoreConfig config) {
    env.getEnvironmentConfig().setGcEnabled(false);
    final Store store = openStoreAutoCommit("store", config);
    final JobProcessor processor = new MultiThreadDelegatingJobProcessor("ConcurrentPutProcessor", 8) {
    };
    processor.setExceptionHandler(new JobProcessorExceptionHandler() {

        @Override
        public void handle(JobProcessor processor, Job job, Throwable t) {
            t.printStackTrace(System.out);
        }
    });
    processor.start();
    final int count = 50000;
    final LongSet keys = new LongHashSet();
    for (int i = 0; i < count; ++i) {
        processor.queue(new Job() {

            @Override
            protected void execute() {
                env.executeInTransaction(new TransactionalExecutable() {

                    @Override
                    public void execute(@NotNull final Transaction txn) {
                        final long key = randomLong();
                        store.put(txn, LongBinding.longToCompressedEntry(key), getValue());
                        if (txn.flush()) {
                            final boolean added;
                            synchronized (keys) {
                                added = keys.add(key);
                            }
                            if (!added) {
                                System.out.println("Happy birthday paradox!");
                            }
                        }
                    }
                });
            }
        });
    }
    processor.waitForJobs(10);
    processor.finish();
    assertEquals(count, keys.size());
    env.executeInTransaction(new TransactionalExecutable() {

        @Override
        public void execute(@NotNull final Transaction txn) {
            final long[] longs = keys.toLongArray();
            for (long key : longs) {
                assertEquals(getValue(), store.get(txn, LongBinding.longToCompressedEntry(key)));
            }
            Arrays.sort(longs);
            try (Cursor cursor = store.openCursor(txn)) {
                int i = 0;
                while (cursor.getNext()) {
                    assertEquals(longs[i++], LongBinding.compressedEntryToLong(cursor.getKey()));
                }
                assertEquals(count, i);
            }
        }
    });
}
Also used : MultiThreadDelegatingJobProcessor(jetbrains.exodus.core.execution.MultiThreadDelegatingJobProcessor) JobProcessor(jetbrains.exodus.core.execution.JobProcessor) LongSet(jetbrains.exodus.core.dataStructures.hash.LongSet) MultiThreadDelegatingJobProcessor(jetbrains.exodus.core.execution.MultiThreadDelegatingJobProcessor) NotNull(org.jetbrains.annotations.NotNull) LongHashSet(jetbrains.exodus.core.dataStructures.hash.LongHashSet) Job(jetbrains.exodus.core.execution.Job) JobProcessorExceptionHandler(jetbrains.exodus.core.execution.JobProcessorExceptionHandler)

Aggregations

LongHashSet (jetbrains.exodus.core.dataStructures.hash.LongHashSet)3 java.util (java.util)1 Pair (jetbrains.exodus.core.dataStructures.Pair)1 LongHashMap (jetbrains.exodus.core.dataStructures.hash.LongHashMap)1 LongSet (jetbrains.exodus.core.dataStructures.hash.LongSet)1 ObjectProcedure (jetbrains.exodus.core.dataStructures.hash.ObjectProcedure)1 Job (jetbrains.exodus.core.execution.Job)1 JobProcessor (jetbrains.exodus.core.execution.JobProcessor)1 JobProcessorExceptionHandler (jetbrains.exodus.core.execution.JobProcessorExceptionHandler)1 MultiThreadDelegatingJobProcessor (jetbrains.exodus.core.execution.MultiThreadDelegatingJobProcessor)1 Cursor (jetbrains.exodus.env.Cursor)1 ITree (jetbrains.exodus.tree.ITree)1 LongIterator (jetbrains.exodus.tree.LongIterator)1 Random (jetbrains.exodus.util.Random)1 NotNull (org.jetbrains.annotations.NotNull)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1 Test (org.junit.Test)1