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 IndexProceduresTest method closeStatementOnClose.
@Test
public void closeStatementOnClose() throws Exception {
KernelTransaction kernelTransaction = mock(KernelTransaction.class);
Statement statement = mock(Statement.class);
when(kernelTransaction.acquireStatement()).thenReturn(statement);
//noinspection EmptyTryBlock
try (IndexProcedures ignored = new IndexProcedures(kernelTransaction, null)) {
}
verify(statement).close();
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class ConstraintIndexCreator method dropUniquenessConstraintIndex.
/**
* You MUST hold a schema write lock before you call this method.
*/
public void dropUniquenessConstraintIndex(NewIndexDescriptor descriptor) throws TransactionFailureException, DropIndexFailureException {
try (KernelTransaction transaction = kernelSupplier.get().newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
Statement statement = transaction.acquireStatement()) {
// NOTE: This creates the index (obviously) but it DOES NOT grab a schema
// write lock. It is assumed that the transaction that invoked this "inner" transaction
// holds a schema write lock, and that it will wait for this inner transaction to do its
// work.
// TODO (Ben+Jake): The Transactor is really part of the kernel internals, so it needs access to the
// internal implementation of Statement. However it is currently used by the external
// RemoveOrphanConstraintIndexesOnStartup job. This needs revisiting.
((KernelStatement) statement).txState().indexDoDrop(descriptor);
transaction.success();
}
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class ConstraintIndexCreator method createConstraintIndex.
public NewIndexDescriptor createConstraintIndex(final LabelSchemaDescriptor schema) {
try (KernelTransaction transaction = kernelSupplier.get().newTransaction(KernelTransaction.Type.implicit, AUTH_DISABLED);
Statement statement = transaction.acquireStatement()) {
// NOTE: This creates the index (obviously) but it DOES NOT grab a schema
// write lock. It is assumed that the transaction that invoked this "inner" transaction
// holds a schema write lock, and that it will wait for this inner transaction to do its
// work.
// TODO (Ben+Jake): The Transactor is really part of the kernel internals, so it needs access to the
// internal implementation of Statement. However it is currently used by the external
// RemoveOrphanConstraintIndexesOnStartup job. This needs revisiting.
NewIndexDescriptor index = NewIndexDescriptorFactory.uniqueForSchema(schema);
((KernelStatement) statement).txState().indexRuleDoAdd(index);
transaction.success();
return index;
} catch (TransactionFailureException e) {
throw new RuntimeException(e);
}
}
Aggregations