use of org.neo4j.kernel.api.index.IndexEntryUpdate 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.IndexEntryUpdate 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.IndexEntryUpdate 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.IndexEntryUpdate in project neo4j by neo4j.
the class MultipleIndexPopulatorTest method testPropertyUpdateFailure.
@Test
public void testPropertyUpdateFailure() throws IOException, IndexEntryConflictException {
IndexEntryUpdate propertyUpdate = createIndexEntryUpdate(index1);
IndexUpdater indexUpdater1 = mock(IndexUpdater.class);
IndexPopulator indexPopulator1 = createIndexPopulator(indexUpdater1);
addPopulator(indexPopulator1, 1);
doThrow(getPopulatorException()).when(indexUpdater1).process(propertyUpdate);
IndexUpdater multipleIndexUpdater = multipleIndexPopulator.newPopulatingUpdater(mock(PropertyAccessor.class));
multipleIndexUpdater.process(propertyUpdate);
verify(indexUpdater1).close();
checkPopulatorFailure(indexPopulator1);
}
use of org.neo4j.kernel.api.index.IndexEntryUpdate in project neo4j by neo4j.
the class MultipleIndexPopulatorTest method testNonApplicableUpdaterDoNotUpdatePopulator.
@Test
public void testNonApplicableUpdaterDoNotUpdatePopulator() throws IOException, IndexEntryConflictException {
IndexUpdater indexUpdater1 = mock(IndexUpdater.class);
IndexPopulator indexPopulator1 = createIndexPopulator(indexUpdater1);
addPopulator(indexPopulator1, 2);
IndexUpdater multipleIndexUpdater = multipleIndexPopulator.newPopulatingUpdater(mock(PropertyAccessor.class));
IndexEntryUpdate propertyUpdate = createIndexEntryUpdate(index1);
multipleIndexUpdater.process(propertyUpdate);
verifyZeroInteractions(indexUpdater1);
}
Aggregations