示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void setUpgradeTransactionMustBeAtomic() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SetUpgradeTransactionMustBeAtomic()
        {
            using (MetaDataStore store = NewMetaDataStore())
            {
                PagedFile pf = store.PagedFile;
                store.SetUpgradeTransaction(0, 0, 0);
                AtomicLong writeCount    = new AtomicLong();
                AtomicLong fileReadCount = new AtomicLong();
                AtomicLong apiReadCount  = new AtomicLong();
                int        upperLimit    = 10_000;
                int        lowerLimit    = 100;
                long       endTime       = currentTimeMillis() + SECONDS.toMillis(10);

                Race race = new Race();
                race.WithEndCondition(() => writeCount.get() >= upperLimit && fileReadCount.get() >= upperLimit && apiReadCount.get() >= upperLimit);
                race.WithEndCondition(() => writeCount.get() >= lowerLimit && fileReadCount.get() >= lowerLimit && apiReadCount.get() >= lowerLimit && currentTimeMillis() >= endTime);
                // writers
                race.AddContestants(3, () =>
                {
                    long count = writeCount.incrementAndGet();
                    store.SetUpgradeTransaction(count, count, count);
                });

                // file readers
                race.AddContestants(3, throwing(() =>
                {
                    using (PageCursor cursor = pf.Io(0, PagedFile.PF_SHARED_READ_LOCK))
                    {
                        assertTrue(cursor.next());
                        long id;
                        long checksum;
                        do
                        {
                            id       = store.GetRecordValue(cursor, MetaDataStore.Position.UpgradeTransactionId);
                            checksum = store.GetRecordValue(cursor, MetaDataStore.Position.UpgradeTransactionChecksum);
                        } while (cursor.shouldRetry());
                        AssertIdEqualsChecksum(id, checksum, "file");
                        fileReadCount.incrementAndGet();
                    }
                }));

                race.AddContestants(3, () =>
                {
                    TransactionId transaction = store.UpgradeTransaction;
                    AssertIdEqualsChecksum(transaction.TransactionIdConflict(), transaction.Checksum(), "API");
                    apiReadCount.incrementAndGet();
                });
                race.Go();
            }
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void transactionClosedMustBeAtomic() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TransactionClosedMustBeAtomic()
        {
            using (MetaDataStore store = NewMetaDataStore())
            {
                PagedFile pf           = store.PagedFile;
                int       initialValue = 2;
                store.TransactionClosed(initialValue, initialValue, initialValue);
                AtomicLong writeCount    = new AtomicLong();
                AtomicLong fileReadCount = new AtomicLong();
                AtomicLong apiReadCount  = new AtomicLong();
                int        upperLimit    = 10_000;
                int        lowerLimit    = 100;
                long       endTime       = currentTimeMillis() + SECONDS.toMillis(10);

                Race race = new Race();
                race.WithEndCondition(() => writeCount.get() >= upperLimit && fileReadCount.get() >= upperLimit && apiReadCount.get() >= upperLimit);
                race.WithEndCondition(() => writeCount.get() >= lowerLimit && fileReadCount.get() >= lowerLimit && apiReadCount.get() >= lowerLimit && currentTimeMillis() >= endTime);
                race.AddContestants(3, () =>
                {
                    long count = writeCount.incrementAndGet();
                    store.TransactionCommitted(count, count, count);
                });

                race.AddContestants(3, throwing(() =>
                {
                    using (PageCursor cursor = pf.Io(0, PagedFile.PF_SHARED_READ_LOCK))
                    {
                        assertTrue(cursor.next());
                        long logVersion;
                        long byteOffset;
                        do
                        {
                            logVersion = store.GetRecordValue(cursor, MetaDataStore.Position.LastClosedTransactionLogVersion);
                            byteOffset = store.GetRecordValue(cursor, MetaDataStore.Position.LastClosedTransactionLogByteOffset);
                        } while (cursor.shouldRetry());
                        AssertLogVersionEqualsByteOffset(logVersion, byteOffset, "file");
                        fileReadCount.incrementAndGet();
                    }
                }));

                race.AddContestants(3, () =>
                {
                    long[] transaction = store.LastClosedTransaction;
                    AssertLogVersionEqualsByteOffset(transaction[0], transaction[1], "API");
                    apiReadCount.incrementAndGet();
                });
                race.Go();
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void concurrentCreatingUniquenessConstraint() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ConcurrentCreatingUniquenessConstraint()
        {
            // given
            Race  race  = (new Race()).withMaxDuration(10, SECONDS);
            Label label = label(0);

            race.AddContestants(10, () =>
            {
                try
                {
                    using (Transaction tx = Db.beginTx())
                    {
                        Db.schema().constraintFor(label).assertPropertyIsUnique(KEY).create();
                        tx.Success();
                    }
                }
                catch (Exception e) when(e is TransientFailureException || e is ConstraintViolationException)
                {                 // It's OK
                }
            }, 300);

            // when
            race.Go();

            using (Transaction tx = Db.beginTx())
            {
                // then
                ConstraintDefinition constraint = single(Db.schema().getConstraints(label));
                assertNotNull(constraint);
                IndexDefinition index = single(Db.schema().getIndexes(label));
                assertNotNull(index);
                tx.Success();
            }
        }
示例#4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPutFromMultipleThreads() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPutFromMultipleThreads()
        {
            // GIVEN
            IdMapper   idMapper   = Mapper(new StringEncoder(), Radix.String, NO_MONITOR);
            AtomicLong highNodeId = new AtomicLong();
            int        batchSize  = 1234;
            Race       race       = new Race();

            System.Func <long, object> inputIdLookup = string.valueOf;
            int countPerThread = 30_000;

            race.AddContestants(_processors, () =>
            {
                int cursor      = batchSize;
                long nextNodeId = 0;
                for (int j = 0; j < countPerThread; j++)
                {
                    if (cursor == batchSize)
                    {
                        nextNodeId = highNodeId.getAndAdd(batchSize);
                        cursor     = 0;
                    }
                    long nodeId = nextNodeId++;
                    cursor++;

                    idMapper.Put(inputIdLookup(nodeId), nodeId, GLOBAL);
                }
            });

            // WHEN
            race.Go();
            idMapper.Prepare(inputIdLookup, mock(typeof(Collector)), Org.Neo4j.Helpers.progress.ProgressListener_Fields.None);

            // THEN
            int count = _processors * countPerThread;
            int countWithGapsWorstCase = count + batchSize * _processors;
            int correctHits            = 0;

            for (long nodeId = 0; nodeId < countWithGapsWorstCase; nodeId++)
            {
                long result = idMapper.Get(inputIdLookup(nodeId), GLOBAL);
                if (result != -1)
                {
                    assertEquals(nodeId, result);
                    correctHits++;
                }
            }
            assertEquals(count, correctHits);
        }
示例#5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void incrementAndGetVersionMustBeAtomic() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void IncrementAndGetVersionMustBeAtomic()
        {
            using (MetaDataStore store = NewMetaDataStore())
            {
                long initialVersion = store.IncrementAndGetVersion();
                int  threads        = Runtime.Runtime.availableProcessors();
                int  iterations     = 500;
                Race race           = new Race();
                race.AddContestants(threads, () =>
                {
                    for (int i = 0; i < iterations; i++)
                    {
                        store.IncrementAndGetVersion();
                    }
                });
                race.Go();
                assertThat(store.IncrementAndGetVersion(), @is(initialVersion + (threads * iterations) + 1));
            }
        }
示例#6
0
        /// <summary>
        /// The test case is basically loads of concurrent CREATE/DELETE NODE or sometimes just CREATE, keeping the created node in an array
        /// for dedicated deleter threads to pick up and delete as fast as they can see them. This concurrently with large creation transactions.
        /// </summary>
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldStressIt() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldStressIt()
        {
            // given
            Race race = (new Race()).withMaxDuration(5, TimeUnit.SECONDS);
            AtomicReferenceArray <Node> nodeHeads = new AtomicReferenceArray <Node>(_numberOfCreators);

            for (int i = 0; i < _numberOfCreators; i++)
            {
                race.AddContestant(Creator(nodeHeads, i));
            }
            race.AddContestants(NUMBER_OF_DELETORS, Deleter(nodeHeads));

            // when
            race.Go();

            // then
            DatabaseLayout dbLayout = Db.databaseLayout();

            Db.shutdownAndKeepStore();
            assertTrue((new ConsistencyCheckService()).runFullConsistencyCheck(dbLayout, defaults(), NONE, toOutputStream(System.out), false, new ConsistencyFlags(true, true, true, true, false)).Successful);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHandleMultipleConcurrentStoreCopyRequests() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHandleMultipleConcurrentStoreCopyRequests()
        {
            // GIVEN
            Race           race    = new Race();
            CountingAction action  = new CountingAction();
            int            threads = Runtime.Runtime.availableProcessors() * 10;

            race.AddContestants(threads, throwing(() =>
            {
                ParkARandomWhile();
                using (Resource @lock = _mutex.storeCopy(action))
                {
                    ParkARandomWhile();
                }
            }));
            race.Go();

            // THEN
            // It's hard to make predictions about what should have been seen. Most importantly is that
            // The lock doesn't hang any requests and that number of calls to the action less than number of threads
            assertThat(action.Count(), lessThan(threads));
        }
示例#8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldKeepItsCoolWhenMultipleThreadsAreHammeringIt() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldKeepItsCoolWhenMultipleThreadsAreHammeringIt()
        {
            // An interesting note is that during tests the call to sequence#offer made no difference
            // in performance, so there seems to be no visible penalty in using ArrayQueueOutOfOrderSequence.

            // GIVEN a sequence with intentionally low starting queue size
            System.Func <long, long[]> metaFunction = number => new long[] { number + 2, number * 2 };
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicLong numberSource = new java.util.concurrent.atomic.AtomicLong();
            AtomicLong numberSource = new AtomicLong();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.util.OutOfOrderSequence sequence = new org.neo4j.kernel.impl.util.ArrayQueueOutOfOrderSequence(numberSource.get(), 5, metaFunction.apply(numberSource.get()));
            OutOfOrderSequence sequence = new ArrayQueueOutOfOrderSequence(numberSource.get(), 5, metaFunction(numberSource.get()));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.test.Race race = new org.neo4j.test.Race().withEndCondition(() -> numberSource.get() > 10_000_000);
            Race race         = (new Race()).withEndCondition(() => numberSource.get() > 10_000_000);
            int  offerThreads = max(2, Runtime.Runtime.availableProcessors() - 1);

            race.AddContestants(offerThreads, () =>
            {
                long number = numberSource.incrementAndGet();
                sequence.Offer(number, metaFunction(number));
            });
            ThreadStart verifier = () =>
            {
                long[] highest      = sequence.Get();
                long[] expectedMeta = metaFunction(highest[0]);
                assertArrayEquals(expectedMeta, copyOfRange(highest, 1, highest.Length));
            };

            race.AddContestant(verifier);
            race.Go();

            // THEN
            verifier.run();
        }