//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldApplyIndexUpdatesInWorkSyncedBatches() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldApplyIndexUpdatesInWorkSyncedBatches()
        {
            // GIVEN
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            long duration = parseTimeMillis.apply(System.getProperty(this.GetType().FullName + ".duration", "2s"));
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
            int numThreads = Integer.getInteger(this.GetType().FullName + ".numThreads", Runtime.Runtime.availableProcessors());
            DefaultFileSystemAbstraction fs   = _fileSystemRule.get();
            PageCache           pageCache     = _pageCacheRule.getPageCache(fs);
            FusionIndexProvider indexProvider = NativeLuceneFusionIndexProviderFactory20.create(pageCache, _directory.databaseDir(), fs, IndexProvider.Monitor_Fields.EMPTY, Config.defaults(), OperationalMode.single, RecoveryCleanupWorkCollector.immediate());
            RecordStorageEngine storageEngine = _storageEngineRule.getWith(fs, pageCache, _directory.databaseLayout()).indexProvider(indexProvider).build();

            storageEngine.Apply(Tx(singletonList(createIndexRule(DESCRIPTOR, 1, _descriptor))), TransactionApplicationMode.EXTERNAL);
            Dependencies dependencies = new Dependencies();

            storageEngine.SatisfyDependencies(dependencies);
            IndexProxy index = dependencies.ResolveDependency(typeof(IndexingService)).getIndexProxy(_descriptor);

            AwaitOnline(index);

            // WHEN
            Workers <Worker> workers = new Workers <Worker>(this.GetType().Name);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean end = new java.util.concurrent.atomic.AtomicBoolean();
            AtomicBoolean end = new AtomicBoolean();

            for (int i = 0; i < numThreads; i++)
            {
                workers.Start(new Worker(this, i, end, storageEngine, 10, index));
            }

            // let the threads hammer the storage engine for some time
            Thread.Sleep(duration);
            end.set(true);

            // THEN (assertions as part of the workers applying transactions)
            workers.AwaitAndThrowOnError();
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = 15000) public void commitDuringContinuousCheckpointing() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CommitDuringContinuousCheckpointing()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.index.Index<org.neo4j.graphdb.Node> index;
            Index <Node> index;

            using (Transaction tx = Db.beginTx())
            {
                index = Db.index().forNodes(INDEX_NAME, stringMap(Org.Neo4j.Graphdb.index.IndexManager_Fields.PROVIDER, DummyIndexExtensionFactory.IDENTIFIER));
                tx.Success();
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean done = new java.util.concurrent.atomic.AtomicBoolean();
            AtomicBoolean         done    = new AtomicBoolean();
            Workers <ThreadStart> workers = new Workers <ThreadStart>(this.GetType().Name);

            for (int i = 0; i < TOTAL_ACTIVE_THREADS; i++)
            {
                workers.Start(new RunnableAnonymousInnerClass(this, index, tx, done));
            }

            Thread.Sleep(SECONDS.toMillis(2));
            done.set(true);
            workers.AwaitAndThrowOnError();

            NeoStores neoStores = GetDependency(typeof(RecordStorageEngine)).testAccessNeoStores();

            assertThat("Count store should be rotated once at least", neoStores.Counts.txId(), greaterThan(0L));

            long lastRotationTx          = GetDependency(typeof(CheckPointer)).forceCheckPoint(new SimpleTriggerInfo("test"));
            TransactionIdStore txIdStore = GetDependency(typeof(TransactionIdStore));

            assertEquals("NeoStore last closed transaction id should be equal last count store rotation transaction id.", txIdStore.LastClosedTransactionId, lastRotationTx);
            assertEquals("Last closed transaction should be last rotated tx in count store", txIdStore.LastClosedTransactionId, neoStores.Counts.txId());
        }
