use of org.neo4j.kernel.api.index.IndexPopulator in project neo4j by neo4j.
the class BatchingMultipleIndexPopulatorTest method pendingBatchesFlushedAfterStoreScan.
@Test
public void pendingBatchesFlushedAfterStoreScan() throws Exception {
NodeUpdates update1 = nodeUpdates(1, propertyId, "foo", labelId);
NodeUpdates update2 = nodeUpdates(2, propertyId, "bar", labelId);
NodeUpdates update3 = nodeUpdates(3, propertyId, "baz", labelId);
NodeUpdates update42 = nodeUpdates(4, 42, "42", 42);
IndexStoreView storeView = newStoreView(update1, update2, update3, update42);
BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(storeView, sameThreadExecutor(), NullLogProvider.getInstance());
IndexPopulator populator1 = addPopulator(batchingPopulator, index1);
IndexPopulator populator42 = addPopulator(batchingPopulator, index42);
batchingPopulator.indexAllNodes().run();
verify(populator1).add(Arrays.asList(forIndex(update1, index1), forIndex(update2, index1), forIndex(update3, index1)));
verify(populator42).add(singletonList(forIndex(update42, index42)));
}
use of org.neo4j.kernel.api.index.IndexPopulator in project neo4j by neo4j.
the class BatchingMultipleIndexPopulatorTest method populateFromQueuePopulatesWhenThresholdReached.
@Test
public void populateFromQueuePopulatesWhenThresholdReached() throws Exception {
setProperty(QUEUE_THRESHOLD_NAME, 2);
NeoStores neoStores = mock(NeoStores.class);
NodeStore nodeStore = mock(NodeStore.class);
when(neoStores.getNodeStore()).thenReturn(nodeStore);
NeoStoreIndexStoreView storeView = new NeoStoreIndexStoreView(LockService.NO_LOCK_SERVICE, neoStores);
BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(storeView, mock(ExecutorService.class), NullLogProvider.getInstance());
IndexPopulator populator1 = addPopulator(batchingPopulator, index1);
IndexUpdater updater1 = mock(IndexUpdater.class);
when(populator1.newPopulatingUpdater(any())).thenReturn(updater1);
IndexPopulator populator2 = addPopulator(batchingPopulator, index42);
IndexUpdater updater2 = mock(IndexUpdater.class);
when(populator2.newPopulatingUpdater(any())).thenReturn(updater2);
batchingPopulator.indexAllNodes();
IndexEntryUpdate update1 = IndexEntryUpdate.add(1, index1.schema(), "foo");
IndexEntryUpdate update2 = IndexEntryUpdate.add(2, index42.schema(), "bar");
IndexEntryUpdate update3 = IndexEntryUpdate.add(3, index1.schema(), "baz");
batchingPopulator.queue(update1);
batchingPopulator.queue(update2);
batchingPopulator.queue(update3);
batchingPopulator.populateFromQueue(42);
verify(updater1).process(update1);
verify(updater1).process(update3);
verify(updater2).process(update2);
}
use of org.neo4j.kernel.api.index.IndexPopulator in project neo4j by neo4j.
the class IndexPopulationJobTest method shouldPopulateIndexWithOneNode.
@Test
public void shouldPopulateIndexWithOneNode() throws Exception {
// GIVEN
String value = "Taylor";
long nodeId = createNode(map(name, value), FIRST);
IndexPopulator populator = spy(inMemoryPopulator(false));
IndexPopulationJob job = newIndexPopulationJob(populator, new FlippableIndexProxy(), false);
LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(0, 0);
// WHEN
job.run();
// THEN
IndexEntryUpdate update = IndexEntryUpdate.add(nodeId, descriptor, value);
verify(populator).create();
verify(populator).configureSampling(true);
verify(populator).includeSample(update);
verify(populator).add(anyListOf(IndexEntryUpdate.class));
verify(populator).sampleResult();
verify(populator).close(true);
verifyNoMoreInteractions(populator);
}
use of org.neo4j.kernel.api.index.IndexPopulator in project neo4j by neo4j.
the class IndexRecoveryIT method shouldBeAbleToRecoverAndUpdateOnlineIndex.
@Test
public void shouldBeAbleToRecoverAndUpdateOnlineIndex() throws Exception {
// Given
startDb();
IndexPopulator populator = mock(IndexPopulator.class);
when(mockedIndexProvider.getPopulator(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(populator);
when(populator.sampleResult()).thenReturn(new IndexSample());
IndexAccessor mockedAccessor = mock(IndexAccessor.class);
when(mockedAccessor.newUpdater(any(IndexUpdateMode.class))).thenReturn(SwallowingIndexUpdater.INSTANCE);
when(mockedIndexProvider.getOnlineAccessor(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(mockedAccessor);
createIndexAndAwaitPopulation(myLabel);
// rotate logs
rotateLogsAndCheckPoint();
// make updates
Set<IndexEntryUpdate> expectedUpdates = createSomeBananas(myLabel);
// And Given
killDb();
when(mockedIndexProvider.getInitialState(anyLong(), any(NewIndexDescriptor.class))).thenReturn(InternalIndexState.ONLINE);
GatheringIndexWriter writer = new GatheringIndexWriter();
when(mockedIndexProvider.getOnlineAccessor(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(writer);
// When
startDb();
// Then
assertThat(getIndexes(db, myLabel), inTx(db, hasSize(1)));
assertThat(getIndexes(db, myLabel), inTx(db, haveState(db, Schema.IndexState.ONLINE)));
verify(mockedIndexProvider, times(1)).getPopulator(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class));
// once when we create the index, and once when we restart the db
int onlineAccessorInvocationCount = 2;
verify(mockedIndexProvider, times(onlineAccessorInvocationCount)).getOnlineAccessor(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class));
assertEquals(expectedUpdates, writer.batchedUpdates);
for (IndexEntryUpdate update : writer.batchedUpdates) {
assertTrue(writer.recoveredNodes.contains(update.getEntityId()));
}
}
use of org.neo4j.kernel.api.index.IndexPopulator in project neo4j by neo4j.
the class IndexPopulationJobTest method shouldTransitionToFailedStateIfPopulationJobCrashes.
@Test
public void shouldTransitionToFailedStateIfPopulationJobCrashes() throws Exception {
// GIVEN
IndexPopulator failingPopulator = mock(IndexPopulator.class);
doThrow(new RuntimeException("BORK BORK")).when(failingPopulator).add(any());
FlippableIndexProxy index = new FlippableIndexProxy();
createNode(map(name, "Taylor"), FIRST);
IndexPopulationJob job = newIndexPopulationJob(failingPopulator, index, false);
// WHEN
job.run();
// THEN
assertThat(index.getState(), equalTo(InternalIndexState.FAILED));
}
Aggregations