@Before public void before() throws Exception { collectionsFactory = Mockito.spy( new TestCollectionsFactory() ); when( headerInformation.getAdditionalHeader() ).thenReturn( new byte[0] ); when( headerInformationFactory.create() ).thenReturn( headerInformation ); when( neoStores.getMetaDataStore() ).thenReturn( metaDataStore ); when( storageEngine.newReader() ).thenReturn( readLayer ); doAnswer( invocation -> ((Collection<StorageCommand>) invocation.getArgument(0) ).add( new Command .RelationshipCountsCommand( 1, 2,3, 4L ) ) ) .when( storageEngine ).createCommands( anyCollection(), any( ReadableTransactionState.class ), any( StorageReader.class ), any( ResourceLocker.class ), anyLong(), any( TxStateVisitor.Decorator.class ) ); }
@Override void flush( GraphDatabaseAPI db ) { IOLimiter limiter = IOLimiter.UNLIMITED; db.getDependencyResolver().resolveDependency( StorageEngine.class ).flushAndForce( limiter ); } },
protected void applyToStore( TransactionToApply batch, CommitEvent commitEvent, TransactionApplicationMode mode ) throws TransactionFailureException { try ( StoreApplyEvent storeApplyEvent = commitEvent.beginStoreApply() ) { storageEngine.apply( batch, mode ); } catch ( Throwable cause ) { throw new TransactionFailureException( TransactionCommitFailed, cause, "Could not apply the transaction to the store after written to log" ); } }
private byte[] createCommands( String tokenName ) { StorageEngine storageEngine = dependencies.resolveDependency( StorageEngine.class ); Collection<StorageCommand> commands = new ArrayList<>(); TransactionState txState = new TxState(); int tokenId = Math.toIntExact( idGeneratorFactory.get( tokenIdType ).nextId() ); createToken( txState, tokenName, tokenId ); try ( StorageStatement statement = storageEngine.storeReadLayer().newStatement() ) { storageEngine.createCommands( commands, txState, statement, ResourceLocker.NONE, Long.MAX_VALUE ); } catch ( CreateConstraintFailureException | TransactionFailureException | ConstraintValidationKernelException e ) { throw new RuntimeException( "Unable to create token '" + tokenName + "'", e ); } return ReplicatedTokenRequestSerializer.commandBytes( commands ); }
commands.add( mock( Command.class ) ); return null; } ).when( storageEngine ).createCommands( any( Collection.class ), any( TransactionState.class ),
StorageEngine storageEngine = mock( StorageEngine.class ); StorageReader storageReader = mock( StorageReader.class ); when( storageEngine.newReader() ).thenReturn( storageReader );
private void clearTransactions() { // We don't want to have buffered ids carry over to the new role storageEngine.clearBufferedIds(); // Get rid of all pooled transactions, as they will otherwise reference // components that have been swapped out during the mode switch. kernelModule.kernelTransactions().disposeAll(); }
storageEngine.forceClose(); storageEngine.forceClose();
private byte[] createCommands( String tokenName ) { StorageEngine storageEngine = dependencies.resolveDependency( StorageEngine.class ); Collection<StorageCommand> commands = new ArrayList<>(); TransactionState txState = new TxState(); int tokenId = Math.toIntExact( idGeneratorFactory.get( tokenIdType ).nextId() ); createToken( txState, tokenName, tokenId ); try ( StorageStatement statement = storageEngine.storeReadLayer().newStatement() ) { storageEngine.createCommands( commands, txState, statement, ResourceLocker.NONE, Long.MAX_VALUE ); } catch ( CreateConstraintFailureException | TransactionFailureException | ConstraintValidationException e ) { throw new RuntimeException( "Unable to create token '" + tokenName + "'", e ); } return ReplicatedTokenRequestSerializer.commandBytes( commands ); }
storageEngine.createCommands( extractedCommands, txState, storageReader,
when( storageReader.constraintsGetForLabel( anyInt() )).thenReturn( Collections.emptyIterator() ); when( storageReader.constraintsGetAll() ).thenReturn( Collections.emptyIterator() ); when( engine.newReader() ).thenReturn( storageReader ); allStoreHolder = new AllStoreHolder( storageReader, transaction, cursors, mock( ExplicitIndexStore.class ), mock( Procedures.class ), mock( SchemaState.class ), new Dependencies() );
private void clearTransactions() { // We don't want to have buffered ids carry over to the new role storageEngine.clearBufferedIds(); // Get rid of all pooled transactions, as they will otherwise reference // components that have been swapped out during the mode switch. kernelModule.kernelTransactions().disposeAll(); }
storageEngine.forceClose(); storageEngine.forceClose();
private static void flush( GraphDatabaseService db ) { ((GraphDatabaseAPI)db).getDependencyResolver().resolveDependency( StorageEngine.class ).flushAndForce( IOLimiter.UNLIMITED ); }
private static KernelTransactions newKernelTransactions( boolean testKernelTransactions, TransactionCommitProcess commitProcess, StorageReader firstReader, StorageReader... otherReaders ) throws Throwable { Locks locks = mock( Locks.class ); Locks.Client client = mock( Locks.Client.class ); when( locks.newClient() ).thenReturn( client ); StorageEngine storageEngine = mock( StorageEngine.class ); when( storageEngine.newReader() ).thenReturn( firstReader, otherReaders ); doAnswer( invocation -> { Collection<StorageCommand> argument = invocation.getArgument( 0 ); argument.add( mock( StorageCommand.class ) ); return null; } ).when( storageEngine ).createCommands( anyCollection(), any( ReadableTransactionState.class ), any( StorageReader.class ), any( ResourceLocker.class ), anyLong(), any( TxStateVisitor.Decorator.class ) ); return newKernelTransactions( locks, storageEngine, commitProcess, testKernelTransactions ); }
storageEngine.createCommands( extractedCommands, txState, storageReader,
static Instances kernelTransactionWithInternals( LoginContext loginContext ) { TransactionHeaderInformation headerInformation = new TransactionHeaderInformation( -1, -1, new byte[0] ); TransactionHeaderInformationFactory headerInformationFactory = mock( TransactionHeaderInformationFactory.class ); when( headerInformationFactory.create() ).thenReturn( headerInformation ); StorageEngine storageEngine = mock( StorageEngine.class ); StorageReader storageReader = mock( StorageReader.class ); when( storageEngine.newReader() ).thenReturn( storageReader ); KernelTransactionImplementation transaction = new KernelTransactionImplementation( Config.defaults(), mock( StatementOperationParts.class ), mock( SchemaWriteGuard.class ), new TransactionHooks(), mock( ConstraintIndexCreator.class ), new Procedures(), headerInformationFactory, mock( TransactionRepresentationCommitProcess.class ), mock( TransactionMonitor.class ), mock( AuxiliaryTransactionStateManager.class ), mock( Pool.class ), Clocks.systemClock(), new AtomicReference<>( CpuClock.NOT_AVAILABLE ), new AtomicReference<>( HeapAllocation.NOT_AVAILABLE ), NULL, LockTracer.NONE, PageCursorTracerSupplier.NULL, storageEngine, new CanWrite(), AutoIndexing.UNSUPPORTED, mock( ExplicitIndexStore.class ), EmptyVersionContextSupplier.EMPTY, ON_HEAP, new StandardConstraintSemantics(), mock( SchemaState.class ), mock( IndexingService.class ), mockedTokenHolders(), new Dependencies() ); StatementLocks statementLocks = new SimpleStatementLocks( new NoOpClient() ); transaction.initialize( 0, 0, statementLocks, KernelTransaction.Type.implicit, loginContext.authorize( s -> -1, GraphDatabaseSettings.DEFAULT_DATABASE_NAME ), 0L, 1L ); return new Instances( transaction ); }
@Override public boolean visit( CommittedTransactionRepresentation transaction ) throws Exception { TransactionRepresentation txRepresentation = transaction.getTransactionRepresentation(); long txId = transaction.getCommitEntry().getTxId(); TransactionToApply tx = new TransactionToApply( txRepresentation, txId ); tx.commitment( NO_COMMITMENT, txId ); tx.logPosition( transaction.getStartEntry().getStartPosition() ); storageEngine.apply( tx, mode ); return false; }
private void flushAll() { db.getDependencyResolver().resolveDependency( StorageEngine.class ).flushAndForce( IOLimiter.UNLIMITED ); } }
@SuppressWarnings( "deprecation" ) @Before public void before() { db = (GraphDatabaseAPI) createGraphDatabase(); DependencyResolver resolver = db.getDependencyResolver(); this.storageReader = resolver.resolveDependency( StorageEngine.class ).newReader(); this.state = new KernelStatement( null, null, storageReader, LockTracer.NONE, null, new ClockContext(), EmptyVersionContextSupplier.EMPTY ); }