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