Search in sources :

Example 16 with IndexEntryUpdate

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);
}
Also used : NeoStoreIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) NodeStore(org.neo4j.kernel.impl.store.NodeStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores) ExecutorService(java.util.concurrent.ExecutorService) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.Test)

Example 17 with IndexEntryUpdate

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);
}
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 18 with IndexEntryUpdate

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()));
    }
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexSample(org.neo4j.storageengine.api.schema.IndexSample) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) Test(org.junit.Test)

Example 19 with IndexEntryUpdate

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);
}
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 20 with IndexEntryUpdate

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);
}
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)

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