use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.
the class IndexingAcceptanceTest method shouldSupportIndexSeekByPrefix.
@Test
public void shouldSupportIndexSeekByPrefix() throws SchemaRuleNotFoundException, IndexNotFoundKernelException, IndexNotApplicableKernelException {
// GIVEN
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
IndexDefinition index = Neo4jMatchers.createIndex(db, LABEL1, "name");
createNodes(db, LABEL1, "name", "Mattias", "Mats", "Carla");
PrimitiveLongSet expected = createNodes(db, LABEL1, "name", "Karl", "Karlsson");
// WHEN
PrimitiveLongSet found = Primitive.longSet();
try (Transaction tx = db.beginTx()) {
Statement statement = getStatement((GraphDatabaseAPI) db);
ReadOperations ops = statement.readOperations();
NewIndexDescriptor descriptor = indexDescriptor(ops, index);
int propertyKeyId = descriptor.schema().getPropertyId();
found.addAll(ops.indexQuery(descriptor, stringPrefix(propertyKeyId, "Karl")));
}
// THEN
assertThat(found, equalTo(expected));
}
use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.
the class IndexingAcceptanceTest method shouldNotIncludeNodesDeletedInSameTxInIndexSeekByPrefix.
@Test
public void shouldNotIncludeNodesDeletedInSameTxInIndexSeekByPrefix() throws SchemaRuleNotFoundException, IndexNotFoundKernelException, IndexNotApplicableKernelException {
// GIVEN
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
IndexDefinition index = Neo4jMatchers.createIndex(db, LABEL1, "name");
createNodes(db, LABEL1, "name", "Mattias");
PrimitiveLongSet toDelete = createNodes(db, LABEL1, "name", "Karlsson", "Mats");
PrimitiveLongSet expected = createNodes(db, LABEL1, "name", "Karl");
// WHEN
PrimitiveLongSet found = Primitive.longSet();
try (Transaction tx = db.beginTx()) {
PrimitiveLongIterator deleting = toDelete.iterator();
while (deleting.hasNext()) {
long id = deleting.next();
db.getNodeById(id).delete();
expected.remove(id);
}
Statement statement = getStatement((GraphDatabaseAPI) db);
ReadOperations readOperations = statement.readOperations();
NewIndexDescriptor descriptor = indexDescriptor(readOperations, index);
int propertyKeyId = descriptor.schema().getPropertyId();
found.addAll(readOperations.indexQuery(descriptor, stringPrefix(propertyKeyId, "Karl")));
}
// THEN
assertThat(found, equalTo(expected));
}
use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.
the class InconsistencyReportReaderTest method shouldReadBasicEntities.
@Test
public void shouldReadBasicEntities() throws Exception {
// GIVEN
ByteArrayOutputStream out = new ByteArrayOutputStream(1_000);
FormattedLog log = FormattedLog.toOutputStream(out);
InconsistencyMessageLogger logger = new InconsistencyMessageLogger(log);
long nodeId = 5;
long relationshipGroupId = 10;
long relationshipId = 15;
long propertyId = 20;
logger.error(RecordType.NODE, new NodeRecord(nodeId), "Some error", "something");
logger.error(RecordType.RELATIONSHIP, new RelationshipRecord(relationshipId), "Some error", "something");
logger.error(RecordType.RELATIONSHIP_GROUP, new RelationshipGroupRecord(relationshipGroupId), "Some error", "something");
logger.error(RecordType.PROPERTY, new PropertyRecord(propertyId), "Some error", "something");
String text = out.toString();
PrimitiveLongSet nodes = Primitive.longSet();
PrimitiveLongSet relationships = Primitive.longSet();
PrimitiveLongSet relationshipGroups = Primitive.longSet();
PrimitiveLongSet properties = Primitive.longSet();
// WHEN
InconsistencyReportReader reader = new InconsistencyReportReader(new Inconsistencies() {
@Override
public void relationshipGroup(long id) {
relationshipGroups.add(id);
}
@Override
public void relationship(long id) {
relationships.add(id);
}
@Override
public void property(long id) {
properties.add(id);
}
@Override
public void node(long id) {
nodes.add(id);
}
});
reader.read(new StringReader(text));
// THEN
assertEquals(asSet(iterator(nodeId)), nodes);
assertEquals(asSet(iterator(relationshipId)), relationships);
assertEquals(asSet(iterator(relationshipGroupId)), relationshipGroups);
assertEquals(asSet(iterator(propertyId)), properties);
}
use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.
the class PrimitiveLongSetTest method shouldContainAddedValues_generated_1.
@Test
public void shouldContainAddedValues_generated_1() throws Exception {
// GIVEN
PrimitiveLongSet set = newSet(15);
Set<Long> expectedValues = new HashSet<>();
long[] valuesToAdd = new long[] { 1207043189, 380713862, 1902858197, 1996873101, 1357024628, 1044248801, 1558157493, 2040311008, 2017660098, 1332670047, 663662790, 2063747422, 1554358949, 1761477445, 1141526838, 1698679618, 1279767067, 508574, 2071755904 };
for (long key : valuesToAdd) {
set.add(key);
expectedValues.add(key);
}
// WHEN/THEN
boolean existedBefore = set.contains(679990875);
boolean added = set.add(679990875);
boolean existsAfter = set.contains(679990875);
assertFalse("679990875 should not exist before adding here", existedBefore);
assertTrue("679990875 should be reported as added here", added);
assertTrue("679990875 should exist", existsAfter);
expectedValues.add(679990875L);
final Set<Long> visitedKeys = new HashSet<>();
set.visitKeys(new PrimitiveLongVisitor() {
@Override
public boolean visited(long value) {
assertTrue(visitedKeys.add(value));
return false;
}
});
assertEquals(expectedValues, visitedKeys);
}
use of org.neo4j.collection.primitive.PrimitiveLongSet in project neo4j by neo4j.
the class PrimitiveLongSetTest method shouldHandleEmptySet.
@Test
public void shouldHandleEmptySet() throws Exception {
// GIVEN
PrimitiveLongSet set = Primitive.longSet(0);
// THEN
assertFalse(set.contains(564));
}
Aggregations