use of org.neo4j.storageengine.api.StorageStatement in project neo4j by neo4j.
the class StatementLifecycleTest method shouldReleaseStoreStatementWhenForceClosingStatements.
@Test
public void shouldReleaseStoreStatementWhenForceClosingStatements() throws Exception {
// given
KernelTransactionImplementation transaction = mock(KernelTransactionImplementation.class);
StorageStatement storageStatement = mock(StorageStatement.class);
KernelStatement statement = getKernelStatement(transaction, storageStatement);
statement.acquire();
// when
statement.forceClose();
// then
verify(storageStatement).release();
}
use of org.neo4j.storageengine.api.StorageStatement in project neo4j by neo4j.
the class StorageLayerPropertyTest method should_get_all_node_properties.
@Test
public void should_get_all_node_properties() throws Exception {
// GIVEN
String longString = "AlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalongAlalalalalong";
Object[] properties = { longString, createNew(String.class), createNew(long.class), createNew(int.class), createNew(byte.class), createNew(short.class), createNew(boolean.class), createNew(char.class), createNew(float.class), createNew(double.class), array(0, String.class), array(0, long.class), array(0, int.class), array(0, byte.class), array(0, short.class), array(0, boolean.class), array(0, char.class), array(0, float.class), array(0, double.class), array(1, String.class), array(1, long.class), array(1, int.class), array(1, byte.class), array(1, short.class), array(1, boolean.class), array(1, char.class), array(1, float.class), array(1, double.class), array(256, String.class), array(256, long.class), array(256, int.class), array(256, byte.class), array(256, short.class), array(256, boolean.class), array(256, char.class), array(256, float.class), array(256, double.class) };
int propKey = disk.propertyKeyGetOrCreateForName("prop");
StorageStatement statement = state.getStoreStatement();
for (Object value : properties) {
// given
long nodeId = createLabeledNode(db, singletonMap("prop", value), label1).getId();
// when
try (Cursor<NodeItem> node = statement.acquireSingleNodeCursor(nodeId)) {
node.next();
Lock lock = node.get().lock();
try (Cursor<PropertyItem> props = statement.acquireSinglePropertyCursor(node.get().nextPropertyId(), propKey, lock)) {
if (props.next()) {
Object propVal = props.get().value();
//then
assertTrue(propVal + ".valueEquals(" + value + ")", Property.property(propKey, propVal).valueEquals(value));
} else {
fail();
}
}
}
}
}
use of org.neo4j.storageengine.api.StorageStatement in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method addMockedIndexReader.
private IndexReader addMockedIndexReader(KernelStatement kernelStatement) throws IndexNotFoundKernelException {
StorageStatement storageStatement = mock(StorageStatement.class);
when(kernelStatement.getStoreStatement()).thenReturn(storageStatement);
return addMockedIndexReader(storageStatement);
}
use of org.neo4j.storageengine.api.StorageStatement in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByNumberWithIndexQuery.
@SuppressWarnings("unchecked")
@Test
public void shouldConsiderTransactionStateDuringIndexBetweenRangeSeekByNumberWithIndexQuery() throws Exception {
// Given
final int propertyKey = 2;
final int inRange = 15;
int lower = 10;
int upper = 20;
TransactionState txState = mock(TransactionState.class);
KernelStatement statement = mock(KernelStatement.class);
when(statement.hasTxStateWithChanges()).thenReturn(true);
when(statement.txState()).thenReturn(txState);
StorageStatement storageStatement = mock(StorageStatement.class);
when(statement.getStoreStatement()).thenReturn(storageStatement);
when(txState.indexUpdatesForRangeSeekByNumber(index, lower, true, upper, false)).thenReturn(new DiffSets<>(Collections.singleton(42L), Collections.singleton(44L)));
when(txState.addedAndRemovedNodes()).thenReturn(new DiffSets<>(Collections.singleton(45L), Collections.singleton(46L)));
StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
when(txState.augmentSingleNodeCursor(any(Cursor.class), anyLong())).thenAnswer(invocationOnMock -> {
long nodeId = (long) invocationOnMock.getArguments()[1];
when(txState.augmentSinglePropertyCursor(any(Cursor.class), any(PropertyContainerState.class), eq(propertyKey))).thenReturn(asPropertyCursor(intProperty(propertyKey, inRange)));
return asNodeCursor(nodeId, nodeId + 20000);
});
IndexReader indexReader = addMockedIndexReader(storageStatement);
IndexQuery.NumberRangePredicate indexQuery = IndexQuery.range(index.schema().getPropertyId(), lower, true, upper, false);
when(indexReader.query(indexQuery)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
when(storageStatement.acquireSingleNodeCursor(anyLong())).thenAnswer(invocationOnMock -> {
long nodeId = (long) invocationOnMock.getArguments()[0];
when(storeReadLayer.nodeGetProperty(eq(storageStatement), any(NodeItem.class), eq(propertyKey))).thenReturn(asPropertyCursor(intProperty(propertyKey, inRange)));
return asNodeCursor(nodeId, nodeId + 20000);
});
StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
// When
PrimitiveLongIterator results = context.indexQuery(statement, index, indexQuery);
// Then
assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
use of org.neo4j.storageengine.api.StorageStatement in project neo4j by neo4j.
the class NeoStoresTest method relAddProperty.
private DefinedProperty relAddProperty(long relationshipId, int key, Object value) {
DefinedProperty property = Property.property(key, value);
Property oldProperty = Property.noRelationshipProperty(relationshipId, key);
try (StorageStatement statement = storeLayer.newStatement();
Cursor<RelationshipItem> cursor = statement.acquireSingleRelationshipCursor(relationshipId)) {
if (cursor.next()) {
Property fetched = getProperty(key, statement, cursor.get().nextPropertyId());
if (fetched != null) {
oldProperty = fetched;
}
}
}
transaction.relationshipDoReplaceProperty(relationshipId, oldProperty, property);
return property;
}
Aggregations