Esempio n. 1
0
//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());
        }
Esempio n. 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") private static IndexStoreView newStoreView(EntityUpdates... updates)
        private static IndexStoreView NewStoreView(params EntityUpdates[] updates)
        {
            IndexStoreView storeView = mock(typeof(IndexStoreView));

            when(storeView.VisitNodes(any(), any(), any(), any(), anyBoolean())).thenAnswer(invocation =>
            {
                Visitor <EntityUpdates, IndexPopulationFailedKernelException> visitorArg = invocation.getArgument(2);
                return(new IndexEntryUpdateScan(updates, visitorArg));
            });
            return(storeView);
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test @SuppressWarnings("unchecked") public void executorForcefullyShutdownIfStoreScanFails() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ExecutorForcefullyShutdownIfStoreScanFails()
        {
            IndexStoreView        storeView        = mock(typeof(IndexStoreView));
            StoreScan <Exception> failingStoreScan = mock(typeof(StoreScan));
            Exception             scanError        = new Exception();

            doThrow(scanError).when(failingStoreScan).run();
            when(storeView.VisitNodes(any(), any(), any(), any(), anyBoolean())).thenReturn(failingStoreScan);

            ExecutorService executor = ImmediateExecutor();

            when(executor.awaitTermination(anyLong(), any())).thenReturn(true);

            BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(storeView, executor, NullLogProvider.Instance, mock(typeof(SchemaState)));

            StoreScan <IndexPopulationFailedKernelException> storeScan = batchingPopulator.IndexAllEntities();

            verify(executor, never()).shutdown();

            try
            {
                storeScan.Run();
                fail("Exception expected");
            }
            catch (Exception t)
            {
                assertSame(scanError, t);
            }

            verify(executor, never()).shutdownNow();
            verify(executor, never()).awaitTermination(anyLong(), any());

            batchingPopulator.Close(false);
            verify(executor).shutdownNow();
            verify(executor).awaitTermination(anyLong(), any());
        }