use of org.neo4j.kernel.impl.api.KernelTransactionImplementation in project neo4j by neo4j.
the class KernelTransactionFactory method kernelTransactionWithInternals.
static Instances kernelTransactionWithInternals(SecurityContext securityContext) {
TransactionHeaderInformation headerInformation = new TransactionHeaderInformation(-1, -1, new byte[0]);
TransactionHeaderInformationFactory headerInformationFactory = mock(TransactionHeaderInformationFactory.class);
when(headerInformationFactory.create()).thenReturn(headerInformation);
StorageEngine storageEngine = mock(StorageEngine.class);
StoreReadLayer storeReadLayer = mock(StoreReadLayer.class);
StorageStatement storageStatement = mock(StorageStatement.class);
when(storeReadLayer.newStatement()).thenReturn(storageStatement);
when(storageEngine.storeReadLayer()).thenReturn(storeReadLayer);
KernelTransactionImplementation transaction = new KernelTransactionImplementation(mock(StatementOperationContainer.class), mock(SchemaWriteGuard.class), new TransactionHooks(), mock(ConstraintIndexCreator.class), new Procedures(), headerInformationFactory, mock(TransactionRepresentationCommitProcess.class), mock(TransactionMonitor.class), mock(Supplier.class), mock(Pool.class), Clocks.systemClock(), NULL, LockTracer.NONE, PageCursorTracerSupplier.NULL, storageEngine, new CanWrite());
StatementLocks statementLocks = new SimpleStatementLocks(new NoOpClient());
transaction.initialize(0, 0, statementLocks, KernelTransaction.Type.implicit, securityContext, 0L);
return new Instances(transaction, storageEngine, storeReadLayer, storageStatement);
}
use of org.neo4j.kernel.impl.api.KernelTransactionImplementation in project neo4j by neo4j.
the class TimeoutGuardTest method allowToProceedWhenTransactionTimeoutNotReached.
@Test
public void allowToProceedWhenTransactionTimeoutNotReached() {
long transactionTimeout = 100000L;
long overtime = 5L;
TimeoutGuard timeoutGuard = buildGuard(logProvider);
initClock();
KernelStatement kernelStatement = getKernelStatement(transactionTimeout);
clock.forward(overtime, TimeUnit.MILLISECONDS);
timeoutGuard.check(kernelStatement);
KernelTransactionImplementation transaction = kernelStatement.getTransaction();
assertFalse(transaction.getReasonIfTerminated().isPresent());
logProvider.assertNoLoggingOccurred();
}
use of org.neo4j.kernel.impl.api.KernelTransactionImplementation in project neo4j by neo4j.
the class TimeoutGuardTest method detectTimedTransaction.
@Test
public void detectTimedTransaction() {
long transactionTimeout = 10L;
long overtime = 1L;
TimeoutGuard timeoutGuard = buildGuard(logProvider);
initClock();
KernelStatement kernelStatement = getKernelStatement(transactionTimeout);
clock.forward(transactionTimeout + overtime, TimeUnit.MILLISECONDS);
String message = "Transaction timeout. (Overtime: 1 ms).";
check(timeoutGuard, kernelStatement, overtime, message);
KernelTransactionImplementation transaction = kernelStatement.getTransaction();
assertSame(Status.Transaction.TransactionTimedOut, transaction.getReasonIfTerminated().get());
logProvider.assertContainsMessageContaining(message);
}
use of org.neo4j.kernel.impl.api.KernelTransactionImplementation in project neo4j by neo4j.
the class PlainOperationsTest method shouldAcquireTxStateBeforeAllocatingSchemaId.
@Test
void shouldAcquireTxStateBeforeAllocatingSchemaId() throws KernelException {
// given
KernelTransactionImplementation ktx = mock(KernelTransactionImplementation.class);
when(ktx.txState()).thenReturn(mock(TransactionState.class));
Locks.Client lockClient = mock(Locks.Client.class);
when(ktx.lockClient()).thenReturn(lockClient);
CommandCreationContext commandCreationContext = mock(CommandCreationContext.class);
IndexingProvidersService indexingProvidersService = mock(IndexingProvidersService.class);
when(indexingProvidersService.getDefaultProvider()).thenReturn(mock(IndexProviderDescriptor.class));
AllStoreHolder allStoreHolder = mock(AllStoreHolder.class);
when(allStoreHolder.index(any())).thenReturn(Iterators.emptyResourceIterator());
when(allStoreHolder.indexGetForName(any())).thenReturn(IndexDescriptor.NO_INDEX);
when(allStoreHolder.constraintsGetForSchema(any())).thenReturn(Iterators.emptyResourceIterator());
Operations operations = new Operations(allStoreHolder, mock(StorageReader.class), mock(IndexTxStateUpdater.class), commandCreationContext, ktx, mock(KernelToken.class), mock(DefaultPooledCursors.class), mock(ConstraintIndexCreator.class), mock(ConstraintSemantics.class), indexingProvidersService, Config.defaults(), INSTANCE, () -> KernelVersion.LATEST, mock(DbmsRuntimeRepository.class));
// when
operations.indexCreate(IndexPrototype.forSchema(schema).withName("name"));
// then
InOrder inOrder = inOrder(ktx, commandCreationContext);
inOrder.verify(ktx).txState();
inOrder.verify(commandCreationContext).reserveSchema();
inOrder.verifyNoMoreInteractions();
}
use of org.neo4j.kernel.impl.api.KernelTransactionImplementation in project neo4j by neo4j.
the class DefaultRelationshipTraversalCursorTest method emptyTxState.
// HELPERS
private static Read emptyTxState() {
KernelTransactionImplementation ktx = mock(KernelTransactionImplementation.class);
Read read = new TestRead(ktx);
when(ktx.securityContext()).thenReturn(SecurityContext.AUTH_DISABLED);
return read;
}
Aggregations