Search in sources :

Example 1 with IndexUpdateListener

use of org.neo4j.storageengine.api.IndexUpdateListener in project neo4j by neo4j.

the class IntegrityValidatorTest method relationshipPropertyIndexesNotAllowedForOldKernelVersions.

@Test
void relationshipPropertyIndexesNotAllowedForOldKernelVersions() {
    // Given
    NeoStores store = mock(NeoStores.class);
    MetaDataStore metaDataStore = mock(MetaDataStore.class);
    when(store.getMetaDataStore()).thenReturn(metaDataStore);
    when(metaDataStore.kernelVersion()).thenReturn(KernelVersion.V4_2);
    IndexUpdateListener indexes = mock(IndexUpdateListener.class);
    IntegrityValidator validator = new IntegrityValidator(store);
    validator.setIndexValidator(indexes);
    var index = IndexPrototype.forSchema(SchemaDescriptor.forRelType(3, 14)).withIndexType(IndexType.BTREE).withName("any name").materialise(4);
    // When
    assertThatThrownBy(() -> validator.validateSchemaRule(index)).isInstanceOf(TransactionFailureException.class).hasMessageContaining("Required kernel version for this transaction is V4_3_D4, but actual version was V4_2.");
}
Also used : TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores) IndexUpdateListener(org.neo4j.storageengine.api.IndexUpdateListener) Test(org.junit.jupiter.api.Test)

Example 2 with IndexUpdateListener

use of org.neo4j.storageengine.api.IndexUpdateListener in project neo4j by neo4j.

the class IntegrityValidatorTest method shouldValidateUniquenessIndexes.

@Test
void shouldValidateUniquenessIndexes() throws Exception {
    // Given
    NeoStores store = mock(NeoStores.class);
    IndexUpdateListener indexes = mock(IndexUpdateListener.class);
    IntegrityValidator validator = new IntegrityValidator(store);
    validator.setIndexValidator(indexes);
    UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel(1, 1);
    doThrow(new ConstraintViolationException("error", new RuntimeException())).when(indexes).validateIndex(2L);
    ConstraintDescriptor record = constraint.withId(1).withOwnedIndexId(2);
    // When
    assertThrows(Exception.class, () -> validator.validateSchemaRule(record));
}
Also used : NeoStores(org.neo4j.kernel.impl.store.NeoStores) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) IndexUpdateListener(org.neo4j.storageengine.api.IndexUpdateListener) ConstraintViolationException(org.neo4j.graphdb.ConstraintViolationException) UniquenessConstraintDescriptor(org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor) Test(org.junit.jupiter.api.Test)

Example 3 with IndexUpdateListener

use of org.neo4j.storageengine.api.IndexUpdateListener 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 4 with IndexUpdateListener

use of org.neo4j.storageengine.api.IndexUpdateListener in project neo4j by neo4j.

the class IntegrityValidatorTest method tokenIndexesNotAllowedForOldKernelVersions.

@Test
void tokenIndexesNotAllowedForOldKernelVersions() {
    // Given
    NeoStores store = mock(NeoStores.class);
    MetaDataStore metaDataStore = mock(MetaDataStore.class);
    when(store.getMetaDataStore()).thenReturn(metaDataStore);
    when(metaDataStore.kernelVersion()).thenReturn(KernelVersion.V4_2);
    IndexUpdateListener indexes = mock(IndexUpdateListener.class);
    IntegrityValidator validator = new IntegrityValidator(store);
    validator.setIndexValidator(indexes);
    var index = IndexPrototype.forSchema(SchemaDescriptor.forAnyEntityTokens(EntityType.NODE)).withIndexType(IndexType.LOOKUP).withName("any name").materialise(4);
    // When
    assertThatThrownBy(() -> validator.validateSchemaRule(index)).isInstanceOf(TransactionFailureException.class).hasMessageContaining("Required kernel version for this transaction is V4_3_D4, but actual version was V4_2.");
}
Also used : TransactionFailureException(org.neo4j.internal.kernel.api.exceptions.TransactionFailureException) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores) IndexUpdateListener(org.neo4j.storageengine.api.IndexUpdateListener) Test(org.junit.jupiter.api.Test)

Example 5 with IndexUpdateListener

use of org.neo4j.storageengine.api.IndexUpdateListener in project neo4j by neo4j.

the class IndexTransactionApplierFactoryTest method shouldProvideTokenIndexUpdatesSortedByNodeId.

@Test
void shouldProvideTokenIndexUpdatesSortedByNodeId() throws Exception {
    // GIVEN
    OrderVerifyingUpdateListener indexUpdateListener = new OrderVerifyingUpdateListener(10, 15, 20);
    WorkSync<IndexUpdateListener, IndexUpdatesWork> indexUpdatesSync = spy(new WorkSync<>(indexUpdateListener));
    PropertyStore propertyStore = mock(PropertyStore.class);
    IndexTransactionApplierFactory applier = new IndexTransactionApplierFactory(indexUpdateListener);
    final SchemaCache mock = mock(SchemaCache.class);
    when(mock.getTokenIndex(EntityType.NODE)).thenReturn(IndexDescriptor.INJECTED_NLI);
    try (var batchContext = new BatchContextImpl(indexUpdateListener, indexUpdatesSync, mock(NodeStore.class), propertyStore, mock(RecordStorageEngine.class), mock, NULL, INSTANCE, mock(IdUpdateListener.class))) {
        try (TransactionApplier txApplier = applier.startTx(new GroupOfCommands(), batchContext)) {
            // WHEN
            txApplier.visitNodeCommand(node(15));
            txApplier.visitNodeCommand(node(20));
            txApplier.visitNodeCommand(node(10));
        }
    }
    indexUpdateListener.done();
    // THEN all assertions happen inside the UpdateListener and #close
    verify(indexUpdatesSync).apply(any());
}
Also used : IndexUpdateListener(org.neo4j.storageengine.api.IndexUpdateListener) NodeStore(org.neo4j.kernel.impl.store.NodeStore) IdUpdateListener(org.neo4j.kernel.impl.store.IdUpdateListener) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)5 IndexUpdateListener (org.neo4j.storageengine.api.IndexUpdateListener)5 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 TransactionFailureException (org.neo4j.internal.kernel.api.exceptions.TransactionFailureException)2 MetaDataStore (org.neo4j.kernel.impl.store.MetaDataStore)2 ConstraintViolationException (org.neo4j.graphdb.ConstraintViolationException)1 NodeCommand (org.neo4j.internal.recordstorage.Command.NodeCommand)1 ConstraintDescriptor (org.neo4j.internal.schema.ConstraintDescriptor)1 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)1 UniquenessConstraintDescriptor (org.neo4j.internal.schema.constraints.UniquenessConstraintDescriptor)1 IdUpdateListener (org.neo4j.kernel.impl.store.IdUpdateListener)1 NodeStore (org.neo4j.kernel.impl.store.NodeStore)1 PropertyStore (org.neo4j.kernel.impl.store.PropertyStore)1 SchemaRecord (org.neo4j.kernel.impl.store.record.SchemaRecord)1 LockGroup (org.neo4j.lock.LockGroup)1