Search in sources :

Example 6 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 7 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 8 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 9 with IndexingService

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

the class Schema method sampleIndexes.

private void sampleIndexes(Label[] labels, String property, boolean sampleAll, boolean forceSample) throws ShellException {
    IndexingService indexingService = getServer().getDb().getDependencyResolver().resolveDependency(IndexingService.class);
    if (indexingService == null) {
        throw new ShellException("Internal error: failed to resolve IndexingService");
    }
    IndexSamplingMode samplingMode = getSamplingMode(forceSample);
    // Trigger sampling for all indices
    if (sampleAll) {
        indexingService.triggerIndexSampling(samplingMode);
        return;
    }
    validateLabelsAndProperty(labels, property);
    Statement statement = getServer().getStatement();
    int labelKey = statement.readOperations().labelGetForName(labels[0].name());
    int propertyKey = statement.readOperations().propertyKeyGetForName(property);
    if (labelKey == -1) {
        throw new ShellException("No label associated with '" + labels[0].name() + "' was found");
    }
    if (propertyKey == -1) {
        throw new ShellException("No property associated with '" + property + "' was found");
    }
    try {
        indexingService.triggerIndexSampling(SchemaDescriptorFactory.forLabel(labelKey, propertyKey), samplingMode);
    } catch (IndexNotFoundKernelException e) {
        throw new ShellException(e.getMessage());
    }
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Statement(org.neo4j.kernel.api.Statement) IndexSamplingMode(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingMode) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) ShellException(org.neo4j.shell.ShellException)

Example 10 with IndexingService

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

the class IndexSamplingManagerBeanTest method setup.

@Before
public void setup() {
    dataSource = mock(NeoStoreDataSource.class);
    storeReadLayer = mock(StoreReadLayer.class);
    indexingService = mock(IndexingService.class);
    when(dataSource.getStoreLayer()).thenReturn(storeReadLayer);
    when(storeReadLayer.labelGetForName(EXISTING_LABEL)).thenReturn(LABEL_ID);
    when(storeReadLayer.propertyKeyGetForName(EXISTING_PROPERTY)).thenReturn(PROPERTY_ID);
    when(storeReadLayer.propertyKeyGetForName(NON_EXISTING_PROPERTY)).thenReturn(-1);
    when(storeReadLayer.labelGetForName(NON_EXISTING_LABEL)).thenReturn(-1);
    DependencyResolver resolver = mock(DependencyResolver.class);
    when(resolver.resolveDependency(IndexingService.class)).thenReturn(indexingService);
    when(dataSource.getDependencyResolver()).thenReturn(resolver);
}
Also used : StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Before(org.junit.Before)

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