Search in sources :

Example 66 with IndexDescriptor

use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.

the class NativeNonUniqueIndexPopulatorTest method updaterShouldApplyDuplicateValues.

@Test
void updaterShouldApplyDuplicateValues() throws Exception {
    // given
    populator.create();
    ValueIndexEntryUpdate<IndexDescriptor>[] updates = valueCreatorUtil.someUpdatesWithDuplicateValues(random);
    try (IndexUpdater updater = populator.newPopulatingUpdater(null_property_accessor, NULL)) {
        // when
        for (ValueIndexEntryUpdate<IndexDescriptor> update : updates) {
            updater.process(update);
        }
    }
    // then
    populator.scanCompleted(nullInstance, populationWorkScheduler, NULL);
    populator.close(true, NULL);
    valueUtil.verifyUpdates(updates, this::getTree);
}
Also used : ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 67 with IndexDescriptor

use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.

the class NativeIndexProviderTest method shouldNotCheckConflictsWhenApplyingUpdatesInOnlineAccessor.

@Test
void shouldNotCheckConflictsWhenApplyingUpdatesInOnlineAccessor() throws IOException, IndexEntryConflictException {
    // given
    Value someValue = Values.of(1);
    provider = newProvider();
    // when
    IndexDescriptor descriptor = descriptorUnique();
    try (IndexAccessor accessor = provider.getOnlineAccessor(descriptor, samplingConfig(), tokenNameLookup);
        IndexUpdater indexUpdater = accessor.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
        indexUpdater.process(IndexEntryUpdate.add(1, descriptor.schema(), someValue));
        // then
        // ... expect no failure on duplicate value
        indexUpdater.process(IndexEntryUpdate.add(2, descriptor.schema(), someValue));
    }
}
Also used : IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) Value(org.neo4j.values.storable.Value) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 68 with IndexDescriptor

use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.

the class NonUniqueDatabaseIndexPopulatorTest method setUp.

@BeforeEach
void setUp() {
    Path folder = testDir.directory("folder");
    PartitionedIndexStorage indexStorage = new PartitionedIndexStorage(dirFactory, fileSystem, folder);
    IndexDescriptor descriptor = IndexPrototype.forSchema(labelSchemaDescriptor).withName("index").materialise(13);
    index = LuceneSchemaIndexBuilder.create(descriptor, writable(), Config.defaults()).withIndexStorage(indexStorage).build();
}
Also used : Path(java.nio.file.Path) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) PartitionedIndexStorage(org.neo4j.kernel.api.impl.index.storage.PartitionedIndexStorage) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 69 with IndexDescriptor

use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.

the class IndexTransactionApplierFactoryTest method shouldRegisterIndexesToActivateIntoTheActivator.

@Test
void shouldRegisterIndexesToActivateIntoTheActivator() throws Exception {
    // given
    IndexUpdateListener indexUpdateListener = mock(IndexUpdateListener.class);
    IndexActivator indexActivator = new IndexActivator(indexUpdateListener);
    long indexId1 = 1;
    long indexId2 = 2;
    long indexId3 = 3;
    long constraintId1 = 10;
    long constraintId2 = 11;
    long constraintId3 = 12;
    String providerKey = "index-key";
    String providerVersion = "v1";
    IndexDescriptor rule1 = uniqueForSchema(forLabel(1, 1), providerKey, providerVersion, indexId1, constraintId1);
    IndexDescriptor rule2 = uniqueForSchema(forLabel(2, 1), providerKey, providerVersion, indexId2, constraintId2);
    IndexDescriptor rule3 = uniqueForSchema(forLabel(3, 1), providerKey, providerVersion, indexId3, constraintId3);
    IndexTransactionApplierFactory applier = new IndexTransactionApplierFactory(indexUpdateListener);
    var batchContext = mock(BatchContext.class);
    when(batchContext.getLockGroup()).thenReturn(new LockGroup());
    when(batchContext.indexUpdates()).thenReturn(mock(IndexUpdates.class));
    when(batchContext.getIndexActivator()).thenReturn(indexActivator);
    try (var txApplier = applier.startTx(new GroupOfCommands(), batchContext)) {
        // activate index 1
        txApplier.visitSchemaRuleCommand(new Command.SchemaRuleCommand(new SchemaRecord(rule1.getId()), asSchemaRecord(rule1, true), rule1));
        // activate index 2
        txApplier.visitSchemaRuleCommand(new Command.SchemaRuleCommand(new SchemaRecord(rule2.getId()), asSchemaRecord(rule2, true), rule2));
        // activate index 3
        txApplier.visitSchemaRuleCommand(new Command.SchemaRuleCommand(new SchemaRecord(rule3.getId()), asSchemaRecord(rule3, true), rule3));
        // drop index 2
        txApplier.visitSchemaRuleCommand(new Command.SchemaRuleCommand(asSchemaRecord(rule2, true), asSchemaRecord(rule2, false), rule2));
    }
    verify(indexUpdateListener).dropIndex(rule2);
    indexActivator.close();
    verify(indexUpdateListener).activateIndex(rule1);
    verify(indexUpdateListener).activateIndex(rule3);
    verifyNoMoreInteractions(indexUpdateListener);
}
Also used : LockGroup(org.neo4j.lock.LockGroup) IndexUpdateListener(org.neo4j.storageengine.api.IndexUpdateListener) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) NodeCommand(org.neo4j.internal.recordstorage.Command.NodeCommand) SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) Test(org.junit.jupiter.api.Test)

Example 70 with IndexDescriptor

use of org.neo4j.internal.schema.IndexDescriptor in project neo4j by neo4j.

the class NeoTransactionIndexApplierTest method shouldCreateIndexGivenCreateSchemaRuleCommand.

@Test
void shouldCreateIndexGivenCreateSchemaRuleCommand() throws Exception {
    // Given
    IndexDescriptor indexRule = indexRule(1, 42, 42);
    IndexTransactionApplierFactory applier = newIndexTransactionApplier();
    SchemaRecord before = new SchemaRecord(1);
    SchemaRecord after = before.copy().initialize(true, 39);
    after.setCreated();
    Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(before, after, indexRule);
    // When
    boolean result;
    try (TransactionApplier txApplier = applier.startTx(transactionToApply, batchContext)) {
        result = txApplier.visitSchemaRuleCommand(command);
    }
    // Then
    assertFalse(result);
    verify(indexingService).createIndexes(SYSTEM, indexRule);
}
Also used : SchemaRecord(org.neo4j.kernel.impl.store.record.SchemaRecord) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Aggregations

IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)404 Test (org.junit.jupiter.api.Test)231 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)81 Value (org.neo4j.values.storable.Value)43 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)33 ArrayList (java.util.ArrayList)31 Transaction (org.neo4j.graphdb.Transaction)31 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)31 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)30 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)30 TokenRead (org.neo4j.internal.kernel.api.TokenRead)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 SchemaRead (org.neo4j.internal.kernel.api.SchemaRead)26 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)25 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)25 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)23 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)23 LabelSchemaDescriptor (org.neo4j.internal.schema.LabelSchemaDescriptor)23 IndexProviderDescriptor (org.neo4j.internal.schema.IndexProviderDescriptor)22 KernelException (org.neo4j.exceptions.KernelException)20