use of org.neo4j.internal.recordstorage.RelationshipLockHelper.SortedLockList in project neo4j by neo4j.
the class RelationshipLockHelperTest method canTraverseUniques.
@Test
void canTraverseUniques() {
// Given
SortedLockList sortedListIterator = new SortedLockList(0);
MutableSortedSet<Long> uniques = SortedSets.mutable.of();
for (long i = 0; i < 100; i++) {
for (int j = 0; j < random.nextInt(5); j++) {
sortedListIterator.add(i);
uniques.add(i);
}
}
// Then
uniques.forEach(unique -> {
assertThat(sortedListIterator.nextUnique()).isTrue();
assertThat(sortedListIterator.currentHighestLockedId()).isEqualTo(unique);
});
assertThat(sortedListIterator.nextUnique()).isFalse();
// Then
SortedSets.immutable.ofAll(Collections.reverseOrder(), uniques).forEach(unique -> {
assertThat(sortedListIterator.prevUnique()).isTrue();
assertThat(sortedListIterator.currentHighestLockedId()).isEqualTo(unique);
});
assertThat(sortedListIterator.prevUnique()).isFalse();
}
use of org.neo4j.internal.recordstorage.RelationshipLockHelper.SortedLockList in project neo4j by neo4j.
the class RelationshipLockHelperTest method canIterateWhileAddingAndRemoving.
@Test
void canIterateWhileAddingAndRemoving() {
MutableLongList shuffle = LongLists.mutable.empty();
SortedLockList sortedListIterator = new SortedLockList(0);
int maxValue = 1000;
for (int i = 0; i < 1000; i++) {
int value = random.nextInt(maxValue);
sortedListIterator.add(value);
shuffle.add(value);
assertThat(sortedListIterator.underlyingList().toArray()).isSorted();
}
while (sortedListIterator.next()) {
long value = sortedListIterator.currentHighestLockedId();
long toAdd = random.nextInt(maxValue);
sortedListIterator.add(toAdd);
assertThat(value).isEqualTo(sortedListIterator.currentHighestLockedId());
if (shuffle.notEmpty()) {
long toRemove = shuffle.removeAtIndex(shuffle.size() - 1);
if (toRemove != value) {
sortedListIterator.remove(toRemove);
}
assertThat(value).isEqualTo(sortedListIterator.currentHighestLockedId());
}
if (random.nextInt(10) == 0) {
int backoff = random.nextInt(5);
while (sortedListIterator.prev() && backoff-- > 0) {
// do nothing
}
}
}
}
use of org.neo4j.internal.recordstorage.RelationshipLockHelper.SortedLockList in project neo4j by neo4j.
the class RelationshipLockHelperTest method shouldKeepListSorted.
@Test
void shouldKeepListSorted() {
MutableLongList shuffle = LongLists.mutable.empty();
int numIds = 1000;
SortedLockList sortedListIterator = new SortedLockList(random.nextInt(numIds));
for (int i = 0; i < numIds; i++) {
int value = random.nextInt(numIds);
sortedListIterator.add(value);
shuffle.add(value);
assertThat(sortedListIterator.underlyingList().toArray()).isSorted();
}
shuffle.shuffleThis();
shuffle.forEach(value -> {
sortedListIterator.remove(value);
assertThat(sortedListIterator.underlyingList().toArray()).isSorted();
});
assertThat(sortedListIterator.underlyingList().toArray()).isEmpty();
}
Aggregations