Search in sources :

Example 1 with BoltResultHandle

use of org.neo4j.bolt.runtime.BoltResultHandle in project neo4j by neo4j.

the class TransactionStateMachineTest method newResultHandle.

private static BoltResultHandle newResultHandle() throws KernelException {
    BoltResultHandle resultHandle = mock(BoltResultHandle.class);
    when(resultHandle.start()).thenReturn(BoltResult.EMPTY);
    return resultHandle;
}
Also used : BoltResultHandle(org.neo4j.bolt.runtime.BoltResultHandle)

Example 2 with BoltResultHandle

use of org.neo4j.bolt.runtime.BoltResultHandle in project neo4j by neo4j.

the class TransactionStateMachineTest method newResultHandle.

private static BoltResultHandle newResultHandle(Throwable t) throws KernelException {
    BoltResultHandle resultHandle = mock(BoltResultHandle.class);
    when(resultHandle.start()).thenThrow(t);
    return resultHandle;
}
Also used : BoltResultHandle(org.neo4j.bolt.runtime.BoltResultHandle)

Example 3 with BoltResultHandle

use of org.neo4j.bolt.runtime.BoltResultHandle in project neo4j by neo4j.

the class TransactionStateMachineTest method shouldTryToTerminateAllActiveStatements.

@Test
void shouldTryToTerminateAllActiveStatements() throws Exception {
    BoltTransaction transaction = newTimedOutTransaction();
    BoltResultHandle resultHandle = newResultHandle();
    doThrow(new RuntimeException("You shall not pass")).doThrow(new RuntimeException("Not pass twice")).when(resultHandle).terminate();
    TransactionStateMachineSPI stateMachineSPI = mock(TransactionStateMachineSPI.class);
    when(stateMachineSPI.beginTransaction(any(), any(), any(), any(), any(), any())).thenReturn(transaction);
    when(stateMachineSPI.executeQuery(any(), anyString(), any())).thenReturn(resultHandle);
    // V4
    when(stateMachineSPI.supportsNestedStatementsInTransaction()).thenReturn(true);
    TransactionStateMachine stateMachine = newTransactionStateMachine(stateMachineSPI);
    // We're in explicit-commit state
    beginTx(stateMachine, List.of());
    assertThat(stateMachine.state).isEqualTo(TransactionStateMachine.State.EXPLICIT_TRANSACTION);
    assertNotNull(stateMachine.ctx.currentTransaction);
    // We run two statements
    stateMachine.run("RETURN 1", null);
    stateMachine.run("RETURN 2", null);
    assertThat(stateMachine.state).isEqualTo(TransactionStateMachine.State.EXPLICIT_TRANSACTION);
    assertNotNull(stateMachine.ctx.currentTransaction);
    assertThat(stateMachine.ctx.statementCounter).isEqualTo(2);
    RuntimeException error = assertThrows(RuntimeException.class, () -> stateMachine.reset());
    assertThat(error.getCause().getMessage()).isEqualTo("You shall not pass");
    assertThat(error.getSuppressed().length).isEqualTo(1);
    assertThat(error.getSuppressed()[0].getMessage()).isEqualTo("Not pass twice");
}
Also used : BoltTransaction(org.neo4j.bolt.dbapi.BoltTransaction) BoltResultHandle(org.neo4j.bolt.runtime.BoltResultHandle) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) Test(org.junit.jupiter.api.Test)

Example 4 with BoltResultHandle

use of org.neo4j.bolt.runtime.BoltResultHandle in project neo4j by neo4j.

the class TransactionStateMachineTest method shouldCloseResultHandlesWhenExecutionFailsInExplicitTransaction.

@Test
void shouldCloseResultHandlesWhenExecutionFailsInExplicitTransaction() throws Exception {
    BoltTransaction transaction = newTransaction();
    BoltResultHandle resultHandle = newResultHandle(new RuntimeException("some error"));
    TransactionStateMachineSPI stateMachineSPI = newTransactionStateMachineSPI(transaction, resultHandle);
    TransactionStateMachine stateMachine = newTransactionStateMachine(stateMachineSPI);
    RuntimeException e = assertThrows(RuntimeException.class, () -> {
        beginTx(stateMachine);
        stateMachine.run("SOME STATEMENT", null);
    });
    assertEquals("some error", e.getMessage());
    assertThat(stateMachine.ctx.statementOutcomes.entrySet()).hasSize(0);
    assertNotNull(stateMachine.ctx.currentTransaction);
}
Also used : BoltTransaction(org.neo4j.bolt.dbapi.BoltTransaction) BoltResultHandle(org.neo4j.bolt.runtime.BoltResultHandle) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) Test(org.junit.jupiter.api.Test)

Example 5 with BoltResultHandle

use of org.neo4j.bolt.runtime.BoltResultHandle in project neo4j by neo4j.

the class TransactionStateMachineTest method shouldCloseResultAndTransactionHandlesWhenExecutionFails.

@Test
void shouldCloseResultAndTransactionHandlesWhenExecutionFails() throws Exception {
    BoltTransaction transaction = newTransaction();
    BoltResultHandle resultHandle = newResultHandle(new RuntimeException("some error"));
    TransactionStateMachineSPI stateMachineSPI = newTransactionStateMachineSPI(transaction, resultHandle);
    TransactionStateMachine stateMachine = newTransactionStateMachine(stateMachineSPI);
    RuntimeException e = assertThrows(RuntimeException.class, () -> stateMachine.run("SOME STATEMENT", null));
    assertEquals("some error", e.getMessage());
    assertThat(stateMachine.ctx.statementOutcomes.entrySet()).hasSize(0);
    assertNull(stateMachine.ctx.currentTransaction);
}
Also used : BoltTransaction(org.neo4j.bolt.dbapi.BoltTransaction) BoltResultHandle(org.neo4j.bolt.runtime.BoltResultHandle) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) Test(org.junit.jupiter.api.Test)

Aggregations

BoltResultHandle (org.neo4j.bolt.runtime.BoltResultHandle)6 TransactionStateMachineSPI (org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI)4 Test (org.junit.jupiter.api.Test)3 BoltTransaction (org.neo4j.bolt.dbapi.BoltTransaction)3