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));
}
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());
}
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);
}
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)));
}
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));
}
Aggregations