use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class TestPlaceboTransaction method before.
@Before
public void before() throws Exception {
ThreadToStatementContextBridge bridge = mock(ThreadToStatementContextBridge.class);
when(bridge.get()).thenReturn(mock(Statement.class));
kernelTransaction = spy(KernelTransaction.class);
Statement statement = mock(Statement.class);
readOps = mock(ReadOperations.class);
when(statement.readOperations()).thenReturn(readOps);
when(bridge.get()).thenReturn(statement);
placeboTx = new PlaceboTransaction(() -> kernelTransaction, bridge);
resource = mock(Node.class);
when(resource.getId()).thenReturn(1L);
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class TopLevelTransactionTest method shouldThrowTransactionExceptionOnTransientKernelException.
@Test
public void shouldThrowTransactionExceptionOnTransientKernelException() throws Exception {
// GIVEN
KernelTransaction kernelTransaction = mock(KernelTransaction.class);
when(kernelTransaction.isOpen()).thenReturn(true);
doThrow(new RuntimeException("Just a random failure")).when(kernelTransaction).close();
ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
// WHEN
transaction.success();
try {
transaction.close();
fail("Should have failed");
} catch (org.neo4j.graphdb.TransactionFailureException e) {
// THEN Good
}
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class TopLevelTransactionTest method shouldLetThroughTransientFailureException.
@Test
public void shouldLetThroughTransientFailureException() throws Exception {
// GIVEN
KernelTransaction kernelTransaction = mock(KernelTransaction.class);
when(kernelTransaction.isOpen()).thenReturn(true);
doThrow(new TransientDatabaseFailureException("Just a random failure")).when(kernelTransaction).close();
ThreadToStatementContextBridge bridge = new ThreadToStatementContextBridge();
TopLevelTransaction transaction = new TopLevelTransaction(kernelTransaction, bridge);
// WHEN
transaction.success();
try {
transaction.close();
fail("Should have failed");
} catch (TransientFailureException e) {
// THEN Good
}
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class GraphDatabaseShellServer method unbindAndRegisterTransaction.
public void unbindAndRegisterTransaction(Serializable clientId) throws ShellException {
try {
ThreadToStatementContextBridge threadToStatementContextBridge = getThreadToStatementContextBridge();
KernelTransaction tx = threadToStatementContextBridge.getTopLevelTransactionBoundToThisThread(false);
threadToStatementContextBridge.unbindTransactionFromCurrentThread();
if (tx == null) {
clients.remove(clientId);
} else {
clients.put(clientId, tx);
}
} catch (Exception e) {
throw wrapException(e);
}
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class ClusterDiscoveryIT method getMembers.
@SuppressWarnings("unchecked")
private List<Map<String, Object>> getMembers(GraphDatabaseFacade db) throws TransactionFailureException, org.neo4j.kernel.api.exceptions.ProcedureException {
KernelAPI kernel = db.getDependencyResolver().resolveDependency(KernelAPI.class);
KernelTransaction transaction = kernel.newTransaction(Type.implicit, AnonymousContext.read());
try (Statement statement = transaction.acquireStatement()) {
// when
List<Object[]> currentMembers = asList(statement.procedureCallOperations().procedureCallRead(procedureName(GET_SERVERS_V1.fullyQualifiedProcedureName()), new Object[0]));
return (List<Map<String, Object>>) currentMembers.get(0)[1];
}
}
Aggregations