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
}
}
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
}
}
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
}
}
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();
}
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();
}
Aggregations