Search in sources :

Example 11 with TransactionStateMachineSPI

use of org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI 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 12 with TransactionStateMachineSPI

use of org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI 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)

Example 13 with TransactionStateMachineSPI

use of org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI in project neo4j by neo4j.

the class StatementProcessorProvider method getStatementProcessor.

public StatementProcessor getStatementProcessor(String databaseName) throws BoltProtocolBreachFatality, BoltIOException {
    memoryTracker.allocateHeap(TransactionStateMachine.SHALLOW_SIZE);
    TransactionStateMachineSPI transactionSPI = spiProvider.getTransactionStateMachineSPI(databaseName, resourceReleaseManger);
    return new TransactionStateMachine(databaseName, transactionSPI, authResult, clock, routingContext);
}
Also used : TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI)

Example 14 with TransactionStateMachineSPI

use of org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI in project neo4j by neo4j.

the class TransactionStateMachineSPIProviderV4Test method shouldReturnTransactionStateMachineSPIIfDatabaseExists.

@Test
void shouldReturnTransactionStateMachineSPIIfDatabaseExists() throws Throwable {
    String databaseName = "database";
    DatabaseManagementService managementService = managementService(databaseName);
    TransactionStateMachineSPIProvider spiProvider = newSpiProvider(managementService);
    TransactionStateMachineSPI spi = spiProvider.getTransactionStateMachineSPI(databaseName, mock(StatementProcessorReleaseManager.class));
    assertThat(spi).isInstanceOf(TransactionStateMachineV4SPI.class);
}
Also used : StatementProcessorReleaseManager(org.neo4j.bolt.runtime.statemachine.StatementProcessorReleaseManager) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) TransactionStateMachineSPIProvider(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPIProvider) Test(org.junit.jupiter.api.Test)

Example 15 with TransactionStateMachineSPI

use of org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI in project neo4j by neo4j.

the class DefaultDatabaseTransactionStateMachineSPIProviderTest method shouldReturnDefaultTransactionStateMachineSPIWithEmptyDatabaseName.

@Test
void shouldReturnDefaultTransactionStateMachineSPIWithEmptyDatabaseName() throws Throwable {
    DatabaseManagementService managementService = managementServiceWithDatabase("neo4j");
    TransactionStateMachineSPIProvider spiProvider = newSpiProvider(managementService);
    TransactionStateMachineSPI spi = spiProvider.getTransactionStateMachineSPI(ABSENT_DB_NAME, mock(StatementProcessorReleaseManager.class));
    assertThat(spi).isInstanceOf(TransactionStateMachineSPI.class);
}
Also used : StatementProcessorReleaseManager(org.neo4j.bolt.runtime.statemachine.StatementProcessorReleaseManager) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) TransactionStateMachineSPIProvider(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPIProvider) Test(org.junit.jupiter.api.Test)

Aggregations

TransactionStateMachineSPI (org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI)21 Test (org.junit.jupiter.api.Test)18 BoltTransaction (org.neo4j.bolt.dbapi.BoltTransaction)13 BoltResultHandle (org.neo4j.bolt.runtime.BoltResultHandle)4 StatementProcessorReleaseManager (org.neo4j.bolt.runtime.statemachine.StatementProcessorReleaseManager)3 TransactionStateMachineSPIProvider (org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPIProvider)3 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)3 StatementOutcome (org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome)2 InOrder (org.mockito.InOrder)1 BoltQueryExecutor (org.neo4j.bolt.dbapi.BoltQueryExecutor)1 BoltConnectionAuthFatality (org.neo4j.bolt.runtime.BoltConnectionAuthFatality)1 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)1 AuthorizationExpiredException (org.neo4j.graphdb.security.AuthorizationExpiredException)1 LoginContext (org.neo4j.internal.kernel.api.security.LoginContext)1