Search in sources :

Example 16 with KernelStatement

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();
}
Also used : KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) Test(org.junit.Test)

Example 17 with KernelStatement

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);
}
Also used : KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) Test(org.junit.Test)

Example 18 with KernelStatement

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());
}
Also used : ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) StatementOperationParts(org.neo4j.kernel.impl.api.StatementOperationParts) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) Test(org.junit.Test)

Example 19 with KernelStatement

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);
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) Test(org.junit.Test)

Example 20 with KernelStatement

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));
}
Also used : PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) TransactionState(org.neo4j.kernel.api.txstate.TransactionState) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) StoreReadLayer(org.neo4j.storageengine.api.StoreReadLayer) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) StateHandlingStatementOperations(org.neo4j.kernel.impl.api.StateHandlingStatementOperations) Test(org.junit.Test)

Aggregations

KernelStatement (org.neo4j.kernel.impl.api.KernelStatement)28 Test (org.junit.Test)19 StateHandlingStatementOperations (org.neo4j.kernel.impl.api.StateHandlingStatementOperations)14 TransactionState (org.neo4j.kernel.api.txstate.TransactionState)13 StoreReadLayer (org.neo4j.storageengine.api.StoreReadLayer)9 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)9 PrimitiveLongIterator (org.neo4j.collection.primitive.PrimitiveLongIterator)8 IndexQuery (org.neo4j.kernel.api.schema_new.IndexQuery)8 NodeItem (org.neo4j.storageengine.api.NodeItem)6 UniquenessConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor)4 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)3 PropertyAccessor (org.neo4j.kernel.api.index.PropertyAccessor)3 ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)3 StatementOperationParts (org.neo4j.kernel.impl.api.StatementOperationParts)3 IndexProxy (org.neo4j.kernel.impl.api.index.IndexProxy)3 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)3 ConstraintIndexCreator (org.neo4j.kernel.impl.api.state.ConstraintIndexCreator)3 RelationshipItem (org.neo4j.storageengine.api.RelationshipItem)3 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2