Search in sources :

Example 56 with IndexRule

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

the class NeoStoreTransactionApplierTest method shouldApplyDeleteIndexRuleSchemaRuleCommandToTheStore.

@Test
public void shouldApplyDeleteIndexRuleSchemaRuleCommandToTheStore() throws Exception {
    // given
    final BatchTransactionApplier base = newApplier(false);
    final BatchTransactionApplier indexApplier = newIndexApplier();
    final BatchTransactionApplierFacade applier = new BatchTransactionApplierFacade(base, indexApplier);
    final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
    record.setInUse(false);
    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)).updateRecord(record);
    verify(indexingService, times(1)).dropIndex(rule);
    verify(cacheAccess, times(1)).removeSchemaRuleFromCache(command.getKey());
}
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) BatchTransactionApplierFacade(org.neo4j.kernel.impl.api.BatchTransactionApplierFacade) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) Test(org.junit.Test)

Example 57 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 58 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 59 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 60 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)

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