use of org.neo4j.kernel.impl.api.KernelStatement 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.KernelStatement 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.KernelStatement in project neo4j by neo4j.
the class ConstraintIndexCreatorTest method shouldReleaseSchemaLockWhileAwaitingIndexPopulation.
@Test
public void shouldReleaseSchemaLockWhileAwaitingIndexPopulation() throws Exception {
// given
StubKernel kernel = new StubKernel();
IndexingService indexingService = mock(IndexingService.class);
StatementOperationParts constraintCreationContext = mockedParts();
PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
KernelStatement state = mockedState();
when(constraintCreationContext.schemaReadOperations().indexGetCommittedId(state, index)).thenReturn(2468L);
IndexProxy indexProxy = mock(IndexProxy.class);
when(indexingService.getIndexProxy(anyLong())).thenReturn(indexProxy);
ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, true);
// when
creator.createUniquenessConstraintIndex(state, constraintCreationContext.schemaReadOperations(), index.schema());
// then
verify(state.locks().pessimistic()).releaseExclusive(ResourceTypes.SCHEMA, ResourceTypes.schemaResource());
verify(state.locks().pessimistic()).acquireExclusive(state.lockTracer(), ResourceTypes.SCHEMA, ResourceTypes.schemaResource());
}
use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method shouldGetAllConstraints.
@Test
public void shouldGetAllConstraints() throws Exception {
// given
UniquenessConstraintDescriptor constraint1 = ConstraintDescriptorFactory.uniqueForLabel(2, 3);
UniquenessConstraintDescriptor constraint2 = ConstraintDescriptorFactory.uniqueForLabel(4, 5);
TransactionState txState = new TxState();
KernelStatement state = mockedState(txState);
when(inner.constraintsGetForSchema(constraint1.schema())).thenAnswer(invocation -> Iterators.emptyIterator());
when(inner.constraintsGetForSchema(constraint2.schema())).thenAnswer(invocation -> Iterators.emptyIterator());
when(inner.constraintsGetAll()).thenAnswer(invocation -> iterator(constraint2));
StateHandlingStatementOperations context = newTxStateOps(inner);
context.uniquePropertyConstraintCreate(state, constraint1.schema());
context.uniquePropertyConstraintCreate(state, constraint2.schema());
// when
Set<ConstraintDescriptor> result = Iterables.asSet(asIterable(context.constraintsGetAll(state)));
// then
assertEquals(asSet(constraint1, constraint2), result);
}
use of org.neo4j.kernel.impl.api.KernelStatement in project neo4j by neo4j.
the class StateHandlingStatementOperationsTest method shouldConsiderTransactionStateDuringIndexRangeSeekBySuffixWithIndexQuery.
@Test
public void shouldConsiderTransactionStateDuringIndexRangeSeekBySuffixWithIndexQuery() throws Exception {
// Given
TransactionState txState = mock(TransactionState.class);
KernelStatement statement = mock(KernelStatement.class);
when(statement.hasTxStateWithChanges()).thenReturn(true);
when(statement.txState()).thenReturn(txState);
when(txState.indexUpdatesForScan(index)).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);
IndexReader indexReader = addMockedIndexReader(statement);
IndexQuery.StringSuffixPredicate indexQuery = IndexQuery.stringSuffix(index.schema().getPropertyId(), "suffix");
when(indexReader.query(indexQuery)).thenReturn(PrimitiveLongCollections.resourceIterator(PrimitiveLongCollections.iterator(43L, 44L, 46L), null));
StateHandlingStatementOperations context = newTxStateOps(storeReadLayer);
// When
PrimitiveLongIterator results = context.indexQuery(statement, index, indexQuery);
// Then
assertEquals(asSet(42L, 43L), PrimitiveLongCollections.toSet(results));
}
Aggregations