use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class NodeGetUniqueFromIndexSeekIT method shouldNotCompositeFindNonMatchingNode.
@Test
public void shouldNotCompositeFindNonMatchingNode() throws Exception {
// given
NewIndexDescriptor index = createUniquenessConstraint(labelId, propertyId1, propertyId2);
String value1 = "value1";
String value2 = "value2";
createNodeWithValues("other_" + value1, "other_" + value2);
// when looking for it
ReadOperations readOperations = readOperationsInNewTransaction();
long foundId = readOperations.nodeGetFromUniqueIndexSeek(index, exact(propertyId1, value1), exact(propertyId2, value2));
commit();
// then
assertTrue("Non-matching created node was found", isNoSuchNode(foundId));
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class LuceneSchemaIndexCorruptionTest method shouldRequestIndexPopulationFailingWithFileNotFoundException.
@Test
public void shouldRequestIndexPopulationFailingWithFileNotFoundException() throws Exception {
// Given
long faultyIndexId = 1;
FileNotFoundException error = new FileNotFoundException("/some/path/somewhere");
LuceneSchemaIndexProvider provider = newFaultySchemaIndexProvider(faultyIndexId, error);
// When
NewIndexDescriptor descriptor = NewIndexDescriptorFactory.forLabel(1, 1);
InternalIndexState initialState = provider.getInitialState(faultyIndexId, descriptor);
// Then
assertThat(initialState, equalTo(InternalIndexState.POPULATING));
logProvider.assertAtLeastOnce(loggedException(error));
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class IndexPopulationFlipRaceIT method verifyThatThereAreExactlyOneIndexEntryPerNodeInTheIndexes.
private void verifyThatThereAreExactlyOneIndexEntryPerNodeInTheIndexes(int i, Pair<long[], long[]> data) throws Exception {
KernelAPI kernelAPI = db.getDependencyResolver().resolveDependency(KernelAPI.class);
try (KernelTransaction tx = kernelAPI.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
Statement statement = tx.acquireStatement()) {
int labelAId = statement.readOperations().labelGetForName(labelA(i).name());
int keyAId = statement.readOperations().propertyKeyGetForName(keyA(i));
int labelBId = statement.readOperations().labelGetForName(labelB(i).name());
int keyBId = statement.readOperations().propertyKeyGetForName(keyB(i));
NewIndexDescriptor indexA = NewIndexDescriptorFactory.forLabel(labelAId, keyAId);
NewIndexDescriptor indexB = NewIndexDescriptorFactory.forLabel(labelBId, keyBId);
for (int j = 0; j < NODES_PER_INDEX; j++) {
long nodeAId = data.first()[j];
assertEquals(1, statement.readOperations().nodesCountIndexed(indexA, nodeAId, nodeAId));
long nodeBId = data.other()[j];
assertEquals(1, statement.readOperations().nodesCountIndexed(indexB, nodeBId, nodeBId));
}
}
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class ConstraintEnforcingEntityOperations method validateNoExistingNodeWithExactValues.
private void validateNoExistingNodeWithExactValues(KernelStatement state, UniquenessConstraintDescriptor constraint, ExactPredicate[] propertyValues, long modifiedNode) throws ConstraintValidationException {
try {
NewIndexDescriptor index = constraint.ownedIndexDescriptor();
assertIndexOnline(state, index);
int labelId = index.schema().getLabelId();
state.locks().optimistic().acquireExclusive(state.lockTracer(), INDEX_ENTRY, indexEntryResourceId(labelId, propertyValues));
long existing = entityReadOperations.nodeGetFromUniqueIndexSeek(state, index, propertyValues);
if (existing != NO_SUCH_NODE && existing != modifiedNode) {
throw new UniquePropertyValueValidationException(constraint, VALIDATION, new IndexEntryConflictException(existing, NO_SUCH_NODE, OrderedPropertyValues.of(propertyValues)));
}
} catch (IndexNotFoundKernelException | IndexBrokenKernelException | IndexNotApplicableKernelException e) {
throw new UnableToValidateConstraintException(constraint, e);
}
}
use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldDropIndexIfPopulationFails.
@Test
public void shouldDropIndexIfPopulationFails() throws Exception {
// given
StatementOperationParts constraintCreationContext = 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);
IndexEntryConflictException cause = new IndexEntryConflictException(2, 1, "a");
doThrow(new IndexPopulationFailedKernelException(SchemaBoundary.map(descriptor), "some index", cause)).when(indexProxy).awaitStoreScanCompleted();
PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, false);
// when
try {
creator.createUniquenessConstraintIndex(state, constraintCreationContext.schemaReadOperations(), descriptor);
fail("expected exception");
}// then
catch (UniquePropertyValueValidationException e) {
assertEquals("Existing data does not satisfy CONSTRAINT ON ( label[123]:label[123] ) ASSERT label[123].property[456] IS UNIQUE.", e.getMessage());
}
assertEquals(2, kernel.statements.size());
TransactionState tx1 = kernel.statements.get(0).txState();
NewIndexDescriptor newIndex = NewIndexDescriptorFactory.uniqueForLabel(123, 456);
verify(tx1).indexRuleDoAdd(newIndex);
verifyNoMoreInteractions(tx1);
verify(constraintCreationContext.schemaReadOperations()).indexGetCommittedId(state, index);
verifyNoMoreInteractions(constraintCreationContext.schemaReadOperations());
TransactionState tx2 = kernel.statements.get(1).txState();
verify(tx2).indexDoDrop(newIndex);
verifyNoMoreInteractions(tx2);
}
Aggregations