Search in sources :

Example 1 with StubNodeCursor

use of org.neo4j.internal.kernel.api.helpers.StubNodeCursor in project neo4j by neo4j.

the class PlainOperationsTest method detachDeleteNodeExclusivelyLockNodes.

@Test
void detachDeleteNodeExclusivelyLockNodes() {
    long nodeId = 1L;
    returnRelationships(transaction, new TestRelationshipChain(nodeId).outgoing(1, 2L, 42));
    when(transaction.ambientNodeCursor()).thenReturn(new StubNodeCursor(false).withNode(nodeId));
    TokenSet labels = mock(TokenSet.class);
    when(labels.all()).thenReturn(EMPTY_LONG_ARRAY);
    when(nodeCursor.labels()).thenReturn(labels);
    when(nodeCursor.next()).thenReturn(true);
    operations.nodeDetachDelete(nodeId);
    order.verify(creationContext).acquireNodeDeletionLock(txState, locks, LockTracer.NONE, nodeId);
    order.verify(locks, never()).releaseExclusive(ResourceTypes.NODE, nodeId);
    order.verify(locks, never()).releaseExclusive(ResourceTypes.NODE, 2L);
    order.verify(txState).nodeDoDelete(nodeId);
}
Also used : StubNodeCursor(org.neo4j.internal.kernel.api.helpers.StubNodeCursor) TokenSet(org.neo4j.internal.kernel.api.TokenSet) TestRelationshipChain(org.neo4j.internal.kernel.api.helpers.TestRelationshipChain) Test(org.junit.jupiter.api.Test)

Example 2 with StubNodeCursor

use of org.neo4j.internal.kernel.api.helpers.StubNodeCursor in project neo4j by neo4j.

the class OperationsTest method returnRelationships.

public static void returnRelationships(KernelTransactionImplementation ktx, final TestRelationshipChain relIds) {
    StubRead read = new StubRead();
    when(ktx.dataRead()).thenReturn(read);
    StubCursorFactory cursorFactory = new StubCursorFactory(true);
    cursorFactory.withRelationshipTraversalCursors(new StubRelationshipCursor(relIds));
    when(ktx.lockTracer()).thenReturn(NONE);
    when(ktx.cursors()).thenReturn(cursorFactory);
    when(ktx.ambientNodeCursor()).thenAnswer(args -> new StubNodeCursor(false).withNode(42L));
}
Also used : StubNodeCursor(org.neo4j.internal.kernel.api.helpers.StubNodeCursor) StubRead(org.neo4j.internal.kernel.api.helpers.StubRead) StubCursorFactory(org.neo4j.internal.kernel.api.helpers.StubCursorFactory) StubRelationshipCursor(org.neo4j.internal.kernel.api.helpers.StubRelationshipCursor)

Example 3 with StubNodeCursor

use of org.neo4j.internal.kernel.api.helpers.StubNodeCursor in project neo4j by neo4j.

the class CursorPropertyAccessorTest method shouldLookupProperty.

@Test
void shouldLookupProperty() throws EntityNotFoundException {
    // given
    long nodeId = 10;
    Value value = Values.of("abc");
    int propertyKeyId = 0;
    StubNodeCursor nodeCursor = new StubNodeCursor().withNode(nodeId, new long[] {}, genericMap(999, Values.of(12345), propertyKeyId, value));
    CursorPropertyAccessor accessor = new CursorPropertyAccessor(nodeCursor, new StubPropertyCursor(), new StubRead());
    // when
    Value readValue = accessor.getNodePropertyValue(nodeId, propertyKeyId, NULL);
    // then
    assertEquals(value, readValue);
}
Also used : StubNodeCursor(org.neo4j.internal.kernel.api.helpers.StubNodeCursor) StubRead(org.neo4j.internal.kernel.api.helpers.StubRead) Value(org.neo4j.values.storable.Value) StubPropertyCursor(org.neo4j.internal.kernel.api.helpers.StubPropertyCursor) Test(org.junit.jupiter.api.Test)

Example 4 with StubNodeCursor

use of org.neo4j.internal.kernel.api.helpers.StubNodeCursor in project neo4j by neo4j.

the class CursorPropertyAccessorTest method shouldReturnNoValueOnMissingProperty.

@Test
void shouldReturnNoValueOnMissingProperty() throws EntityNotFoundException {
    // given
    long nodeId = 10;
    StubNodeCursor nodeCursor = new StubNodeCursor().withNode(nodeId, new long[] {}, genericMap(999, Values.of(12345)));
    CursorPropertyAccessor accessor = new CursorPropertyAccessor(nodeCursor, new StubPropertyCursor(), new StubRead());
    // when
    Value readValue = accessor.getNodePropertyValue(nodeId, 0, NULL);
    // then
    assertEquals(NO_VALUE, readValue);
}
Also used : StubNodeCursor(org.neo4j.internal.kernel.api.helpers.StubNodeCursor) StubRead(org.neo4j.internal.kernel.api.helpers.StubRead) Value(org.neo4j.values.storable.Value) StubPropertyCursor(org.neo4j.internal.kernel.api.helpers.StubPropertyCursor) Test(org.junit.jupiter.api.Test)

Example 5 with StubNodeCursor

use of org.neo4j.internal.kernel.api.helpers.StubNodeCursor in project neo4j by neo4j.

the class CursorPropertyAccessorTest method shouldThrowOnEntityNotFound.

@Test
void shouldThrowOnEntityNotFound() {
    // given
    long nodeId = 10;
    Value value = Values.of("abc");
    int propertyKeyId = 0;
    StubNodeCursor nodeCursor = new StubNodeCursor().withNode(nodeId, new long[] {}, genericMap(999, Values.of(12345), propertyKeyId, value));
    CursorPropertyAccessor accessor = new CursorPropertyAccessor(nodeCursor, new StubPropertyCursor(), new StubRead());
    // when
    assertThrows(EntityNotFoundException.class, () -> accessor.getNodePropertyValue(nodeId + 1, propertyKeyId, NULL));
}
Also used : StubNodeCursor(org.neo4j.internal.kernel.api.helpers.StubNodeCursor) StubRead(org.neo4j.internal.kernel.api.helpers.StubRead) Value(org.neo4j.values.storable.Value) StubPropertyCursor(org.neo4j.internal.kernel.api.helpers.StubPropertyCursor) Test(org.junit.jupiter.api.Test)

Aggregations

StubNodeCursor (org.neo4j.internal.kernel.api.helpers.StubNodeCursor)7 Test (org.junit.jupiter.api.Test)6 StubRead (org.neo4j.internal.kernel.api.helpers.StubRead)4 TokenSet (org.neo4j.internal.kernel.api.TokenSet)3 StubPropertyCursor (org.neo4j.internal.kernel.api.helpers.StubPropertyCursor)3 TestRelationshipChain (org.neo4j.internal.kernel.api.helpers.TestRelationshipChain)3 Value (org.neo4j.values.storable.Value)3 InOrder (org.mockito.InOrder)1 StubCursorFactory (org.neo4j.internal.kernel.api.helpers.StubCursorFactory)1 StubRelationshipCursor (org.neo4j.internal.kernel.api.helpers.StubRelationshipCursor)1