Search in sources :

Example 1 with SchemaReadOperations

use of org.neo4j.kernel.impl.api.operations.SchemaReadOperations in project neo4j by neo4j.

the class OperationsFacadeTest method testThrowExceptionWhenDuplicateUniqueIndexFound.

@Test
public void testThrowExceptionWhenDuplicateUniqueIndexFound() throws SchemaRuleNotFoundException, DuplicateSchemaRuleException {
    SchemaReadOperations readOperations = setupSchemaReadOperations();
    NewIndexDescriptor index = NewIndexDescriptorFactory.forSchema(SchemaBoundary.map(descriptor));
    Mockito.when(readOperations.uniqueIndexesGetForLabel(Mockito.any(KernelStatement.class), Mockito.eq(descriptor.getLabelId()))).thenReturn(Iterators.iterator(index, index));
    TokenNameLookup tokenNameLookup = getDefaultTokenNameLookup();
    expectedException.expect(DuplicateSchemaRuleException.class);
    expectedException.expect(new KernelExceptionUserMessageMatcher<>(tokenNameLookup, "Multiple constraint indexs found for :Label1(Prop1)."));
    operationsFacade.uniqueIndexGetForLabelAndPropertyKey(descriptor);
}
Also used : TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) SchemaReadOperations(org.neo4j.kernel.impl.api.operations.SchemaReadOperations) Test(org.junit.Test)

Example 2 with SchemaReadOperations

use of org.neo4j.kernel.impl.api.operations.SchemaReadOperations in project neo4j by neo4j.

the class OperationsFacadeTest method setupSchemaReadOperations.

private SchemaReadOperations setupSchemaReadOperations() {
    SchemaReadOperations readOperations = Mockito.mock(SchemaReadOperations.class);
    Mockito.when(statementOperationParts.schemaReadOperations()).thenReturn(readOperations);
    return readOperations;
}
Also used : SchemaReadOperations(org.neo4j.kernel.impl.api.operations.SchemaReadOperations)

Example 3 with SchemaReadOperations

use of org.neo4j.kernel.impl.api.operations.SchemaReadOperations in project neo4j by neo4j.

the class OperationsFacadeTest method testThrowExceptionWhenUniqueIndexNotFound.

@Test
public void testThrowExceptionWhenUniqueIndexNotFound() throws SchemaRuleNotFoundException, DuplicateSchemaRuleException {
    SchemaReadOperations readOperations = setupSchemaReadOperations();
    TokenNameLookup tokenNameLookup = getDefaultTokenNameLookup();
    Mockito.when(readOperations.uniqueIndexesGetForLabel(Mockito.any(KernelStatement.class), anyInt())).thenReturn(Iterators.emptyIterator());
    expectedException.expect(SchemaRuleNotFoundException.class);
    expectedException.expect(new KernelExceptionUserMessageMatcher<>(tokenNameLookup, "No constraint index was found for :Label1(Prop1)."));
    operationsFacade.uniqueIndexGetForLabelAndPropertyKey(descriptor);
}
Also used : TokenNameLookup(org.neo4j.kernel.api.TokenNameLookup) SchemaReadOperations(org.neo4j.kernel.impl.api.operations.SchemaReadOperations) Test(org.junit.Test)

Example 4 with SchemaReadOperations

use of org.neo4j.kernel.impl.api.operations.SchemaReadOperations in project neo4j by neo4j.

the class IndexTxStateUpdaterTest method setup.

@Before
public void setup() {
    state = mock(KernelStatement.class);
    txState = mock(TransactionState.class);
    when(state.txState()).thenReturn(txState);
    SchemaReadOperations schemaReadOps = mock(SchemaReadOperations.class);
    when(schemaReadOps.indexesGetAll(state)).thenAnswer(x -> filter(GENERAL, indexes.iterator()));
    when(schemaReadOps.uniqueIndexesGetAll(state)).thenAnswer(x -> filter(UNIQUE, indexes.iterator()));
    when(schemaReadOps.indexesGetForLabel(state, labelId1)).thenAnswer(x -> filter(GENERAL, filter(hasLabel(labelId1), indexes.iterator())));
    when(schemaReadOps.uniqueIndexesGetForLabel(state, labelId1)).thenAnswer(x -> filter(UNIQUE, filter(hasLabel(labelId1), indexes.iterator())));
    when(schemaReadOps.indexesGetForLabel(state, labelId2)).thenAnswer(x -> filter(GENERAL, filter(hasLabel(labelId2), indexes.iterator())));
    when(schemaReadOps.uniqueIndexesGetForLabel(state, labelId2)).thenAnswer(x -> filter(UNIQUE, filter(hasLabel(labelId2), indexes.iterator())));
    PrimitiveIntSet labels = Primitive.intSet();
    labels.add(labelId1);
    labels.add(labelId2);
    Cursor<NodeItem> nodeItemCursor = StubCursors.asNodeCursor(0, labels);
    nodeItemCursor.next();
    node = nodeItemCursor.get();
    PrimitiveIntSet defaultPropertyIds = PrimitiveIntCollections.asSet(new int[] { propId1, propId2, propId3 });
    EntityReadOperations readOps = mock(EntityReadOperations.class);
    when(readOps.nodeGetPropertyKeys(state, node)).thenReturn(defaultPropertyIds);
    when(readOps.nodeGetProperties(state, node)).thenAnswer(p -> StubCursors.asPropertyCursor(Property.property(propId1, "hi1"), Property.property(propId2, "hi2"), Property.property(propId3, "hi3")));
    when(readOps.nodeGetProperty(state, node, propId1)).thenReturn("hi1");
    when(readOps.nodeGetProperty(state, node, propId2)).thenReturn("hi2");
    when(readOps.nodeGetProperty(state, node, propId3)).thenReturn("hi3");
    indexTxUpdater = new IndexTxStateUpdater(schemaReadOps, readOps);
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) NodeItem(org.neo4j.storageengine.api.NodeItem) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) SchemaReadOperations(org.neo4j.kernel.impl.api.operations.SchemaReadOperations) PrimitiveIntSet(org.neo4j.collection.primitive.PrimitiveIntSet) EntityReadOperations(org.neo4j.kernel.impl.api.operations.EntityReadOperations) Before(org.junit.Before)

Aggregations

SchemaReadOperations (org.neo4j.kernel.impl.api.operations.SchemaReadOperations)4 Test (org.junit.Test)2 TokenNameLookup (org.neo4j.kernel.api.TokenNameLookup)2 Before (org.junit.Before)1 PrimitiveIntSet (org.neo4j.collection.primitive.PrimitiveIntSet)1 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)1 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)1 KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)1 EntityReadOperations (org.neo4j.kernel.impl.api.operations.EntityReadOperations)1 NodeItem (org.neo4j.storageengine.api.NodeItem)1