Search in sources :

Example 6 with IndexEntryUpdate

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);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) Test(org.junit.Test)

Example 7 with IndexEntryUpdate

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);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.Test)

Example 8 with IndexEntryUpdate

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);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.Test)

Example 9 with IndexEntryUpdate

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();
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) NodeStoreScan(org.neo4j.kernel.impl.transaction.state.storeview.NodeStoreScan) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) List(java.util.List) RecordLoad(org.neo4j.kernel.impl.store.record.RecordLoad) Test(org.junit.Test)

Example 10 with IndexEntryUpdate

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());
        }
    }
}
Also used : IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate)

Aggregations

IndexEntryUpdate (org.neo4j.kernel.api.index.IndexEntryUpdate)20 Test (org.junit.Test)16 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)10 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)7 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)5 PropertyAccessor (org.neo4j.kernel.api.index.PropertyAccessor)4 IndexSample (org.neo4j.storageengine.api.schema.IndexSample)4 NeoStoreIndexStoreView (org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView)3 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)2 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)2 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2 NodeStore (org.neo4j.kernel.impl.store.NodeStore)2 File (java.io.File)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Boolean.parseBoolean (java.lang.Boolean.parseBoolean)1 ArrayList (java.util.ArrayList)1