use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method logMessagesAboutConstraintCreation.
@Test
void logMessagesAboutConstraintCreation() throws SchemaKernelException, UniquePropertyValueValidationException, TransactionFailureException, IndexNotFoundKernelException {
IndexProxy indexProxy = mock(IndexProxy.class);
IndexingService indexingService = mock(IndexingService.class);
when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
when(indexProxy.getDescriptor()).thenReturn(index);
when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
KernelTransactionImplementation transaction = createTransaction();
creator.createUniquenessConstraintIndex(transaction, constraint, prototype);
String constraintString = constraint.userDescription(tokenRead);
assertThat(logProvider).containsMessages(format("Starting constraint creation: %s.", constraintString), format("Constraint %s populated, starting verification.", constraintString), format("Constraint %s verified.", constraintString));
}
use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldReleaseLabelLockWhileAwaitingIndexPopulation.
@Test
void shouldReleaseLabelLockWhileAwaitingIndexPopulation() throws Exception {
// given
IndexingService indexingService = mock(IndexingService.class);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
when(schemaRead.index(schema)).thenReturn(Iterators.emptyResourceIterator());
when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
// when
KernelTransactionImplementation transaction = createTransaction();
creator.createUniquenessConstraintIndex(transaction, constraint, prototype);
// then
verify(transaction.lockClient()).releaseExclusive(ResourceTypes.LABEL, schema.getLabelId());
verify(transaction.lockClient()).acquireExclusive(transaction.lockTracer(), ResourceTypes.LABEL, schema.getLabelId());
}
use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldDropIndexIfPopulationFails.
@Test
void shouldDropIndexIfPopulationFails() throws Exception {
// given
IndexingService indexingService = mock(IndexingService.class);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(index)).thenReturn(indexProxy);
when(indexProxy.getDescriptor()).thenReturn(index);
when(schemaRead.indexGetForName(constraint.getName())).thenReturn(IndexDescriptor.NO_INDEX, index);
IndexEntryConflictException cause = new IndexEntryConflictException(2, 1, Values.of("a"));
doThrow(new IndexPopulationFailedKernelException("some index", cause)).when(indexProxy).awaitStoreScanCompleted(anyLong(), any());
when(schemaRead.index(any(SchemaDescriptor.class))).thenReturn(// first claim it doesn't exist, because it doesn't... so
Iterators.emptyResourceIterator()).thenReturn(// then after it failed claim it does exist
Iterators.iterator(index));
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
// when
KernelTransactionImplementation transaction = createTransaction();
UniquePropertyValueValidationException exception = assertThrows(UniquePropertyValueValidationException.class, () -> creator.createUniquenessConstraintIndex(transaction, constraint, prototype));
assertEquals("Existing data does not satisfy Constraint( name='constraint', type='UNIQUENESS', schema=(:Label {prop}) ): " + "Both node 2 and node 1 share the property value ( String(\"a\") )", exception.getMessage());
assertEquals(2, kernel.transactions.size());
KernelTransactionImplementation tx1 = kernel.transactions.get(0);
verify(tx1).indexUniqueCreate(prototype);
verify(schemaRead, times(2)).indexGetForName(constraint.getName());
verifyNoMoreInteractions(schemaRead);
KernelTransactionImplementation kti2 = kernel.transactions.get(1);
verify(kti2).addIndexDoDropToTxState(index);
}
use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldThrowOnExistingOrphanedConstraintIndexWithSameName.
@Test
void shouldThrowOnExistingOrphanedConstraintIndexWithSameName() throws Exception {
// given
IndexingService indexingService = mock(IndexingService.class);
long orphanedConstraintIndexId = 111;
String orphanedName = "constraint";
IndexDescriptor orphanedIndex = IndexPrototype.uniqueForSchema(schema).withName(orphanedName).materialise(orphanedConstraintIndexId);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(orphanedIndex)).thenReturn(indexProxy);
when(schemaRead.index(schema)).thenReturn(Iterators.iterator(orphanedIndex));
when(schemaRead.indexGetForName(orphanedName)).thenReturn(orphanedIndex);
when(schemaRead.indexGetOwningUniquenessConstraintId(orphanedIndex)).thenReturn(// which means it has no owner
null);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, logProvider);
// when
KernelTransactionImplementation transaction = createTransaction();
assertThrows(AlreadyConstrainedException.class, () -> creator.createUniquenessConstraintIndex(transaction, constraint, prototype));
// then
assertEquals(0, kernel.transactions.size(), "There should have been no need to acquire a statement to create the constraint index");
verify(schemaRead).indexGetForName(constraint.getName());
verifyNoMoreInteractions(schemaRead);
}
use of org.neo4j.kernel.impl.api.index.IndexProxy in project neo4j by neo4j.
the class MultiIndexPopulationConcurrentUpdatesIT method waitIndexOnline.
private void waitIndexOnline(IndexingService indexService, int propertyId, int labelId) throws IndexNotFoundKernelException, IndexPopulationFailedKernelException, InterruptedException, IndexActivationFailedKernelException {
IndexProxy indexProxy = indexService.getIndexProxy(SchemaDescriptorFactory.forLabel(labelId, propertyId));
indexProxy.awaitStoreScanCompleted();
indexProxy.activate();
}
Aggregations