Search in sources :

Example 36 with IndexPopulator

use of org.neo4j.kernel.api.index.IndexPopulator in project neo4j by neo4j.

the class IndexPopulationJobTest method shouldCloseAndFailOnFailure.

@Test
public void shouldCloseAndFailOnFailure() throws Exception {
    createNode(map(name, "irrelephant"), FIRST);
    LogProvider logProvider = NullLogProvider.getInstance();
    FlippableIndexProxy index = mock(FlippableIndexProxy.class);
    IndexPopulator populator = spy(inMemoryPopulator(false));
    IndexPopulationJob job = newIndexPopulationJob(populator, index, indexStoreView, logProvider, false);
    String failureMessage = "not successful";
    IllegalStateException failure = new IllegalStateException(failureMessage);
    doThrow(failure).when(populator).create();
    // When
    job.run();
    // Then
    verify(populator).markAsFailed(Matchers.contains(failureMessage));
}
Also used : NullLogProvider(org.neo4j.logging.NullLogProvider) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) LogProvider(org.neo4j.logging.LogProvider) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) Test(org.junit.Test)

Example 37 with IndexPopulator

use of org.neo4j.kernel.api.index.IndexPopulator in project neo4j by neo4j.

the class IndexPopulationJobTest method shouldBeAbleToCancelPopulationJob.

@Test
public void shouldBeAbleToCancelPopulationJob() throws Exception {
    // GIVEN
    createNode(map(name, "Mattias"), FIRST);
    IndexPopulator populator = mock(IndexPopulator.class);
    FlippableIndexProxy index = mock(FlippableIndexProxy.class);
    IndexStoreView storeView = mock(IndexStoreView.class);
    ControlledStoreScan storeScan = new ControlledStoreScan();
    when(storeView.visitNodes(any(int[].class), any(IntPredicate.class), Matchers.<Visitor<NodeUpdates, RuntimeException>>any(), Matchers.<Visitor<NodeLabelUpdate, RuntimeException>>any(), anyBoolean())).thenReturn(storeScan);
    final IndexPopulationJob job = newIndexPopulationJob(populator, index, storeView, NullLogProvider.getInstance(), false);
    OtherThreadExecutor<Void> populationJobRunner = cleanup.add(new OtherThreadExecutor<>("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, times(0)).flip(Matchers.any(), Matchers.any());
}
Also used : IntPredicate(java.util.function.IntPredicate) NodeLabelUpdate(org.neo4j.kernel.api.labelscan.NodeLabelUpdate) NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) Test(org.junit.Test)

Example 38 with IndexPopulator

use of org.neo4j.kernel.api.index.IndexPopulator in project neo4j by neo4j.

the class IndexPopulationJobTest method shouldFlushSchemaStateAfterPopulation.

@Test
public void shouldFlushSchemaStateAfterPopulation() throws Exception {
    // GIVEN
    String value = "Taylor";
    createNode(map(name, value), FIRST);
    stateHolder.apply(MapUtil.stringMap("key", "original_value"));
    IndexPopulator populator = spy(inMemoryPopulator(false));
    IndexPopulationJob job = newIndexPopulationJob(populator, new FlippableIndexProxy(), false);
    // WHEN
    job.run();
    // THEN
    String result = stateHolder.get("key");
    assertEquals(null, result);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) Test(org.junit.Test)

Example 39 with IndexPopulator

use of org.neo4j.kernel.api.index.IndexPopulator in project neo4j by neo4j.

the class IndexPopulationJobTest method shouldLogJobFailure.

@Test
public void shouldLogJobFailure() throws Exception {
    // Given
    createNode(map(name, "irrelephant"), FIRST);
    AssertableLogProvider logProvider = new AssertableLogProvider();
    FlippableIndexProxy index = mock(FlippableIndexProxy.class);
    IndexPopulator populator = spy(inMemoryPopulator(false));
    IndexPopulationJob job = newIndexPopulationJob(populator, index, indexStoreView, logProvider, false);
    Throwable failure = new IllegalStateException("not successful");
    doThrow(failure).when(populator).create();
    // When
    job.run();
    // Then
    LogMatcherBuilder match = inLog(IndexPopulationJob.class);
    logProvider.assertAtLeastOnce(match.error(is("Failed to populate index: [:FIRST(name)]"), sameInstance(failure)));
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) LogMatcherBuilder(org.neo4j.logging.AssertableLogProvider.LogMatcherBuilder) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider) Test(org.junit.Test)

