Search in sources :

Example 1 with IndexingService

use of org.neo4j.kernel.impl.api.index.IndexingService in project neo4j by neo4j.

the class IntegrityValidatorTest method shouldValidateUniquenessIndexes.

@Test
public void shouldValidateUniquenessIndexes() throws Exception {
    // Given
    NeoStores store = mock(NeoStores.class);
    IndexingService indexes = mock(IndexingService.class);
    IntegrityValidator validator = new IntegrityValidator(store, indexes);
    UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForLabel(1, 1);
    doThrow(new UniquePropertyValueValidationException(constraint, ConstraintValidationException.Phase.VERIFICATION, new RuntimeException())).when(indexes).validateIndex(2L);
    ConstraintRule record = ConstraintRule.constraintRule(1L, constraint, 2L);
    // When
    try {
        validator.validateSchemaRule(record);
        fail("Should have thrown integrity error.");
    } catch (Exception e) {
    // good
    }
}
Also used : UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) NeoStores(org.neo4j.kernel.impl.store.NeoStores) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) ConstraintValidationException(org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException) Test(org.junit.Test)

Example 2 with IndexingService

use of org.neo4j.kernel.impl.api.index.IndexingService in project neo4j by neo4j.

the class IntegrityValidatorTest method deletingNodeWithRelationshipsIsNotAllowed.

@Test
public void deletingNodeWithRelationshipsIsNotAllowed() throws Exception {
    // Given
    NeoStores store = mock(NeoStores.class);
    IndexingService indexes = mock(IndexingService.class);
    IntegrityValidator validator = new IntegrityValidator(store, indexes);
    NodeRecord record = new NodeRecord(1L, false, 1L, -1L);
    record.setInUse(false);
    // When
    try {
        validator.validateNodeRecord(record);
        fail("Should have thrown integrity error.");
    } catch (Exception e) {
    // good
    }
}
Also used : NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) NeoStores(org.neo4j.kernel.impl.store.NeoStores) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) ConstraintValidationException(org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException) Test(org.junit.Test)

Example 3 with IndexingService

use of org.neo4j.kernel.impl.api.index.IndexingService in project neo4j by neo4j.

the class IntegrityValidatorTest method transactionsStartedBeforeAConstraintWasCreatedAreDisallowed.

@Test
public void transactionsStartedBeforeAConstraintWasCreatedAreDisallowed() throws Exception {
    // Given
    NeoStores store = mock(NeoStores.class);
    MetaDataStore metaDataStore = mock(MetaDataStore.class);
    when(store.getMetaDataStore()).thenReturn(metaDataStore);
    IndexingService indexes = mock(IndexingService.class);
    when(metaDataStore.getLatestConstraintIntroducingTx()).thenReturn(10L);
    IntegrityValidator validator = new IntegrityValidator(store, indexes);
    // When
    try {
        validator.validateTransactionStartKnowledge(1);
        fail("Should have thrown integrity error.");
    } catch (Exception e) {
    // good
    }
}
Also used : MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) NeoStores(org.neo4j.kernel.impl.store.NeoStores) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) ConstraintValidationException(org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException) Test(org.junit.Test)

Example 4 with IndexingService

use of org.neo4j.kernel.impl.api.index.IndexingService in project neo4j by neo4j.

the class NeoStoreFileListingTest method shouldCloseIndexAndLabelScanSnapshots.

@Test
public void shouldCloseIndexAndLabelScanSnapshots() throws Exception {
    // Given
    LabelScanStore labelScanStore = mock(LabelScanStore.class);
    IndexingService indexingService = mock(IndexingService.class);
    LegacyIndexProviderLookup legacyIndexes = mock(LegacyIndexProviderLookup.class);
    when(legacyIndexes.all()).thenReturn(Collections.emptyList());
    File storeDir = mock(File.class);
    filesInStoreDirAre(storeDir, STANDARD_STORE_DIR_FILES, STANDARD_STORE_DIR_DIRECTORIES);
    StorageEngine storageEngine = mock(StorageEngine.class);
    NeoStoreFileListing fileListing = new NeoStoreFileListing(storeDir, labelScanStore, indexingService, legacyIndexes, storageEngine);
    ResourceIterator<File> scanSnapshot = scanStoreFilesAre(labelScanStore, new String[] { "blah/scan.store", "scan.more" });
    ResourceIterator<File> indexSnapshot = indexFilesAre(indexingService, new String[] { "schema/index/my.index" });
    ResourceIterator<StoreFileMetadata> result = fileListing.listStoreFiles(false);
    // When
    result.close();
    // Then
    verify(scanSnapshot).close();
    verify(indexSnapshot).close();
}
Also used : LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) LegacyIndexProviderLookup(org.neo4j.kernel.impl.api.LegacyIndexProviderLookup) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata) StorageEngine(org.neo4j.storageengine.api.StorageEngine) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) File(java.io.File) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) Test(org.junit.Test)

Example 5 with IndexingService

use of org.neo4j.kernel.impl.api.index.IndexingService in project neo4j by neo4j.

the class ConstraintIndexCreatorTest method shouldCreateIndexInAnotherTransaction.

@Test
public void shouldCreateIndexInAnotherTransaction() throws Exception {
    // given
    StatementOperationParts constraintCreationContext = mockedParts();
    StatementOperationParts indexCreationContext = mockedParts();
    KernelStatement state = mockedState();
    IndexingService indexingService = mock(IndexingService.class);
    StubKernel kernel = new StubKernel();
    when(constraintCreationContext.schemaReadOperations().indexGetCommittedId(state, index)).thenReturn(2468L);
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexingService.getIndexProxy(2468L)).thenReturn(indexProxy);
    PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, false);
    // when
    long indexId = creator.createUniquenessConstraintIndex(state, constraintCreationContext.schemaReadOperations(), descriptor);
    // then
    assertEquals(2468L, indexId);
    assertEquals(1, kernel.statements.size());
    verify(kernel.statements.get(0).txState()).indexRuleDoAdd(eq(index));
    verifyNoMoreInteractions(indexCreationContext.schemaWriteOperations());
    verify(constraintCreationContext.schemaReadOperations()).indexGetCommittedId(state, index);
    verifyNoMoreInteractions(constraintCreationContext.schemaReadOperations());
    verify(indexProxy).awaitStoreScanCompleted();
}
Also used : ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) StatementOperationParts(org.neo4j.kernel.impl.api.StatementOperationParts) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) Test(org.junit.Test)

Aggregations

IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)12 Test (org.junit.Test)9 UniquePropertyValueValidationException (org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException)4 PropertyAccessor (org.neo4j.kernel.api.index.PropertyAccessor)4 ConstraintIndexCreator (org.neo4j.kernel.impl.api.state.ConstraintIndexCreator)4 ConstraintValidationException (org.neo4j.kernel.api.exceptions.schema.ConstraintValidationException)3 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)3 StatementOperationParts (org.neo4j.kernel.impl.api.StatementOperationParts)3 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)3 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)2 File (java.io.File)1 Supplier (java.util.function.Supplier)1 Before (org.junit.Before)1 WorkSync (org.neo4j.concurrent.WorkSync)1 DependencyResolver (org.neo4j.graphdb.DependencyResolver)1 Transaction (org.neo4j.graphdb.Transaction)1 NeoStoreDataSource (org.neo4j.kernel.NeoStoreDataSource)1 ReadOperations (org.neo4j.kernel.api.ReadOperations)1 Statement (org.neo4j.kernel.api.Statement)1