//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReportProgressInTheSpecifiedIntervals()
        public virtual void ShouldReportProgressInTheSpecifiedIntervals()
        {
            // given
            Indicator        indicator        = IndicatorMock();
            ProgressListener progressListener = Factory.mock(indicator, 10).singlePart(TestName.MethodName, 16);

            // when
            progressListener.Started();
            for (int i = 0; i < 16; i++)
            {
                progressListener.Add(1);
            }
            progressListener.Done();

            // then
            InOrder order = inOrder(indicator);

            order.verify(indicator).startProcess(16);
            for (int i = 0; i < 10; i++)
            {
                order.verify(indicator).progress(i, i + 1);
            }
            order.verify(indicator).completeProcess();
            order.verifyNoMoreInteractions();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAllowStartingAPartBeforeCompletionOfMultiPartBuilder()
        public virtual void ShouldAllowStartingAPartBeforeCompletionOfMultiPartBuilder()
        {
            // given
            Indicator indicator = mock(typeof(Indicator));

            ProgressMonitorFactory.MultiPartBuilder builder = Factory.mock(indicator, 10).multipleParts(TestName.MethodName);
            ProgressListener part1 = builder.ProgressForPart("part1", 1);
            ProgressListener part2 = builder.ProgressForPart("part2", 1);

            // when
            part1.Add(1);
            builder.Build();
            part2.Add(1);
            part1.Done();
            part2.Done();

            // then
            InOrder order = inOrder(indicator);

            order.verify(indicator).startPart("part1", 1);
            order.verify(indicator).startProcess(2);
            order.verify(indicator).startPart("part2", 1);
            order.verify(indicator).completePart("part1");
            order.verify(indicator).completePart("part2");
            order.verify(indicator).completeProcess();
        }
Exemple #3
0
        private static void ConsistencyCheckLabelScanStore(LabelScanStore labelScanStore, ConsistencyReporter report, ProgressListener listener)
        {
            ConsistencyReporter.FormattingDocumentedHandler handler = report.FormattingHandler(RecordType.LABEL_SCAN_DOCUMENT);
            ReporterFactory proxyFactory = new ReporterFactory(handler);

            labelScanStore.ConsistencyCheck(proxyFactory);
            handler.UpdateSummary();
            listener.Add(1);
        }
Exemple #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void detectDuplicateInputIds(Radix radix, org.neo4j.unsafe.impl.batchimport.input.Collector collector, org.neo4j.helpers.progress.ProgressListener progress) throws InterruptedException
        private void DetectDuplicateInputIds(Radix radix, Collector collector, ProgressListener progress)
        {
            // We do this collision sort using ParallelSort which has the data cache and the tracker cache,
            // the tracker cache gets sorted, data cache stays intact. In the collision data case we actually
            // have one more layer in here so we have tracker cache pointing to collisionNodeIdCache
            // pointing to dataCache. This can be done using the ParallelSort.Comparator abstraction.
            //
            // The Comparator below takes into account dataIndex for each eId its comparing so that an extra
            // comparison based on dataIndex is done if it's comparing two equal eIds. We do this so that
            // stretches of multiple equal eIds are sorted by dataIndex (i.e. node id) order,
            // to be able to write an efficient duplication scanning below and to have deterministic duplication reporting.
            Comparator duplicateComparator = new ComparatorAnonymousInnerClass(this);

            (new ParallelSort(radix, As5ByteLongArray(_collisionNodeIdCache), _numberOfCollisions - 1, _collisionTrackerCache, _processorsForParallelWork, progress, duplicateComparator)).run();

            // Here we have a populated C
            // We want to detect duplicate input ids within it
            long previousEid             = 0;
            int  previousGroupId         = -1;
            SameInputIdDetector detector = new SameInputIdDetector();

            progress.Started("DEDUPLICATE");
            for (int i = 0; i < _numberOfCollisions; i++)
            {
                long collisionIndex = _collisionTrackerCache.get(i);
                long nodeId         = _collisionNodeIdCache.get5ByteLong(collisionIndex, 0);
                long offset         = _collisionNodeIdCache.get6ByteLong(collisionIndex, 5);
                long eid            = _dataCache.get(nodeId);
                int  groupId        = GroupOf(nodeId);
                // collisions of same eId AND groupId are always together
                bool same = eid == previousEid && previousGroupId == groupId;
                if (!same)
                {
                    detector.Clear();
                }

                // Potential duplicate
                object inputId            = _collisionValues.get(offset);
                long   nonDuplicateNodeId = detector.Add(nodeId, inputId);
                if (nonDuplicateNodeId != -1)
                {                         // Duplicate
                    collector.CollectDuplicateNode(inputId, nodeId, _groups.get(groupId).name());
                    _trackerCache.markAsDuplicate(nodeId);
                    UnmarkAsCollision(nonDuplicateNodeId);
                }

                previousEid     = eid;
                previousGroupId = groupId;
                progress.Add(1);
            }
            progress.Done();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldAggregateProgressFromMultipleProcesses()
        public virtual void ShouldAggregateProgressFromMultipleProcesses()
        {
            // given
            Indicator indicator = IndicatorMock();

            ProgressMonitorFactory.MultiPartBuilder builder = Factory.mock(indicator, 10).multipleParts(TestName.MethodName);
            ProgressListener first = builder.ProgressForPart("first", 5);
            ProgressListener other = builder.ProgressForPart("other", 5);

            builder.Build();
            InOrder order = inOrder(indicator);

            order.verify(indicator).startProcess(10);
            order.verifyNoMoreInteractions();

            // when
            first.Started();
            for (int i = 0; i < 5; i++)
            {
                first.Add(1);
            }
            first.Done();

            // then
            order.verify(indicator).startPart("first", 5);
            for (int i = 0; i < 5; i++)
            {
                order.verify(indicator).progress(i, i + 1);
            }
            order.verify(indicator).completePart("first");
            order.verifyNoMoreInteractions();

            // when
            other.Started();
            for (int i = 0; i < 5; i++)
            {
                other.Add(1);
            }
            other.Done();

            // then
            order.verify(indicator).startPart("other", 5);
            for (int i = 5; i < 10; i++)
            {
                order.verify(indicator).progress(i, i + 1);
            }
            order.verify(indicator).completePart("other");
            order.verify(indicator).completeProcess();
            order.verifyNoMoreInteractions();
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPrintADotEveryHalfPercentAndFullPercentageEveryTenPercentEvenWhenStepResolutionIsLower()
        public virtual void ShouldPrintADotEveryHalfPercentAndFullPercentageEveryTenPercentEvenWhenStepResolutionIsLower()
        {
            // given
            StringWriter     writer           = new StringWriter();
            ProgressListener progressListener = ProgressMonitorFactory.Textual(writer).singlePart(TestName.MethodName, 50);

            // when
            for (int i = 0; i < 50; i++)
            {
                progressListener.Add(1);
            }

            // then
            assertEquals(TestName.MethodName + lineSeparator() + _expectedTextualOutput, writer.ToString());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPrintADotEveryHalfPercentAndFullPercentageEveryTenPercentWithTextualIndicator() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPrintADotEveryHalfPercentAndFullPercentageEveryTenPercentWithTextualIndicator()
        {
            // given
            MemoryStream     stream           = new MemoryStream();
            ProgressListener progressListener = ProgressMonitorFactory.Textual(stream).singlePart(TestName.MethodName, 1000);

            // when
            for (int i = 0; i < 1000; i++)
            {
                progressListener.Add(1);
            }

            // then
            assertEquals(TestName.MethodName + lineSeparator() + _expectedTextualOutput, stream.ToString(Charset.defaultCharset().name()));
        }
Exemple #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private long applyTransactions(java.io.File fromPath, org.neo4j.kernel.internal.GraphDatabaseAPI toDb, org.neo4j.kernel.configuration.Config toConfig, long fromTxExclusive, long toTxInclusive, java.io.PrintStream out) throws Exception
		 private long ApplyTransactions( File fromPath, GraphDatabaseAPI toDb, Config toConfig, long fromTxExclusive, long toTxInclusive, PrintStream @out )
		 {
			  DependencyResolver resolver = toDb.DependencyResolver;
			  TransactionRepresentationCommitProcess commitProcess = new TransactionRepresentationCommitProcess( resolver.ResolveDependency( typeof( TransactionAppender ) ), resolver.ResolveDependency( typeof( StorageEngine ) ) );
			  LifeSupport life = new LifeSupport();
			  try
			  {
					  using ( DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), JobScheduler jobScheduler = createInitialisedScheduler(), PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem, jobScheduler) )
					  {
						LogicalTransactionStore source = life.Add( new ReadOnlyTransactionStore( pageCache, fileSystem, DatabaseLayout.of( fromPath ), Config.defaults(), new Monitors() ) );
						life.Start();
						long lastAppliedTx = fromTxExclusive;
						// Some progress if there are more than a couple of transactions to apply
						ProgressListener progress = toTxInclusive - fromTxExclusive >= 100 ? textual( @out ).singlePart( "Application progress", toTxInclusive - fromTxExclusive ) : Org.Neo4j.Helpers.progress.ProgressListener_Fields.None;
						using ( IOCursor<CommittedTransactionRepresentation> cursor = source.GetTransactions( fromTxExclusive + 1 ) )
						{
							 while ( cursor.next() )
							 {
								  CommittedTransactionRepresentation transaction = cursor.get();
								  TransactionRepresentation transactionRepresentation = transaction.TransactionRepresentation;
								  try
								  {
										commitProcess.Commit( new TransactionToApply( transactionRepresentation ), NULL, EXTERNAL );
										progress.Add( 1 );
								  }
//JAVA TO C# CONVERTER WARNING: 'final' catch parameters are not available in C#:
//ORIGINAL LINE: catch (final Throwable e)
								  catch ( Exception e )
								  {
										Console.Error.WriteLine( "ERROR applying transaction " + transaction.CommitEntry.TxId );
										throw e;
								  }
								  lastAppliedTx = transaction.CommitEntry.TxId;
								  if ( lastAppliedTx == toTxInclusive )
								  {
										break;
								  }
							 }
						}
						return lastAppliedTx;
					  }
			  }
			  finally
			  {
					life.Shutdown();
			  }
		 }
Exemple #9
0
        private static void ConsistencyCheckSchemaIndexes(IndexAccessors indexes, ConsistencyReporter report, ProgressListener listener)
        {
            IList <StoreIndexDescriptor> rulesToRemove = new List <StoreIndexDescriptor>();

            foreach (StoreIndexDescriptor onlineRule in indexes.OnlineRules())
            {
                ConsistencyReporter.FormattingDocumentedHandler handler = report.FormattingHandler(RecordType.INDEX);
                ReporterFactory reporterFactory = new ReporterFactory(handler);
                IndexAccessor   accessor        = indexes.AccessorFor(onlineRule);
                if (!accessor.ConsistencyCheck(reporterFactory))
                {
                    rulesToRemove.Add(onlineRule);
                }
                handler.UpdateSummary();
                listener.Add(1);
            }
            foreach (StoreIndexDescriptor toRemove in rulesToRemove)
            {
                indexes.Remove(toRemove);
            }
        }
Exemple #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void buildCollisionInfo(System.Func<long, Object> inputIdLookup, long pessimisticNumberOfCollisions, org.neo4j.unsafe.impl.batchimport.input.Collector collector, org.neo4j.helpers.progress.ProgressListener progress) throws InterruptedException
        private void BuildCollisionInfo(System.Func <long, object> inputIdLookup, long pessimisticNumberOfCollisions, Collector collector, ProgressListener progress)
        {
            progress.Started("RESOLVE (~" + pessimisticNumberOfCollisions + " collisions)");
            Radix radix = _radixFactory.newInstance();

            _collisionNodeIdCache  = _cacheFactory.newByteArray(pessimisticNumberOfCollisions, new sbyte[COLLISION_ENTRY_SIZE]);
            _collisionTrackerCache = _trackerFactory.create(_cacheFactory, pessimisticNumberOfCollisions);
            _collisionValues       = _collisionValuesFactory.apply(pessimisticNumberOfCollisions);
            for (long nodeId = 0; nodeId <= _highestSetIndex; nodeId++)
            {
                long eId = _dataCache.get(nodeId);
                if (IsCollision(eId))
                {
                    // Store this collision input id for matching later in get()
                    long   collisionIndex         = _numberOfCollisions++;
                    object id                     = inputIdLookup(nodeId);
                    long   eIdFromInputId         = Encode(id);
                    long   eIdWithoutCollisionBit = ClearCollision(eId);
                    Debug.Assert(eIdFromInputId == eIdWithoutCollisionBit, format("Encoding mismatch during building of " + "collision info. input id %s (a %s) marked as collision where this id was encoded into " + "%d when put, but was now encoded into %d", id, id.GetType().Name, eIdWithoutCollisionBit, eIdFromInputId));
                    long offset = _collisionValues.add(id);
                    _collisionNodeIdCache.set5ByteLong(collisionIndex, 0, nodeId);
                    _collisionNodeIdCache.set6ByteLong(collisionIndex, 5, offset);

                    // The base of our sorting this time is going to be node id, so register that in the radix
                    radix.RegisterRadixOf(eIdWithoutCollisionBit);
                }
                progress.Add(1);
            }
            progress.Done();

            // Detect input id duplicates within the same group, with source information, line number and the works
            DetectDuplicateInputIds(radix, collector, progress);

            // We won't be needing these anymore
            _collisionTrackerCache.close();
            _collisionTrackerCache = null;
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldStartProcessAutomaticallyIfNotDoneBefore()
        public virtual void ShouldStartProcessAutomaticallyIfNotDoneBefore()
        {
            // given
            Indicator        indicator        = IndicatorMock();
            ProgressListener progressListener = Factory.mock(indicator, 10).singlePart(TestName.MethodName, 16);

            // when
            for (int i = 0; i < 16; i++)
            {
                progressListener.Add(1);
            }
            progressListener.Done();

            // then
            InOrder order = inOrder(indicator);

            order.verify(indicator, times(1)).startProcess(16);
            for (int i = 0; i < 10; i++)
            {
                order.verify(indicator).progress(i, i + 1);
            }
            order.verify(indicator).completeProcess();
            order.verifyNoMoreInteractions();
        }
Exemple #12
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");
            }
        }