use of org.neo4j.kernel.api.index.IndexEntryUpdate in project neo4j by neo4j.
the class IndexPopulationJobTest method shouldPopulateIndexWithASmallDataset.
@Test
public void shouldPopulateIndexWithASmallDataset() throws Exception {
// GIVEN
String value = "Mattias";
long node1 = createNode(map(name, value), FIRST);
createNode(map(name, value), SECOND);
createNode(map(age, 31), FIRST);
long node4 = createNode(map(age, 35, 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 update1 = IndexEntryUpdate.add(node1, descriptor, value);
IndexEntryUpdate update2 = add(node4, descriptor, value);
verify(populator).create();
verify(populator).configureSampling(true);
verify(populator).includeSample(update1);
verify(populator).includeSample(update2);
verify(populator, times(2)).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 MultipleIndexPopulatorTest method testMultiplePopulatorUpdater.
@Test
public void testMultiplePopulatorUpdater() throws IOException, IndexEntryConflictException {
IndexUpdater indexUpdater1 = mock(IndexUpdater.class);
IndexPopulator indexPopulator1 = createIndexPopulator(indexUpdater1);
IndexPopulator indexPopulator2 = createIndexPopulator();
addPopulator(indexPopulator1, 1);
addPopulator(indexPopulator2, 2);
doThrow(getPopulatorException()).when(indexPopulator2).newPopulatingUpdater(any(PropertyAccessor.class));
IndexUpdater multipleIndexUpdater = multipleIndexPopulator.newPopulatingUpdater(mock(PropertyAccessor.class));
IndexEntryUpdate propertyUpdate = createIndexEntryUpdate(index1);
multipleIndexUpdater.process(propertyUpdate);
checkPopulatorFailure(indexPopulator2);
verify(indexUpdater1).process(propertyUpdate);
}
use of org.neo4j.kernel.api.index.IndexEntryUpdate in project neo4j by neo4j.
the class MultipleIndexPopulatorTest method testMultiplePropertyUpdateFailures.
@Test
public void testMultiplePropertyUpdateFailures() throws IOException, IndexEntryConflictException {
PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
IndexEntryUpdate update1 = IndexEntryUpdate.add(1, index1, "foo");
IndexEntryUpdate update2 = IndexEntryUpdate.add(2, index1, "bar");
IndexUpdater updater = mock(IndexUpdater.class);
IndexPopulator populator = createIndexPopulator(updater);
addPopulator(populator, 1);
doThrow(getPopulatorException()).when(updater).process(any(IndexEntryUpdate.class));
IndexUpdater multipleIndexUpdater = multipleIndexPopulator.newPopulatingUpdater(propertyAccessor);
multipleIndexUpdater.process(update1);
multipleIndexUpdater.process(update2);
verify(updater).process(update1);
verify(updater, never()).process(update2);
verify(updater).close();
checkPopulatorFailure(populator);
}
use of org.neo4j.kernel.api.index.IndexEntryUpdate in project neo4j by neo4j.
the class NodeStoreScanTest method shouldGiveBackCompletionPercentage.
@Test
public void shouldGiveBackCompletionPercentage() throws Throwable {
// given
final int total = 10;
when(nodeStore.getHighId()).thenReturn((long) total);
NodeRecord inUseRecord = new NodeRecord(42);
inUseRecord.setInUse(true);
when(nodeStore.getRecord(anyLong(), any(NodeRecord.class), any(RecordLoad.class))).thenReturn(inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord, inUseRecord);
final PercentageSupplier percentageSupplier = new PercentageSupplier();
final NodeStoreScan scan = new NodeStoreScan(nodeStore, locks, total) {
private int read = 0;
@Override
public void acceptUpdate(MultipleIndexPopulator.MultipleIndexUpdater updater, IndexEntryUpdate update, long currentlyIndexedNodeId) {
// no-op
}
@Override
public void configure(List list) {
// no-op
}
@Override
public void process(NodeRecord node) {
// then
read++;
float expected = (float) read / total;
float actual = percentageSupplier.get();
assertEquals(String.format("%f==%f", expected, actual), expected, actual, 0.0);
}
};
percentageSupplier.setStoreScan(scan);
// when
scan.run();
}
use of org.neo4j.kernel.api.index.IndexEntryUpdate in project neo4j by neo4j.
the class MultipleIndexPopulator method populateFromQueueIfAvailable.
private void populateFromQueueIfAvailable(long currentlyIndexedNodeId) {
if (!queue.isEmpty()) {
try (MultipleIndexUpdater updater = newPopulatingUpdater(storeView)) {
do {
// no need to check for null as nobody else is emptying this queue
IndexEntryUpdate update = queue.poll();
storeScan.acceptUpdate(updater, update, currentlyIndexedNodeId);
} while (!queue.isEmpty());
}
}
}
Aggregations