use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class ConstraintTestBase method shouldFindAllConstraints.
@Test
void shouldFindAllConstraints() throws Exception {
// GIVEN
addConstraints("FOO", "prop1", "BAR", "prop2", "BAZ", "prop3");
try (KernelTransaction tx = beginTransaction()) {
// WHEN
List<ConstraintDescriptor> constraints = asList(tx.schemaRead().constraintsGetAll());
// THEN
assertThat(constraints).hasSize(3);
}
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class ConstraintTestBase method shouldFindConstraintsBySchema.
@Test
void shouldFindConstraintsBySchema() throws Exception {
// GIVEN
addConstraints("FOO", "prop");
try (KernelTransaction tx = beginTransaction()) {
int label = tx.tokenWrite().labelGetOrCreateForName("FOO");
int prop = tx.tokenWrite().propertyKeyGetOrCreateForName("prop");
LabelSchemaDescriptor descriptor = labelSchemaDescriptor(label, prop);
// WHEN
List<ConstraintDescriptor> constraints = asList(tx.schemaRead().constraintsGetForSchema(descriptor));
// THEN
assertThat(constraints).hasSize(1);
assertThat(constraints.get(0).schema().getPropertyId()).isEqualTo(prop);
}
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class ParallelNodeCursorTransactionStateTestBase method createNodes.
private MutableLongSet createNodes(int size) throws TransactionFailureException, InvalidTransactionTypeKernelException {
MutableLongSet nodes = LongSets.mutable.empty();
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
for (int i = 0; i < size; i++) {
nodes.add(write.nodeCreate());
}
tx.commit();
}
return nodes;
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class ParallelNodeLabelScanTestBase method createTestGraph.
@Override
public void createTestGraph(GraphDatabaseService graphDb) {
MutableLongSet fooNodes = LongSets.mutable.empty();
MutableLongSet barNodes = LongSets.mutable.empty();
try (KernelTransaction tx = beginTransaction()) {
TokenWrite tokenWrite = tx.tokenWrite();
FOO_LABEL = tokenWrite.labelGetOrCreateForName("foo");
BAR_LABEL = tokenWrite.labelGetOrCreateForName("bar");
Write write = tx.dataWrite();
for (int i = 0; i < NUMBER_OF_NODES; i++) {
long node = write.nodeCreate();
if (i % 2 == 0) {
write.nodeAddLabel(node, FOO_LABEL);
fooNodes.add(node);
} else {
write.nodeAddLabel(node, BAR_LABEL);
barNodes.add(node);
}
}
FOO_NODES = fooNodes;
BAR_NODES = barNodes;
tx.commit();
} catch (KernelException e) {
throw new AssertionError(e);
}
}
use of org.neo4j.kernel.api.KernelTransaction in project neo4j by neo4j.
the class ParallelNodeLabelScanTransactionStateTestBase method scanShouldSeeAddedNodes.
@Test
void scanShouldSeeAddedNodes() throws Exception {
int size = 64;
int label = label("L");
MutableLongSet existing = LongSets.mutable.withAll(createNodesWithLabel(label, size));
try (KernelTransaction tx = beginTransaction()) {
MutableLongSet added = LongSets.mutable.withAll(createNodesWithLabel(tx.dataWrite(), label, size));
try (NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
Scan<NodeLabelIndexCursor> scan = tx.dataRead().nodeLabelScan(label);
Set<Long> seen = new HashSet<>();
while (scan.reserveBatch(cursor, 64)) {
while (cursor.next()) {
long nodeId = cursor.nodeReference();
assertTrue(seen.add(nodeId), format("%d was seen multiple times", nodeId));
assertTrue(existing.remove(nodeId) || added.remove(nodeId));
}
}
// make sure we have seen all nodes
assertTrue(existing.isEmpty());
assertTrue(added.isEmpty());
}
}
}
Aggregations