Search in sources :

Example 51 with IndexRule

use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.

the class NeoTransactionIndexApplierTest method shouldCreateIndexGivenCreateSchemaRuleCommand.

@Test
public void shouldCreateIndexGivenCreateSchemaRuleCommand() throws Exception {
    // Given
    final IndexRule indexRule = indexRule(1, 42, 42, INDEX_DESCRIPTOR);
    final IndexBatchTransactionApplier applier = newIndexTransactionApplier();
    final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(emptyDynamicRecords, singleton(createdDynamicRecord(1)), indexRule);
    // When
    boolean result;
    try (TransactionApplier txApplier = applier.startTx(transactionToApply)) {
        result = txApplier.visitSchemaRuleCommand(command);
    }
    // Then
    assertFalse(result);
    verify(indexingService).createIndexes(indexRule);
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) TransactionApplier(org.neo4j.kernel.impl.api.TransactionApplier) Test(org.junit.Test)

Example 52 with IndexRule

use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.

the class NeoTransactionIndexApplierTest method shouldDropIndexGivenDropSchemaRuleCommand.

@Test
public void shouldDropIndexGivenDropSchemaRuleCommand() throws Exception {
    // Given
    final IndexRule indexRule = indexRule(1, 42, 42, INDEX_DESCRIPTOR);
    final IndexBatchTransactionApplier applier = newIndexTransactionApplier();
    final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(singleton(createdDynamicRecord(1)), singleton(dynamicRecord(1, false)), indexRule);
    // When
    boolean result;
    try (TransactionApplier txApplier = applier.startTx(transactionToApply)) {
        result = txApplier.visitSchemaRuleCommand(command);
    }
    // Then
    assertFalse(result);
    verify(indexingService).dropIndex(indexRule);
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) TransactionApplier(org.neo4j.kernel.impl.api.TransactionApplier) Test(org.junit.Test)

Example 53 with IndexRule

use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyCreateIndexRuleSchemaRuleCommandToTheStoreInRecovery.

@Test
public void shouldApplyCreateIndexRuleSchemaRuleCommandToTheStoreInRecovery() throws Exception {
    // given
    final BatchTransactionApplier applier = newApplierFacade(newIndexApplier(), newApplier(true));
    final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
    record.setCreated();
    final Collection<DynamicRecord> recordsAfter = Arrays.asList(record);
    final IndexRule rule = indexRule(0, 1, 2, new SchemaIndexProvider.Descriptor("K", "X.Y"));
    final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(Collections.<DynamicRecord>emptyList(), recordsAfter, rule);
    // when
    boolean result = apply(applier, command::handle, transactionToApply);
    // then
    assertFalse(result);
    verify(schemaStore, times(1)).setHighestPossibleIdInUse(record.getId());
    verify(schemaStore, times(1)).updateRecord(record);
    verify(indexingService, times(1)).createIndexes(rule);
    verify(cacheAccess, times(1)).addSchemaRule(rule);
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Example 54 with IndexRule

use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.

the class IndexingServiceIntegrationTest method testManualIndexPopulation.

@Test
public void testManualIndexPopulation() throws IOException, IndexNotFoundKernelException, InterruptedException {
    IndexingService indexingService = getIndexingService(database);
    SchemaStore schemaStore = getSchemaStore(database);
    LabelTokenHolder labelTokenHolder = getLabelTokenHolder(database);
    PropertyKeyTokenHolder propertyKeyTokenHolder = getPropertyKeyTokenHolder(database);
    int foodId = labelTokenHolder.getIdByName(FOOD_LABEL);
    int propertyId = propertyKeyTokenHolder.getIdByName(PROPERTY_NAME);
    IndexRule rule = IndexRule.indexRule(schemaStore.nextId(), NewIndexDescriptorFactory.forLabel(foodId, propertyId), indexDescriptor);
    indexingService.createIndexes(rule);
    IndexProxy indexProxy = indexingService.getIndexProxy(rule.getId());
    waitIndexOnline(indexProxy);
    assertEquals(InternalIndexState.ONLINE, indexProxy.getState());
    PopulationProgress progress = indexProxy.getIndexPopulationProgress();
    assertEquals(progress.getCompleted(), progress.getTotal());
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) PopulationProgress(org.neo4j.storageengine.api.schema.PopulationProgress) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) PropertyKeyTokenHolder(org.neo4j.kernel.impl.core.PropertyKeyTokenHolder) LabelTokenHolder(org.neo4j.kernel.impl.core.LabelTokenHolder) Test(org.junit.Test)

Example 55 with IndexRule

use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.

the class IndexingServiceTest method shouldCreateMultipleIndexesInOneCall.

@Test
public void shouldCreateMultipleIndexesInOneCall() throws Exception {
    // GIVEN
    IndexingService.Monitor monitor = IndexingService.NO_MONITOR;
    IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, accessor, withData(addNodeUpdate(0, "value", 1)), monitor);
    life.start();
    // WHEN
    IndexRule indexRule1 = indexRule(0, 0, 0, PROVIDER_DESCRIPTOR);
    IndexRule indexRule2 = indexRule(1, 0, 1, PROVIDER_DESCRIPTOR);
    IndexRule indexRule3 = indexRule(2, 1, 0, PROVIDER_DESCRIPTOR);
    indexing.createIndexes(indexRule1, indexRule2, indexRule3);
    // THEN
    verify(indexProvider).getPopulator(eq(0L), eq(NewIndexDescriptorFactory.forLabel(0, 0)), any(IndexSamplingConfig.class));
    verify(indexProvider).getPopulator(eq(1L), eq(NewIndexDescriptorFactory.forLabel(0, 1)), any(IndexSamplingConfig.class));
    verify(indexProvider).getPopulator(eq(2L), eq(NewIndexDescriptorFactory.forLabel(1, 0)), any(IndexSamplingConfig.class));
    waitForIndexesToComeOnline(indexing, 0, 1, 2);
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) Test(org.junit.Test)

Aggregations

IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)60 Test (org.junit.Test)42 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)24 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)22 SchemaRuleUtil.constraintIndexRule (org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule)14 NodePropertyDescriptor (org.neo4j.kernel.api.schema.NodePropertyDescriptor)9 ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)9 LabelTokenRecord (org.neo4j.kernel.impl.store.record.LabelTokenRecord)9 PropertyKeyTokenRecord (org.neo4j.kernel.impl.store.record.PropertyKeyTokenRecord)9 ConsistencyReport (org.neo4j.consistency.report.ConsistencyReport)8 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)8 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)8 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)7 BatchTransactionApplier (org.neo4j.kernel.impl.api.BatchTransactionApplier)7 SchemaStorage (org.neo4j.kernel.impl.store.SchemaStorage)7 LabelTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand)7 PropertyKeyTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand)7 RelationshipTypeTokenCommand (org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand)7 ArrayList (java.util.ArrayList)6 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)6