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 IndexingServiceTest method shouldDeliverUpdatesThatOccurDuringPopulationToPopulator.
@SuppressWarnings("unchecked")
@Test
public void shouldDeliverUpdatesThatOccurDuringPopulationToPopulator() throws Exception {
// given
when(populator.newPopulatingUpdater(storeView)).thenReturn(updater);
CountDownLatch latch = new CountDownLatch(1);
doAnswer(afterAwaiting(latch)).when(populator).add(anyList());
IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData(addNodeUpdate(1, "value1")));
life.start();
// when
indexingService.createIndexes(IndexRule.indexRule(0, index, PROVIDER_DESCRIPTOR));
IndexProxy proxy = indexingService.getIndexProxy(0);
assertEquals(InternalIndexState.POPULATING, proxy.getState());
IndexEntryUpdate value2 = add(2, "value2");
try (IndexUpdater updater = proxy.newUpdater(IndexUpdateMode.ONLINE)) {
updater.process(value2);
}
latch.countDown();
waitForIndexesToComeOnline(indexingService, 0);
verify(populator, timeout(1000)).close(true);
// then
assertEquals(InternalIndexState.ONLINE, proxy.getState());
InOrder order = inOrder(populator, accessor, updater);
order.verify(populator).create();
order.verify(populator).includeSample(add(1, "value1"));
order.verify(populator).add(Mockito.anyListOf(IndexEntryUpdate.class));
// invoked from indexAllNodes(), empty because the id we added (2) is bigger than the one we indexed (1)
//
// (We don't get an update for value2 here because we mock a fake store that doesn't contain it
// just for the purpose of testing this behavior)
order.verify(populator).newPopulatingUpdater(storeView);
order.verify(updater).close();
order.verify(populator).sampleResult();
order.verify(populator).close(true);
verifyNoMoreInteractions(updater);
verifyNoMoreInteractions(populator);
verifyZeroInteractions(accessor);
}
use of org.neo4j.kernel.api.index.IndexEntryUpdate in project neo4j by neo4j.
the class IndexRecoveryIT method createSomeBananas.
private Set<IndexEntryUpdate> createSomeBananas(Label label) {
Set<IndexEntryUpdate> updates = new HashSet<>();
try (Transaction tx = db.beginTx()) {
ThreadToStatementContextBridge ctxSupplier = db.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
try (Statement statement = ctxSupplier.get()) {
int labelId = statement.readOperations().labelGetForName(label.name());
int propertyKeyId = statement.readOperations().propertyKeyGetForName(key);
LabelSchemaDescriptor schemaDescriptor = SchemaDescriptorFactory.forLabel(labelId, propertyKeyId);
for (int number : new int[] { 4, 10 }) {
Node node = db.createNode(label);
node.setProperty(key, number);
updates.add(IndexEntryUpdate.add(node.getId(), schemaDescriptor, number));
}
}
tx.success();
return updates;
}
}
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);
}
Aggregations