Example 40 with IndexPopulator

use of org.neo4j.kernel.api.index.IndexPopulator in project neo4j by neo4j.

the class MultipleIndexPopulatorUpdatesTest method updateForHigherNodeIgnoredWhenUsingFullNodeStoreScan.

@Test
public void updateForHigherNodeIgnoredWhenUsingFullNodeStoreScan() throws IndexPopulationFailedKernelException, IOException, IndexEntryConflictException {
    NeoStores neoStores = Mockito.mock(NeoStores.class);
    CountsTracker countsTracker = mock(CountsTracker.class);
    NodeStore nodeStore = mock(NodeStore.class);
    PropertyStore propertyStore = mock(PropertyStore.class);
    NodeRecord nodeRecord = getNodeRecord();
    PropertyRecord propertyRecord = getPropertyRecord();
    when(neoStores.getCounts()).thenReturn(countsTracker);
    when(neoStores.getNodeStore()).thenReturn(nodeStore);
    when(neoStores.getPropertyStore()).thenReturn(propertyStore);
    when(propertyStore.getPropertyRecordChain(anyInt())).thenReturn(Collections.singletonList(propertyRecord));
    when(countsTracker.nodeCount(anyInt(), any(Register.DoubleLongRegister.class))).thenReturn(Registers.newDoubleLongRegister(3, 3));
    when(nodeStore.getHighestPossibleIdInUse()).thenReturn(20L);
    when(nodeStore.newRecord()).thenReturn(nodeRecord);
    when(nodeStore.getRecord(anyInt(), eq(nodeRecord), any(RecordLoad.class))).thenAnswer(new SetNodeIdRecordAnswer(nodeRecord, 1));
    when(nodeStore.getRecord(eq(7L), eq(nodeRecord), any(RecordLoad.class))).thenAnswer(new SetNodeIdRecordAnswer(nodeRecord, 7));
    ProcessListenableNeoStoreIndexView storeView = new ProcessListenableNeoStoreIndexView(LockService.NO_LOCK_SERVICE, neoStores);
    MultipleIndexPopulator indexPopulator = new MultipleIndexPopulator(storeView, logProvider);
    storeView.setProcessListener(new NodeUpdateProcessListener(indexPopulator));
    IndexPopulator populator = createIndexPopulator();
    IndexUpdater indexUpdater = mock(IndexUpdater.class);
    when(populator.newPopulatingUpdater(storeView)).thenReturn(indexUpdater);
    addPopulator(indexPopulator, populator, 1, NewIndexDescriptorFactory.forLabel(1, 1));
    indexPopulator.create();
    StoreScan<IndexPopulationFailedKernelException> storeScan = indexPopulator.indexAllNodes();
    storeScan.run();
    Mockito.verify(indexUpdater, times(0)).process(any(IndexEntryUpdate.class));
}
Also used : IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) RecordLoad(org.neo4j.kernel.impl.store.record.RecordLoad) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) NodeStore(org.neo4j.kernel.impl.store.NodeStore) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NeoStores(org.neo4j.kernel.impl.store.NeoStores) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) Test(org.junit.Test)

Aggregations

IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)45 Test (org.junit.Test)37 IndexEntryUpdate (org.neo4j.kernel.api.index.IndexEntryUpdate)11 PropertyAccessor (org.neo4j.kernel.api.index.PropertyAccessor)8 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)7 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)7 NeoStoreIndexStoreView (org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView)7 NodeUpdates (org.neo4j.kernel.api.index.NodeUpdates)6 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)6 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)6 BatchInserter (org.neo4j.unsafe.batchinsert.BatchInserter)5 ExecutorService (java.util.concurrent.ExecutorService)3 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)3 IndexPopulation (org.neo4j.kernel.impl.api.index.MultipleIndexPopulator.IndexPopulation)3 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 NodeStore (org.neo4j.kernel.impl.store.NodeStore)3 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)3 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)3 IntPredicate (java.util.function.IntPredicate)2 NodeLabelUpdate (org.neo4j.kernel.api.labelscan.NodeLabelUpdate)2