Пример #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void oneRound() throws Throwable
        private void OneRound()
        {
            // GIVEN a cluster and a node
            const string key = "key";

            ClusterManager.ManagedCluster cluster = ClusterRule.startCluster();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.graphdb.GraphDatabaseService master = cluster.getMaster();
            GraphDatabaseService master = cluster.Master;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final long nodeId = createNode(master);
            long nodeId = CreateNode(master);

            cluster.Sync();

            // and a bunch of workers contending on that node, each changing it
            Workers <ThreadStart> transactors = new Workers <ThreadStart>("Transactors");
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger successes = new java.util.concurrent.atomic.AtomicInteger();
            AtomicInteger successes = new AtomicInteger();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean end = new java.util.concurrent.atomic.AtomicBoolean();
            AtomicBoolean end = new AtomicBoolean();

            for (int i = 0; i < 10; i++)
            {
                transactors.Start(() =>
                {
                    Random random = ThreadLocalRandom.current();
                    while (!end.get())
                    {
                        bool committed = true;
                        try
                        {
                            using (Transaction tx = master.BeginTx())
                            {
                                Node node = master.GetNodeById(nodeId);

                                // Acquiring lock, read int property value, increment, set incremented int property
                                // should not break under any circumstances.
                                tx.acquireWriteLock(node);
                                node.setProperty(key, ( int? )node.getProperty(key, 0) + 1);
                                // Throw in relationship for good measure
                                node.createRelationshipTo(master.CreateNode(), TEST);

                                Thread.Sleep(random.Next(1_000));
                                tx.success();
                            }
                        }
                        catch (Exception)
                        {
                            // It's OK
                            committed = false;
                        }
                        if (committed)
                        {
                            successes.incrementAndGet();
                        }
                    }
                });
            }

            // WHEN entering a period of induced cluster instabilities
            ReelectTheSameMasterMakingItGoToPendingAndBack(cluster);

            // ... letting transactions run a bit after the role switch as well.
            long targetSuccesses = successes.get() + 20;

            while (successes.get() < targetSuccesses)
            {
                Thread.Sleep(100);
            }
            end.set(true);
            transactors.AwaitAndThrowOnError();

            // THEN verify that the count is equal to the number of successful transactions
            assertEquals(successes.get(), GetNodePropertyValue(master, nodeId, key));
        }
Пример #4
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public static <RECORD> void distributeRecords(int numberOfThreads, String workerNames, int queueSize, java.util.Iterator<RECORD> records, final org.neo4j.helpers.progress.ProgressListener progress, RecordProcessor<RECORD> processor, org.neo4j.consistency.checking.full.QueueDistribution_QueueDistributor<RECORD> idDistributor)
        public static void DistributeRecords <RECORD>(int numberOfThreads, string workerNames, int queueSize, IEnumerator <RECORD> records, ProgressListener progress, RecordProcessor <RECORD> processor, QueueDistribution_QueueDistributor <RECORD> idDistributor)
        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            if (!records.hasNext())
            {
                return;
            }

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") final java.util.concurrent.ArrayBlockingQueue<RECORD>[] recordQ = new java.util.concurrent.ArrayBlockingQueue[numberOfThreads];
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            ArrayBlockingQueue <RECORD>[] recordQ = new ArrayBlockingQueue[numberOfThreads];
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.Workers<RecordCheckWorker<RECORD>> workers = new org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.Workers<>(workerNames);
            Workers <RecordCheckWorker <RECORD> > workers = new Workers <RecordCheckWorker <RECORD> >(workerNames);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger idGroup = new java.util.concurrent.atomic.AtomicInteger(-1);
            AtomicInteger idGroup = new AtomicInteger(-1);

            for (int threadId = 0; threadId < numberOfThreads; threadId++)
            {
                recordQ[threadId] = new ArrayBlockingQueue <RECORD>(queueSize);
                workers.Start(new RecordCheckWorker <RECORD>(threadId, idGroup, recordQ[threadId], processor));
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int[] recsProcessed = new int[numberOfThreads];
            int[] recsProcessed = new int[numberOfThreads];
            RecordConsumer <RECORD> recordConsumer = (record, qIndex) =>
            {
                recordQ[qIndex].put(record);
                recsProcessed[qIndex]++;
            };

            try
            {
                while (records.MoveNext())
                {
                    try
                    {
                        // Put records into the queues using the queue distributor. Each Worker will pull and process.
                        RECORD record = records.Current;
                        idDistributor.Distribute(record, recordConsumer);
                        progress.Add(1);
                    }
                    catch (InterruptedException)
                    {
                        Thread.CurrentThread.Interrupt();
                        break;
                    }
                }

                // No more records to distribute, mark as done so that the workers will exit when no more records in queue.
                foreach (RecordCheckWorker <RECORD> worker in workers)
                {
                    worker.Done();
                }

                workers.AwaitAndThrowOnError();
            }
            catch (InterruptedException)
            {
                Thread.CurrentThread.Interrupt();
                throw new Exception("Was interrupted while awaiting completion");
            }
        }