use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class NodeScanIT method trackPageCacheAccessOnNodeLabelScan.
@Test
void trackPageCacheAccessOnNodeLabelScan() throws KernelException {
var testLabel = Label.label("testLabel");
try (KernelTransaction tx = kernel.beginTransaction(IMPLICIT, read())) {
var cursorContext = tx.cursorContext();
assertThat(cursorContext.getCursorTracer().pins()).isZero();
var label = tx.tokenRead().nodeLabel(testLabel.name());
IndexDescriptor index = tx.schemaRead().index(SchemaDescriptor.forAnyEntityTokens(EntityType.NODE)).next();
TokenReadSession tokenReadSession = tx.dataRead().tokenReadSession(index);
try (NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(cursorContext)) {
tx.dataRead().nodeLabelScan(tokenReadSession, cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(label));
assertThat(cursorContext.getCursorTracer().pins()).isNotZero();
}
}
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class KernelReadTracerTest method shouldTraceLabelScan.
@Test
void shouldTraceLabelScan() throws KernelException {
// given
TestKernelReadTracer tracer = new TestKernelReadTracer();
int barId = token.labelGetOrCreateForName("Bar");
List<TraceEvent> expectedEvents = new ArrayList<>();
expectedEvents.add(OnLabelScan(barId));
try (NodeLabelIndexCursor cursor = cursors.allocateNodeLabelIndexCursor(NULL)) {
// when
cursor.setTracer(tracer);
read.nodeLabelScan(getTokenReadSession(tx, EntityType.NODE), cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(barId));
while (cursor.next()) {
expectedEvents.add(OnNode(cursor.nodeReference()));
}
}
// then
tracer.assertEvents(expectedEvents);
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class NodeLabelTokenIndexCursorTest method shouldFindNodesByLabelInTx.
@Test
void shouldFindNodesByLabelInTx() throws Exception {
long inStore;
long deletedInTx;
long createdInTx;
try (KernelTransaction tx = beginTransaction()) {
inStore = createNode(tx.dataWrite(), labelOne);
createNode(tx.dataWrite(), labelTwo);
deletedInTx = createNode(tx.dataWrite(), labelOne);
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
tx.dataWrite().nodeDelete(deletedInTx);
createdInTx = createNode(tx.dataWrite(), labelOne);
createNode(tx.dataWrite(), labelTwo);
Read read = tx.dataRead();
var session = getTokenReadSession(tx);
try (NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
MutableLongSet uniqueIds = new LongHashSet();
// when
read.nodeLabelScan(session, cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(labelOne));
// then
assertNodes(cursor, uniqueIds, inStore, createdInTx);
}
}
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class NodeTransactionStateTestBase method shouldFindUpdatedNodeInInLabelScan.
@Test
void shouldFindUpdatedNodeInInLabelScan() throws Exception {
// Given
Node node = createNode();
try (KernelTransaction tx = beginTransaction();
NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
// when
int label = tx.tokenWrite().labelGetOrCreateForName("label");
tx.dataWrite().nodeAddLabel(node.node, label);
tx.dataRead().nodeLabelScan(getTokenReadSession(tx, EntityType.NODE), cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(label));
// then
assertTrue(cursor.next());
assertEquals(node.node, cursor.nodeReference());
}
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class NodeTransactionStateTestBase method shouldNotFindDeletedNodeInLabelScan.
@Test
void shouldNotFindDeletedNodeInLabelScan() throws Exception {
// Given
Node node = createNode("label");
try (KernelTransaction tx = beginTransaction();
NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
// when
tx.dataWrite().nodeDelete(node.node);
tx.dataRead().nodeLabelScan(getTokenReadSession(tx, EntityType.NODE), cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(node.labels[0]));
// then
assertFalse(cursor.next());
}
}
Aggregations