use of org.neo4j.storageengine.api.StorageReader in project neo4j by neo4j.
the class GraphStoreFixture method nodeAsUpdates.
public EntityUpdates nodeAsUpdates(long nodeId) {
try (StorageReader storeReader = storageEngine.newReader();
StorageNodeCursor nodeCursor = storeReader.allocateNodeCursor(NULL);
StoragePropertyCursor propertyCursor = storeReader.allocatePropertyCursor(NULL, INSTANCE)) {
nodeCursor.single(nodeId);
long[] labels;
if (!nodeCursor.next() || !nodeCursor.hasProperties() || (labels = nodeCursor.labels()).length == 0) {
return null;
}
nodeCursor.properties(propertyCursor);
EntityUpdates.Builder update = EntityUpdates.forEntity(nodeId, true).withTokens(labels);
while (propertyCursor.next()) {
update.added(propertyCursor.propertyKey(), propertyCursor.propertyValue());
}
return update.build();
}
}
use of org.neo4j.storageengine.api.StorageReader in project neo4j by neo4j.
the class EntityValueUpdatesTest method assertNoLoading.
private static StorageReader assertNoLoading() {
StorageReader reader = mock(StorageReader.class);
IllegalStateException exception = new IllegalStateException("Should never attempt to load properties!");
when(reader.allocateNodeCursor(any())).thenThrow(exception);
when(reader.allocateRelationshipScanCursor(any())).thenThrow(exception);
when(reader.allocateRelationshipTraversalCursor(any())).thenThrow(exception);
when(reader.allocatePropertyCursor(any(), any())).thenThrow(exception);
return reader;
}
use of org.neo4j.storageengine.api.StorageReader in project neo4j by neo4j.
the class TransactionRecordStateTest method indexUpdatesOf.
private Iterable<Iterable<IndexEntryUpdate<IndexDescriptor>>> indexUpdatesOf(NeoStores neoStores, CommandsToApply transaction) throws IOException {
IndexUpdatesExtractor extractor = new IndexUpdatesExtractor();
transaction.accept(extractor);
StorageReader reader = new RecordStorageReader(neoStores);
List<Iterable<IndexEntryUpdate<IndexDescriptor>>> updates = new ArrayList<>();
OnlineIndexUpdates onlineIndexUpdates = new OnlineIndexUpdates(neoStores.getNodeStore(), schemaCache, new PropertyPhysicalToLogicalConverter(neoStores.getPropertyStore(), NULL), reader, NULL, INSTANCE);
onlineIndexUpdates.feed(extractor.getNodeCommands(), extractor.getRelationshipCommands(), transaction.transactionId());
updates.add(onlineIndexUpdates);
reader.close();
return updates;
}
use of org.neo4j.storageengine.api.StorageReader in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method createTransaction.
private KernelTransactionImplementation createTransaction() {
KernelTransactionImplementation transaction = mock(KernelTransactionImplementation.class);
try {
StorageEngine storageEngine = mock(StorageEngine.class);
StorageReader storageReader = mock(StorageReader.class);
when(storageEngine.newReader()).thenReturn(storageReader);
Locks.Client locks = mock(Locks.Client.class);
when(transaction.lockClient()).thenReturn(locks);
when(transaction.tokenRead()).thenReturn(tokenRead);
when(transaction.schemaRead()).thenReturn(schemaRead);
when(transaction.schemaWrite()).thenReturn(schemaWrite);
TransactionState transactionState = mock(TransactionState.class);
when(transaction.txState()).thenReturn(transactionState);
when(transaction.indexUniqueCreate(any(IndexPrototype.class))).thenAnswer(i -> i.<IndexPrototype>getArgument(0).materialise(INDEX_ID));
when(transaction.newStorageReader()).thenReturn(mock(StorageReader.class));
} catch (InvalidTransactionTypeKernelException e) {
fail("Expected write transaction");
}
return transaction;
}
use of org.neo4j.storageengine.api.StorageReader in project neo4j by neo4j.
the class KernelTransactionsTest method transactionClosesUnderlyingStoreReaderWhenDisposed.
@Test
void transactionClosesUnderlyingStoreReaderWhenDisposed() throws Throwable {
StorageReader storeStatement1 = mock(StorageReader.class);
StorageReader storeStatement2 = mock(StorageReader.class);
StorageReader storeStatement3 = mock(StorageReader.class);
KernelTransactions kernelTransactions = newKernelTransactions(mock(TransactionCommitProcess.class), storeStatement1, storeStatement2, storeStatement3);
// start and close 3 transactions from different threads
startAndCloseTransaction(kernelTransactions);
executorService.submit(() -> startAndCloseTransaction(kernelTransactions)).get();
// this is to guarantee that the execution will be in a new thread, not reused one
var executorService2 = Executors.newSingleThreadExecutor();
try {
executorService2.submit(() -> startAndCloseTransaction(kernelTransactions)).get();
} finally {
executorService2.shutdown();
}
kernelTransactions.disposeAll();
verify(storeStatement1).close();
verify(storeStatement2).close();
verify(storeStatement3).close();
}
Aggregations