use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.
the class Neo4jTransactionalContextTest method shouldNotBeTopLevelWithExplicitTx.
@Test
void shouldNotBeTopLevelWithExplicitTx() {
InternalTransaction tx = mock(InternalTransaction.class);
when(tx.transactionType()).thenReturn(KernelTransaction.Type.EXPLICIT);
Neo4jTransactionalContext context = newContext(tx);
assertFalse(context.isTopLevelTx());
}
use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.
the class Neo4jTransactionalContextTest method shouldThrowWhenGettingTxAfterTermination.
@Test
void shouldThrowWhenGettingTxAfterTermination() {
MutableObject<Status> terminationReason = new MutableObject<>();
InternalTransaction tx = mock(InternalTransaction.class);
doAnswer(invocation -> {
terminationReason.setValue(Status.Transaction.Terminated);
return null;
}).when(tx).terminate();
when(tx.terminationReason()).then(invocation -> Optional.ofNullable(terminationReason.getValue()));
Neo4jTransactionalContext context = newContext(tx);
context.terminate();
assertThrows(TransactionTerminatedException.class, context::getOrBeginNewIfClosed);
}
use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.
the class CompositeStringLengthValidationIT method shouldHandleCompositeSizesCloseToTheLimit.
@Test
void shouldHandleCompositeSizesCloseToTheLimit() throws KernelException {
String firstSlot = random.nextAlphaNumericString(firstSlotLength, firstSlotLength);
String secondSlot = random.nextAlphaNumericString(secondSlotLength, secondSlotLength);
// given
IndexDescriptor index = createIndex(KEY, KEY2);
Node node;
try (Transaction tx = db.beginTx()) {
node = tx.createNode(LABEL);
node.setProperty(KEY, firstSlot);
node.setProperty(KEY2, secondSlot);
tx.commit();
}
try (Transaction tx = db.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
int propertyKeyId1 = ktx.tokenRead().propertyKey(KEY);
int propertyKeyId2 = ktx.tokenRead().propertyKey(KEY2);
try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
IndexReadSession indexReadSession = ktx.dataRead().indexReadSession(index);
ktx.dataRead().nodeIndexSeek(indexReadSession, cursor, unconstrained(), PropertyIndexQuery.exact(propertyKeyId1, firstSlot), PropertyIndexQuery.exact(propertyKeyId2, secondSlot));
assertTrue(cursor.next());
assertEquals(node.getId(), cursor.nodeReference());
assertFalse(cursor.next());
}
tx.commit();
}
}
use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.
the class UniqueIndexSeekIT method lockNodeUsingUniqueIndexSeek.
private static void lockNodeUsingUniqueIndexSeek(GraphDatabaseAPI database, String nameProperty) throws KernelException {
try (Transaction transaction = database.beginTx()) {
KernelTransaction kernelTransaction = ((InternalTransaction) transaction).kernelTransaction();
TokenRead tokenRead = kernelTransaction.tokenRead();
Read dataRead = kernelTransaction.dataRead();
int propertyId = tokenRead.propertyKey(nameProperty);
IndexDescriptor indexReference = kernelTransaction.schemaRead().indexGetForName(CONSTRAINT_NAME);
try (NodeValueIndexCursor cursor = kernelTransaction.cursors().allocateNodeValueIndexCursor(kernelTransaction.cursorContext(), kernelTransaction.memoryTracker())) {
dataRead.lockingNodeUniqueIndexSeek(indexReference, cursor, PropertyIndexQuery.ExactPredicate.exact(propertyId, "value"));
}
transaction.commit();
}
}
use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.
the class MultipleOpenCursorsTest method multipleIteratorsNestedInnerNewExists.
@ParameterizedTest
@MethodSource(value = "params")
void multipleIteratorsNestedInnerNewExists(IndexCoordinator indexCoordinator) throws Exception {
indexCoordinator.init(db);
try (Transaction tx = db.beginTx()) {
// when
KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
try (NodeValueIndexCursor cursor1 = indexCoordinator.queryExists(ktx)) {
List<Long> actual1 = new ArrayList<>();
while (cursor1.next()) {
actual1.add(cursor1.nodeReference());
try (NodeValueIndexCursor cursor2 = indexCoordinator.queryExists(ktx)) {
List<Long> actual2 = asList(cursor2);
indexCoordinator.assertExistsResult(actual2);
}
}
// then
indexCoordinator.assertExistsResult(actual1);
}
tx.commit();
}
}
Aggregations