Search in sources :

Example 86 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class NodeGetUniqueFromIndexSeekIT method shouldNotFindNonMatchingNode.

@Test
public void shouldNotFindNonMatchingNode() throws Exception {
    // given
    NewIndexDescriptor index = createUniquenessConstraint(labelId, propertyId1);
    String value = "value";
    createNodeWithValue("other_" + value);
    // when looking for it
    ReadOperations readOperations = readOperationsInNewTransaction();
    long foundId = readOperations.nodeGetFromUniqueIndexSeek(index, exact(propertyId1, value));
    commit();
    // then
    assertTrue("Non-matching created node was found", isNoSuchNode(foundId));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Test(org.junit.Test)

Example 87 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class NodeGetUniqueFromIndexSeekIT method shouldFindMatchingNode.

// nodeGetUniqueWithLabelAndProperty(statement, :Person, foo=val)
//
// Given we have a unique constraint on :Person(foo)
// (If not, throw)
//
// If there is a node n with n:Person and n.foo == val, return it
// If there is no such node, return ?
//
// Ensure that if that method is called again with the same argument from some other transaction,
// that transaction blocks until this transaction has finished
//
// [X] must return node from the unique index with the given property
// [X] must return NO_SUCH_NODE if it is not in the index for the given property
//
// must block other transactions that try to call it with the same arguments
@Test
public void shouldFindMatchingNode() throws Exception {
    // given
    NewIndexDescriptor index = createUniquenessConstraint(labelId, propertyId1);
    String value = "value";
    long nodeId = createNodeWithValue(value);
    // when looking for it
    ReadOperations readOperations = readOperationsInNewTransaction();
    int propertyId = index.schema().getPropertyId();
    long foundId = readOperations.nodeGetFromUniqueIndexSeek(index, exact(propertyId, value));
    commit();
    // then
    assertTrue("Created node was not found", nodeId == foundId);
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Test(org.junit.Test)

Example 88 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class NodeGetUniqueFromIndexSeekIT method createUniquenessConstraint.

private NewIndexDescriptor createUniquenessConstraint(int labelId, int... propertyIds) throws Exception {
    Statement statement = statementInNewTransaction(SecurityContext.AUTH_DISABLED);
    LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(labelId, propertyIds);
    statement.schemaWriteOperations().uniquePropertyConstraintCreate(descriptor);
    NewIndexDescriptor result = statement.readOperations().uniqueIndexGetForLabelAndPropertyKey(SchemaBoundary.map(descriptor));
    commit();
    return result;
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)

Example 89 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class SchemaTransactionStateTest method before.

@Before
public void before() throws Exception {
    txState = new TxState();
    state = StatementOperationsTestHelper.mockedState(txState);
    store = mock(StoreReadLayer.class);
    when(store.indexesGetForLabel(labelId1)).then(asAnswer(Collections.<NewIndexDescriptor>emptyList()));
    when(store.indexesGetForLabel(labelId2)).then(asAnswer(Collections.<NewIndexDescriptor>emptyList()));
    when(store.indexesGetAll()).then(asAnswer(Collections.<NewIndexDescriptor>emptyList()));
    txContext = new StateHandlingStatementOperations(store, mock(InternalAutoIndexing.class), mock(ConstraintIndexCreator.class), mock(LegacyIndexStore.class));
    storeStatement = mock(StoreStatement.class);
    when(state.getStoreStatement()).thenReturn(storeStatement);
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) StoreStatement(org.neo4j.kernel.impl.api.store.StoreStatement) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Before(org.junit.Before)

Example 90 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class SchemaTransactionStateTest method shouldNotReturnRulesAddedInTransactionWithDifferentLabelOrPropertyFromLookup.

@Test
public void shouldNotReturnRulesAddedInTransactionWithDifferentLabelOrPropertyFromLookup() throws Exception {
    // GIVEN
    // -- the store already have an index on the label and a different property
    NewIndexDescriptor existingIndex1 = NewIndexDescriptorFactory.forLabel(labelId1, key1);
    when(indexGetForLabelAndPropertyKey(store, labelId1, key1)).thenReturn(existingIndex1);
    // -- the store already have an index on a different label with the same property
    NewIndexDescriptor existingIndex2 = NewIndexDescriptorFactory.forLabel(labelId2, key2);
    when(indexGetForLabelAndPropertyKey(store, labelId2, key2)).thenReturn(existingIndex2);
    // -- a non-existent rule has been added in the transaction
    indexCreate(txContext, state, labelId1, key2);
    // WHEN
    NewIndexDescriptor lookupRule1 = indexGetForLabelAndPropertyKey(txContext, state, labelId1, key1);
    NewIndexDescriptor lookupRule2 = indexGetForLabelAndPropertyKey(txContext, state, labelId2, key2);
    // THEN
    assertEquals(existingIndex1, lookupRule1);
    assertEquals(existingIndex2, lookupRule2);
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Test(org.junit.Test)

Aggregations

NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)99 Test (org.junit.Test)55 Statement (org.neo4j.kernel.api.Statement)24 ReadOperations (org.neo4j.kernel.api.ReadOperations)17 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)10 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)9 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)9 InternalIndexState (org.neo4j.kernel.api.index.InternalIndexState)7 Transaction (org.neo4j.graphdb.Transaction)6 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)5 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)5 SchemaRuleNotFoundException (org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException)5 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Label (org.neo4j.graphdb.Label)4 NotFoundException (org.neo4j.graphdb.NotFoundException)4 KernelException (org.neo4j.kernel.api.exceptions.KernelException)4 NodePropertyDescriptor (org.neo4j.kernel.api.schema.NodePropertyDescriptor)4