//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToCancelPopulationJob() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToCancelPopulationJob()
        {
            // GIVEN
            CreateNode(map(_name, "Mattias"), _first);
            IndexPopulator      populator = mock(typeof(IndexPopulator));
            FlippableIndexProxy index     = mock(typeof(FlippableIndexProxy));
            IndexStoreView      storeView = mock(typeof(IndexStoreView));
            ControlledStoreScan storeScan = new ControlledStoreScan();

            when(storeView.VisitNodes(any(typeof(int[])), any(typeof(System.Func <int, bool>)), ArgumentMatchers.any(), ArgumentMatchers.any <Visitor <NodeLabelUpdate, Exception> >(), anyBoolean())).thenReturn(storeScan);

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final IndexPopulationJob job = newIndexPopulationJob(populator, index, storeView, org.neo4j.logging.NullLogProvider.getInstance(), org.neo4j.storageengine.api.EntityType.NODE, indexDescriptor(FIRST, name, false));
            IndexPopulationJob job = NewIndexPopulationJob(populator, index, storeView, NullLogProvider.Instance, EntityType.NODE, IndexDescriptor(_first, _name, false));

            OtherThreadExecutor <Void> populationJobRunner = Cleanup.add(new OtherThreadExecutor <Void>("Population job test runner", null));
            Future <Void> runFuture = populationJobRunner.ExecuteDontWait(state =>
            {
                job.Run();
                return(null);
            });

            storeScan.Latch.waitForAllToStart();
            job.Cancel().get();
            storeScan.Latch.waitForAllToFinish();

            // WHEN
            runFuture.get();

            // THEN
            verify(populator, times(1)).close(false);
            verify(index, never()).flip(any(), any());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void logConstraintJobProgress() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void LogConstraintJobProgress()
        {
            // Given
            CreateNode(map(_name, "irrelephant"), _first);
            AssertableLogProvider logProvider = new AssertableLogProvider();
            FlippableIndexProxy   index       = mock(typeof(FlippableIndexProxy));

            when(index.State).thenReturn(InternalIndexState.POPULATING);
            IndexPopulator populator = spy(IndexPopulator(false));

            try
            {
                IndexPopulationJob job = NewIndexPopulationJob(populator, index, _indexStoreView, logProvider, EntityType.NODE, IndexDescriptor(_first, _name, true));

                // When
                job.Run();

                // Then
                AssertableLogProvider.LogMatcherBuilder match = inLog(typeof(IndexPopulationJob));
                logProvider.AssertExactly(match.info("Index population started: [%s]", ":FIRST(name)"), match.info("Index created. Starting data checks. Index [%s] is %s.", ":FIRST(name)", "POPULATING"), match.info(containsString("TIME/PHASE Final: SCAN[")));
            }
            finally
            {
                populator.Close(true);
            }
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRemoveViaConcurrentIndexUpdatesWhilePopulating() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRemoveViaConcurrentIndexUpdatesWhilePopulating()
        {
            // GIVEN
            string             value1        = "Mattias";
            string             value2        = "Jacob";
            string             value3        = "Stefan";
            long               node1         = CreateNode(map(_name, value1), _first);
            long               node2         = CreateNode(map(_name, value2), _first);
            long               node3         = CreateNode(map(_name, value3), _first);
            int                propertyKeyId = GetPropertyKeyForName(_name);
            NodeDeletingWriter populator     = new NodeDeletingWriter(this, node2, propertyKeyId, value2, _labelId);
            IndexPopulationJob job           = NewIndexPopulationJob(populator, new FlippableIndexProxy(), EntityType.NODE, IndexDescriptor(_first, _name, false));

            populator.Job = job;

            // WHEN
            job.Run();

            // THEN
            IDictionary <long, object> expectedAdded = genericMap(node1, value1, node2, value2, node3, value3);

            assertEquals(expectedAdded, populator.Added);
            IDictionary <long, object> expectedRemoved = genericMap(node2, value2);

            assertEquals(expectedRemoved, populator.Removed);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIndexConcurrentUpdatesWhilePopulating() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldIndexConcurrentUpdatesWhilePopulating()
        {
            // GIVEN
            object value1       = "Mattias";
            object value2       = "Jacob";
            object value3       = "Stefan";
            object changedValue = "changed";
            long   node1        = CreateNode(map(_name, value1), _first);
            long   node2        = CreateNode(map(_name, value2), _first);
            long   node3        = CreateNode(map(_name, value3), _first);
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("UnnecessaryLocalVariable") long changeNode = node1;
            long changeNode              = node1;
            int  propertyKeyId           = GetPropertyKeyForName(_name);
            NodeChangingWriter populator = new NodeChangingWriter(this, changeNode, propertyKeyId, value1, changedValue, _labelId);
            IndexPopulationJob job       = NewIndexPopulationJob(populator, new FlippableIndexProxy(), EntityType.NODE, IndexDescriptor(_first, _name, false));

            populator.Job = job;

            // WHEN
            job.Run();

            // THEN
            ISet <Pair <long, object> > expected = asSet(Pair.of(node1, value1), Pair.of(node2, value2), Pair.of(node3, value3), Pair.of(node1, changedValue));

            assertEquals(expected, populator.Added);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPopulateIndexWithASmallDataset() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPopulateIndexWithASmallDataset()
        {
            // GIVEN
            string value = "Mattias";
            long   node1 = CreateNode(map(_name, value), _first);

            CreateNode(map(_name, value), _second);
            CreateNode(map(_age, 31), _first);
            long                  node4      = CreateNode(map(_age, 35, _name, value), _first);
            IndexPopulator        populator  = spy(IndexPopulator(false));
            LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(0, 0);
            IndexPopulationJob    job        = NewIndexPopulationJob(populator, new FlippableIndexProxy(), EntityType.NODE, IndexDescriptorFactory.forSchema(descriptor));

            // WHEN
            job.Run();

            // THEN
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> update1 = add(node1, descriptor, org.neo4j.values.storable.Values.of(value));
            IndexEntryUpdate <object> update1 = add(node1, descriptor, Values.of(value));
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> update2 = add(node4, descriptor, org.neo4j.values.storable.Values.of(value));
            IndexEntryUpdate <object> update2 = add(node4, descriptor, Values.of(value));

            verify(populator).create();
            verify(populator).includeSample(update1);
            verify(populator).includeSample(update2);
            verify(populator, times(2)).add(anyCollection());
            verify(populator).sampleResult();
            verify(populator).close(true);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCloseMultiPopulatorOnSuccessfulPopulation()
        public virtual void ShouldCloseMultiPopulatorOnSuccessfulPopulation()
        {
            // given
            NullLogProvider logProvider = NullLogProvider.Instance;
            TrackingMultipleIndexPopulator populator     = new TrackingMultipleIndexPopulator(IndexStoreView_Fields.Empty, logProvider, EntityType.NODE, new DatabaseSchemaState(logProvider));
            IndexPopulationJob             populationJob = new IndexPopulationJob(populator, NO_MONITOR, false);

            // when
            populationJob.Run();

            // then
            assertTrue(populator.Closed);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCloseMultiPopulatorOnFailedPopulation()
        public virtual void ShouldCloseMultiPopulatorOnFailedPopulation()
        {
            // given
            NullLogProvider logProvider                  = NullLogProvider.Instance;
            IndexStoreView  failingStoreView             = new IndexStoreView_AdaptorAnonymousInnerClass(this);
            TrackingMultipleIndexPopulator populator     = new TrackingMultipleIndexPopulator(failingStoreView, logProvider, EntityType.NODE, new DatabaseSchemaState(logProvider));
            IndexPopulationJob             populationJob = new IndexPopulationJob(populator, NO_MONITOR, false);

            // when
            populationJob.Run();

            // then
            assertTrue(populator.Closed);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFlipToFailedUsingFailedIndexProxyFactory() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFlipToFailedUsingFailedIndexProxyFactory()
        {
            // Given
            FailedIndexProxyFactory failureDelegateFactory = mock(typeof(FailedIndexProxyFactory));
            IndexPopulator          populator = spy(IndexPopulator(false));
            IndexPopulationJob      job       = NewIndexPopulationJob(failureDelegateFactory, populator, new FlippableIndexProxy(), _indexStoreView, NullLogProvider.Instance, EntityType.NODE, IndexDescriptor(_first, _name, false));

            System.InvalidOperationException failure = new System.InvalidOperationException("not successful");
            doThrow(failure).when(populator).close(true);

            // When
            job.Run();

            // Then
            verify(failureDelegateFactory).create(any(typeof(Exception)));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTransitionToFailedStateIfPopulationJobCrashes() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTransitionToFailedStateIfPopulationJobCrashes()
        {
            // GIVEN
            IndexPopulator failingPopulator = mock(typeof(IndexPopulator));

            doThrow(new Exception("BORK BORK")).when(failingPopulator).add(any(typeof(System.Collections.ICollection)));

            FlippableIndexProxy index = new FlippableIndexProxy();

            CreateNode(map(_name, "Taylor"), _first);
            IndexPopulationJob job = NewIndexPopulationJob(failingPopulator, index, EntityType.NODE, IndexDescriptor(_first, _name, false));

            // WHEN
            job.Run();

            // THEN
            assertThat(index.State, equalTo(InternalIndexState.FAILED));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFlushSchemaStateAfterPopulation() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFlushSchemaStateAfterPopulation()
        {
            // GIVEN
            string value = "Taylor";

            CreateNode(map(_name, value), _first);
            _stateHolder.put("key", "original_value");
            IndexPopulator     populator = spy(IndexPopulator(false));
            IndexPopulationJob job       = NewIndexPopulationJob(populator, new FlippableIndexProxy(), EntityType.NODE, IndexDescriptor(_first, _name, false));

            // WHEN
            job.Run();

            // THEN
            string result = _stateHolder.get("key");

            assertNull(result);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCloseAndFailOnFailure() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldCloseAndFailOnFailure()
        {
            CreateNode(map(_name, "irrelephant"), _first);
            LogProvider         logProvider = NullLogProvider.Instance;
            FlippableIndexProxy index       = mock(typeof(FlippableIndexProxy));
            IndexPopulator      populator   = spy(IndexPopulator(false));
            IndexPopulationJob  job         = NewIndexPopulationJob(populator, index, _indexStoreView, logProvider, EntityType.NODE, IndexDescriptor(_first, _name, false));

            string failureMessage = "not successful";

            System.InvalidOperationException failure = new System.InvalidOperationException(failureMessage);
            doThrow(failure).when(populator).create();

            // When
            job.Run();

            // Then
            verify(populator).markAsFailed(contains(failureMessage));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLogJobFailure() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLogJobFailure()
        {
            // Given
            CreateNode(map(_name, "irrelephant"), _first);
            AssertableLogProvider logProvider = new AssertableLogProvider();
            FlippableIndexProxy   index       = mock(typeof(FlippableIndexProxy));
            IndexPopulator        populator   = spy(IndexPopulator(false));
            IndexPopulationJob    job         = NewIndexPopulationJob(populator, index, _indexStoreView, logProvider, EntityType.NODE, IndexDescriptor(_first, _name, false));

            Exception failure = new System.InvalidOperationException("not successful");

            doThrow(failure).when(populator).create();

            // When
            job.Run();

            // Then
            AssertableLogProvider.LogMatcherBuilder match = inLog(typeof(IndexPopulationJob));
            logProvider.AssertAtLeastOnce(match.error(@is("Failed to populate index: [:FIRST(name)]"), sameInstance(failure)));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPopulateRelatonshipIndexWithASmallDataset() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPopulateRelatonshipIndexWithASmallDataset()
        {
            // GIVEN
            string value = "Philip J.Fry";
            long   node1 = CreateNode(map(_name, value), _first);
            long   node2 = CreateNode(map(_name, value), _second);
            long   node3 = CreateNode(map(_age, 31), _first);
            long   node4 = CreateNode(map(_age, 35, _name, value), _first);

            long rel1 = CreateRelationship(map(_name, value), _likes, node1, node3);

            CreateRelationship(map(_name, value), _knows, node3, node1);
            CreateRelationship(map(_age, 31), _likes, node2, node1);
            long rel4 = CreateRelationship(map(_age, 35, _name, value), _likes, node4, node4);

            IndexDescriptor    descriptor = IndexDescriptorFactory.forSchema(SchemaDescriptorFactory.forRelType(0, 0));
            IndexPopulator     populator  = spy(IndexPopulator(descriptor));
            IndexPopulationJob job        = NewIndexPopulationJob(populator, new FlippableIndexProxy(), EntityType.RELATIONSHIP, descriptor);

            // WHEN
            job.Run();

            // THEN
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> update1 = add(rel1, descriptor, org.neo4j.values.storable.Values.of(value));
            IndexEntryUpdate <object> update1 = add(rel1, descriptor, Values.of(value));
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> update2 = add(rel4, descriptor, org.neo4j.values.storable.Values.of(value));
            IndexEntryUpdate <object> update2 = add(rel4, descriptor, Values.of(value));

            verify(populator).create();
            verify(populator).includeSample(update1);
            verify(populator).includeSample(update2);
            verify(populator, times(2)).add(anyCollection());
            verify(populator).sampleResult();
            verify(populator).close(true);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPopulateIndexWithOneRelationship() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPopulateIndexWithOneRelationship()
        {
            // GIVEN
            string             value        = "Taylor";
            long               nodeId       = CreateNode(map(_name, value), _first);
            long               relationship = CreateRelationship(map(_name, _age), _likes, nodeId, nodeId);
            IndexDescriptor    descriptor   = IndexDescriptorFactory.forSchema(SchemaDescriptorFactory.forRelType(0, 0));
            IndexPopulator     populator    = spy(IndexPopulator(descriptor));
            IndexPopulationJob job          = NewIndexPopulationJob(populator, new FlippableIndexProxy(), EntityType.RELATIONSHIP, descriptor);

            // WHEN
            job.Run();

            // THEN
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.kernel.api.index.IndexEntryUpdate<?> update = org.neo4j.kernel.api.index.IndexEntryUpdate.add(relationship, descriptor, org.neo4j.values.storable.Values.of(age));
            IndexEntryUpdate <object> update = IndexEntryUpdate.add(relationship, descriptor, Values.of(_age));

            verify(populator).create();
            verify(populator).includeSample(update);
            verify(populator, times(2)).add(any(typeof(System.Collections.ICollection)));
            verify(populator).sampleResult();
            verify(populator).close(true);
        }